65 Output_*
const output,
68 const auto left_NR = left.
nrow();
69 const auto common_dim = left.
ncol();
70 const auto right_NC = right.
ncol();
78 auto right_non_empty = filter_non_empty_sparse(
80 [&](
const RightIndex_) ->
void {}
84 std::optional<std::vector<std::optional<std::vector<Output_> > > > tmp_results;
86 tmp_results.emplace(sanisizer::cast<I<
decltype(tmp_results->size())> >(options.
num_threads - 1));
89 std::fill_n(output, sanisizer::product_unsafe<std::size_t>(left_NR, right_NC), 0);
93 const LeftIndex_ cd_total = (right_non_empty.has_value() ?
static_cast<LeftIndex_
>(right_non_empty->size()) : common_dim);
94 const int num_used =
tatami::parallelize([&](
int t, LeftIndex_ start, LeftIndex_ length) ->
void {
95 std::optional<std::vector<Output_> > tmp_output;
97 if (!do_parallel || t == 0) {
100 tmp_output.emplace(sanisizer::product<I<
decltype(tmp_output->size())> >(left_NR, right_NC));
101 outptr = tmp_output->data();
104 auto task = [&](std::unique_ptr<tatami::OracularDenseExtractor<LeftValue_, LeftIndex_> >& ext,
auto converter) ->
void {
107 for (LeftIndex_ cd = 0; cd < length; ++cd) {
108 const auto lptr = ext->fetch(dbuffer.data());
109 const auto actual_cd = converter(cd);
110 const auto& right_values = rhs_data.value[actual_cd];
111 const auto& right_indices = rhs_data.index[actual_cd];
112 const RightIndex_ right_nnz = right_values.size();
113 for (LeftIndex_ lr = 0; lr < left_NR; ++lr) {
114 const Output_ mult = lptr[lr];
115 for (RightIndex_ x = 0; x < right_nnz; ++x) {
116 outptr[sanisizer::nd_offset<std::size_t>(right_indices[x], right_NC, lr)] += mult *
static_cast<Output_
>(right_values[x]);
122 std::vector<std::vector<LeftValue_> > left_buffers;
123 std::vector<const LeftValue_*> left_ptrs;
125 const LeftIndex_ max_block_cols = sanisizer::min(length, options.
block_size);
126 left_buffers.reserve(max_block_cols);
127 for (LeftIndex_ cd = 0; cd < max_block_cols; ++cd) {
130 sanisizer::resize(left_ptrs, max_block_cols);
134 while (cd < length) {
135 const auto cd_num = sanisizer::min(options.
block_size, length - cd);
136 for (LeftIndex_ cd_counter = 0; cd_counter < cd_num; ++cd_counter) {
137 left_ptrs[cd_counter] = ext->fetch(left_buffers[cd_counter].data());
140 for (LeftIndex_ lr = 0; lr < left_NR; ++lr) {
141 for (LeftIndex_ cd_counter = 0; cd_counter < cd_num; ++cd_counter) {
142 const auto mult = left_ptrs[cd_counter][lr];
143 const auto actual_cd = converter(cd + cd_counter);
144 const auto& right_values = rhs_data.value[actual_cd];
145 const auto& right_indices = rhs_data.index[actual_cd];
146 const RightIndex_ right_nnz = right_values.size();
147 for (RightIndex_ x = 0; x < right_nnz; ++x) {
148 outptr[sanisizer::nd_offset<std::size_t>(right_indices[x], right_NC, lr)] += mult *
static_cast<Output_
>(right_values[x]);
158 if (right_non_empty.has_value()) {
162 [&](
const LeftIndex_ cd) -> LeftIndex_ {
163 return (*right_non_empty)[start + cd];
170 [&](
const LeftIndex_ cd) -> LeftIndex_ {
176 if (do_parallel && t > 0) {
177 (*tmp_results)[t - 1] = std::move(tmp_output);
182 for (
int u = 1; u < num_used; ++u) {
183 const auto& tmp = *((*tmp_results)[u - 1]);
184 const auto N = tmp.size();
185 for (I<
decltype(N)> x = 0; x < N; ++x) {
void multiply_dense_column_with_sparse_column_matrix_to_row_output(const tatami::Matrix< LeftValue_, LeftIndex_ > &left, const tatami::Matrix< RightValue_, RightIndex_ > &right, Output_ *const output, const MultiplyDenseColumnWithSparseColumnMatrixToRowOutputOptions &options)
Definition column_to_row.hpp:62