public void TestScalarMul()
        {
            Vector a = Vector.Create(1.0, 2.0);

            VectorOperations.ScalarMul(a, 0.5, ref a);
            Assert.IsTrue(VectorComparison.Close(a, Vector.Create(0.5, 1.0), FloatComparison.DefaultEps));
        }
Esempio n. 2
0
        public void TestVectorOperations()
        {
            VectorOperations.Sub(_a, _b, ref _dest);
            Assert.AreEqual(-2.0, _dest[0], FloatComparison.DefaultEps);
            Assert.AreEqual(-2.0, _dest[1], FloatComparison.DefaultEps);

            VectorOperations.Add(_a, _b, ref _dest);
            Assert.AreEqual(4.0, _dest[0], FloatComparison.DefaultEps);
            Assert.AreEqual(6.0, _dest[1], FloatComparison.DefaultEps);

            VectorOperations.ScalarMul(_a, 2, ref _dest);
            Assert.AreEqual(2.0, _dest[0], FloatComparison.DefaultEps);
            Assert.AreEqual(4.0, _dest[1], FloatComparison.DefaultEps);

            VectorOperations.Copy(_a, ref _dest);
            Assert.AreEqual(1.0, _dest[0], FloatComparison.DefaultEps);
            Assert.AreEqual(2.0, _dest[1], FloatComparison.DefaultEps);

            VectorOperations.Normalize(_a, ref _dest);
            Assert.AreEqual(0.44721359549995793, _dest[0], FloatComparison.DefaultEps);
            Assert.AreEqual(0.89442719099991586, _dest[1], FloatComparison.DefaultEps);

            VectorOperations.Fill(ref _dest, 5.0);
            Assert.AreEqual(5.0, _dest[0], FloatComparison.DefaultEps);
            Assert.AreEqual(5.0, _dest[1], FloatComparison.DefaultEps);
        }