Skip to content

Commit

Permalink
Detach Pupil from MATLAB
Browse files Browse the repository at this point in the history
  • Loading branch information
willGraham01 committed Jun 5, 2023
1 parent 2d7af8c commit bd713f8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 88 deletions.
12 changes: 5 additions & 7 deletions tdms/include/arrays/tdms_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ class Matrix {
* definition. */
typedef Matrix<double> CCoefficientMatrix;

/** TODO: Docstring */
struct GratingStructure : public Matrix<int> {
GratingStructure(const mxArray *ptr, int I_tot);
};

/**
* @brief Defines the numerical aperture of the objective, assuming that the
* lens is centred on the origin of the PSTD simulation.
Expand All @@ -105,8 +100,11 @@ struct GratingStructure : public Matrix<int> {
* Pupil(i, j) thus takes the value 1 for those (i,j) indices within the
* aperture of the lens.
*/
struct Pupil : public Matrix<double> {
void initialise_from_matlab(const mxArray *ptr, int n_rows, int n_cols);
typedef Matrix<double> Pupil;

/** TODO: Docstring */
struct GratingStructure : public Matrix<int> {
GratingStructure(const mxArray *ptr, int I_tot);
};

/**
Expand Down
18 changes: 0 additions & 18 deletions tdms/src/arrays/tdms_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,6 @@ GratingStructure::GratingStructure(const mxArray *ptr, int I_tot) {
free_cast_matlab_2D_array(matlab_buffer);
}

void Pupil::initialise_from_matlab(const mxArray *ptr, int n_rows, int n_cols) {

if (mxIsEmpty(ptr)) { return; }

auto dims = (int *) mxGetDimensions(ptr);

if (mxGetNumberOfDimensions(ptr) != 2 || dims[0] != n_rows ||
dims[1] != n_cols) {
throw runtime_error("Pupil has dimension " + to_string(dims[0]) + "x" +
to_string(dims[1]) + " but it needed to be " +
to_string(n_rows) + "x" + to_string(n_cols));
}

double **matlab_buffer = cast_matlab_2D_array(mxGetPr(ptr), n_rows, n_cols);
initialise(matlab_buffer, n_rows, n_cols, true);
free_cast_matlab_2D_array(matlab_buffer);
}

void Vertices::initialise_from_matlab(const mxArray *ptr) {

auto element = ptr_to_matrix_in(ptr, "vertices", "campssample");
Expand Down
3 changes: 1 addition & 2 deletions tdms/src/simulation_manager/objects_from_infile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ IndependentObjectsFromInfile::IndependentObjectsFromInfile(
// if exdetintegral is flagged, setup pupil, D_tilde, and f_vec accordingly
if (params.exdetintegral) {
INPUT_FILE.read(f_vec);
pupil.initialise_from_matlab(matrices_from_input_file["Pupil"],
f_vec.x.size(), f_vec.y.size());
INPUT_FILE.read("Pupil", pupil);
D_tilde.initialise(matrices_from_input_file["D_tilde"], f_vec.x.size(),
f_vec.y.size());

Expand Down
13 changes: 0 additions & 13 deletions tdms/tests/include/array_test_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,6 @@ class GratingStructureTest : public AbstractArrayTest {
std::string get_class_name() override { return "GratingStructure"; }
};

/** @brief Unit tests for Pupil */
class PupilTest : public AbstractArrayTest {
private:
const int n_rows = 4, n_cols = 8;

void test_empty_construction() override;
void test_wrong_input_dimensions() override;
void test_correct_construction() override;

public:
std::string get_class_name() override { return "Pupil"; }
};

/** @brief Unit tests for Tensor3D */
class Tensor3DTest : public AbstractArrayTest {
private:
Expand Down
49 changes: 1 addition & 48 deletions tdms/tests/unit/array_tests/test_Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file test_Matrix.cpp
* @author William Graham ([email protected])
* @brief Tests for the Matrix class and its subclasses (Vertices,
* GratingStructure, Pupil)
* GratingStructure)
*/
#include <catch2/catch_test_macros.hpp>
#include <spdlog/spdlog.h>
Expand Down Expand Up @@ -114,55 +114,8 @@ void GratingStructureTest::test_correct_construction() {
delete gs;
}

void PupilTest::test_empty_construction() {
Pupil p;
dimensions_2d[0] = 0;
dimensions_2d[1] = n_cols;
create_numeric_array(2, dimensions_2d);
// passing in an empty array to initialise() doesn't error, but also doesn't
// assign additionally, the rows and columns arguments aren't even used, so
// can be garbage
p.initialise_from_matlab(matlab_input, 1, 1);
REQUIRE(!p.has_elements());// shouldn't have assigned any memory or pointers
}

void PupilTest::test_wrong_input_dimensions() {
Pupil p;
SECTION("Wrong number of dimensions (3D)") {
dimensions_3d[0] = n_rows;
dimensions_3d[1] = n_cols;
dimensions_3d[2] = 2;
create_numeric_array(3, dimensions_3d);
REQUIRE_THROWS_AS(p.initialise_from_matlab(matlab_input, n_rows, n_cols),
std::runtime_error);
REQUIRE(!p.has_elements());
}
SECTION("Wrong dimension size") {
dimensions_2d[0] = 2 * n_rows;
dimensions_2d[1] = n_cols + 1;
create_numeric_array(2, dimensions_2d);
REQUIRE_THROWS_AS(p.initialise_from_matlab(matlab_input, n_rows, n_cols),
std::runtime_error);
REQUIRE(!p.has_elements());
}
}

void PupilTest::test_correct_construction() {
Pupil p;
SECTION("Default constructor") { REQUIRE(!p.has_elements()); }
SECTION("Overloaded constructor") {
dimensions_2d[0] = n_rows;
dimensions_2d[1] = n_cols;
create_numeric_array(2, dimensions_2d);
REQUIRE_NOTHROW(p.initialise_from_matlab(matlab_input, n_rows, n_cols));
REQUIRE(p.has_elements());
}
}

TEST_CASE("Matrix") { MatrixTest().run_all_class_tests(); }

TEST_CASE("Vertices") { VerticesTest().run_all_class_tests(); }

TEST_CASE("GratingStructure") { GratingStructureTest().run_all_class_tests(); }

TEST_CASE("Pupil") { PupilTest().run_all_class_tests(); }

0 comments on commit bd713f8

Please sign in to comment.