# forum.alglib.net

ALGLIB forum
 It is currently Sat Jul 13, 2024 9:13 am

 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.

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Why does alglib::rmatrixcopy transpose a before copying?Posted: Wed Jun 26, 2024 11:47 pm

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

 Post subject: Re: Why does alglib::rmatrixcopy transpose a before copying?Posted: Thu Jun 27, 2024 1:34 pm

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

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

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

 Post subject: Re: Why does alglib::rmatrixcopy transpose a before copying?Posted: Thu Jul 04, 2024 8:39 am

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

Top

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

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

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 3 guests

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

Search for: