public void Fold2SkipZeros(TestVectorStorage aType, TestVectorStorage bType)
 {
     var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
     var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
     var result = a.Fold2(b, (acc, u, v) => acc + u + v, 0.0, Zeros.AllowSkip);
     Assert.That(result, Is.EqualTo(65));
 }
 public void Fold2ForceIncludeZeros(TestVectorStorage aType, TestVectorStorage bType)
 {
     var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
     var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
     var result = a.Fold2(b, (acc, u, v) => acc + u + v + 1.0, 0.0, Zeros.Include);
     Assert.That(result, Is.EqualTo(71));
 }
 public void MapToAutoIncludeZeros(TestVectorStorage aType, TestVectorStorage resultType)
 {
     var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
     var result = TestData.VectorStorage<double>(resultType, 4);
     var expected = new DenseVectorStorage<double>(4, new[] { 0.0, -1.0, 1.0, -3.0 });
     a.MapTo(result, u => -u + 1.0, Zeros.AllowSkip);
     Assert.That(result.Equals(expected));
 }
Beispiel #4
0
        public void Fold2ForceIncludeZeros(TestVectorStorage aType, TestVectorStorage bType)
        {
            var a      = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
            var b      = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
            var result = a.Fold2(b, (acc, u, v) => acc + u + v + 1.0, 0.0, Zeros.Include);

            Assert.That(result, Is.EqualTo(71));
        }
Beispiel #5
0
        public void Fold2SkipZeros(TestVectorStorage aType, TestVectorStorage bType)
        {
            var a      = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
            var b      = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
            var result = a.Fold2(b, (acc, u, v) => acc + u + v, 0.0, Zeros.AllowSkip);

            Assert.That(result, Is.EqualTo(65));
        }
Beispiel #6
0
        public void MapToAutoIncludeZeros(TestVectorStorage aType, TestVectorStorage resultType)
        {
            var a        = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
            var result   = TestData.VectorStorage <double>(resultType, 4);
            var expected = new DenseVectorStorage <double>(4, new[] { 0.0, -1.0, 1.0, -3.0 });

            a.MapTo(result, u => - u + 1.0, Zeros.AllowSkip);
            Assert.That(result.Equals(expected));
        }
Beispiel #7
0
        public void MapToSkipZeros(TestVectorStorage aType, TestVectorStorage resultType)
        {
            var a        = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
            var result   = TestData.VectorStorage <double>(resultType, 4);
            var expected = new DenseVectorStorage <double>(4, new[] { -1.0, -2.0, 0.0, -4.0 });

            a.MapTo(result, u => - u, Zeros.AllowSkip, ExistingData.Clear);
            Assert.That(result.Equals(expected));
        }
 public void Map2ToAutoIncludeZeros(TestVectorStorage aType, TestVectorStorage bType, TestVectorStorage resultType)
 {
     var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
     var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
     var result = TestData.VectorStorage<double>(resultType, 6);
     var expected = new DenseVectorStorage<double>(6, new[] { 13.0, 15.0, 14.0, 5.0, 1.0, 23.0 });
     a.Map2To(result, b, (u, v) => u + v + 1.0, Zeros.AllowSkip);
     Assert.That(result.Equals(expected));
 }
 public void MapIndexedToSkipZeros(TestVectorStorage aType, TestVectorStorage resultType)
 {
     var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
     var result = TestData.VectorStorage<double>(resultType, 4);
     var expected = new DenseVectorStorage<double>(4, new[] { -1.0, -2.0, 0.0, -4.0 });
     int badValueCount = 0; // one time is OK for zero-check
     a.MapIndexedTo(result, (i, u) => { if (a.At(i) != u) Interlocked.Increment(ref badValueCount); return -u; }, Zeros.AllowSkip);
     Assert.That(badValueCount, Is.LessThanOrEqualTo(1));
     Assert.That(result.Equals(expected));
 }
Beispiel #10
0
        public void Map2ToAutoIncludeZeros(TestVectorStorage aType, TestVectorStorage bType, TestVectorStorage resultType)
        {
            var a        = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
            var b        = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
            var result   = TestData.VectorStorage <double>(resultType, 6);
            var expected = new DenseVectorStorage <double>(6, new[] { 13.0, 15.0, 14.0, 5.0, 1.0, 23.0 });

            a.Map2To(result, b, (u, v) => u + v + 1.0, Zeros.AllowSkip);
            Assert.That(result.Equals(expected));
        }
Beispiel #11
0
        public void Map2ToSkipZeros(TestVectorStorage aType, TestVectorStorage bType, TestVectorStorage resultType)
        {
            var a        = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 });
            var b        = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 });
            var result   = TestData.VectorStorage <double>(resultType, 6);
            var expected = new DenseVectorStorage <double>(6, new[] { 12.0, 14.0, 13.0, 4.0, 0.0, 22.0 });

            a.Map2To(result, b, (u, v) => u + v, Zeros.AllowSkip, ExistingData.Clear);
            Assert.That(result.Equals(expected));
        }
Beispiel #12
0
        public void MapIndexedToForceIncludeZeros(TestVectorStorage aType, TestVectorStorage resultType)
        {
            var a             = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 });
            var result        = TestData.VectorStorage <double>(resultType, 4);
            var expected      = new DenseVectorStorage <double>(4, new[] { 0.0, -1.0, 1.0, -3.0 });
            int badValueCount = 0; // one time is OK for zero-check

            a.MapIndexedTo(result, (i, u) => { if (a.At(i) != u)
                                               {
                                                   Interlocked.Increment(ref badValueCount);
                                               }
                                               return(-u + 1.0); }, Zeros.Include);
            Assert.That(badValueCount, Is.LessThanOrEqualTo(1));
            Assert.That(result.Equals(expected));
        }
Beispiel #13
0
        public static VectorStorage <T> VectorStorage <T>(TestVectorStorage type, int length)
            where T : struct, IEquatable <T>, IFormattable
        {
            switch (type)
            {
            case TestVectorStorage.DenseVector:
                return(new DenseVectorStorage <T>(length));

            case TestVectorStorage.SparseVector:
                return(new SparseVectorStorage <T>(length));

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #14
0
        public static VectorStorage <T> VectorStorage <T>(TestVectorStorage type, IEnumerable <T> data)
            where T : struct, IEquatable <T>, IFormattable
        {
            switch (type)
            {
            case TestVectorStorage.DenseVector:
                return(DenseVectorStorage <T> .OfEnumerable(data));

            case TestVectorStorage.SparseVector:
                return(SparseVectorStorage <T> .OfEnumerable(data));

            default:
                throw new NotSupportedException();
            }
        }