You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This can even be extended to higher types of "tensors", and combined with the [idx] syntax to do additional interesting things. E.g. extract a column (but as a "row vector"):
The drawback of mat{idx1}{idx2} is that that it works by first extracting the rows of mat corresponding to idx1, and then from each row extracts the entries with indices in idx2. This is sensible and fine if all matrices are "lists of row vectors". But for matrix objects which e.g. store their entries "flat", using this syntax is either not possible, or requires using relatively expensive "proxy row objects".
For access of single entries, we already introduced the syntax m[i,j] as alternative to m[i][j]. I suggest we do something quite similar for the {...} syntax:
For some years now, GAP also supported passing arbitrary elements as "index" to \[\] methods. Initially we used this for a[[i,j]] as a simple alternative to a[i,j]. However, I don't think much code ever used this.
We could therefore use this feature to implement the above feature with [] instead of {}. Indeed, it just requires a few methods to work for basic lists-of-lists
So this is much simpler to do. However, I am concerned that it might cause problems for people who are e.g. still using the mat[[i,j]] trick.
Th
Implementation
For the mat[idxlist1, idxlist2] variant, I already sketched a basic pure GAP implementation above; of course one would want to install specialized methods for e.g. compressed matrices later on (but that same also holds for the mat{idxlist1, idxlist2} variant).
For the mat{idxlist1, idxlist2} variant, I could sketch how this could be implemented with not that much work required. However, let's first settle which variant we'd prefer, if any at all.
The text was updated successfully, but these errors were encountered:
fingolfin
changed the title
Syntax extension: allow mat{idxlist1, idxist2} as alternative for mat{idx1}{idx2} (OR allow `mat[idx1,
Syntax extension: allow mat{idxlist1, idxlist2} as alternative for mat{idx1}{idx2} (OR allow mat[idxlist1, idxlist2])
Mar 29, 2021
fingolfin
changed the title
Syntax extension: allow mat{idxlist1, idxlist2} as alternative for mat{idx1}{idx2} (OR allow mat[idxlist1, idxlist2])
Syntax extension: allow mat{idxlist1, idxlist2} as alternative for mat{idxlist1}{idxlist2} (OR allow mat[idxlist1, idxlist2])
Mar 29, 2021
I quite like this idea. Tbh I didn't know that this existed until now. I wouldn't use the alternative though as it would be more consistent to have curly brackets. I am curious though, why is is necessary to have list{[x,y]} instead of just list{x,y} why the additional brackets? For matrices this of course would make sense to distinguish row and column indices...
The proposal
In GAP, one can reference a sublist or "slice" of a list via the syntax
list{idx}
whereidx
is a list of indices. For example:This can also be nested to reference a submatrix:
This can even be extended to higher types of "tensors", and combined with the
[idx]
syntax to do additional interesting things. E.g. extract a column (but as a "row vector"):Note that while I only discuss extracting submatrices, of course everything also applies to the assignment counterpart:
The drawback of
mat{idx1}{idx2}
is that that it works by first extracting the rows ofmat
corresponding toidx1
, and then from each row extracts the entries with indices inidx2
. This is sensible and fine if all matrices are "lists of row vectors". But for matrix objects which e.g. store their entries "flat", using this syntax is either not possible, or requires using relatively expensive "proxy row objects".For access of single entries, we already introduced the syntax
m[i,j]
as alternative tom[i][j]
. I suggest we do something quite similar for the{...}
syntax:This could even be further extended to emulate
mat{idxlist}[idx]
andmat[idx]{idxlist}
, by allowing one ofidx1
andidx2
to beAlternatives
For some years now, GAP also supported passing arbitrary elements as "index" to
\[\]
methods. Initially we used this fora[[i,j]]
as a simple alternative toa[i,j]
. However, I don't think much code ever used this.We could therefore use this feature to implement the above feature with
[]
instead of{}
. Indeed, it just requires a few methods to work for basic lists-of-listsSo this is much simpler to do. However, I am concerned that it might cause problems for people who are e.g. still using the
mat[[i,j]]
trick.Th
Implementation
For the
mat[idxlist1, idxlist2]
variant, I already sketched a basic pure GAP implementation above; of course one would want to install specialized methods for e.g. compressed matrices later on (but that same also holds for themat{idxlist1, idxlist2}
variant).For the
mat{idxlist1, idxlist2}
variant, I could sketch how this could be implemented with not that much work required. However, let's first settle which variant we'd prefer, if any at all.The text was updated successfully, but these errors were encountered: