Skip to content

Commit 5fff7d4

Browse files
committed
Adding tests for parse_slices
1 parent 475d084 commit 5fff7d4

File tree

8 files changed

+27
-75
lines changed

8 files changed

+27
-75
lines changed

libtokamap/TODO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- [ ] Make mapping directory nesting configurable
1111
- [x] ~~Remove SignalType logic~~
1212
- [ ] Add C++20 template constraints
13-
- [ ] Replace std::string{} with string_literals
13+
- [x] ~~Replace std::string{} with string_literals~~
1414
- [ ] Fix logging
15-
- [ ] Add tests for parse_slices
15+
- [x] ~~Add tests for parse_slices~~
1616
- [x] ~~Replace gsl::span with std::span~~

libtokamap/src/map_types/data_source_mapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ libtokamap::TypedDataArray libtokamap::DataSourceMapping::map(const MapArguments
2424
}
2525
}
2626
TypedDataArray array = m_data_source->get(args, arguments, m_ram_cache.get());
27-
subset::update_array(array, m_slice, m_scale, m_offset);
27+
update_array(array, m_slice, m_scale, m_offset);
2828
return array;
2929
}
3030

libtokamap/src/utils/subset.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,13 @@ template <typename T> libtokamap::SubsetInfo parse_slice(const T& slice, size_t
5151
throw std::runtime_error{"invalid subset: " + slice.to_string()};
5252
}
5353

54-
std::vector<libtokamap::SubsetInfo> parse_slices(const std::string& slice, const std::vector<size_t>& shape)
55-
{
56-
size_t dim_idx = 0;
57-
std::vector<libtokamap::SubsetInfo> subsets;
58-
for (const auto& token : ctre::search_all<token_re>(slice)) {
59-
if (dim_idx == shape.size()) {
60-
throw std::runtime_error{"to many slices provided"};
61-
}
62-
subsets.push_back(parse_slice(token.get<1>(), shape[dim_idx]));
63-
++dim_idx;
64-
}
65-
return subsets;
66-
}
67-
6854
void apply_subset(libtokamap::TypedDataArray& input, const std::optional<std::string>& slice)
6955
{
7056
if (!slice) {
7157
return;
7258
}
7359

74-
std::vector<libtokamap::SubsetInfo> subset_info = parse_slices(slice.value(), input.shape());
60+
std::vector<libtokamap::SubsetInfo> subset_info = libtokamap::parse_slices(slice.value(), input.shape());
7561
using libtokamap::DataType;
7662
switch (libtokamap::type_index_map(input.type_index())) {
7763
case DataType::Short:
@@ -154,8 +140,22 @@ void apply_scale_offset(libtokamap::TypedDataArray& input, std::optional<float>
154140

155141
} // namespace
156142

157-
void libtokamap::subset::update_array(libtokamap::TypedDataArray& input, const std::optional<std::string>& slice,
158-
std::optional<float> scale_factor, std::optional<float> offset)
143+
std::vector<libtokamap::SubsetInfo> libtokamap::parse_slices(const std::string& slice, const std::vector<size_t>& shape)
144+
{
145+
size_t dim_idx = 0;
146+
std::vector<libtokamap::SubsetInfo> subsets;
147+
for (const auto& token : ctre::search_all<token_re>(slice)) {
148+
if (dim_idx == shape.size()) {
149+
throw std::runtime_error{"to many slices provided"};
150+
}
151+
subsets.push_back(parse_slice(token.get<1>(), shape[dim_idx]));
152+
++dim_idx;
153+
}
154+
return subsets;
155+
}
156+
157+
void libtokamap::update_array(libtokamap::TypedDataArray& input, const std::optional<std::string>& slice,
158+
std::optional<float> scale_factor, std::optional<float> offset)
159159
{
160160
apply_subset(input, slice);
161161
apply_scale_offset(input, scale_factor, offset);

libtokamap/src/utils/subset.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include <chrono>
4-
#include <cmath>
54
#include <cstdint>
65
#include <cstdlib>
76
#include <ctime>
@@ -11,12 +10,15 @@
1110
#include <optional>
1211
#include <string>
1312
#include <string_view>
13+
#include <vector>
1414

1515
#include "map_types/map_arguments.hpp"
1616

17-
namespace libtokamap::subset
17+
namespace libtokamap
1818
{
1919

20+
std::vector<libtokamap::SubsetInfo> parse_slices(const std::string& slice, const std::vector<size_t>& shape);
21+
2022
void update_array(TypedDataArray& input, const std::optional<std::string>& slice, std::optional<float> scale_factor,
2123
std::optional<float> offset);
2224

@@ -62,4 +64,4 @@ inline int log(LogLevel log_level, std::string_view log_msg)
6264
return 0;
6365
}
6466

65-
} // namespace libtokamap::subset
67+
} // namespace libtokamap

libtokamap/test/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ set( CMAKE_CXX_EXTENSIONS OFF )
1313
set( TEST_SOURCES
1414
src/data_source_mapping_test.cpp
1515
src/indices_test.cpp
16-
src/json_plugin_test.cpp
17-
src/main_test.cpp
16+
src/parse_slices_test.cpp
1817
src/syntax_parser_test.cpp
19-
src/value_mapping_test.cpp
20-
src/subset_test.cpp
2118
src/typed_data_array_test.cpp
19+
src/value_mapping_test.cpp
2220
)
2321

2422
include( FetchContent )

libtokamap/test/src/json_plugin_test.cpp

Lines changed: 0 additions & 6 deletions
This file was deleted.

libtokamap/test/src/main_test.cpp

Lines changed: 0 additions & 5 deletions
This file was deleted.

libtokamap/test/src/subset_test.cpp

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)