@@ -37,14 +37,13 @@ class ChunkCacher {
37
37
store_ = store;
38
38
}
39
39
40
- template <size_t N>
41
- ElementType operator ()(const Index (&indices)[N]) {
40
+ ElementType get_next_element () {
42
41
if (current_index_ < array_size_)
43
42
return *(array_.data () + current_index_++);
44
-
45
- load_chunk (indices);
46
43
47
- return (*this )(indices);
44
+ load_next_chunk ();
45
+
46
+ return get_next_element ();
48
47
}
49
48
50
49
private:
@@ -56,23 +55,28 @@ class ChunkCacher {
56
55
array_;
57
56
Index current_index_ = 0 ;
58
57
Index array_size_ = 0 ;
58
+ Index chunk_index_ = 0 ;
59
59
60
- template <size_t N>
61
- void load_chunk (const Index (&indices)[N]) {
60
+ void load_next_chunk () {
62
61
const auto shape = store_.domain ().shape ();
63
- const auto chunk_shape = store_.chunk_layout ().value ().read_chunk ().shape ();
62
+ const auto chunk_shape =
63
+ store_.chunk_layout ().value ().read_chunk ().shape ();
64
64
65
65
std::vector<Index> chunk_starts (1 );
66
66
std::vector<Index> chunk_ends (1 );
67
67
68
- const Index chunk_index = indices[0 ] / chunk_shape[0 ];
69
- chunk_starts[0 ] = chunk_index * chunk_shape[0 ];
68
+ chunk_starts[0 ] = chunk_index_ * chunk_shape[0 ];
70
69
chunk_ends[0 ] = std::min (shape[0 ], chunk_starts[0 ] + chunk_shape[0 ]);
71
70
72
- array_ = tensorstore::Read<tensorstore::zero_origin>(store_ | tensorstore::Dims (0 ).HalfOpenInterval (chunk_starts, chunk_ends)).value ();
71
+ array_ = tensorstore::Read<tensorstore::zero_origin>(
72
+ store_ | tensorstore::Dims (0 ).HalfOpenInterval (
73
+ chunk_starts, chunk_ends))
74
+ .value ();
73
75
const auto array_shape = array_.shape ();
74
76
current_index_ = 0 ;
75
- array_size_ = std::accumulate (array_shape.begin (), array_shape.end (), 1 , std::multiplies<Index>());
77
+ array_size_ = std::accumulate (array_shape.begin (), array_shape.end (), 1 ,
78
+ std::multiplies<Index>());
79
+ chunk_index_ += 1 ;
76
80
}
77
81
};
78
82
@@ -171,7 +175,7 @@ class VczClass::Impl {
171
175
t_ref = " A" ;
172
176
t_alt = " B" ;
173
177
t_marker = " ID" ;
174
- t_pos = m_variant_position_array ({m_marker_index} );
178
+ t_pos = m_variant_position_array. get_next_element ( );
175
179
t_chr = " 1" ;
176
180
t_altFreq = 0.0 ;
177
181
t_altCounts = 0.0 ;
@@ -185,10 +189,8 @@ class VczClass::Impl {
185
189
186
190
for (Index sample_index = 0 ; sample_index < sample_count;
187
191
sample_index++) {
188
- const int8_t a =
189
- m_call_genotype_array ({m_marker_index, sample_index, 0 });
190
- const int8_t b =
191
- m_call_genotype_array ({m_marker_index, sample_index, 1 });
192
+ const int8_t a = m_call_genotype_array.get_next_element ();
193
+ const int8_t b = m_call_genotype_array.get_next_element ();
192
194
193
195
if (a >= 0 && b >= 0 ) {
194
196
const double dosage = a + b;
0 commit comments