tatami_chunked
Helpers to create custom chunked tatami matrices
Loading...
Searching...
No Matches
SparseSlabFactory.hpp
Go to the documentation of this file.
1#ifndef TATAMI_CHUNKED_SPARSE_SLAB_FACTORY_HPP
2#define TATAMI_CHUNKED_SPARSE_SLAB_FACTORY_HPP
3
4#include <vector>
5#include "SlabCacheStats.hpp"
6
12namespace tatami_chunked {
13
27template<typename Value_, typename Index_, typename Count_ = Index_>
40 my_target_dim(target_dim),
41 my_non_target_dim(non_target_dim),
42 my_slab_size(slab_size),
43 my_needs_value(needs_value),
44 my_needs_index(needs_index),
45 my_number_pool(max_slabs * target_dim)
46 {
48 if (needs_value) {
49 my_value_pool.resize(total_size);
50 }
51 if (needs_index) {
52 my_index_pool.resize(total_size);
53 }
54 }
55
66
76 SparseSlabFactory(target_dim, non_target_dim, stats.slab_size_in_elements, stats.max_slabs_in_cache, needs_value, needs_index) {}
77
81 // Delete the copy constructors as we're passing out pointers.
82 SparseSlabFactory(const SparseSlabFactory&) = delete;
83 SparseSlabFactory& operator=(const SparseSlabFactory&) = delete;
84
85 // Move constructors are okay though.
87 SparseSlabFactory& operator=(SparseSlabFactory&&) = default;
92private:
93 size_t my_offset_slab = 0, my_offset_number = 0;
94 size_t my_target_dim, my_non_target_dim, my_slab_size;
95 bool my_needs_value, my_needs_index;
96 std::vector<Value_> my_value_pool;
97 std::vector<Index_> my_index_pool;
98 std::vector<Count_> my_number_pool;
99
100public:
104 struct Slab {
113 std::vector<Value_*> values;
114
123 std::vector<Index_*> indices;
124
132 };
133
141 Slab output;
142 output.number = my_number_pool.data() + my_offset_number;
143 my_offset_number += my_target_dim;
144
145 if (my_needs_value) {
146 output.values.reserve(my_target_dim);
147 auto vptr = my_value_pool.data() + my_offset_slab;
148 for (size_t p = 0; p < my_target_dim; ++p, vptr += my_non_target_dim) {
149 output.values.push_back(vptr);
150 }
151 }
152
153 if (my_needs_index) {
154 output.indices.reserve(my_target_dim);
155 auto iptr = my_index_pool.data() + my_offset_slab;
156 for (size_t p = 0; p < my_target_dim; ++p, iptr += my_non_target_dim) {
157 output.indices.push_back(iptr);
158 }
159 }
160
161 my_offset_slab += my_slab_size;
162 return output;
163 }
164};
165
166}
167
168#endif
Slab cache statistics.
Methods to handle chunked tatami matrices.
Definition ChunkDimensionStats.hpp:4
Statistics for regular chunks along a dimension.
Definition ChunkDimensionStats.hpp:35
Statistics for slab caching.
Definition SlabCacheStats.hpp:20
Sparse slab.
Definition SparseSlabFactory.hpp:104
std::vector< Index_ * > indices
Definition SparseSlabFactory.hpp:123
std::vector< Value_ * > values
Definition SparseSlabFactory.hpp:113
Count_ * number
Definition SparseSlabFactory.hpp:131
Factory for sparse slabs.
Definition SparseSlabFactory.hpp:28
Slab create()
Definition SparseSlabFactory.hpp:140
SparseSlabFactory(size_t target_dim, size_t non_target_dim, size_t max_slabs, bool needs_value, bool needs_index)
Definition SparseSlabFactory.hpp:64
SparseSlabFactory(size_t target_dim, size_t non_target_dim, size_t slab_size, size_t max_slabs, bool needs_value, bool needs_index)
Definition SparseSlabFactory.hpp:39
SparseSlabFactory(size_t target_dim, size_t non_target_dim, const SlabCacheStats &stats, bool needs_value, bool needs_index)
Definition SparseSlabFactory.hpp:75