Skip to content

Commit d82b61b

Browse files
authored
654 grb::set matrix to matrix broken in mixed domain (#290)
This MR fixes the behaviour of `grb::set( matrix, * )` by 1) correctly interpreting output masks and 2) fixes the behaviour of casting values from the input matrix value type to that of the output matrix. This MR also - adds a unit test for both fixes to guard against regressions; - fixes / updates the base specification of `grb::set( matrix, * )`; - allows for `grb::set( matrix, matrix[, scalar] )` to work for two matrices with different index / offset types; - improves debug tracing for the reference `Compressed_Storage` class; - includes minor code style fixes. Thanks to Benjamin Lozes for initially identifying the issue and providing the fix!
1 parent 3ff4480 commit d82b61b

File tree

9 files changed

+491
-174
lines changed

9 files changed

+491
-174
lines changed

include/graphblas/base/io.hpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,13 +1181,14 @@ namespace grb {
11811181
*/
11821182
template<
11831183
Descriptor descr = descriptors::no_operation,
1184-
typename OutputType, typename RIT, typename CIT, typename NIT,
1185-
typename InputType,
1184+
typename OutputType, typename InputType,
1185+
typename RIT1, typename CIT1, typename NIT1,
1186+
typename RIT2, typename CIT2, typename NIT2,
11861187
Backend backend
11871188
>
11881189
RC set(
1189-
Matrix< OutputType, backend, RIT, CIT, NIT > &C,
1190-
const Matrix< InputType, backend, RIT, CIT, NIT > &A,
1190+
Matrix< OutputType, backend, RIT1, CIT1, NIT1 > &A,
1191+
const Matrix< InputType, backend, RIT2, CIT2, NIT2 > &C,
11911192
const Phase &phase = EXECUTE,
11921193
const typename std::enable_if<
11931194
!grb::is_object< OutputType >::value &&
@@ -1198,8 +1199,8 @@ namespace grb {
11981199
const bool should_not_call_base_matrix_set = false;
11991200
assert( should_not_call_base_matrix_set );
12001201
#endif
1201-
(void) C;
12021202
(void) A;
1203+
(void) C;
12031204
(void) phase;
12041205
return UNSUPPORTED;
12051206
}
@@ -1222,10 +1223,10 @@ namespace grb {
12221223
* mutually exclusive for this primitive.
12231224
* \endparblock
12241225
*
1225-
* @tparam DataType The type of each element in the given matrix.
1226-
* @tparam MaskType The type of each element in the given mask.
1227-
* @tparam ValueType The type of the given value. Should be convertible
1228-
* to \a DataType.
1226+
* @tparam OutputType The type of each element in the given matrix.
1227+
* @tparam MaskType The type of each element in the given mask.
1228+
* @tparam ValueType The type of the given value. Should be convertible
1229+
* to \a OutputType.
12291230
* @tparam RIT The integer type for encoding row indices.
12301231
* @tparam CIT The integer type for encoding column indices.
12311232
* @tparam NIT The integer type for encoding nonzero indices.
@@ -1264,7 +1265,7 @@ namespace grb {
12641265
*
12651266
* When \a descr includes #grb::descriptors::no_casting then code shall not
12661267
* compile if one of the following conditions are met:
1267-
* -# \a ValueType does not match \a DataType; or
1268+
* -# \a ValueType does not match \a OutputType; or
12681269
* -# \a MaskType does not match <tt>bool</tt>.
12691270
*
12701271
* In these cases, the code shall not compile: implementations must throw
@@ -1292,18 +1293,18 @@ namespace grb {
12921293
*/
12931294
template<
12941295
Descriptor descr = descriptors::no_operation,
1295-
typename DataType, typename RIT, typename CIT, typename NIT,
1296-
typename MaskType,
1297-
typename ValueType,
1296+
typename OutputType, typename MaskType, typename ValueType,
1297+
typename RIT1, typename CIT1, typename NIT1,
1298+
typename RIT2, typename CIT2, typename NIT2,
12981299
Backend backend
12991300
>
13001301
RC set(
1301-
Matrix< DataType, backend, RIT, CIT, NIT > &C,
1302-
const Matrix< MaskType, backend, RIT, CIT, NIT > &mask,
1303-
const ValueType& val,
1302+
Matrix< OutputType, backend, RIT1, CIT1, NIT1 > &C,
1303+
const Matrix< MaskType, backend, RIT2, CIT2, NIT2 > &mask,
1304+
const ValueType &val,
13041305
const Phase &phase = EXECUTE,
13051306
const typename std::enable_if<
1306-
!grb::is_object< DataType >::value &&
1307+
!grb::is_object< OutputType >::value &&
13071308
!grb::is_object< ValueType >::value &&
13081309
!grb::is_object< MaskType >::value,
13091310
void >::type * const = nullptr

include/graphblas/bsp1d/io.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ namespace grb {
17231723
// each thread writes to a different interval of the destination array
17241724
// give pointers to hint at memmove whenever possible
17251725
// (StorageType should be trivially copyable)
1726-
std::copy_n(
1726+
(void) std::copy_n(
17271727
local_out.data(), num_nnz_local,
17281728
out.data() + first_nnz_local
17291729
);

include/graphblas/nonblocking/io.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,8 @@ namespace grb {
11341134
std::cout << "Called grb::set (matrix-to-matrix, nonblocking)" << std::endl;
11351135
#endif
11361136
// static checks
1137-
NO_CAST_ASSERT( ( !(descr & descriptors::no_casting) ||
1137+
NO_CAST_ASSERT(
1138+
( !(descr & descriptors::no_casting) ||
11381139
std::is_same< InputType, OutputType >::value
11391140
), "grb::set",
11401141
"called with non-matching value types" );
@@ -1170,11 +1171,12 @@ namespace grb {
11701171
template<
11711172
Descriptor descr = descriptors::no_operation,
11721173
typename OutputType, typename InputType1, typename InputType2,
1173-
typename RIT, typename CIT, typename NIT
1174+
typename RIT1, typename CIT1, typename NIT1,
1175+
typename RIT2, typename CIT2, typename NIT2
11741176
>
11751177
RC set(
1176-
Matrix< OutputType, nonblocking, RIT, CIT, NIT > &C,
1177-
const Matrix< InputType1, nonblocking, RIT, CIT, NIT > &A,
1178+
Matrix< OutputType, nonblocking, RIT1, CIT1, NIT1 > &C,
1179+
const Matrix< InputType1, nonblocking, RIT2, CIT2, NIT2 > &A,
11781180
const InputType2 &val,
11791181
const Phase &phase = EXECUTE,
11801182
const typename std::enable_if<

0 commit comments

Comments
 (0)