Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        /// <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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 11
0
 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);
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
 public void Set(ColumnWiseMatrix matrix, int row)
 {
     cubes[row].ReadFrom(matrix);
 }
Exemplo n.º 17
0
 public static void KroneckerProduct(ColumnWiseMatrix output, Vector lhs, Vector rhs, double alpha = 1.0)
 {
     CuBlasApi.KroneckerProduct(output._buffer, lhs.Buffer, rhs.Buffer, alpha);
 }
Exemplo n.º 18
0
        public static ColumnWiseMatrix ElementWiseProduct(ColumnWiseMatrix lhs, ColumnWiseMatrix rhs)
        {
            ColumnWiseMatrix ret = lhs % rhs;

            return(ret);
        }
Exemplo n.º 19
0
 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);
 }
Exemplo n.º 20
0
 public Tensor(ColumnWiseMatrix rhs)
     : this(rhs.nRows, rhs.nCols, 1, rhs.memorySpace, rhs.mathDomain)
 {
     ReadFrom(rhs);
 }
Exemplo n.º 21
0
 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);
 }