/// <summary>
        /// Same version as above, but gives the possibility of reusing the output buffer
        /// </summary>
        /// <param name="output"></param>
        /// <param name="rhs"></param>
        /// <param name="lhsOperation"></param>
        /// <param name="rhsOperation"></param>
        /// <param name="alpha"></param>
        public void Multiply(ColumnWiseMatrix output, ColumnWiseMatrix rhs, MatrixOperation lhsOperation = MatrixOperation.None, MatrixOperation rhsOperation = MatrixOperation.None, double alpha = 1.0, double beta = 0.0)
        {
            if (lhsOperation == MatrixOperation.None)
            {
                Debug.Assert(rhs.nRows == nCols);
                Debug.Assert(output.nRows == nRows);
                Debug.Assert(output.nCols == rhs.nCols);
            }
            else
            {
                Debug.Assert(rhs.nCols == nCols);
                Debug.Assert(output.nCols == nRows);
                Debug.Assert(output.nRows == rhs.nCols);
            }

            Debug.Assert(memorySpace == rhs.memorySpace);
            Debug.Assert(memorySpace == output.memorySpace);
            Debug.Assert(mathDomain == rhs.mathDomain);
            Debug.Assert(mathDomain == output.mathDomain);
            Debug.Assert(Buffer.pointer != 0);
            Debug.Assert(rhs.Buffer.pointer != 0);
            Debug.Assert(output.Buffer.pointer != 0);

            CuBlasApi.Multiply(output._buffer, _buffer, rhs._buffer, nRows, rhs.nRows, lhsOperation, rhsOperation, alpha, beta);
        }
        /// <summary>
        /// Solve A * X = B, B is overwritten
        /// </summary>
        /// <param name="rhs"></param>
        /// <param name="lhsOperation"></param>
        public void Solve(ColumnWiseMatrix rhs, MatrixOperation lhsOperation = MatrixOperation.None)
        {
            Debug.Assert(nRows == nCols);
            Debug.Assert(Buffer.pointer != 0);

            CuBlasApi.Solve(_buffer, rhs._buffer, lhsOperation);
        }
        public static ColumnWiseMatrix Eye(int nRows, MemorySpace memorySpace = MemorySpace.Device, MathDomain mathDomain = MathDomain.Float)
        {
            ColumnWiseMatrix I = new ColumnWiseMatrix(nRows, nRows, memorySpace, mathDomain);

            I.MakeIdentity();

            return(I);
        }
        public static ColumnWiseMatrix LinSpace(int nRows, int nCols, double x0, double x1, MemorySpace memorySpace = MemorySpace.Device, MathDomain mathDomain = MathDomain.Float)
        {
            var mat = new ColumnWiseMatrix(nRows, nCols, memorySpace, mathDomain);

            mat.LinSpace(x0, x1);

            return(mat);
        }
        /// <summary>
        /// A = alpha * B * C + beta * A
        /// </summary>
        /// <param name="rhs"></param>
        /// <param name="lhsOperation"></param>
        /// <param name="rhsOperation"></param>
        /// <param name="alpha"></param>
        /// <param name="beta"></param>
        /// <returns></returns>
        public ColumnWiseMatrix Multiply(ColumnWiseMatrix rhs, MatrixOperation lhsOperation = MatrixOperation.None, MatrixOperation rhsOperation = MatrixOperation.None, double alpha = 1.0, double beta = 0.0)
        {
            ColumnWiseMatrix ret = new ColumnWiseMatrix(nRows, rhs.nCols, memorySpace, rhs.mathDomain);

            Multiply(ret, rhs, lhsOperation, rhsOperation, alpha, beta);

            return(ret);
        }
        public static ColumnWiseMatrix RandomGaussian(int nRows, int nCols, int seed, MemorySpace memorySpace = MemorySpace.Device, MathDomain mathDomain = MathDomain.Float)
        {
            var mat = new ColumnWiseMatrix(nRows, nCols, memorySpace, mathDomain);

            mat.RandomGaussian(seed);

            return(mat);
        }
        public static ColumnWiseMatrix KroneckerProduct(Vector lhs, Vector rhs, double alpha = 1.0)
        {
            ColumnWiseMatrix ret = new ColumnWiseMatrix(lhs.Size, rhs.Size, 0.0, lhs.memorySpace, lhs.mathDomain);

            KroneckerProduct(ret, lhs, rhs, alpha);

            return(ret);
        }
        public static ColumnWiseMatrix Subtract(ColumnWiseMatrix lhs, ColumnWiseMatrix rhs, MatrixOperation lhsOperation = MatrixOperation.None, MatrixOperation rhsOperation = MatrixOperation.None)
        {
            ColumnWiseMatrix ret = new ColumnWiseMatrix(lhs);

            CuBlasApi.AddEqualMatrix(ret._buffer, rhs._buffer, lhsOperation, rhsOperation, -1.0, 1.0);

            return(ret);
        }
        /// <summary>
        ///  A = alpha * B + beta * A
        /// </summary>
        /// <param name="lhs"></param>
        /// <param name="rhs"></param>
        /// <param name="lhsOperation"></param>
        /// <param name="rhsOperation"></param>
        /// <param name="alpha"></param>
        /// <param name="beta"></param>
        /// <returns></returns>
        public static ColumnWiseMatrix Add(ColumnWiseMatrix lhs, ColumnWiseMatrix rhs, MatrixOperation lhsOperation = MatrixOperation.None, MatrixOperation rhsOperation = MatrixOperation.None, double alpha = 1.0, double beta = 1.0)
        {
            ColumnWiseMatrix ret = new ColumnWiseMatrix(lhs);

            CuBlasApi.AddEqualMatrix(ret._buffer, rhs._buffer, lhsOperation, rhsOperation, alpha, beta);

            return(ret);
        }
Beispiel #10
0
        public Tensor(int nRows, int nCols, int nCubes, MemorySpace memorySpace = MemorySpace.Device, MathDomain mathDomain = MathDomain.Float)
            : base(true, memorySpace, mathDomain)
        {
            _buffer = new MemoryCube(0, (uint)nRows, (uint)nCols, (uint)nCubes, memorySpace, mathDomain);
            ctor(_buffer);

            cubes = new ColumnWiseMatrix[nCubes];
            SetCubesPointers();
        }
 public void ReadFrom(ColumnWiseMatrix rhs)
 {
     Debug.Assert(_buffer.pointer != 0);
     Debug.Assert(rhs._buffer.pointer != 0);
     Debug.Assert(Size == rhs.Size);
     Debug.Assert(nRows == rhs.nRows);
     Debug.Assert(nCols == rhs.nCols);
     base.ReadFrom(rhs);
 }
Beispiel #12
0
        private void SetCubesPointers()
        {
            uint shift = _buffer.ElementarySize();

            for (int i = 0; i < nCubes; i++)
            {
                MemoryTile columnBuffer = new MemoryTile(_buffer.pointer + (PtrT)(i * nRows * nCols * shift), (uint)nRows, (uint)nCols, memorySpace, mathDomain);
                cubes[i] = new ColumnWiseMatrix(columnBuffer);
            }
        }
        public static ColumnWiseMatrix operator *(ColumnWiseMatrix lhs, ColumnWiseMatrix rhs)
        {
            Debug.Assert(rhs.nRows == lhs.nCols);
            Debug.Assert(lhs.memorySpace == rhs.memorySpace);
            Debug.Assert(lhs.mathDomain == rhs.mathDomain);
            Debug.Assert(lhs.Buffer.pointer != 0);
            Debug.Assert(rhs.Buffer.pointer != 0);

            ColumnWiseMatrix ret = new ColumnWiseMatrix(lhs.nRows, rhs.nCols, lhs.memorySpace, rhs.mathDomain);

            CuBlasApi.Multiply(ret._buffer, lhs._buffer, rhs._buffer, lhs.nRows, rhs.nRows, MatrixOperation.None, MatrixOperation.None, 1.0, 0.0);

            return(ret);
        }
        public static ColumnWiseMatrix operator %(ColumnWiseMatrix lhs, ColumnWiseMatrix rhs)
        {
            Debug.Assert(lhs.nRows == rhs.nRows);
            Debug.Assert(lhs.nCols == rhs.nCols);
            Debug.Assert(lhs.memorySpace == rhs.memorySpace);
            Debug.Assert(lhs.mathDomain == rhs.mathDomain);
            Debug.Assert(lhs.Buffer.pointer != 0);
            Debug.Assert(rhs.Buffer.pointer != 0);

            ColumnWiseMatrix tmp = new ColumnWiseMatrix(lhs);

            ElementWiseProduct(tmp.Buffer, rhs.Buffer);

            return(tmp);
        }
        public static ColumnWiseMatrix operator -(ColumnWiseMatrix lhs, ColumnWiseMatrix rhs)
        {
            Debug.Assert(lhs.nRows == rhs.nRows);
            Debug.Assert(lhs.nCols == rhs.nCols);
            Debug.Assert(lhs.memorySpace == rhs.memorySpace);
            Debug.Assert(lhs.mathDomain == rhs.mathDomain);
            Debug.Assert(lhs.Buffer.pointer != 0);
            Debug.Assert(rhs.Buffer.pointer != 0);

            ColumnWiseMatrix tmp = new ColumnWiseMatrix(lhs);

            CuBlasApi.AddEqualMatrix(tmp._buffer, rhs._buffer, MatrixOperation.None, MatrixOperation.None, -1.0, 1.0);

            return(tmp);
        }
Beispiel #16
0
 public void Set(ColumnWiseMatrix matrix, int row)
 {
     cubes[row].ReadFrom(matrix);
 }
 public static void KroneckerProduct(ColumnWiseMatrix output, Vector lhs, Vector rhs, double alpha = 1.0)
 {
     CuBlasApi.KroneckerProduct(output._buffer, lhs.Buffer, rhs.Buffer, alpha);
 }
        public static ColumnWiseMatrix ElementWiseProduct(ColumnWiseMatrix lhs, ColumnWiseMatrix rhs)
        {
            ColumnWiseMatrix ret = lhs % rhs;

            return(ret);
        }
 public static void Dot(Vector output, ColumnWiseMatrix lhs, Vector rhs, MatrixOperation lhsOperation = MatrixOperation.None, double alpha = 1.0, double beta = 0.0)
 {
     lhs.Dot(output, rhs, lhsOperation, alpha, beta);
 }
Beispiel #20
0
 public Tensor(ColumnWiseMatrix rhs)
     : this(rhs.nRows, rhs.nCols, 1, rhs.memorySpace, rhs.mathDomain)
 {
     ReadFrom(rhs);
 }
 public static void Multiply(ColumnWiseMatrix output, ColumnWiseMatrix lhs, ColumnWiseMatrix rhs, MatrixOperation lhsOperation = MatrixOperation.None, MatrixOperation rhsOperation = MatrixOperation.None, double alpha = 1.0, double beta = 0.0)
 {
     lhs.Multiply(output, rhs, lhsOperation, rhsOperation, alpha, beta);
 }