Пример #1
0
        internal static Tensor <T> MatrixMultiply <T>(this Tensor <T> left, Tensor <T> right)
        {
            if (left.Rank != 2)
            {
                throw new InvalidOperationException($"{nameof(MatrixMultiply)} is only valid for a {nameof(Tensor<T>)} of {nameof(left.Rank)} 2.");
            }

            if (right.Rank != 2)
            {
                throw new ArgumentException($"{nameof(Tensor<T>)} {nameof(right)} must have {nameof(left.Rank)} 2.", nameof(right));
            }

            if (left.dimensions[1] != right.dimensions[0])
            {
                throw new ArgumentException($"{nameof(Tensor<T>)} {nameof(right)} must have first dimension of {left.dimensions[1]}.", nameof(right));
            }

            return(TensorOperations.Contract(left, right, s_oneArray, s_zeroArray));
        }
Пример #2
0
        public void SliceIncrement(TensorConstructor constructor)
        {
            var slice       = Get3DSlice(constructor);
            var incremented = TensorOperations.Increment(slice);

            var expected = new[, , ]
            {
                {
                    { 3, 4 },
                    { 7, 8 },
                    { 11, 12 },
                },
                {
                    { 15, 16 },
                    { 19, 20 },
                    { 23, 24 },
                },
            };

            Assert.True(StructuralComparisons.StructuralEqualityComparer.Equals(incremented, expected));
            Assert.Equal(constructor.IsReversedStride, incremented.IsReversedStride);
        }