Example #1
0
        public FloatTensor MM(FloatTensor x)
        {
            if (this.shape.Length != 2 || x.shape.Length != 2)
            {
                throw new InvalidOperationException(
                          "Cannot do MM on tensors that aren't 2 dimentional. Try calling view() to reshape");
            }

            var resultShape = new int[2];

            resultShape[0] = shape[0];
            resultShape[1] = x.shape[1];

            var result = new FloatTensor(_controller: controller, _shape: resultShape);

            if (this.dataOnGpu)
            {
                result.Gpu(shader);
            }

            result.AddMatrixMultiply(this, x);

            if (autograd)
            {
                HookAutograd(ref result, ref x, "mm");
            }

            return(result);
        }
Example #2
0
        public FloatTensor MM(FloatTensor x, FloatTensor result = null)
        {
            if (!IsContiguous() || !x.IsContiguous())
            {
                throw new InvalidOperationException("All tensors must be contiguous, call Contiguous() to convert");
            }

            if (this.shape.Length != 2 || x.shape.Length != 2)
            {
                throw new InvalidOperationException(
                          "Cannot do MM on tensors that aren't 2 dimentional. Try calling view() to reshape");
            }

            result = HookAutograd(ref result, ref x, "mm", false, new int[] { shape[0], x.shape[1] });

            result.AddMatrixMultiply(this, x);

            return(result);
        }