64 Output_*
const output,
67 const auto left_NR = left.
nrow();
68 const auto common_dim = left.
ncol();
69 const auto right_NC = right.
ncol();
72 std::optional<std::vector<std::optional<std::vector<Output_> > > > tmp_results;
74 tmp_results.emplace(sanisizer::cast<I<
decltype(tmp_results->size())> >(options.
num_threads - 1));
77 std::fill_n(output, sanisizer::product_unsafe<std::size_t>(left_NR, right_NC), 0);
79 const int num_used =
tatami::parallelize([&](
int t, LeftIndex_ start, LeftIndex_ length) ->
void {
83 std::optional<std::vector<Output_> > tmp_output;
85 if (!do_parallel || t == 0) {
88 tmp_output.emplace(sanisizer::product<I<
decltype(tmp_output->size())> >(left_NR, right_NC));
89 outptr = tmp_output->data();
97 for (LeftIndex_ cd = 0; cd < length; ++cd) {
98 const auto lptr = left_ext->fetch(dbuffer.data());
99 const auto rrange = right_ext->fetch(vbuffer.data(), ibuffer.data());
102 if (rrange.number == 0) {
106 for (LeftIndex_ lr = 0; lr < left_NR; ++lr) {
107 const Output_ mult = lptr[lr];
108 for (RightIndex_ x = 0; x < rrange.number; ++x) {
109 outptr[sanisizer::nd_offset<std::size_t>(rrange.index[x], right_NC, lr)] += mult *
static_cast<Output_
>(rrange.value[x]);
115 std::vector<std::vector<LeftValue_> > left_dbuffers;
116 std::vector<const LeftValue_*> left_ptrs;
117 std::vector<std::vector<RightValue_> > right_vbuffers;
118 std::vector<std::vector<RightIndex_> > right_ibuffers;
119 std::vector<tatami::SparseRange<RightValue_, RightIndex_> > right_ranges;
121 const LeftIndex_ max_block_cols = sanisizer::min(length, options.
block_size);
122 left_dbuffers.reserve(max_block_cols);
123 right_vbuffers.reserve(max_block_cols);
124 right_ibuffers.reserve(max_block_cols);
125 for (LeftIndex_ cd = 0; cd < max_block_cols; ++cd) {
130 sanisizer::resize(left_ptrs, max_block_cols);
131 sanisizer::resize(right_ranges, max_block_cols);
135 while (cd < length) {
138 LeftIndex_ cd_num = 0;
140 auto lptr = left_ext->fetch(left_dbuffers[cd_num].data());
141 auto rrange = right_ext->fetch(right_vbuffers[cd_num].data(), right_ibuffers[cd_num].data());
144 if (rrange.number == 0) {
149 left_ptrs[cd_num] = lptr;
150 right_ranges[cd_num] = std::move(rrange);
154 if (sanisizer::is_equal(cd_num, options.
block_size)) {
157 }
while (cd < length);
159 for (LeftIndex_ lr = 0; lr < left_NR; ++lr) {
160 for (LeftIndex_ cd_counter = 0; cd_counter < cd_num; ++cd_counter) {
161 const auto mult = left_ptrs[cd_counter][lr];
162 const auto rrange = right_ranges[cd_counter];
163 for (RightIndex_ x = 0; x < rrange.number; ++x) {
164 outptr[sanisizer::nd_offset<std::size_t>(rrange.index[x], right_NC, lr)] += mult *
static_cast<Output_
>(rrange.value[x]);
171 if (do_parallel && t > 0) {
172 (*tmp_results)[t - 1] = std::move(tmp_output);
177 for (
int u = 1; u < num_used; ++u) {
178 const auto& tmp = *((*tmp_results)[u - 1]);
179 const auto N = tmp.size();
180 for (I<
decltype(N)> x = 0; x < N; ++x) {
void multiply_dense_column_with_sparse_row_matrix_to_row_output(const tatami::Matrix< LeftValue_, LeftIndex_ > &left, const tatami::Matrix< RightValue_, RightIndex_ > &right, Output_ *const output, const MultiplyDenseColumnWithSparseRowMatrixToRowOutputOptions &options)
Definition row_to_row.hpp:61