Exemple #1
0
        /// <summary>
        /// Copy denseVector to host, numerically finds the non-zero indices, and then copy back to device
        /// </summary>
        public CompressedSparseRowMatrix(ColumnWiseMatrix denseMatrix)
            : base(false, denseMatrix.memorySpace, denseMatrix.mathDomain)
        {
            _buffer = new SparseMemoryTile(0, 0, 0, 0, (uint)denseMatrix.nRows, (uint)denseMatrix.nCols, denseMatrix.memorySpace, denseMatrix.mathDomain);

            switch (denseMatrix.mathDomain)
            {
            case MathDomain.Int:
                Compress <int>(denseMatrix);
                break;

            case MathDomain.Float:
                Compress <float>(denseMatrix);
                break;

            case MathDomain.Double:
                Compress <double>(denseMatrix);
                break;

            default:
                break;
            }

            SyncPointers();
        }
        public static void SparseMultiply(MemoryTile A, SparseMemoryTile B, MemoryTile C, int leadingDimensionB, int leadingDimensionC, MatrixOperation bOperation, MatrixOperation cOperation, double alpha)
        {
            int err = _SparseMultiplyRaw(A.pointer, B.pointer, C.pointer, B.size, B.nonZeroColumnIndices, B.nNonZeroRows, B.nRows, C.nRows, C.nCols, B.memorySpace, B.mathDomain, (uint)leadingDimensionB, (uint)leadingDimensionC, bOperation, alpha);

            if (err != 0)
            {
                Exceptions.CuBlasKernelExceptionFactory.ThrowException("_SparseMultiplyRaw", err);
            }
        }
        public static void SparseDot(MemoryBuffer y, SparseMemoryTile A, MemoryBuffer x, MatrixOperation aOperation, double alpha)
        {
            int err = _SparseDotRaw(y.pointer, A.pointer, x.pointer, A.size, A.nonZeroColumnIndices, A.nNonZeroRows, A.nRows, A.nCols, A.memorySpace, A.mathDomain, aOperation, alpha);

            if (err != 0)
            {
                Exceptions.CuBlasKernelExceptionFactory.ThrowException("_SparseDotRaw", err);
            }
        }
Exemple #4
0
        public CompressedSparseRowMatrix(int nRows, int nCols, Vector nonZeroColumnIndices, Vector nNonZeroRows, MathDomain mathDomain)
            : base(false, // SparseVector doesn't allocate its memory in its buffer, but it uses the convenience vector this.values
                   nonZeroColumnIndices.memorySpace, mathDomain)
        {
            _buffer = new SparseMemoryTile(0, (uint)nonZeroColumnIndices.Size, 0, 0, (uint)nRows, (uint)nCols, nonZeroColumnIndices.memorySpace, mathDomain);
            Debug.Assert(denseSize > nonZeroColumnIndices.Size);

            values = new Vector(nonZeroColumnIndices.Size, nonZeroColumnIndices.memorySpace, mathDomain);
            this.nonZeroColumnIndices = nonZeroColumnIndices;
            this.nNonZeroRows         = nNonZeroRows;

            SyncPointers();
        }