public void Find_NotFound_ThrowException()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var output = IndexFunction <int> .Find(10, source);
        }
Beispiel #2
0
        public void Replicate_NegativeRepeats_ThrowException()
        {
            // arrange
            var input = NdArray <int> .Arange(HostDevice.Instance, 0, 2 * 3, 1).Reshape(new[] { 2, 3 });

            // action
            var result = NdArrayOperator <int> .Replicate(0, -10, input);
        }
        public void Trace_WithInvalidDimension_ThrowException()
        {
            // arrange
            var device = HostDevice.Instance;
            var input  = NdArray <int> .Arange(device, 0, 27, 1);

            // action
            var trace = ReductionFunction <int> .Trace(input);
        }
Beispiel #4
0
        public void Diag_OneDimensionalArray_ThrowException()
        {
            // arrange
            var device = HostDevice.Instance;
            var input  = NdArray <int> .Arange(device, 0, 9, 1);

            // action
            var diag = NdArrayOperator <int> .Diag(input);
        }
Beispiel #5
0
        public void DiagMatAxis_InvalidAxis()
        {
            // arrange
            var axis1 = 1;
            var axis2 = 3;
            var input = NdArray <int> .Arange(HostDevice.Instance, 0, 10, 1).Reshape(new[] { 2, 5 });

            // action
            var diagMat = NdArrayOperator <int> .DiagMatAxis(axis1, axis2, input);
        }
        public void ArgMax()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var output = IndexFunction <int> .ArgMax(source);

            // assert
            CollectionAssert.AreEqual(new[] { 1, 3 }, output);
        }
        public void TryFind_NotFound()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var output = IndexFunction <int> .TryFind(10, source);

            // assert
            Assert.IsTrue(output.Length == 0);
        }
        public void AllElements()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 0, 9, 1).Reshape(new[] { 3, 3 });

            // action
            var output = IndexFunction <int> .AllElements(source);

            // assert
            CollectionAssert.AreEqual(Enumerable.Range(0, 9).ToArray(), output);
        }
Beispiel #9
0
        public void Replicate()
        {
            // arrange
            var input = NdArray <int> .Arange(HostDevice.Instance, 0, 2 * 3, 1).Reshape(new[] { 2, 3 });

            // action
            var result = NdArrayOperator <int> .Replicate(0, 10, input);

            // assert
            CollectionAssert.AreEqual(new[] { 20, 3 }, result.Shape);
        }
Beispiel #10
0
        public void Diff()
        {
            // arrange
            var input = NdArray <int> .Arange(HostDevice.Instance, 0, 9, 1).Reshape(new[] { 3, 3 });

            // action
            var result = NdArrayOperator <int> .Diff(input);

            // assert
            CollectionAssert.AreEqual(new[] { 3, 2 }, result.Shape);
        }
Beispiel #11
0
        public void DiagMat()
        {
            // arrange
            var input = NdArray <int> .Arange(HostDevice.Instance, 0, 3, 1);

            // action
            var diagMat = NdArrayOperator <int> .DiagMat(input);

            // assert
            CollectionAssert.AreEqual(new[] { 3, 3 }, diagMat.Shape);
        }
        public void FindAxis()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 0, 8, 1).Reshape(new[] { 2, 4 });

            // action
            var output = IndexFunction <int> .FindAxis(2, 1, source);

            // assert
            Assert.AreEqual(2, output[0].Value);
            Assert.AreEqual(SpecialIdx.NotFound, output[1].Value);
        }
        public void MeanAxis()
        {
            // arrange
            var device = HostDevice.Instance;
            var input  = NdArray <double> .Arange(device, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var mean = ReductionFunction <double> .MeanAxis(1, input);

            // assert
            Assert.AreEqual(2.5, mean[0].Value);
        }
        public void Mean()
        {
            // arrange
            var device = HostDevice.Instance;
            var input  = NdArray <double> .Arange(device, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var sum = ReductionFunction <double> .Mean(input);

            // assert
            Assert.AreEqual(4.5, sum);
        }
        public void ProductNdArray()
        {
            // arrange
            var device = HostDevice.Instance;
            var input  = NdArray <double> .Arange(device, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var product = ReductionFunction <double> .ProductNdArray(input);

            // assert
            Assert.AreEqual(40320.0, product[0].Value);
        }
        public void MinNdArray()
        {
            // arrange
            var device = HostDevice.Instance;
            var input  = NdArray <double> .Arange(device, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var min = ReductionFunction <double> .MinNdArray(input);

            // assert
            Assert.AreEqual(1.0, min[0].Value);
        }
        public void SumAxis()
        {
            // arrange
            var device = HostDevice.Instance;
            var input  = NdArray <double> .Arange(device, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var sum = ReductionFunction <double> .SumAxis(1, input);

            // assert
            Assert.AreEqual(10.0, sum[0].Value);
        }
Beispiel #18
0
        public void Copy_ColumnMajor()
        {
            // arrange
            var input = NdArray <int> .Arange(HostDevice.Instance, 0, 10, 1).Reshape(new[] { 2, 5 });

            // action
            var copy = NdArrayOperator <int> .Copy(input, Order.ColumnMajor);

            // assert
            CollectionAssert.AreEqual(new[] { 2, 5 }, copy.Shape);
            CollectionAssert.AreEqual(new[] { 1, 2 }, copy.Layout.Stride);
        }
        public void TryReshape_WithoutCopyCase1_ReturnNewLayout()
        {
            // arrange
            var array = NdArray <int> .Arange(HostDevice.Instance, 0, 10, 1);

            // action
            var newShape  = new[] { 10, 1 };
            var newLayout = Layout.TryReshape(newShape, array);

            // assert
            CollectionAssert.AreEqual(newShape, newLayout.Shape);
        }
Beispiel #20
0
        public void IsClose_SameDoubleVectors_ReturnTrues()
        {
            // arrange
            var device = HostDevice.Instance;
            var source = NdArray <double> .Arange(device, 0, 10, 1);

            // action
            var close = ComparisonFunction <double> .IsClose(source, source);

            // assert
            CollectionAssert.AreEqual(new[] { 10 }, close.Shape);
        }
Beispiel #21
0
        public void IsClose_DifferentDoubleVectorsWithBigTolerence_ReturnTrue()
        {
            // arrange
            var device = HostDevice.Instance;
            var source = NdArray <double> .Arange(device, 0, 10, 1);

            // action
            var close = ComparisonFunction <double> .IsClose(source, source + 1.0, 2.0);

            // assert
            CollectionAssert.AreEqual(new[] { 10 }, close.Shape);
        }
Beispiel #22
0
        public void UnaryMinus()
        {
            // arrange
            var device = HostDevice.Instance;
            var input  = NdArray <int> .Arange(device, 0, 10, 1);

            // action
            var output = -input;

            // assert
            CollectionAssert.AreEqual(new[] { 10 }, output.Shape);
        }
        public void ArgMinAxis()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 1, 9, 1).Reshape(new[] { 2, 4 });

            // action
            var output = IndexFunction <int> .ArgMinAxis(1, source);

            // assert
            Assert.AreEqual(0, output[0].Value);
            Assert.AreEqual(0, output[1].Value);
        }
Beispiel #24
0
        public void DiagMatAxis()
        {
            // arrange
            var axis1 = 0;
            var axis2 = 1;
            var input = NdArray <int> .Arange(HostDevice.Instance, 0, 12, 1).Reshape(new[] { 4, 3 });

            // action
            var diagMat = NdArrayOperator <int> .DiagMatAxis(axis1, axis2, input);

            // assert
            CollectionAssert.AreEqual(new[] { 4, 4, 3 }, diagMat.Shape);
        }
        public void TryFind()
        {
            // arrange
            var source = NdArray <int> .Arange(HostDevice.Instance, 1, 9, 1).Reshape(new[] { 2, 4 });

            source[new[] { 1, 3 }] = 2;

            // action
            var output = IndexFunction <int> .TryFind(2, source);

            // assert
            CollectionAssert.AreEqual(new[] { 0, 1 }, output);
        }
        public void ReverseAxis()
        {
            // arrange
            var input = NdArray <int> .Arange(HostDevice.Instance, 0, 4, 1);

            // action
            var output = ShapeFunction <int> .ReverseAxis(0, input);

            var s = output.ToString();

            // assert
            Assert.AreEqual(4, output.Shape[0]);
            Assert.AreEqual(-1, output.Layout.Stride[0]);
        }
Beispiel #27
0
        public void NotEqual()
        {
            // arrange
            var device  = HostDevice.Instance;
            var sourceA = NdArray <int> .Arange(device, 0, 10, 1);

            var sourceB = NdArray <int> .Arange(device, 0, 10, 1);

            // action
            var result = ComparisonFunction <int> .NotEqual(sourceA, sourceB);

            // assert
            CollectionAssert.AreEqual(new[] { 10 }, result.Shape);
        }
Beispiel #28
0
        public void Add_ScalarWithVector()
        {
            // arrange
            var device = HostDevice.Instance;
            var inputA = NdArray <int> .Arange(device, 0, 10, 1);

            var inputB = NdArray <int> .Scalar(device, 3);

            // action
            var equal = inputB + inputA;

            // assert
            CollectionAssert.AreEqual(new[] { 10 }, equal.Shape);
        }
Beispiel #29
0
        public void Modulo_VectorWithScalar()
        {
            // arrange
            var device = HostDevice.Instance;
            var inputA = NdArray <int> .Arange(device, 1, 11, 1);

            var inputB = NdArray <int> .Scalar(device, 3);

            // action
            var equal = inputA % inputB;

            // assert
            CollectionAssert.AreEqual(new[] { 10 }, equal.Shape);
        }
Beispiel #30
0
        public void Multiply_VectorWithVector()
        {
            // arrange
            var device = HostDevice.Instance;
            var inputA = NdArray <int> .Arange(device, 0, 10, 1);

            var inputB = NdArray <int> .Arange(device, 0, 10, 1);

            // action
            var equal = inputA * inputB;

            // assert
            CollectionAssert.AreEqual(new[] { 10 }, equal.Shape);
        }