예제 #1
0
        public Vector Add(Vector rhs, double alpha = 1.0)
        {
            Debug.Assert(denseSize == rhs.Size);
            Debug.Assert(memorySpace == rhs.memorySpace);
            Debug.Assert(mathDomain == rhs.mathDomain);
            Debug.Assert(Buffer.pointer != 0);
            Debug.Assert(rhs.Buffer.pointer != 0);

            Vector ret = new Vector(rhs.Size);

            CuSparseApi.SparseAdd(ret.Buffer, _buffer, rhs.Buffer, alpha);

            return(ret);
        }
예제 #2
0
        public static Vector operator -(Vector lhs, SparseVector rhs)
        {
            Debug.Assert(lhs.Size == rhs.denseSize);
            Debug.Assert(lhs.memorySpace == rhs.memorySpace);
            Debug.Assert(lhs.mathDomain == rhs.mathDomain);
            Debug.Assert(lhs.Buffer.pointer != 0);
            Debug.Assert(rhs.Buffer.pointer != 0);

            Vector ret = new Vector(lhs.Size);

            CuSparseApi.SparseAdd(ret.Buffer, rhs._buffer, lhs.Buffer, -1.0);

            return(ret);
        }
예제 #3
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="alpha"></param>
        public void Dot(Vector output, Vector rhs, MatrixOperation lhsOperation = MatrixOperation.None, double alpha = 1.0)
        {
            Debug.Assert(rhs.Size == nCols);
            Debug.Assert(output.Size == rhs.Size);
            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);

            CuSparseApi.SparseDot(output.Buffer, _buffer, rhs.Buffer, lhsOperation, alpha);
        }
예제 #4
0
        public static Vector operator *(CompressedSparseRowMatrix lhs, Vector rhs)
        {
            Debug.Assert(rhs.Size == 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);

            Vector ret = new Vector(rhs.Size, lhs.memorySpace, lhs.mathDomain);

            CuSparseApi.SparseDot(ret.Buffer, lhs._buffer, rhs.Buffer, MatrixOperation.None, 1.0);

            return(ret);
        }
예제 #5
0
        public static ColumnWiseMatrix operator *(CompressedSparseRowMatrix 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, lhs.mathDomain);

            CuSparseApi.SparseMultiply(ret.Buffer as MemoryTile, lhs._buffer, rhs.Buffer as MemoryTile, lhs.nRows, rhs.nRows, MatrixOperation.None, MatrixOperation.None, 1.0);

            return(ret);
        }
예제 #6
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)
        {
            Debug.Assert(rhs.nRows == nCols);
            Debug.Assert(output.nRows == nRows);
            Debug.Assert(output.nCols == 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);

            CuSparseApi.SparseMultiply(output.Buffer as MemoryTile, _buffer, rhs.Buffer as MemoryTile, nRows, rhs.nRows, lhsOperation, rhsOperation, alpha);
        }