[eigen] Documenting functions which return an Matrix |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] Documenting functions which return an Matrix
- From: Dale Lukas Peterson <hazelnusse@xxxxxxxxx>
- Date: Wed, 13 Feb 2013 12:52:35 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=rkfRexs4w8wCYuOcfZtjJx4W3ZSLovHYAlMwLjtRwvg=; b=KRPbbHbwnGeLUztaVkSNMUlYPA3QDmpsAOTCQEj9PFbtDBUVtuYF8h64/j2Rn1pgpj XCFOUkHSWVCGSJifObPdUaBmAHeKQ9hRyFD2JNmh2AkABmcMrqF2CKKJ1R0sXTmciFVk V6ky9IBRXvU3a9+Us9fvWYBSaAEpKI19VAVr1ngDKmDLJDVX6jWid1oi7Lgk0hIpkIXD 5RmRrWoLao/gogUfy1KvT/G0JWv96fTcNdCFMTXz6wUkW+B3M85bAy3Sz9UMpZRRp6p6 83rvpEqy5qGFYTL6GnMGWB///awrZYKuqvu4tJwcjA7NKINGfI3l6HHWp0vZJ1lmLpRP hdig==
I have some functions which need to return Matrices of specific sizes
and I would like clients of the class to see at a glance what size
those matrices are. I have been doing things like:
Matrix<double, 3, 6, RowMajor> my_func();
then in client code:
a = my_func();
The reason I am declaring the function this way is primarily so users
who see it know what size matrix they are getting back. Is this the
preferred way to do this?
Some of my matrices are small (3x3), and some are bigger (20x20).
Inside of my_func(), I typically declare a matrix on the heap to do
the necessary calculations and populate the matrix, and then return
it. I am fine with all things being on the heap, but it would be nice
to know that I'm not copying things unnecessarily because of the way
I've declared the function.
I realize I can require clients to pass a const reference to a Matrix
of their choosing (Dynamic or Fixed) as a function parameter, rather
than using return, but the syntax of operator= is nicer and I don't
really want to give up that syntax.
1) How do people document their functions that return matrices of
known size, even if those matrices are allocated on the heap?
2) I see four cases that I'm not 100% clear on what happens when I do
something like a = my_func():
a) a is a dynamic sized Matrix and my_func returns a fixed size Matrix.
b) a is a dynamic sized Matrix and my_func returns a dynamic size Matrix.
c) a is a fixed sized Matrix and my_func returns a fixed size Matrix.
d) a is a fixed sized Matrix and my_func returns a dynamic size Matrix.
Can anybody clarify this for me and give me recommendations on how to
make it clear to users what the size of the matrices are without
shooting myself in the foot?
Thanks,
Luke