public void Setup() { var _ = ScalarMemoryPool.Instance; var __ = InfoOf <byte> .Size; shape = new Shape(2, 1, 50_000); ndarray = np.array(Enumerable.Range(0, 100_000).ToArray()).reshape(ref shape); iter = new NDIterator <int>((IMemoryBlock <int>)ndarray.Data <int>(), shape, null); }
public void Case1() { var sh = new NDIterator <int>(np.arange(10), false); var acc = 0; var next = sh.HasNext; var move = sh.MoveNext; while (next()) { Console.WriteLine(acc += move()); } acc.Should().Be(Enumerable.Range(0, 10).Sum()); }
public void Case2() { Console.WriteLine(); var nd = np.arange(10); var sh = new NDIterator <int>(nd, true); int acc = 0; for (int i = 0; i < nd.size * 10; i++, sh.HasNext()) { var val = sh.MoveNext(); Console.WriteLine((acc += val) + " | " + val); } acc.Should().Be(Enumerable.Range(0, 10).Sum() * 10); }
public void Case3_GetData_All() { var lhs = np.full(5, (6, 3, 3), NPTypeCode.Int32); var slice = lhs.Storage.GetData(new int[0]); slice.Count.Should().Be(6 * 3 * 3); slice.Shape.IsScalar.Should().BeFalse(); slice.Shape.IsSliced.Should().BeFalse("Slicing should occurs only when lhs is already sliced."); //via enumerator var iter = new NDIterator <int>(slice); for (int i = 0; i < 6 * 3 * 3; i++, iter.HasNext()) { iter.MoveNext().Should().Be(5); } }