| Bill Allombert on Wed, 03 Apr 2013 22:21:27 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: slice of matrices |
On Tue, Apr 02, 2013 at 11:21:29AM -0400, jacques G wrote:
> 2. The problem with the proposed mixed types of slices is that one has to check
> the type before some operations.
I should clarify that the proposal never require to check the type of the
result, since it is defined syntactically:
M[a,...] will always be a t_VEC and
M[...,a] will always be a t_COL, the rest being always a t_MAT.
> 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]
If this matters, note that matsize() also work correctly on t_COL/t_VEC, so
using Mat(M) for thoses types is spurious.
You can rewrite sz as follow:
sz(M=[-3,0;2,0;0,0]) = { my([K, J] = matsize(M));
while( K>0 && !M[K,], K-- ); while( J>0 && !M[,J], J-- );
M[1..K,1..J] }
Cheers,
Bill.