asc-community / GenericTensor

The only library allowing to create Tensors (matrices extension) with custom types
https://angouri.org/#generictensor
MIT License
50 stars 5 forks source link

`Iterate` to return state machine object #36

Open WhiteBlackGoose opened 2 years ago

WhiteBlackGoose commented 2 years ago

It currently returns IEnumerable, which has a virtual call. We can make it much faster by writing a value type state machine (foreach does not force IEnumerable).

WhiteBlackGoose commented 2 years ago

For internal API there should be an indexing state machine which would work like this:

Span<int> id = stackalloc[shape.Length];
var indexMachine = new IndexIterator(id);
while (indexMachine.Move())
{
    myTensor[id] = myTensor[id];
}