1#ifndef TATAMI_CHUNKED_MOCK_DENSE_CHUNK_HPP
2#define TATAMI_CHUNKED_MOCK_DENSE_CHUNK_HPP
16namespace MockDenseChunk_internal {
18template<
typename InflatedValue_>
19using Workspace = std::vector<InflatedValue_>;
26 Core(Blob_ chunk) : my_chunk(std::move(chunk)) {}
31 typedef typename Blob_::value_type value_type;
34 auto get_target_chunkdim(
bool row)
const {
36 return my_chunk.nrow();
38 return my_chunk.ncol();
42 auto get_non_target_chunkdim(
bool row)
const {
44 return my_chunk.ncol();
46 return my_chunk.nrow();
51 template<
typename Index_>
52 void extract(
bool row, Index_ target_start, Index_ target_length, Index_ non_target_start, Index_ non_target_length, Workspace<value_type>& work, value_type* output,
size_t stride)
const {
53 my_chunk.inflate(work);
54 output +=
static_cast<size_t>(target_start) * stride;
56 if (my_chunk.is_row_major() == row) {
57 size_t non_target_chunkdim = get_non_target_chunkdim(row);
58 auto srcptr = work.data() +
static_cast<size_t>(target_start) * non_target_chunkdim +
static_cast<size_t>(non_target_start);
59 for (Index_ p = 0; p < target_length; ++p) {
60 std::copy_n(srcptr, non_target_length, output);
61 srcptr += non_target_chunkdim;
66 size_t target_chunkdim = get_target_chunkdim(row);
67 auto srcptr = work.data() +
static_cast<size_t>(non_target_start) * target_chunkdim +
static_cast<size_t>(target_start);
68 for (Index_ p = 0; p < target_length; ++p) {
69 auto copy_srcptr = srcptr;
70 auto copy_output = output;
71 for (Index_ s = 0; s < non_target_length; ++s) {
72 *copy_output = *copy_srcptr;
74 copy_srcptr += target_chunkdim;
82 template<
typename Index_>
83 void extract(
bool row, Index_ target_start, Index_ target_length,
const std::vector<Index_>& non_target_indices, Workspace<value_type>& work, value_type* output,
size_t stride)
const {
84 my_chunk.inflate(work);
85 output +=
static_cast<size_t>(target_start) * stride;
87 if (my_chunk.is_row_major() == row) {
88 size_t non_target_chunkdim = get_non_target_chunkdim(row);
89 auto srcptr = work.data() +
static_cast<size_t>(target_start) * non_target_chunkdim;
90 for (Index_ p = 0; p < target_length; ++p) {
91 auto copy_output = output;
92 for (
auto x : non_target_indices) {
93 *copy_output = srcptr[x];
96 srcptr += non_target_chunkdim;
101 size_t target_chunkdim = get_target_chunkdim(row);
102 auto srcptr = work.data() +
static_cast<size_t>(target_start);
103 for (Index_ p = 0; p < target_length; ++p) {
104 auto copy_output = output;
105 for (
size_t x : non_target_indices) {
106 *copy_output = srcptr[x * target_chunkdim];
116 template<
typename Index_>
117 void extract(
bool row,
const std::vector<Index_>& target_indices, Index_ non_target_start, Index_ non_target_length, Workspace<value_type>& work, value_type* output,
size_t stride)
const {
118 my_chunk.inflate(work);
120 if (my_chunk.is_row_major() == row) {
121 size_t non_target_chunkdim = get_non_target_chunkdim(row);
122 size_t offset = non_target_start;
123 for (
size_t p : target_indices) {
124 auto srcptr = work.data() + p * non_target_chunkdim + offset;
125 std::copy_n(srcptr, non_target_length, output + p * stride);
129 size_t target_chunkdim = get_target_chunkdim(row);
130 auto srcptr = work.data() +
static_cast<size_t>(non_target_start) * target_chunkdim;
131 for (
size_t p : target_indices) {
132 auto copy_srcptr = srcptr + p;
133 auto copy_output = output + p * stride;
134 for (Index_ s = 0; s < non_target_length; ++s) {
135 *copy_output = *copy_srcptr;
137 copy_srcptr += target_chunkdim;
143 template<
typename Index_>
144 void extract(
bool row,
const std::vector<Index_>& target_indices,
const std::vector<Index_>& non_target_indices, Workspace<value_type>& work, value_type* output,
size_t stride)
const {
145 my_chunk.inflate(work);
147 if (my_chunk.is_row_major() == row) {
148 size_t non_target_chunkdim = get_non_target_chunkdim(row);
149 for (
size_t p : target_indices) {
150 auto srcptr = work.data() + p * non_target_chunkdim;
151 auto copy_output = output + p * stride;
152 for (
auto x : non_target_indices) {
153 *copy_output = srcptr[x];
159 size_t target_chunkdim = get_target_chunkdim(row);
160 for (
size_t p : target_indices) {
161 auto srcptr = work.data() + p;
162 auto copy_output = output + p * stride;
163 for (
size_t x : non_target_indices) {
164 *copy_output = srcptr[x * target_chunkdim];
174 MockBlob(std::vector<double> data,
size_t nrow,
size_t ncol) : my_data(std::move(data)), my_nrow(nrow), my_ncol(ncol) {}
175 MockBlob() =
default;
177 typedef double value_type;
179 bool is_row_major()
const {
184 std::vector<double> my_data;
189 size_t nrow()
const {
193 size_t ncol()
const {
197 void inflate(std::vector<double>& buffer)
const {
198 buffer.resize(my_data.size());
199 std::copy(my_data.begin(), my_data.end(), buffer.begin());
233 MockDenseChunk_internal::Workspace<value_type>
work;
257 MockDenseChunk_internal::Core<MockDenseChunk_internal::MockBlob> my_core;
285 template<
typename Index_>
313 template<
typename Index_>
344 typedef typename Blob_::value_type value_type;
346 typedef MockDenseChunk_internal::Workspace<value_type> Workspace;
348 static constexpr bool use_subset =
false;
358 MockDenseChunk_internal::Core<Blob_> my_core;
364 template<
typename Index_>
369 template<
typename Index_>
405 MockDenseChunk_internal::Workspace<value_type>
work;
427 MockDenseChunk_internal::Core<MockDenseChunk_internal::MockBlob> my_core;
459 template<
typename Index_>
491 template<
typename Index_>
524 template<
typename Index_>
554 template<
typename Index_>
Mock a simple dense chunk for a CustomDenseChunkedMatrix.
Definition mock_dense_chunk.hpp:216
double value_type
Definition mock_dense_chunk.hpp:222
void extract(bool row, Index_ non_target_start, Index_ non_target_length, Workspace &work, value_type *output, size_t stride) const
Definition mock_dense_chunk.hpp:286
static constexpr bool use_subset
Definition mock_dense_chunk.hpp:243
void extract(bool row, const std::vector< Index_ > &non_target_indices, Workspace &work, value_type *output, size_t stride) const
Definition mock_dense_chunk.hpp:314
Mock a subsettable dense chunk for a CustomDenseChunkedMatrix.
Definition mock_dense_chunk.hpp:388
void extract(bool row, Index_ target_start, Index_ target_length, Index_ non_target_start, Index_ non_target_length, Workspace &work, value_type *output, size_t stride) const
Definition mock_dense_chunk.hpp:460
void extract(bool row, const std::vector< Index_ > &target_indices, const std::vector< Index_ > &non_target_indices, Workspace &work, value_type *output, size_t stride) const
Definition mock_dense_chunk.hpp:555
static constexpr bool use_subset
Definition mock_dense_chunk.hpp:415
void extract(bool row, const std::vector< Index_ > &target_indices, Index_ non_target_start, Index_ non_target_length, Workspace &work, value_type *output, size_t stride) const
Definition mock_dense_chunk.hpp:525
void extract(bool row, Index_ target_start, Index_ target_length, const std::vector< Index_ > &non_target_indices, Workspace &work, value_type *output, size_t stride) const
Definition mock_dense_chunk.hpp:492
double value_type
Definition mock_dense_chunk.hpp:394
Create a dense chunk for a CustomDenseChunkedMatrix.
Definition mock_dense_chunk.hpp:339
Methods to handle chunked tatami matrices.
Definition ChunkDimensionStats.hpp:4
Statistics for regular chunks along a dimension.
Definition ChunkDimensionStats.hpp:35
ChunkDimensionStats()
Definition ChunkDimensionStats.hpp:50
Definition mock_dense_chunk.hpp:229
Definition mock_dense_chunk.hpp:401