Skip to content

Commit 8609cd2

Browse files
authored
Hotfixes/missing comma (#20)
* Fixing a missing comma * Bumping the version
1 parent 43fcada commit 8609cd2

File tree

10 files changed

+36
-5
lines changed

10 files changed

+36
-5
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333

3434
# Misc
3535
.vscode
36-
build
36+
build*

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [2021-02-09 - Version 1.2.2](https://github.com/matajoh/libnpy/releases/tag/v1.2.2)
4+
5+
Improvements:
6+
- Bug fix for a missing comma on 1d shape
7+
38
## [2021-02-08 - Version 1.2.1](https://github.com/matajoh/libnpy/releases/tag/v1.2.1)
49

510
Improvements:

RELEASE_NOTES

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
Improvements:
2-
- Bug fix for scalar tensor reading
3-
- Bug fix with memstream buffer size at initialization
4-
- ".npy" will be added to tensor names in NPZ writing if not already present
2+
- Bug fix for a missing comma on 1d shape

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.1
1+
1.2.2

assets/test/int32_array.npy

228 Bytes
Binary file not shown.

include/npy/npy.h

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ void write_npy_header(std::basic_ostream<CHAR> &output,
8383
buff << ", ";
8484
}
8585
}
86+
87+
if(shape.size() == 1)
88+
{
89+
buff << ",";
90+
}
91+
8692
buff << "), }";
8793
std::string dictionary = buff.str();
8894
auto dict_length = dictionary.size() + 1;

test/libnpy_tests.h

+9
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ std::string npy_scalar_stream(npy::endian_t endianness = npy::endian_t::NATIVE)
175175
return actual_stream.str();
176176
}
177177

178+
template <typename T>
179+
std::string npy_array_stream(npy::endian_t endianness = npy::endian_t::NATIVE)
180+
{
181+
std::ostringstream actual_stream;
182+
npy::tensor<T> tensor = test_tensor<T>({25});
183+
npy::save(actual_stream, tensor, endianness);
184+
return actual_stream.str();
185+
}
186+
178187
template <typename T>
179188
std::string npy_fortran_stream(npy::endian_t endianness = npy::endian_t::NATIVE)
180189
{

test/npy_read.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ int test_npy_read()
1414
test_read<std::int32_t>(result, "int32");
1515
test_read<std::int32_t>(result, "int32_big");
1616
test_read_scalar<std::int32_t>(result, "int32_scalar");
17+
test_read_array<std::int32_t>(result, "int32_array");
1718
test_read<std::uint64_t>(result, "uint64");
1819
test_read<std::int64_t>(result, "int64");
1920
test_read<float>(result, "float32");

test/npy_read.h

+8
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,12 @@ void test_read_scalar(int &result, const std::string &name)
2727
test::assert_equal(expected, actual, result, "npy_read_" + name);
2828
}
2929

30+
template <typename T>
31+
void test_read_array(int& result, const std::string &name)
32+
{
33+
npy::tensor<T> expected = test::test_tensor<T>({25});
34+
npy::tensor<T> actual = npy::load<T, npy::tensor>(test::asset_path(name + ".npy"));
35+
test::assert_equal(expected, actual, result, "npy_read_" + name);
36+
}
37+
3038
#endif

test/npy_write.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ int test_npy_write()
4747
actual = test::npy_scalar_stream<std::int32_t>(npy::endian_t::LITTLE);
4848
test::assert_equal(expected, actual, result, "npy_write_int32_scalar");
4949

50+
expected = test::read_asset("int32_array.npy");
51+
actual = test::npy_array_stream<std::int32_t>(npy::endian_t::LITTLE);
52+
test::assert_equal(expected, actual, result, "npy_write_int32_array");
53+
5054
expected = test::read_asset("uint64.npy");
5155
actual = test::npy_stream<std::uint64_t>(npy::endian_t::LITTLE);
5256
test::assert_equal(expected, actual, result, "npy_write_uint64");

0 commit comments

Comments
 (0)