Exemplo n.º 1
0
        /**
         * Converts SMatrixTriplet_64 into a SMatrixCC_64.
         *
         * @param src Original matrix which is to be copied.  Not modified.
         * @param dst Destination. Will be a copy.  Modified.
         * @param hist Workspace.  Should be at least as long as the number of columns.  Can be null.
         */
        public static FMatrixSparseCSC convert(FMatrixSparseTriplet src, FMatrixSparseCSC dst, int[] hist)
        {
            if (dst == null)
            {
                dst = new FMatrixSparseCSC(src.numRows, src.numCols, src.nz_length);
            }
            else
            {
                dst.reshape(src.numRows, src.numCols, src.nz_length);
            }

            if (hist == null)
            {
                hist = new int[src.numCols];
            }
            else if (hist.Length >= src.numCols)
            {
                Array.Clear(hist, 0, src.numCols);
            }
            else
            {
                throw new ArgumentException("Length of hist must be at least numCols");
            }

            // compute the number of elements in each columns
            for (int i = 0; i < src.nz_length; i++)
            {
                hist[src.nz_data[i].col]++;
            }

            // define col_idx
            dst.colsum(hist);

            // now write the row indexes and the values
            for (int i = 0; i < src.nz_length; i++)
            {
                FMatrixSparseTriplet.Element e = src.nz_data[i];

                int index = hist[e.col]++;
                dst.nz_rows[index]   = e.row;
                dst.nz_values[index] = e.value;
            }
            dst.indicesSorted = false;

            return(dst);
        }
Exemplo n.º 2
0
        public static FMatrixRMaj convert(FMatrixSparseTriplet src, FMatrixRMaj dst)
        {
            if (dst == null)
            {
                dst = new FMatrixRMaj(src.numRows, src.numCols);
            }
            else
            {
                dst.reshape(src.numRows, src.numCols);
                dst.zero();
            }

            for (int i = 0; i < src.nz_length; i++)
            {
                FMatrixSparseTriplet.Element e = src.nz_data[i];

                dst.unsafe_set(e.row, e.col, e.value);
            }

            return(dst);
        }