hermann on Mon, 18 Nov 2024 19:37:34 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Is there a function for sum of square matrix antidiagonal like "trace()" for main diagonal? |
On 2024-11-18 19:21, Bill Allombert wrote:
? atr2 (~M)->sum(i=1,#M,M[i,#M+1-i]) ? for(i=1,100000,atr2(~M)) cpu time = 615 ms, real time = 614 ms. ? op(~M)=trace(Mat(Vecrev(M))); ? for(i=1,100000,op(~M)) cpu time = 589 ms, real time = 591 ms.I would be very happy if that were true, but M=matrix(100,100,i,j,random(1000)); atr2(~M)=sum(i=1,#M,M[i,#M+1-i]); op(~M)=trace(Mat(Vecrev(M))); for(i=1,100000,atr2(~M)) *** last result computed in 1,201 ms. for(i=1,100000,op(~M)) *** last result computed in 11,051 ms. I assume your matrix is very small ?
Sorry, yes, it was a 15x15 Primes square matrix I wrote a validate.gp script for: https://www.mersenneforum.org/node/1055343?p=1061101#post1061101 Definitely trace(Mat(Vecrev(~M))) looks nicer, but should not be used for larger matrices. Regards, Hermann.