Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement classes for dealing with complex vectors and complex multidimensional arrays #5

Open
S-Dafarra opened this issue Sep 2, 2020 · 2 comments
Assignees

Comments

@S-Dafarra
Copy link
Member

No description provided.

@S-Dafarra
Copy link
Member Author

It would be nice to maintain interoperability with Eigen. Eigen uses std::complex as a type for complex arrays (https://eigen.tuxfamily.org/dox/classEigen_1_1ComplexEigenSolver.html#a3604c99a69fac3bee42c88cb2b589143), while matio has its own type: https://github.com/tbeu/matio/blob/master/src/matio.h#L164-L167.
Moreover, the data in the matvar_t is not stored as an array of a pair of numbers, but rather the real and imaginary parts are two separate vectors. Hence, I think we cannot have matioCpp::Vector<std::complex<double>> since we cannot cast the internal data to std::complex<double>* as it would be required by data().

An alternative might be to specialize all the code relative to Element, Vector, VectorIterator and MultiDimensionalArray just for complex types, but this would require reimplementing (and testing) basically half of the codebase.

Still investigating possible alternatives.

@S-Dafarra
Copy link
Member Author

I just spotted this from https://en.cppreference.com/w/cpp/numeric/complex:

In order to satisfy the requirements of array-oriented access, an implementation is constrained to store the real and imaginary components of a std::complex specialization in separate and adjacent memory locations. Possible declarations for its non-static data members include:

  • an array of type value_type[2], with the first element holding the real component and the second element holding the imaginary component (e.g. Microsoft Visual Studio)

Hence, I wonder if is possible to convert a mat_complex_split_t to a std::complex<T*>. In this case, the pointer type of Vector would be std::complex<T*>*. Nevertheless, I would still need some ad-hoc element accessors for retrieving a specific element or reference, and an ad-hoc iterator, but the code of Vector, Element and MultiDimensionalArray might remain the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant