Пример #1
0
        public void Sub()
        {
            SparseVectord sub = v1 - v2;

            Assert.AreEqual((double)2.0, sub[1]);
            Assert.AreEqual((double)-2.0, sub[2]);
        }
Пример #2
0
        public void Add()
        {
            SparseVectord add = v1 + v2;

            Assert.AreEqual((double)2.0, add[1]);
            Assert.AreEqual((double)2.0, add[2]);
            Assert.AreEqual(0.0, add[3]);
            Assert.AreEqual((double)14.0, add[5]);
            Assert.AreEqual((double)5.0, add[12]);
            Assert.AreEqual((double)5.0, add[14]);
        }
Пример #3
0
        public void ElementConstructionAndAccess()
        {
            // We construct giant sparse vector.
            SparseVectord v = new SparseVectord(
                new SparseElementd[] {
                new SparseElementd(1, (double)2.0),
                new SparseElementd(5, (double)3.0),
                new SparseElementd(12, (double)4.0),
                new SparseElementd(115, (double)70.0)
            }, 150);

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

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