/**
         * 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 DMatrixSparseCSC convert(DMatrixSparseTriplet src, DMatrixSparseCSC dst, int[] hist)
        {
            if (dst == null)
            {
                dst = new DMatrixSparseCSC(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++)
            {
                DMatrixSparseTriplet.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);
        }
Example #2
0
        public static bool isEquals(DMatrixSparseTriplet a, DMatrixSparseTriplet b, double tol)
        {
            if (!isSameShape(a, b))
            {
                return(false);
            }

            for (int i = 0; i < a.nz_length; i++)
            {
                DMatrixSparseTriplet.Element ea = a.nz_data[i];
                DMatrixSparseTriplet.Element eb = b.nz_data[b.nz_index(ea.row, ea.col)];

                if (eb == null || Math.Abs(ea.value - eb.value) > tol)
                {
                    return(false);
                }
            }
            return(true);
        }
        public static DMatrixRMaj convert(DMatrixSparseTriplet src, DMatrixRMaj dst)
        {
            if (dst == null)
            {
                dst = new DMatrixRMaj(src.numRows, src.numCols);
            }
            else
            {
                dst.reshape(src.numRows, src.numCols);
                dst.zero();
            }

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

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

            return(dst);
        }