matrix_type
strangulation strategy
#2335
pinkwah
started this conversation in
Libres Payback
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
matrix_type
to EigenEigen is a C++ linear algebra package that allows us to write readable maths that is compiled into fairly efficient executable code.
At the moment, we use a home-grown solution called
matrix_type
. This provides some basic arithmetic and some slightly more advanced functionality via the BLAS and LAPACK libraries.matrix_type
's memory layout is similar to that of Eigen dense matrices (and probably all other dense matrix implementations in the known universe).While there are a lot of similarities between the two APIs, having
matrix_type
be backed by anEigen::MatrixXd
(arbitrary dimension dense matrix of typedouble
), it would require a single PR that replaces the entirety of the 2000+ line implementation that we have today, while providing little benefit. Most of Eigen's magic comes from its use of temporary objects. Eg, in Eigen,matrix.transpose()
returns a typeEigen::Transpose<MatrixType>
which is an ephemeral (prvalue in C++ terminology) and can be used together with other expressions to force the compiler to optimise the code properly. Becausematrix_type
's API works on wholematrix_type
s, no such optimisations can take place in user code.Since
Eigen::MatrixXd
types have a very similar layout tomatrix_type
today, another strangulation strategy would be to replacematrix_type
's internals with a singleEigen::MatrixXd
object and have some logic to have amatrix_type
-like view into the Eigen object. Functions that haven't been ported yet may rely on this compatibility view to perform their job as before. However, manipulating an object whose code-base we don't own would make us prone to errors.The approach that I think is the most defensible is creating a new class
ert::MatrixXd
which will be a subset ofEigen::MatrixXd
's API, but be a thin wrapper aroundmatrix_type
. This will allow us to start iteratively implementing an Eigen-like API. The hope is that at some point in the future we'll simply be able tos/ert::MatrixXd/Eigen::MatrixXd/
and remove the legacy code.Actionable steps
ert::MatrixXd
with a nicer initialising ctor, arithmetic operators and astd::unique_ptr
-like object management API (ie:.get() -> matrix_type*
,.release() -> matrix_type*
,.reset(matrix_type*)
)Beta Was this translation helpful? Give feedback.
All reactions