public void CanDotProductUsingOperator()
        {
            var dataA = CreateVector(Data);
            var dataB = CreateVector(Data);

            AssertHelpers.AreEqual(new Complex(50, 30), dataA * dataB);
        }
        public void CanDotProduct()
        {
            var dataA = CreateVector(Data);
            var dataB = CreateVector(Data);

            AssertHelpers.AreEqual(new Complex(50, 30), dataA.DotProduct(dataB));
        }
Exemplo n.º 3
0
        public void MatrixFrom2DArrayIsCopy()
        {
            var matrix = new SparseMatrix(TestData2D["Singular3x3"]);

            matrix[0, 0] = 10.0;
            AssertHelpers.AreEqual(new Complex(1.0, 1), TestData2D["Singular3x3"][0, 0]);
        }
        public void CanMultiplySparseVectorByComplexUsingOperators()
        {
            var vector = new SparseVector(Data);

            vector = vector * new Complex(2.0, 1);

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(Data[i] * new Complex(2.0, 1), vector[i]);
            }

            vector = vector * 1.0;
            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(Data[i] * new Complex(2.0, 1), vector[i]);
            }

            vector = new SparseVector(Data);
            vector = new Complex(2.0, 1) * vector;

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(Data[i] * new Complex(2.0, 1), vector[i]);
            }

            vector = 1.0 * vector;
            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(Data[i] * new Complex(2.0, 1), vector[i]);
            }
        }
Exemplo n.º 5
0
        public void PointwiseMultiplyResult()
        {
            foreach (var data in TestMatrices.Values)
            {
                var other  = data.Clone();
                var result = data.Clone();
                data.PointwiseMultiply(other, result);
                for (var i = 0; i < data.RowCount; i++)
                {
                    for (var j = 0; j < data.ColumnCount; j++)
                    {
                        AssertHelpers.AreEqual(data[i, j] * other[i, j], result[i, j]);
                    }
                }

                result = data.PointwiseMultiply(other);
                for (var i = 0; i < data.RowCount; i++)
                {
                    for (var j = 0; j < data.ColumnCount; j++)
                    {
                        AssertHelpers.AreEqual(data[i, j] * other[i, j], result[i, j]);
                    }
                }
            }
        }
        public void CanMultiplyVectorByScalarUsingOperators()
        {
            var vector = CreateVector(Data);

            vector = vector * 2.0;

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(Data[i] * 2.0, vector[i]);
            }

            vector = vector * 1.0;
            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(Data[i] * 2.0, vector[i]);
            }

            vector = CreateVector(Data);
            vector = 2.0 * vector;

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(Data[i] * 2.0, vector[i]);
            }

            vector = 1.0 * vector;
            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(Data[i] * 2.0, vector[i]);
            }
        }
Exemplo n.º 7
0
        public void Trace()
        {
            var matrix = TestMatrices["Square3x3"];
            var trace  = matrix.Trace();

            AssertHelpers.AreEqual(new Complex(6.6, 3), trace);
        }
Exemplo n.º 8
0
        public void MatrixFrom1DArrayIsReference()
        {
            var data   = new[] { new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(2.0f, 1), new Complex32(2.0f, 1), new Complex32(2.0f, 1) };
            var matrix = new DenseMatrix(3, 3, data);

            matrix[0, 0] = 10.0f;
            AssertHelpers.AreEqual(10.0f, data[0]);
        }
        public void CanFindAbsoluteMaximum()
        {
            var source   = CreateVector(Data);
            var expected = new Complex(5, 1).Magnitude;
            var actual   = source.AbsoluteMaximum();

            AssertHelpers.AreEqual(expected, actual);
        }
        public void CanSum()
        {
            Complex[] testData = { new Complex(-20, -1), new Complex(-10, -1), new Complex(10, 1), new Complex(20, 1), new Complex(30, 1) };
            var       vector   = CreateVector(testData);
            var       actual   = vector.Sum();
            var       expected = new Complex(30, 1);

            AssertHelpers.AreEqual(expected, actual);
        }
        public void GetIndexedEnumerator()
        {
            var vector = CreateVector(Data);

            foreach (var pair in vector.GetIndexedEnumerator())
            {
                AssertHelpers.AreEqual(Data[pair.Key], pair.Value);
            }
        }
        public void CanSubtractVectorFromItself()
        {
            var copy   = CreateVector(Data);
            var vector = copy.Subtract(copy);

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(0.0, vector[i]);
            }
        }
        public void CanSetValues()
        {
            var vector = CreateVector(Data);

            vector.SetValues(Data);
            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(vector[i], Data[i]);
            }
        }
        public void CanEnumerateOverVectorUsingIEnumerable()
        {
            var enumerable = (IEnumerable)CreateVector(Data);
            var index      = 0;

            foreach (var element in enumerable)
            {
                AssertHelpers.AreEqual(Data[index++], (Complex)element);
            }
        }
        public void CanCreateSparseVectorFromUserDefinedVector()
        {
            var vector = new UserDefinedVector(Data);
            var other  = new SparseVector(vector);

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(vector[i], other[i]);
            }
        }
        public void CanAddVectorToItself()
        {
            var copy   = CreateVector(Data);
            var vector = copy.Add(copy);

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(Data[i] * 2.0, vector[i]);
            }
        }
        public void CanCallPlus()
        {
            var vector = CreateVector(Data);
            var other  = vector.Plus();

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(vector[i], other[i]);
            }
        }
        public void CanCallUnaryPlusOperator()
        {
            var vector = CreateVector(Data);
            var other  = +vector;

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(vector[i], other[i]);
            }
        }
        public void CanCallUnaryNegationOperatorOnSparseVector()
        {
            var vector = new SparseVector(Data);
            var other  = -vector;

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(-Data[i], other[i]);
            }
        }
        public void CanClearVector()
        {
            Complex[] testData = { new Complex(-20, -1), new Complex(-10, -1), new Complex(10, 1), new Complex(20, 1), new Complex(30, 1) };
            var       vector   = CreateVector(testData);

            vector.Clear();
            foreach (var element in vector)
            {
                AssertHelpers.AreEqual(Complex.Zero, element);
            }
        }
        public void CanGetSubVector(int index, int length)
        {
            var vector = CreateVector(Data);
            var sub    = vector.SubVector(index, length);

            Assert.AreEqual(length, sub.Count);
            for (var i = 0; i < length; i++)
            {
                AssertHelpers.AreEqual(vector[i + index], sub[i]);
            }
        }
        public void CanAddTwoVectors()
        {
            var copy   = CreateVector(Data);
            var other  = CreateVector(Data);
            var vector = copy.Add(other);

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(Data[i] * 2.0, vector[i]);
            }
        }
        public void CanDivideVectorByScalarUsingOperators()
        {
            var vector = CreateVector(Data);

            vector = vector / 2.0;

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(Data[i] / 2.0, vector[i]);
            }
        }
        public void PointWiseDivide()
        {
            var vector1 = CreateVector(Data);
            var vector2 = vector1.Clone();
            var result  = vector1.PointwiseDivide(vector2);

            for (var i = 0; i < vector1.Count; i++)
            {
                AssertHelpers.AreEqual(Data[i] / Data[i], result[i]);
            }
        }
        public void CanSubtractTwoVectors()
        {
            var copy   = CreateVector(Data);
            var other  = CreateVector(Data);
            var vector = copy.Subtract(other);

            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(0.0, vector[i]);
            }
        }
        public void CanCreateSparseVectorFromAnotherVector()
        {
            var vector = (Vector <Complex>) new SparseVector(Data);
            var other  = new SparseVector(vector);

            Assert.AreNotSame(vector, other);
            for (var i = 0; i < Data.Length; i++)
            {
                AssertHelpers.AreEqual(vector[i], other[i]);
            }
        }
Exemplo n.º 27
0
        public void CanCreateMatrixWithUniformValues()
        {
            var matrix = new SparseMatrix(10, 10, new Complex(10.0, 1));

            for (var i = 0; i < matrix.RowCount; i++)
            {
                for (var j = 0; j < matrix.ColumnCount; j++)
                {
                    AssertHelpers.AreEqual(matrix[i, j], new Complex(10.0, 1));
                }
            }
        }
Exemplo n.º 28
0
        public void CanCopyPartialVectorToSelf()
        {
            var vector = CreateVector(Data);

            vector.CopyTo(vector, 0, 2, 2);

            AssertHelpers.AreEqual(new Complex32(1, 1), vector[0]);
            AssertHelpers.AreEqual(new Complex32(2, 1), vector[1]);
            AssertHelpers.AreEqual(new Complex32(1, 1), vector[2]);
            AssertHelpers.AreEqual(new Complex32(2, 1), vector[3]);
            AssertHelpers.AreEqual(new Complex32(5, 1), vector[4]);
        }
Exemplo n.º 29
0
        public void CanCreateMatrixFrom2DArray(string name)
        {
            var matrix = new SparseMatrix(TestData2D[name]);

            for (var i = 0; i < TestData2D[name].GetLength(0); i++)
            {
                for (var j = 0; j < TestData2D[name].GetLength(1); j++)
                {
                    AssertHelpers.AreEqual(TestData2D[name][i, j], matrix[i, j]);
                }
            }
        }
Exemplo n.º 30
0
        public void CanCreateIdentity()
        {
            var matrix = SparseMatrix.Identity(5);

            for (var i = 0; i < matrix.RowCount; i++)
            {
                for (var j = 0; j < matrix.ColumnCount; j++)
                {
                    AssertHelpers.AreEqual(i == j ? Complex.One : Complex.Zero, matrix[i, j]);
                }
            }
        }