37
37
namespace matx {
38
38
namespace experimental {
39
39
40
+ // Helper method to create empty storage.
41
+ template <typename T>
42
+ __MATX_INLINE__ static auto makeDefaultNonOwningStorage () {
43
+ raw_pointer_buffer<T, matx_allocator<T>> buf{nullptr , 0 , /* owning=*/ false };
44
+ return basic_storage<decltype (buf)>{std::move (buf)};
45
+ }
46
+
40
47
//
41
48
// MatX implements a universal sparse tensor type that uses a tensor format
42
49
// DSL (Domain Specific Language) to describe a vast space of storage formats.
@@ -51,7 +58,7 @@ namespace experimental {
51
58
// column. Duplicate entries should not occur. Explicit zeros may be stored.
52
59
template <typename ValTensor, typename CrdTensor>
53
60
auto make_tensor_coo (ValTensor &val, CrdTensor &row, CrdTensor &col,
54
- const index_t (&shape)[2], bool owning = false ) {
61
+ const index_t (&shape)[2]) {
55
62
static_assert (ValTensor::Rank () == 1 && CrdTensor::Rank () == 1 );
56
63
using VAL = typename ValTensor::value_type;
57
64
using CRD = typename CrdTensor::value_type;
@@ -66,50 +73,45 @@ auto make_tensor_coo(ValTensor &val, CrdTensor &row, CrdTensor &col,
66
73
ptr[0 ] = 0 ;
67
74
ptr[1 ] = val.Size (0 );
68
75
raw_pointer_buffer<POS, matx_allocator<POS>> topp{ptr, 2 * sizeof (POS),
69
- owning};
76
+ /* owning= */ false };
70
77
basic_storage<decltype (topp)> tp{std::move (topp)};
71
- raw_pointer_buffer<POS, matx_allocator<POS>> emptyp{nullptr , 0 , owning};
72
- basic_storage<decltype (emptyp)> ep{std::move (emptyp)};
73
78
return sparse_tensor_t <VAL, CRD, POS, COO>(
74
- shape, val.GetStorage (), {row.GetStorage (), col.GetStorage ()}, {tp, ep});
79
+ shape, val.GetStorage (), {row.GetStorage (), col.GetStorage ()},
80
+ {tp, makeDefaultNonOwningStorage<POS>()});
75
81
}
76
82
77
83
// Constructs a sparse matrix in CSR format directly from the values, the row
78
84
// positions, and column coordinates vectors. The entries should be sorted by
79
85
// row, then column. Explicit zeros may be stored.
80
86
template <typename ValTensor, typename PosTensor, typename CrdTensor>
81
87
auto make_tensor_csr (ValTensor &val, PosTensor &rowp, CrdTensor &col,
82
- const index_t (&shape)[2], bool owning = false ) {
88
+ const index_t (&shape)[2]) {
83
89
static_assert (ValTensor::Rank () == 1 && CrdTensor::Rank () == 1 &&
84
90
PosTensor::Rank () == 1 );
85
91
using VAL = typename ValTensor::value_type;
86
92
using CRD = typename CrdTensor::value_type;
87
93
using POS = typename PosTensor::value_type;
88
- raw_pointer_buffer<CRD, matx_allocator<CRD>> emptyc{nullptr , 0 , owning};
89
- basic_storage<decltype (emptyc)> ec{std::move (emptyc)};
90
- raw_pointer_buffer<POS, matx_allocator<POS>> emptyp{nullptr , 0 , owning};
91
- basic_storage<decltype (emptyp)> ep{std::move (emptyp)};
92
94
return sparse_tensor_t <VAL, CRD, POS, CSR>(
93
- shape, val.GetStorage (), {ec, col.GetStorage ()}, {ep, rowp.GetStorage ()});
95
+ shape, val.GetStorage (),
96
+ {makeDefaultNonOwningStorage<CRD>(), col.GetStorage ()},
97
+ {makeDefaultNonOwningStorage<POS>(), rowp.GetStorage ()});
94
98
}
95
99
96
100
// Constructs a sparse matrix in CSC format directly from the values,
97
101
// the row coordinates, and column position vectors. The entries should
98
102
// be sorted by column, then row. Explicit zeros may be stored.
99
103
template <typename ValTensor, typename PosTensor, typename CrdTensor>
100
104
auto make_tensor_csc (ValTensor &val, CrdTensor &row, PosTensor &colp,
101
- const index_t (&shape)[2], bool owning = false ) {
105
+ const index_t (&shape)[2]) {
102
106
static_assert (ValTensor::Rank () == 1 && CrdTensor::Rank () == 1 &&
103
107
PosTensor::Rank () == 1 );
104
108
using VAL = typename ValTensor::value_type;
105
109
using CRD = typename CrdTensor::value_type;
106
110
using POS = typename PosTensor::value_type;
107
- raw_pointer_buffer<CRD, matx_allocator<CRD>> emptyc{nullptr , 0 , owning};
108
- basic_storage<decltype (emptyc)> ec{std::move (emptyc)};
109
- raw_pointer_buffer<POS, matx_allocator<POS>> emptyp{nullptr , 0 , owning};
110
- basic_storage<decltype (emptyp)> ep{std::move (emptyp)};
111
111
return sparse_tensor_t <VAL, CRD, POS, CSC>(
112
- shape, val.GetStorage (), {ec, row.GetStorage ()}, {ep, colp.GetStorage ()});
112
+ shape, val.GetStorage (),
113
+ {makeDefaultNonOwningStorage<CRD>(), row.GetStorage ()},
114
+ {makeDefaultNonOwningStorage<POS>(), colp.GetStorage ()});
113
115
}
114
116
115
117
} // namespace experimental
0 commit comments