[GAP Forum] Matrix Operations and saving cpu cycles

Alexander Konovalov alexander.konovalov at gmail.com
Wed Apr 12 12:56:17 BST 2006


Dear Laurent,

thanks for your remark. Let me just add a few comments on it:

1) Dependently on the size of matrices and maybe other factors,
another implementation could be more CPU time saving. For
example, the following function swaps i-th and j-th row of a
matrix mat and returns the resulting matrix m:

Swap:=function(mat,i,j)
local  m, t;
m := ShallowCopy(mat);
t := m[i];
m[i] := m[j];
m[j] := t;
return m;
end;

gap> e := RandomMat(1000,1000);;
gap> for i in [1..10000] do x:=Permuted(e,(1,2)); od; time;
4534
gap> for i in [1..10000] do x:=Swap(e,1,2); od; time;
211

And you can save even more time, if you can use the destructive
counterpart of this Swap function, changing the argument mat:

SwapDestructive:=function(m,i,j)
local  t;
t := m[i];
m[i] := m[j];
m[j] := t;
end;

gap> for i in [1..10000] do SwapDestructive(e,1,2); od; time;
20


2) The function PermutedCols actually belongs to the GUAVA
package, see http://www.gap-system.org/Manuals/pkg/guava/htm/ 
chap7.html#s3ss8.

So the GUAVA package should be loaded first before calling PermutedCols


Best wishes,
Alexander


On 10 Apr 2006, at 18:24, Laurent Bartholdi wrote:

> Dear Alexander, Dear Forum,
>
>> GAP does not have standard functions to swap rows or columns,
>> but these operations can be easily described in GAP. Please
>> let me know if you need more help to implement them.
>
> In fact, GAP does have such commands -- even though they're not
> documented as such. See Permuted() and PermutedCols()
>
> --
> Laurent Bartholdi          \  laurent.bartholdi<at>gmail<dot>com
> EPFL SB SMA IMB MAD         \    Téléphone: +41 21-6935458
> Station 8                    \ Secrétaire: +41 21-6935501
> CH-1015 Lausanne, Switzerland \      Fax: +41 21-6930339




More information about the Forum mailing list