forum.alglib.net http://forum.alglib.net/ |
|
Why does alglib::rmatrixcopy transpose a before copying? http://forum.alglib.net/viewtopic.php?f=2&t=4609 |
Page 1 of 1 |
Author: | dvblackham [ Wed Jun 26, 2024 11:47 pm ] |
Post subject: | Why does alglib::rmatrixcopy transpose a before copying? |
I need a function to copy a matrix/submatrix a into matrix/submatrix b without transposing a. I wrote the function below to address this, is there a more efficient way to do this? Out of curiosity, why does rmatrixcopy transpose a before copying? Thanks, Dave /************************************************************************* Copy Input parameters: M - number of rows N - number of columns A - source matrix, MxN submatrix is copied without transposing IA - submatrix offset (row index) JA - submatrix offset (column index) B - destination matrix, must be large enough to store result IB - submatrix offset (row index) JB - submatrix offset (column index) *************************************************************************/ static void algMatCopy(const alglib::ae_int_t m, const alglib:ae_int_t n, const alglib:real_2d_array &a, const alglib:ae_int_t ia, const alglib:ae_int_t ja, alglib:real_2d_array &b, const alglib:ae_int_t ib, const alglib:ae_int_t jb) { alglib::real_2d_array aT; aT.setlength(n,m); // because rmatrixcopy transposes a before copying to b. alglib::rmatrixcopy(m, n, a, ia, ja, aT, 0, 0); alglib::rmatrixcopy(m, n, aT, 0, 0, b, ib, jb); } |
Author: | Sergey.Bochkanov [ Thu Jun 27, 2024 1:34 pm ] |
Post subject: | Re: Why does alglib::rmatrixcopy transpose a before copying? |
Hi! It does not transpose the matrix! The comment says 'without transposing' because there is a similar functions which performs copy-and-transpose. So, there is no need to copy the matrix via temporary storage. Actually, the design reminds me of one old joke: 'our CPU implements multiplication via division by the inverse number'. |
Author: | dvblackham [ Wed Jul 03, 2024 4:23 pm ] |
Post subject: | Re: Why does alglib::rmatrixcopy transpose a before copying? |
Sergey, Thank you for your response. I am sorry for the confusion my initial post created. I included a function that I wrote to copy the matrix due to rmatrixcopy transposing the matrix, I simply created a similar header for the function I wrote that calls rmatrixcopy twice in order to deal with the transpose issue. Is there a function that copies without transposing? I couldn't find it. Thanks, Dave Here's a copy from the C++ manual for rmatrixcopy: /************************************************************************* Copy Input parameters: M - number of rows N - number of columns A - source matrix, MxN submatrix is copied and transposed IA - submatrix offset (row index) JA - submatrix offset (column index) B - destination matrix, must be large enough to store result IB - submatrix offset (row index) JB - submatrix offset (column index) *************************************************************************/ void rmatrixcopy(const ae_int_t m, const ae_int_t n, const real_2d_array &a, const ae_int_t ia, const ae_int_t ja, real_2d_array &b, const ae_int_t ib, const ae_int_t jb, const xparams _xparams = alglib::xdefault); |
Author: | Sergey.Bochkanov [ Thu Jul 04, 2024 8:39 am ] |
Post subject: | Re: Why does alglib::rmatrixcopy transpose a before copying? |
Hi! It is merely a mistake in the documentation, a copy-paste from rmatrixtranspose(). I will fix it in the next release. |
Author: | dvblackham [ Fri Jul 12, 2024 11:26 pm ] |
Post subject: | Re: Why does alglib::rmatrixcopy transpose a before copying? |
Thanks Sergey |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |