Skip to content

Commit

Permalink
Hotfixes/missing comma (#20)
Browse files Browse the repository at this point in the history
* Fixing a missing comma

* Bumping the version
  • Loading branch information
matajoh authored Feb 9, 2021
1 parent 43fcada commit 8609cd2
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@

# Misc
.vscode
build
build*
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [2021-02-09 - Version 1.2.2](https://github.com/matajoh/libnpy/releases/tag/v1.2.2)

Improvements:
- Bug fix for a missing comma on 1d shape

## [2021-02-08 - Version 1.2.1](https://github.com/matajoh/libnpy/releases/tag/v1.2.1)

Improvements:
Expand Down
4 changes: 1 addition & 3 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
Improvements:
- Bug fix for scalar tensor reading
- Bug fix with memstream buffer size at initialization
- ".npy" will be added to tensor names in NPZ writing if not already present
- Bug fix for a missing comma on 1d shape
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.1
1.2.2
Binary file added assets/test/int32_array.npy
Binary file not shown.
6 changes: 6 additions & 0 deletions include/npy/npy.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ void write_npy_header(std::basic_ostream<CHAR> &output,
buff << ", ";
}
}

if(shape.size() == 1)
{
buff << ",";
}

buff << "), }";
std::string dictionary = buff.str();
auto dict_length = dictionary.size() + 1;
Expand Down
9 changes: 9 additions & 0 deletions test/libnpy_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ std::string npy_scalar_stream(npy::endian_t endianness = npy::endian_t::NATIVE)
return actual_stream.str();
}

template <typename T>
std::string npy_array_stream(npy::endian_t endianness = npy::endian_t::NATIVE)
{
std::ostringstream actual_stream;
npy::tensor<T> tensor = test_tensor<T>({25});
npy::save(actual_stream, tensor, endianness);
return actual_stream.str();
}

template <typename T>
std::string npy_fortran_stream(npy::endian_t endianness = npy::endian_t::NATIVE)
{
Expand Down
1 change: 1 addition & 0 deletions test/npy_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ int test_npy_read()
test_read<std::int32_t>(result, "int32");
test_read<std::int32_t>(result, "int32_big");
test_read_scalar<std::int32_t>(result, "int32_scalar");
test_read_array<std::int32_t>(result, "int32_array");
test_read<std::uint64_t>(result, "uint64");
test_read<std::int64_t>(result, "int64");
test_read<float>(result, "float32");
Expand Down
8 changes: 8 additions & 0 deletions test/npy_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ void test_read_scalar(int &result, const std::string &name)
test::assert_equal(expected, actual, result, "npy_read_" + name);
}

template <typename T>
void test_read_array(int& result, const std::string &name)
{
npy::tensor<T> expected = test::test_tensor<T>({25});
npy::tensor<T> actual = npy::load<T, npy::tensor>(test::asset_path(name + ".npy"));
test::assert_equal(expected, actual, result, "npy_read_" + name);
}

#endif
4 changes: 4 additions & 0 deletions test/npy_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ int test_npy_write()
actual = test::npy_scalar_stream<std::int32_t>(npy::endian_t::LITTLE);
test::assert_equal(expected, actual, result, "npy_write_int32_scalar");

expected = test::read_asset("int32_array.npy");
actual = test::npy_array_stream<std::int32_t>(npy::endian_t::LITTLE);
test::assert_equal(expected, actual, result, "npy_write_int32_array");

expected = test::read_asset("uint64.npy");
actual = test::npy_stream<std::uint64_t>(npy::endian_t::LITTLE);
test::assert_equal(expected, actual, result, "npy_write_uint64");
Expand Down

0 comments on commit 8609cd2

Please sign in to comment.