jacques G on Tue, 02 Apr 2013 17:21:36 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

RE: slice of matrices


Two observations on this topic.

1. Someone should update the Wikipedia page to add PARI 
                http://en.wikipedia.org/wiki/Array_slicing
("Kenneth Iverson's APL (1957) had very flexible multi-dimensional array slicing, which contributed much to the 
language's expressive power and popularity.").

2. The problem with the proposed mixed types of slices is that one has to check 
the type before some operations. Not difficult, but clumsy. Here is an apllication,
dealing with (semi) infinite matrices represented by finite arrays of different 
sizes that need to be ADDED and reduced to NONZERO terms. 
Would slices work as inputs here, and simplify the code of "sz" ?

row(M) = matsize(Mat(M))[1]
col(M) = matsize(Mat(M))[2]

sa(M=[1;2],N=[3,4;5,6;7,8]) = { matrix( max(row(M),row(N)), max(col(M),col(N)), k,j,
		if( k<=row(M) && j<=col(M), Mat(M)[k,j] ) + if( k<=row(N) && j<=col(N), Mat(N)[k,j] ) ) }

sz(M=[-3,0;2,0;0,0]) = { local( K = row(M), J = col(M) );
		if( type(M) != "t_MAT", M = Mat(M) );
		while( K>0 && !M[K,], K-- ); while( J>0 && !M[,J], J-- );
		if(K==1, vector(J,j,M[1,j]), matrix(K,J, k,j, M[k,j] )) }


Jacques Gélinas