mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-19 10:37:12 +02:00
Added expression templates (#98)
- Works with NDArray - Works with NDView
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#include "aare/NDArray.hpp"
|
||||
#include <array>
|
||||
#include <catch2/benchmark/catch_benchmark.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
using aare::NDArray;
|
||||
@ -101,7 +102,8 @@ TEST_CASE("Elementwise multiplication of 3D image") {
|
||||
a(i) = i;
|
||||
b(i) = i;
|
||||
}
|
||||
auto c = a * b;
|
||||
// auto c = a * b; // This works but the result is a lazy ArrayMul object
|
||||
NDArray<double, 3> c = a * b;
|
||||
REQUIRE(c(0, 0, 0) == 0 * 0);
|
||||
REQUIRE(c(0, 0, 1) == 1 * 1);
|
||||
REQUIRE(c(0, 1, 1) == 3 * 3);
|
||||
@ -109,6 +111,39 @@ TEST_CASE("Elementwise multiplication of 3D image") {
|
||||
REQUIRE(c(2, 3, 1) == 23 * 23);
|
||||
}
|
||||
|
||||
NDArray<int> MultiplyNDArrayUsingOperator(NDArray<int> &a, NDArray<int> &b) {
|
||||
// return a * a * b * b;
|
||||
NDArray<int>c = a*b;
|
||||
return c;
|
||||
}
|
||||
|
||||
NDArray<int> MultiplyNDArrayUsingIndex(NDArray<int> &a, NDArray<int> &b) {
|
||||
NDArray<int> res(a.shape());
|
||||
for (uint32_t i = 0; i < a.size(); i++) {
|
||||
// res(i) = a(i) * a(i) * b(i) * b(i);
|
||||
res(i) = a(i) * b(i);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NDArray<int> AddNDArrayUsingOperator(NDArray<int> &a, NDArray<int> &b) {
|
||||
// return a * a * b * b;
|
||||
// NDArray<int>c = a+b;
|
||||
NDArray<int> c(a.shape());
|
||||
c = a + b;
|
||||
return c;
|
||||
}
|
||||
|
||||
NDArray<int> AddNDArrayUsingIndex(NDArray<int> &a, NDArray<int> &b) {
|
||||
NDArray<int> res(a.shape());
|
||||
for (uint32_t i = 0; i < a.size(); i++) {
|
||||
// res(i) = a(i) * a(i) * b(i) * b(i);
|
||||
res(i) = a(i) + b(i);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Compare two images") {
|
||||
NDArray<int> a;
|
||||
NDArray<int> b;
|
||||
@ -168,7 +203,6 @@ TEST_CASE("Bitwise and on data") {
|
||||
REQUIRE(a(2) == 384);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Elementwise operations on images") {
|
||||
std::array<int64_t, 2> shape{5, 5};
|
||||
double a_val = 3.0;
|
||||
@ -178,7 +212,8 @@ TEST_CASE("Elementwise operations on images") {
|
||||
NDArray<double> A(shape, a_val);
|
||||
NDArray<double> B(shape, b_val);
|
||||
|
||||
auto C = A + B;
|
||||
NDArray<double> C = A + B;
|
||||
// auto C = A+B; // This works but the result is a lazy ArraySum object
|
||||
|
||||
// Value of C matches
|
||||
for (uint32_t i = 0; i < C.size(); ++i) {
|
||||
@ -202,7 +237,8 @@ TEST_CASE("Elementwise operations on images") {
|
||||
SECTION("Subtract two images") {
|
||||
NDArray<double> A(shape, a_val);
|
||||
NDArray<double> B(shape, b_val);
|
||||
auto C = A - B;
|
||||
NDArray<double> C = A - B;
|
||||
// auto C = A - B; // This works but the result is a lazy ArraySub object
|
||||
|
||||
// Value of C matches
|
||||
for (uint32_t i = 0; i < C.size(); ++i) {
|
||||
@ -226,7 +262,8 @@ TEST_CASE("Elementwise operations on images") {
|
||||
SECTION("Multiply two images") {
|
||||
NDArray<double> A(shape, a_val);
|
||||
NDArray<double> B(shape, b_val);
|
||||
auto C = A * B;
|
||||
// auto C = A * B; // This works but the result is a lazy ArrayMul object
|
||||
NDArray<double> C = A * B;
|
||||
|
||||
// Value of C matches
|
||||
for (uint32_t i = 0; i < C.size(); ++i) {
|
||||
@ -250,7 +287,8 @@ TEST_CASE("Elementwise operations on images") {
|
||||
SECTION("Divide two images") {
|
||||
NDArray<double> A(shape, a_val);
|
||||
NDArray<double> B(shape, b_val);
|
||||
auto C = A / B;
|
||||
// auto C = A / B; // This works but the result is a lazy ArrayDiv object
|
||||
NDArray<double> C = A / B;
|
||||
|
||||
// Value of C matches
|
||||
for (uint32_t i = 0; i < C.size(); ++i) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
using aare::Dtype;
|
||||
using aare::NumpyFile;
|
||||
TEST_CASE("Read a 1D numpy file with int32 data type") {
|
||||
TEST_CASE("Read a 1D numpy file with int32 data type", "[.integration]") {
|
||||
|
||||
auto fpath = test_data_path() / "numpy" / "test_1d_int32.npy";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
@ -23,8 +23,8 @@ TEST_CASE("Read a 1D numpy file with int32 data type") {
|
||||
REQUIRE(data(i) == i);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Read a 3D numpy file with np.double data type") {
|
||||
|
||||
TEST_CASE("Read a 3D numpy file with np.double data type", "[.integration]") {
|
||||
|
||||
auto fpath = test_data_path() / "numpy" / "test_3d_double.npy";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
using aare::File;
|
||||
|
||||
TEST_CASE("Read number of frames from a jungfrau raw file") {
|
||||
TEST_CASE("Read number of frames from a jungfrau raw file", "[.integration]") {
|
||||
|
||||
auto fpath = test_data_path() / "jungfrau" / "jungfrau_single_master_0.json";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
@ -16,7 +16,7 @@ TEST_CASE("Read number of frames from a jungfrau raw file") {
|
||||
REQUIRE(f.total_frames() == 10);
|
||||
}
|
||||
|
||||
TEST_CASE("Read frame numbers from a jungfrau raw file") {
|
||||
TEST_CASE("Read frame numbers from a jungfrau raw file", "[.integration]") {
|
||||
auto fpath = test_data_path() / "jungfrau" / "jungfrau_single_master_0.json";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
||||
@ -32,7 +32,7 @@ TEST_CASE("Read frame numbers from a jungfrau raw file") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Read a frame number too high throws") {
|
||||
TEST_CASE("Read a frame number too high throws", "[.integration]") {
|
||||
auto fpath = test_data_path() / "jungfrau" / "jungfrau_single_master_0.json";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
||||
@ -46,7 +46,7 @@ TEST_CASE("Read a frame number too high throws") {
|
||||
REQUIRE_THROWS(f.frame_number(10));
|
||||
}
|
||||
|
||||
TEST_CASE("Read a frame numbers where the subfile is missing throws") {
|
||||
TEST_CASE("Read a frame numbers where the subfile is missing throws", "[.integration]") {
|
||||
auto fpath = test_data_path() / "jungfrau" / "jungfrau_missing_subfile_master_0.json";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
||||
@ -67,7 +67,7 @@ TEST_CASE("Read a frame numbers where the subfile is missing throws") {
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Read data from a jungfrau 500k single port raw file") {
|
||||
TEST_CASE("Read data from a jungfrau 500k single port raw file", "[.integration]") {
|
||||
auto fpath = test_data_path() / "jungfrau" / "jungfrau_single_master_0.json";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
||||
@ -83,7 +83,7 @@ TEST_CASE("Read data from a jungfrau 500k single port raw file") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Read frame numbers from a raw file") {
|
||||
TEST_CASE("Read frame numbers from a raw file", "[.integration]") {
|
||||
auto fpath = test_data_path() / "eiger" / "eiger_500k_16bit_master_0.json";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
||||
@ -96,7 +96,7 @@ TEST_CASE("Read frame numbers from a raw file") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Compare reading from a numpy file with a raw file") {
|
||||
TEST_CASE("Compare reading from a numpy file with a raw file", "[.integration]") {
|
||||
auto fpath_raw = test_data_path() / "jungfrau" / "jungfrau_single_master_0.json";
|
||||
REQUIRE(std::filesystem::exists(fpath_raw));
|
||||
|
||||
@ -116,7 +116,7 @@ TEST_CASE("Compare reading from a numpy file with a raw file") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Read multipart files") {
|
||||
TEST_CASE("Read multipart files", "[.integration]") {
|
||||
auto fpath = test_data_path() / "jungfrau" / "jungfrau_double_master_0.json";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
||||
@ -141,7 +141,7 @@ TEST_CASE("Read multipart files") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Read file with unordered frames") {
|
||||
TEST_CASE("Read file with unordered frames", "[.integration]") {
|
||||
//TODO! Better explanation and error message
|
||||
auto fpath = test_data_path() / "mythen" / "scan242_master_3.raw";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
@ -58,7 +58,7 @@ TEST_CASE("A disabled scan"){
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Parse a master file in .json format"){
|
||||
TEST_CASE("Parse a master file in .json format", "[.integration]"){
|
||||
auto fpath = test_data_path() / "jungfrau" / "jungfrau_single_master_0.json";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
RawMasterFile f(fpath);
|
||||
@ -139,7 +139,7 @@ TEST_CASE("Parse a master file in .json format"){
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Parse a master file in .raw format"){
|
||||
TEST_CASE("Parse a master file in .raw format", "[.integration]"){
|
||||
|
||||
auto fpath = test_data_path() / "moench/moench04_noise_200V_sto_both_100us_no_light_thresh_900_master_0.raw";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
@ -204,7 +204,7 @@ TEST_CASE("Parse a master file in .raw format"){
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Read eiger master file"){
|
||||
TEST_CASE("Read eiger master file", "[.integration]"){
|
||||
auto fpath = test_data_path() / "eiger" / "eiger_500k_32bit_master_0.json";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
RawMasterFile f(fpath);
|
||||
|
Reference in New Issue
Block a user