rainwoodman / vast

vala and scientific numerical computation
11 stars 1 forks source link

Optimized View and Optimized Iterator. #22

Open rainwoodman opened 7 years ago

rainwoodman commented 7 years ago

An Optimized View of an array shall have the as many as possible number of last axes trivially iterable.

OptimizedIterator will

for partially trivially iterable arrays, N can include a full step of the entire trivally iterable subspace.

arteymix commented 7 years ago

I thought about this and we should maybe design the current iterator to know the number of contiguous entry and skip chunks.

There's a ravel utility in NumPy which flattens an array into a contiguous 1D vector. If the Iterator class could know, looking at the strides, how many contiguous elements are coming and its memory layout, that would be great.

var iter = array.ravel ().iterator ();

int num_elements; // number of contigous elements
ssize_t stride; // how memory is layed out
while (iter.next ()) {
    if (iter.contigous_stride == arrary.scalar_size && iter.contiguous_elements >= 4) {
        var double_vec = (double_v16) iter.get (); // cast into vector
    } else {
        // make copy
    }
}

I don't see why we would need more than two iterator (multi and single) if we can perform most iterating strategy my changing the view.

Also, if we need some buffering strategy, we might as well derive Array once we will extract a proper interface and reuse existing iterators.

rainwoodman commented 7 years ago