-
Notifications
You must be signed in to change notification settings - Fork 113
Selectors and Indexing
- Provide the ability to view indexed subsets of arrays and optionally modifying them (like MatLab)
- Convenient syntax
- Consistency with other core.matrix operations / functional style
General purpose indexing operations add some overhead are provided mainly for developer convenience. They should generally be implemented using fast lower-level core.matrix protocols, so that users of low level operations do not pay the cost of indexing features they are not using.
Some implementations, including Vectorz, provide a facility for lightweight views over subsets of arrays. These are very cheap to construct, and allow mutation of the original array via the view. Ideally, any new APIs would make use of this feature if possible.
Therefore, all the higher level functions should be protocol based with default implementations delegating to lower level protocols, wihch enables each implementation to do it the most efficient way.
See PR: https://github.com/mikera/core.matrix/pull/118
Several types may be useful for indexing along a given dimension:
- integer values
=>
slice to a specific value on the dimension (removes the dimension) - lists / vectors
=>
select the specific indexed values in the order given - sets
=>
select the specified elements in numerical order TODO: Not certain about sets, as order is important in selecting. Matlab example: A = [1,2;3,4] B = A([2,1],:) => B = [3,4;1,2] - functions
=>
call with (f array dim-number) to get a new indexing value -
:all
=>
selects the entire dimension (all indexes) TODO: Not sure about allowing the:all
special keyword as it can be easily replaced by anall
function selector. If:all
gets supported, it should be the only special case. Maybe:.
could be a good short keyword for this. or:*
- maps
=>
optional advanced indexing arguments? TODO: Example needed. - arbitrary core.matrix vector
=>
use the values in the vector for indexing (treat as a list)
Question: Do we need to reify first class selection objects?
This might be useful to separate the result of a selection from operations on selections - e.g. if the selection was going to be used to selectively update parts of multiple arrays.
How should the Setting of the selection be supported?
- Via methods
sel-set
andsel-set!
? - make it possible via
mset
andmset!
(not sure)?