Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes wrong majority swap with string labels #31

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions include/cdfpp/cdf-io/majority-swap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ namespace _private
}

}
template <typename shape_t, typename data_t,
bool is_string = std::is_same_v<typename data_t::value_type, char>>

template <bool is_string, typename shape_t, typename data_t>
void swap(data_t& data, const shape_t& shape)
{
const auto dimensions = std::size(shape);
// Basically a variable with shape=2 is a variable with 1D records
if (dimensions > 2 or (is_string and dimensions > 2))
if ((dimensions > 2 && !is_string) or (is_string and dimensions > 3))
{
const std::size_t records_count = is_string ? 1 : shape[0];
const std::vector<std::size_t> record_shape(
Expand Down Expand Up @@ -174,48 +174,48 @@ void swap(data_t& data, const no_init_vector<uint32_t>& shape)
{
case CDF_Types::CDF_BYTE:
case CDF_Types::CDF_INT1:
swap(data.get<int8_t>(), shape);
swap<false>(data.get<int8_t>(), shape);
break;
case CDF_Types::CDF_CHAR:
swap(data.get<CDF_Types::CDF_CHAR>(), shape);
swap<true>(data.get<CDF_Types::CDF_CHAR>(), shape);
break;
case CDF_Types::CDF_UCHAR:
swap(data.get<CDF_Types::CDF_UCHAR>(), shape);
swap<true>(data.get<CDF_Types::CDF_UCHAR>(), shape);
break;
case CDF_Types::CDF_UINT1:
swap(data.get<unsigned char>(), shape);
swap<false>(data.get<unsigned char>(), shape);
break;
case CDF_Types::CDF_UINT2:
swap(data.get<uint16_t>(), shape);
swap<false>(data.get<uint16_t>(), shape);
break;
case CDF_Types::CDF_UINT4:
swap(data.get<uint32_t>(), shape);
swap<false>(data.get<uint32_t>(), shape);
break;
case CDF_Types::CDF_INT2:
swap(data.get<int16_t>(), shape);
swap<false>(data.get<int16_t>(), shape);
break;
case CDF_Types::CDF_INT4:
swap(data.get<int32_t>(), shape);
swap<false>(data.get<int32_t>(), shape);
break;
case CDF_Types::CDF_INT8:
swap(data.get<int64_t>(), shape);
swap<false>(data.get<int64_t>(), shape);
break;
case CDF_Types::CDF_FLOAT:
case CDF_Types::CDF_REAL4:
swap(data.get<float>(), shape);
swap<false>(data.get<float>(), shape);
break;
case CDF_Types::CDF_DOUBLE:
case CDF_Types::CDF_REAL8:
swap(data.get<double>(), shape);
swap<false>(data.get<double>(), shape);
break;
case CDF_Types::CDF_EPOCH:
swap(data.get<epoch>(), shape);
swap<false>(data.get<epoch>(), shape);
break;
case CDF_Types::CDF_EPOCH16:
swap(data.get<epoch16>(), shape);
swap<false>(data.get<epoch16>(), shape);
break;
case CDF_Types::CDF_TIME_TT2000:
swap(data.get<tt2000_t>(), shape);
swap<false>(data.get<tt2000_t>(), shape);
break;
default:
break;
Expand Down
12 changes: 6 additions & 6 deletions subprojects/catch2.wrap
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[wrap-file]
directory = Catch2-3.6.0
source_url = https://github.com/catchorg/Catch2/archive/v3.6.0.tar.gz
source_filename = Catch2-3.6.0.tar.gz
source_hash = 485932259a75c7c6b72d4b874242c489ea5155d17efa345eb8cc72159f49f356
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/catch2_3.6.0-1/Catch2-3.6.0.tar.gz
wrapdb_version = 3.6.0-1
directory = Catch2-3.7.0
source_url = https://github.com/catchorg/Catch2/archive/v3.7.0.tar.gz
source_filename = Catch2-3.7.0.tar.gz
source_hash = 5b10cd536fa3818112a82820ce0787bd9f2a906c618429e7c4dea639983c8e88
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/catch2_3.7.0-1/Catch2-3.7.0.tar.gz
wrapdb_version = 3.7.0-1

[provide]
catch2 = catch2_dep
Expand Down
18 changes: 9 additions & 9 deletions subprojects/fmt.wrap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[wrap-file]
directory = fmt-10.2.0
source_url = https://github.com/fmtlib/fmt/archive/10.2.0.tar.gz
source_filename = fmt-10.2.0.tar.gz
source_hash = 3ca91733a7313a8ad41c0885929415f8ec0a2a31d4dc7e27e9331412f4ca26ac
patch_filename = fmt_10.2.0-2_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/fmt_10.2.0-2/get_patch
patch_hash = 2428c3a386a8390c76378f81ef804a297f4edc3b789499dd56629b7902b8ddb7
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/fmt_10.2.0-2/fmt-10.2.0.tar.gz
wrapdb_version = 10.2.0-2
directory = fmt-11.0.2
source_url = https://github.com/fmtlib/fmt/archive/11.0.2.tar.gz
source_filename = fmt-11.0.2.tar.gz
source_hash = 6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f
patch_filename = fmt_11.0.2-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/fmt_11.0.2-1/get_patch
patch_hash = 90c9e3b8e8f29713d40ca949f6f93ad115d78d7fb921064112bc6179e6427c5e
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/fmt_11.0.2-1/fmt-11.0.2.tar.gz
wrapdb_version = 11.0.2-1

[provide]
fmt = fmt_dep
18 changes: 9 additions & 9 deletions subprojects/pybind11.wrap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[wrap-file]
directory = pybind11-2.12.0
source_url = https://github.com/pybind/pybind11/archive/refs/tags/v2.12.0.tar.gz
source_filename = pybind11-2.12.0.tar.gz
source_hash = bf8f242abd1abcd375d516a7067490fb71abd79519a282d22b6e4d19282185a7
patch_filename = pybind11_2.12.0-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/pybind11_2.12.0-1/get_patch
patch_hash = e651b2357e9a1f3e5f8e4e0e1b9ce76dacc1f712bc0e657f8843ba0c14b8e798
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/pybind11_2.12.0-1/pybind11-2.12.0.tar.gz
wrapdb_version = 2.12.0-1
directory = pybind11-2.13.5
source_url = https://github.com/pybind/pybind11/archive/refs/tags/v2.13.5.tar.gz
source_filename = pybind11-2.13.5.tar.gz
source_hash = b1e209c42b3a9ed74da3e0b25a4f4cd478d89d5efbb48f04b277df427faf6252
patch_filename = pybind11_2.13.5-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/pybind11_2.13.5-1/get_patch
patch_hash = ecb031b830481560b3d8487ed63ba4f5509a074be42f5d19af64d844c795e15b
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/pybind11_2.13.5-1/pybind11-2.13.5.tar.gz
wrapdb_version = 2.13.5-1

[provide]
pybind11 = pybind11_dep
2 changes: 1 addition & 1 deletion tests/majority/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ SCENARIO("Swapping from col to row major", "[CDF]")
// clang-format on
WHEN("Swapping to row major")
{
cdf::majority::swap(input, std::array { 2, 3, 4, 5 });
cdf::majority::swap<false>(input, std::array { 2, 3, 4, 5 });
THEN("array should be row major")
{
// clang-format off
Expand Down
5 changes: 5 additions & 0 deletions tests/python_loading/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ def test_ace_h0_mfi_label_time_shape(self):
f'{os.path.dirname(os.path.abspath(__file__))}/../resources/ac_h0_mfi_00000000_v01.cdf')
self.assertEqual(cdf['label_time'].shape, (1, 3, 27))

def test_solo_l2_rpw_lfr_surv_swf_e_labels(self):
cdf = pycdfpp.load(
f'{os.path.dirname(os.path.abspath(__file__))}/../resources/solo_l2_rpw-lfr-surv-swf-e_00000000_v01.cdf')
self.assertListEqual(cdf['VDC_LABEL'].values_encoded[0].tolist(), ["Vdc1", "Vdc2", "Vdc3"])

def test_empty_NRV_char_var_to_buffer(self):
cdf = pycdfpp.load(
f'{os.path.dirname(os.path.abspath(__file__))}/../resources/uy_proton-distributions_swoops_00000000_v01.cdf')
Expand Down
Binary file not shown.