Esempio n. 1
0
        public void Sub()
        {
            SparseVectorf sub = v1 - v2;

            Assert.AreEqual((float)2.0, sub[1]);
            Assert.AreEqual((float)-2.0, sub[2]);
        }
Esempio n. 2
0
        public void Add()
        {
            SparseVectorf add = v1 + v2;

            Assert.AreEqual((float)2.0, add[1]);
            Assert.AreEqual((float)2.0, add[2]);
            Assert.AreEqual(0.0f, add[3]);
            Assert.AreEqual((float)14.0, add[5]);
            Assert.AreEqual((float)5.0, add[12]);
            Assert.AreEqual((float)5.0, add[14]);
        }
Esempio n. 3
0
        public void ElementConstructionAndAccess()
        {
            // We construct giant sparse vector.
            SparseVectorf v = new SparseVectorf(
                new SparseElementf[] {
                new SparseElementf(1, (float)2.0),
                new SparseElementf(5, (float)3.0),
                new SparseElementf(12, (float)4.0),
                new SparseElementf(115, (float)70.0)
            }, 150);

            // Accessor test.
            Assert.AreEqual(0.0f, v[7]);
            Assert.AreEqual((float)3.0, v[5]);
            Assert.AreEqual((float)70.0, v[115]);
            Assert.AreEqual(0.0f, v[145]);

            // Setting test.
            v[15] = (float)6.0;
            Assert.AreEqual((float)6.0, v[15]);
            v[5] = (float)3.0;
            Assert.AreEqual((float)3.0, v[5]);
        }