forum.alglib.net

ALGLIB forum
It is currently Mon Dec 09, 2024 8:02 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Why does alglib::rmatrixcopy transpose a before copying?
PostPosted: Wed Jun 26, 2024 11:47 pm 
Offline

Joined: Wed Jun 26, 2024 11:37 pm
Posts: 5
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);
}


Top
 Profile  
 
 Post subject: Re: Why does alglib::rmatrixcopy transpose a before copying?
PostPosted: Thu Jun 27, 2024 1:34 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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'.


Top
 Profile  
 
 Post subject: Re: Why does alglib::rmatrixcopy transpose a before copying?
PostPosted: Wed Jul 03, 2024 4:23 pm 
Offline

Joined: Wed Jun 26, 2024 11:37 pm
Posts: 5
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);


Top
 Profile  
 
 Post subject: Re: Why does alglib::rmatrixcopy transpose a before copying?
PostPosted: Thu Jul 04, 2024 8:39 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
Hi! It is merely a mistake in the documentation, a copy-paste from rmatrixtranspose(). I will fix it in the next release.


Top
 Profile  
 
 Post subject: Re: Why does alglib::rmatrixcopy transpose a before copying?
PostPosted: Fri Jul 12, 2024 11:26 pm 
Offline

Joined: Wed Jun 26, 2024 11:37 pm
Posts: 5
Thanks Sergey


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group