Discussion:
[eigen] feature request: implement hybrid matrix class template
Vincent Hui
2018-01-01 09:27:00 UTC
Permalink
Hi,

Happy new year, In 2018, can hybrid matrix class template
<https://bitbucket.org/blaze-lib/blaze/wiki/Matrix%20Types#!hybridmatrix>
be implemented in Eigen? Hybrid matrix class template combines the
flexibility of a dynamically sized matrix with the efficiency and
performance of a fixed size matrix.

Thanks,
Vincent
Adrien Escande
2018-01-01 10:39:21 UTC
Permalink
Hi Vincent,

Happy new year as well.
This feature is already implemented through the two last optional template
parameters of the Matrix class (see
http://eigen.tuxfamily.org/dox/group__TutorialMatrixClass.html).
If you want a matrix M with maximum size (6,4) for example, you can write
Matrix<double, Dynamic, Dynamic, 0, 6, 4> M; // 0 specifies a
column-major storage

Cheers,
Adrien
Post by Vincent Hui
Hi,
Happy new year, In 2018, can hybrid matrix class template
<https://bitbucket.org/blaze-lib/blaze/wiki/Matrix%20Types#!hybridmatrix>
be implemented in Eigen? Hybrid matrix class template combines the
flexibility of a dynamically sized matrix with the efficiency and
performance of a fixed size matrix.
Thanks,
Vincent
Andre Krause
2018-01-01 10:47:34 UTC
Permalink
But is that stack allocated , like the blaze hybrid matrix ?
Post by Adrien Escande
Hi Vincent,
Happy new year as well.
This feature is already implemented through the two last optional template
parameters of the Matrix class (see
http://eigen.tuxfamily.org/dox/group__TutorialMatrixClass.html).
If you want a matrix M with maximum size (6,4) for example, you can write
Matrix<double, Dynamic, Dynamic, 0, 6, 4> M; // 0 specifies a
column-major storage
Cheers,
Adrien
Post by Vincent Hui
Hi,
Happy new year, In 2018, can hybrid matrix class template
<https://bitbucket.org/blaze-lib/blaze/wiki/Matrix%20Types#!hybridmatrix>
Post by Vincent Hui
be implemented in Eigen? Hybrid matrix class template combines the
flexibility of a dynamically sized matrix with the efficiency and
performance of a fixed size matrix.
Thanks,
Vincent
--
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.
Adrien Escande
2018-01-01 11:23:37 UTC
Permalink
Yes, this allocates a static buffer for the matrix.

Adrien
Post by Andre Krause
But is that stack allocated , like the blaze hybrid matrix ?
Am 1. Januar 2018 11:39:21 MEZ schrieb Adrien Escande <
Post by Adrien Escande
Hi Vincent,
Happy new year as well.
This feature is already implemented through the two last optional
template parameters of the Matrix class (see http://eigen.tuxfamily.org/
dox/group__TutorialMatrixClass.html).
If you want a matrix M with maximum size (6,4) for example, you can write
Matrix<double, Dynamic, Dynamic, 0, 6, 4> M; // 0 specifies a
column-major storage
Cheers,
Adrien
Post by Vincent Hui
Hi,
Happy new year, In 2018, can hybrid matrix class template
<https://bitbucket.org/blaze-lib/blaze/wiki/Matrix%20Types#!hybridmatrix>
be implemented in Eigen? Hybrid matrix class template combines the
flexibility of a dynamically sized matrix with the efficiency and
performance of a fixed size matrix.
Thanks,
Vincent
--
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.
Vincent Hui
2018-01-01 11:08:55 UTC
Permalink
Hi Adrien,

Thanks for your quick reply and great help. I am not aware two last
optional template parameters. Perhaps it is useful to typedef a type for
two last optional template parameters to let user use optional parameters
easily. e.g. HybridMatrix

// Definition of a 3x4 integral row-major matrix with maximum dimensions of
6x8
HybridMatrix<int,6UL,8UL> A( 3UL, 4UL );

Thanks,
Vincent
Post by Adrien Escande
Hi Vincent,
Happy new year as well.
This feature is already implemented through the two last optional template
parameters of the Matrix class (see http://eigen.tuxfamily.org/dox/group__
TutorialMatrixClass.html).
If you want a matrix M with maximum size (6,4) for example, you can write
Matrix<double, Dynamic, Dynamic, 0, 6, 4> M; // 0 specifies a
column-major storage
Cheers,
Adrien
Post by Vincent Hui
Hi,
Happy new year, In 2018, can hybrid matrix class template
<https://bitbucket.org/blaze-lib/blaze/wiki/Matrix%20Types#!hybridmatrix>
be implemented in Eigen? Hybrid matrix class template combines the
flexibility of a dynamically sized matrix with the efficiency and
performance of a fixed size matrix.
Thanks,
Vincent
Andre Krause
2018-01-02 12:35:28 UTC
Permalink
or maybe a different term called "Dynamic_on_stack" to make it clearer ?

without reading the docs, it is not clear that

Matrix<double, Dynamic, Dynamic, 0, 6, 4> M;

is a stack-allocated matrix.
Post by Vincent Hui
Hi Adrien,
Thanks for your quick reply and great help. I am not aware two last
optional template parameters. Perhaps it is useful to typedef a type for
two last optional template parameters to let user use optional
parameters easily. e.g. HybridMatrix
// Definition of a 3x4 integral row-major matrix with maximum dimensions
of 6x8
HybridMatrix<int,6UL,8UL> A( 3UL, 4UL );
Thanks,
Vincent
Hi Vincent,
Happy new year as well.
This feature is already implemented through the two last optional
template parameters of the Matrix class (see
http://eigen.tuxfamily.org/dox/group__TutorialMatrixClass.html
<http://eigen.tuxfamily.org/dox/group__TutorialMatrixClass.html>).
If you want a matrix M with maximum size (6,4) for example, you can write
Matrix<double, Dynamic, Dynamic, 0, 6, 4> M;    // 0 specifies a
column-major storage
Cheers,
Adrien
Hi,
Happy new year, In 2018, can hybrid matrix class template
<https://bitbucket.org/blaze-lib/blaze/wiki/Matrix%20Types#%21hybridmatrix>
be implemented in Eigen? Hybrid matrix class template combines
the flexibility of a dynamically sized matrix with the
efficiency and performance of a fixed size matrix.
Thanks,
Vincent
Vincent Hui
2018-01-02 12:59:49 UTC
Permalink
Hi Andre,

What I understand from what Adrien said is that two last optional template
parameters can make Matrix a static buffer on stack. I think Hybrid Matrix
is better name because it means fix size on stack and dynamic matrix size.

Thanks,
Vincent
Post by Andre Krause
or maybe a different term called "Dynamic_on_stack" to make it clearer ?
without reading the docs, it is not clear that
Matrix<double, Dynamic, Dynamic, 0, 6, 4> M;
is a stack-allocated matrix.
Post by Vincent Hui
Hi Adrien,
Thanks for your quick reply and great help. I am not aware two last
optional template parameters. Perhaps it is useful to typedef a type for
two last optional template parameters to let user use optional
parameters easily. e.g. HybridMatrix
// Definition of a 3x4 integral row-major matrix with maximum dimensions
of 6x8
HybridMatrix<int,6UL,8UL> A( 3UL, 4UL );
Thanks,
Vincent
Hi Vincent,
Happy new year as well.
This feature is already implemented through the two last optional
template parameters of the Matrix class (see
http://eigen.tuxfamily.org/dox/group__TutorialMatrixClass.html
<http://eigen.tuxfamily.org/dox/group__TutorialMatrixClass.html>).
If you want a matrix M with maximum size (6,4) for example, you can write
Matrix<double, Dynamic, Dynamic, 0, 6, 4> M; // 0 specifies a
column-major storage
Cheers,
Adrien
Hi,
Happy new year, In 2018, can hybrid matrix class template
<https://bitbucket.org/blaze-lib/blaze/wiki/Matrix%20Types#
%21hybridmatrix>
Post by Vincent Hui
be implemented in Eigen? Hybrid matrix class template combines
the flexibility of a dynamically sized matrix with the
efficiency and performance of a fixed size matrix.
Thanks,
Vincent
Marc Glisse
2018-01-02 13:18:32 UTC
Permalink
Post by Vincent Hui
What I understand from what Adrien said is that two last optional template
parameters can make Matrix a static buffer on stack. I think Hybrid Matrix
is better name because it means fix size on stack and dynamic matrix size.
It seems to me that those typedefs, as well as comments explaining the
user's choices, belong in the user's code.

// Float matrix with 3 columns and at most R rows, no dynamic allocation.
template<size_t R>
using MyHybridMatrixf3 = Matrix<float, Dynamic, 3, RowMajor, R>;

Eigen does provide a few "convenience" typedefs like Vector3d, but this
dynamic on-stack matrix is not as general and different users may not want
exactly the same thing.
--
Marc Glisse
Adrien Escande
2018-01-02 14:56:25 UTC
Permalink
Hi Vincent, Andre,
I think Hybrid Matrix is better name because it means fix size on stack
and dynamic matrix size.
Names are quite subjective. Presumably you are used to blaze terminology
where static and dynamic matrix are implemented in distinct classes, so
that the term hybrid makes sense. Before this conversation, I would have
been clueless as to what a HybridMatrix could be.
Anyway, if you are using c++11 or later, you can declare the following, *in
the Eigen namespace*:

*template<typename Scalar, int r, int c>using HybridMatrix = Matrix<Scalar,
Dynamic, Dynamic, 0, r, c>;*

and use HybridMatrix the same way as in blaze:
*HybridMatrix<int, 6, 8> A(3,4);*

You can even declare the following to get as close as possible to the blaze
object

*template<typename Type, int M, int N, int SO = RowMajor>using HybridMatrix
= Matrix<Type, Dynamic, Dynamic, SO, M, N>;*
however there are not so many cases where the storage order matters, and I
would make the (educated?) guess that Eigen is better optimized for
column-major matrices.
or maybe a different term called "Dynamic_on_stack" to make it clearer ?
I can't speak for the devs, but the Eigen philosophy seems to be that all
dense matrices are (specialized) instances of the Matrix class,
irrespective of the storage scheme, to avoid burdening casual users with
the distinction between static and dynamic storage. The distinction between
fix- and dynamic-size matrices is easy enough to grasp and use. As for the
"hybrid" case, it is more meant for power users, and for very specific
cases where the upper bounds on the number of rows and column can be known
at compile time and are small enough (be careful that Eigen defines a limit
on the size of a buffer allocated on the stack - 128kb by default - with
EIGEN_STACK_ALLOCATION_LIMIT). I do agree that *Matrix<double, Dynamic,
Dynamic, 0, 6, 4>* is not very clear but I would argue that the power user
writing that should use aliases with application-meaningful names.

Best regards,
Adrien
Loading...