public void TryReshape_TwoRemainders_ThrowException() { // arrange var array = NdArray <int> .Ones(HostDevice.Instance, new[] { 2, 3, 4 }); // action var newShape = new[] { 3, SpecialIdx.Remainder, SpecialIdx.Remainder }; var newLayout = Layout.TryReshape(newShape, array); }
public void TryReshape_DifferentNumElements_ThrowException() { // arrange var array = NdArray <int> .Ones(HostDevice.Instance, new[] { 10 }); // action var newShape = new[] { 3, 2, 5 }; var newLayout = Layout.TryReshape(newShape, array); }
public void TryReshape_WithRemainder_ReturnNewLayout() { // arrange var array = NdArray <int> .Ones(HostDevice.Instance, new[] { 2, 3, 4 }); // action var newShape = new[] { 4, SpecialIdx.Remainder, 2 }; var newLayout = Layout.TryReshape(newShape, array); // assert CollectionAssert.AreEqual(new[] { 4, 3, 2 }, newLayout.Shape); }
public void TryReshape_WithoutCopyCase6_ReturnNewLayout() { // arrange var array = NdArray <int> .Ones(HostDevice.Instance, new[] { 6, 8 }); // action var newShape = new[] { 2, 12, 2 }; var newLayout = Layout.TryReshape(newShape, array); // assert CollectionAssert.AreEqual(newShape, newLayout.Shape); }
public void All() { // arrange var input = NdArray <bool> .Ones(HostDevice.Instance, new int[] { 2, 4 }); input[new[] { 0, 1 }] = false; // action var output = LogicalFunction <bool> .All(input); // assert Assert.AreEqual(false, output); }
public void FillIsFinite() { // arrange var device = HostDevice.Instance; var source = NdArray <int> .Zeros(device, new[] { 2, 3, 4 }); var result = NdArray <bool> .Ones(device, new[] { 2, 3, 4 }); // action ComparisonFunction <int> .FillIsFinite(result, source); // assert Assert.IsTrue(NdArray <int> .All(result)); }
public void Minimum() { // arrange var srcArray1 = NdArray <double> .Zeros(HostDevice.Instance, new[] { 3 }); var srcArray2 = NdArray <double> .Ones(HostDevice.Instance, new[] { 3 }); // action var newArray = ElementWiseMathFunction <double> .Minimum(srcArray1, srcArray2); // assert Assert.AreEqual(0.0, newArray[0].Value); Assert.AreEqual(0.0, newArray[1].Value); Assert.AreEqual(0.0, newArray[2].Value); }
public void CountTrue() { // arrange var input = NdArray <bool> .Ones(HostDevice.Instance, new int[] { 2, 4 }); input[new[] { 0, 1 }] = false; input[new[] { 1, 0 }] = false; input[new[] { 1, 3 }] = false; // action var output = LogicalFunction <bool> .CountTrue(input); // assert Assert.AreEqual(5, output); }
public void Xor() { // arrange var input1 = NdArray <bool> .Zeros(HostDevice.Instance, new int[] { 2 }); var input2 = NdArray <bool> .Ones(HostDevice.Instance, new int[] { 2 }); input2[0].Value = false; // action var output = LogicalFunction <bool> .Xor(input1, input2); // assert Assert.AreEqual(false, output[0].Value); Assert.AreEqual(true, output[1].Value); }
public void AllAxis() { // arrange var input = NdArray <bool> .Ones(HostDevice.Instance, new int[] { 2, 4 }); input[new[] { 0, 1 }] = false; // action var output0 = LogicalFunction <bool> .AllAxis(0, input); var output1 = LogicalFunction <bool> .AllAxis(1, input); // assert Assert.AreEqual(true, output0[0].Value); Assert.AreEqual(true, output1[1].Value); }
public void Or() { // arrange var input1 = NdArray <bool> .Zeros(HostDevice.Instance, new int[] { 4 }); var input2 = NdArray <bool> .Ones(HostDevice.Instance, new int[] { 4 }); // action var output = LogicalFunction <bool> .Or(input1, input2); // assert var expected = NdArray <bool> .Ones(HostDevice.Instance, new int[] { 4 }); var result = expected == output; Assert.IsTrue(NdArray <bool> .All(result)); }
public void ZerosLike() { // arrange var device = HostDevice.Instance; var ones = NdArray <int> .Ones(device, new[] { 2, 2 }); // action var array = Constructor <int> .ZerosLike(ones); // assert var expectedLayout = new Layout(new[] { 2, 2 }, 0, new[] { 1 }); Assert.AreEqual(0, array[new[] { 0, 0 }]); Assert.AreEqual(0, array[new[] { 0, 1 }]); Assert.AreEqual(0, array[new[] { 1, 0 }]); Assert.AreEqual(0, array[new[] { 1, 1 }]); }
public void Execute() { // Creates with 1-D array and shape definition. var ndarray1 = NdArray.Create(new double[24], new int[] { 2, 3, 4 }); WriteLine(ndarray1); // Creates with multi-dimension array. var ndarray2 = NdArray.Create(new double[2, 3, 4]); WriteLine(ndarray2); // Basic NdArray is immutable. // If you need mutable NdArray, use `CreateMutable` instead of `Create`. var ndarray3 = NdArray.CreateMutable(new double[2, 3, 4]); WriteLine(ndarray3); // You can convert mutable <-> immutable NdArray with `ToImmutable`/`ToMutable`. // These methods create copy. var ndarray4 = ndarray3.ToImmutable(); WriteLine(ndarray4); var ndarray5 = ndarray1.ToMutable(); WriteLine(ndarray5); // You can also convert mutable -> immutable with `MoveTommutable`. // This method moves internal buffer, but does not create copy. // Please note this method destroys the source mutable NdArray. var ndarray6 = ndarray3.MoveToImmutable(); WriteLine(ndarray6); // If generic data type T has `0`/`1` value, you can use `Zeros`/`Ones`. var ndarray7 = NdArray.Zeros <double>(new int[] { 2, 3, 4 }); WriteLine(ndarray7); var ndarray8 = NdArray.Ones <double>(new int[] { 2, 3, 4 }); WriteLine(ndarray8); }
public void IfThenElse() { // arrange var condition = NdArray <bool> .Ones(HostDevice.Instance, new int[] { 4 }); var ifTrue = NdArray <int> .Ones(HostDevice.Instance, new int[] { 4 }); var ifFalse = NdArray <int> .Zeros(HostDevice.Instance, new int[] { 4 }); condition[new[] { 0 }] = false; condition[new[] { 2 }] = false; // action var output = LogicalFunction <int> .IfThenElse(condition, ifTrue, ifFalse); // assert Assert.AreEqual(0, output[0].Value); Assert.AreEqual(1, output[1].Value); Assert.AreEqual(0, output[2].Value); Assert.AreEqual(1, output[3].Value); }
public static NdArray <T> OnesLike <T>(NdArray <T> template) { return(NdArray <T> .Ones(template.Storage.Device, template.Shape)); }
public static NdArray <T> Ones <T>(int[] shape) { return(NdArray <T> .Ones(Device, shape)); }