Skip to content

Commit 498f5c1

Browse files
committed
Tidy up VCZ.cpp
1 parent 21dfcbe commit 498f5c1

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/VCZ.cpp

+19-17
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ class ChunkCacher {
3737
store_ = store;
3838
}
3939

40-
template <size_t N>
41-
ElementType operator()(const Index (&indices)[N]) {
40+
ElementType get_next_element() {
4241
if (current_index_ < array_size_)
4342
return *(array_.data() + current_index_++);
44-
45-
load_chunk(indices);
4643

47-
return (*this)(indices);
44+
load_next_chunk();
45+
46+
return get_next_element();
4847
}
4948

5049
private:
@@ -56,23 +55,28 @@ class ChunkCacher {
5655
array_;
5756
Index current_index_ = 0;
5857
Index array_size_ = 0;
58+
Index chunk_index_ = 0;
5959

60-
template <size_t N>
61-
void load_chunk(const Index (&indices)[N]) {
60+
void load_next_chunk() {
6261
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();
6464

6565
std::vector<Index> chunk_starts(1);
6666
std::vector<Index> chunk_ends(1);
6767

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];
7069
chunk_ends[0] = std::min(shape[0], chunk_starts[0] + chunk_shape[0]);
7170

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();
7375
const auto array_shape = array_.shape();
7476
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;
7680
}
7781
};
7882

@@ -171,7 +175,7 @@ class VczClass::Impl {
171175
t_ref = "A";
172176
t_alt = "B";
173177
t_marker = "ID";
174-
t_pos = m_variant_position_array({m_marker_index});
178+
t_pos = m_variant_position_array.get_next_element();
175179
t_chr = "1";
176180
t_altFreq = 0.0;
177181
t_altCounts = 0.0;
@@ -185,10 +189,8 @@ class VczClass::Impl {
185189

186190
for (Index sample_index = 0; sample_index < sample_count;
187191
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();
192194

193195
if (a >= 0 && b >= 0) {
194196
const double dosage = a + b;

0 commit comments

Comments
 (0)