Пример #1
0
    void pretty_print_matrix(std::ostream &ostr, MatrixT const &mat)
    {
        IndexType rows, cols;
        mat.get_shape(rows, cols);
        typename MatrixT::ScalarType zero(mat.get_zero());

        for (IndexType row = 0; row < rows; ++row)
        {
            ostr << ((row == 0) ? "[[" : " [");
            if (cols > 0)
            {
                auto val = mat.get_value_at(row, 0);
                if (val == zero)
                    ostr << " ";
                else
                    ostr << val;
            }

            for (IndexType col = 1; col < cols; ++col)
            {
                auto val = mat.get_value_at(row, col);
                if (val == zero)
                    ostr << ",  ";
                else
                    ostr << ", " << val;
            }
            ostr << ((row == rows - 1) ? "]]\n" : "]\n");
        }
    }
Пример #2
0
    void row_index_of(MatrixT &mat)
    {
        graphblas::IndexType rows, cols;
        mat.get_shape(rows, cols);

        for (IndexType i = 0; i < rows; ++i)
        {
            for (IndexType j = 0; j < cols; ++j)
            {
                auto mat_ij = mat.get_value_at(i, j);
                if (mat_ij != mat.get_zero())
                {
                    mat.set_value_at(i, j, i);
                }
            }
        }
    }