Skip to content

Commit

Permalink
Adding transpose capability to input matrix of assign.
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-smcmillan committed Jun 26, 2018
1 parent f542e1d commit aa8dd92
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/graphblas/Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ namespace GraphBLAS
class Matrix
{
public:
typedef matrix_tag tag_type;

typedef matrix_tag tag_type;

typedef ScalarT ScalarType;
typedef ScalarT ScalarType;
typedef typename detail::matrix_generator::result<
ScalarT,
detail::SparsenessCategoryTag,
Expand Down
22 changes: 21 additions & 1 deletion src/graphblas/TransposeView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace GraphBLAS
class TransposeView
{
public:
typedef matrix_tag tag_type;

typedef typename backend::TransposeView<
typename MatrixT::BackendType> BackendType;
typedef typename MatrixT::ScalarType ScalarType;
Expand All @@ -54,7 +56,6 @@ namespace GraphBLAS
{
}


~TransposeView() { }

/// @todo need to change to mix and match internal types
Expand Down Expand Up @@ -272,6 +273,25 @@ namespace GraphBLAS
IndexType col_index,
bool replace_flag);

//--------------------------------------------------------------------
// 4.3.7.2: assign - standard matrix variant
template<typename CMatrixT,
typename MaskT,
typename AccumT,
typename AMatrixT,
typename RowSequenceT,
typename ColSequenceT,
typename std::enable_if<
std::is_same<matrix_tag,
typename AMatrixT::tag_type>::value,
int>::type>
friend inline void assign(CMatrixT &C,
MaskT const &Mask,
AccumT accum,
AMatrixT const &A,
RowSequenceT const &row_indices,
ColSequenceT const &col_indices,
bool replace_flag);

//--------------------------------------------------------------------
// 4.3.8.2: matrix variant
Expand Down
49 changes: 48 additions & 1 deletion src/graphblas/platforms/sequential/sparse_assign.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace GraphBLAS
{
namespace backend
{
//********************************************************************
struct IndexCompare
{
inline bool operator()(std::pair<IndexType, IndexType> const &i1,
Expand All @@ -45,6 +46,7 @@ namespace GraphBLAS
}
};

//********************************************************************
// Builds a simple mapping
template <typename SequenceT>
void compute_outin_mapping(SequenceT const & Indices,
Expand All @@ -64,6 +66,7 @@ namespace GraphBLAS
std::sort(inputOrder.begin(), inputOrder.end(), IndexCompare());
}

//********************************************************************
template <typename TScalarT,
typename AScalarT>
void vectorExpand(std::vector<std::tuple<IndexType, TScalarT>> &vec_dest,
Expand Down Expand Up @@ -130,6 +133,7 @@ namespace GraphBLAS
}
}

//********************************************************************
template<typename TScalarT,
typename AScalarT,
typename RowSequenceT,
Expand Down Expand Up @@ -179,6 +183,49 @@ namespace GraphBLAS
}
}

//********************************************************************
template<typename TScalarT,
typename AMatrixT,
typename RowSequenceT,
typename ColSequenceT>
void matrixExpand(LilSparseMatrix<TScalarT> &T,
backend::TransposeView<AMatrixT> const &A,
RowSequenceT const &row_Indices,
ColSequenceT const &col_Indices)
{
// NOTE!! - Backend code. We expect that all dimension
// checks done elsewhere.
typedef typename AMatrixT::ScalarType AScalarT;
//typedef std::vector<std::tuple<IndexType,AScalarT> > ARowType;
typedef std::vector<std::tuple<IndexType,TScalarT> > TRowType;

T.clear();

// Build the mapping pairs once up front
std::vector<std::pair<IndexType, IndexType>> oi_pairs;
compute_outin_mapping(col_Indices, oi_pairs);

// Walk the rows
for (IndexType in_row_index = 0;
in_row_index < row_Indices.size();
++in_row_index)
{
IndexType out_row_index = row_Indices[in_row_index];
auto row(A.getRow(in_row_index));
auto row_it = row.begin();

TRowType out_row;

// Extract the values from the row
//std::cerr << "Expanding row " << in_row_index << " to " << out_row_index << std::endl;
vectorExpand(out_row, row, oi_pairs);

if (!out_row.empty())
T.setRow(out_row_index, out_row);
}
}

//********************************************************************
template <typename ValueT, typename RowIteratorT, typename ColIteratorT >
void assignConstant(LilSparseMatrix<ValueT> &T,
ValueT const value,
Expand All @@ -204,7 +251,7 @@ namespace GraphBLAS
}
}


//********************************************************************
template <typename ValueT,
typename RowIndicesT,
typename ColIndicesT>
Expand Down
6 changes: 6 additions & 0 deletions src/test/test_assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ BOOST_AUTO_TEST_CASE(assign_vec_test_mask_no_accum)
BOOST_CHECK_EQUAL(w, result2);
}

//****************************************************************************
BOOST_AUTO_TEST_CASE(assign_vec_test_mask_accum)
{
// w = { 8, 9, 1, 7, - }
Expand Down Expand Up @@ -376,6 +377,11 @@ BOOST_AUTO_TEST_CASE(assign_mat_test_bad_dimensions)
(assign(c, GraphBLAS::NoMask(), GraphBLAS::NoAccumulate(),
a, vect_I, vect_J)),
DimensionException);

BOOST_CHECK_THROW(
(assign(c, GraphBLAS::NoMask(), GraphBLAS::NoAccumulate(),
transpose(a), vect_I, vect_J)),
DimensionException);
}

//****************************************************************************
Expand Down

0 comments on commit aa8dd92

Please sign in to comment.