Skip to content

Commit

Permalink
Addressing NPZ version bug + misc (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
matajoh authored May 28, 2021
1 parent 5c05ade commit 71f721a
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 159 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ before_install:
script:
- mkdir build
- cd build
- /usr/bin/cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
- /usr/bin/cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=1 ..
- /usr/bin/cmake --build .
- /usr/bin/ctest -C RelWithDebInfo
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# Changelog

## [2021-05-28 - Version 1.4.0](https://github.com/matajoh/libnpy/releases/tag/v1.4.0)

Improvements:
- Further minor CMake changes to improve ease of use
- NPZ streams now have `is_open` methods to check for successful file opening
- Minor code style changes

Bug fixes:
- NPZ files will now correctly handle PKZIP versions after 2.0, both for reading and writing

## [2021-05-21 - Version 1.3.1](https://github.com/matajoh/libnpy/releases/tag/v1.3.1)

New Features:
Improvements:
- Updated CMake integration to make the library easier to use via `FetchContent`

## [2021-02-10 - Version 1.3.0](https://github.com/matajoh/libnpy/releases/tag/v1.3.0)
Expand Down
29 changes: 18 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ project( libnpy VERSION ${LIBNPY_VERSION} LANGUAGES CXX)

# -------------------- Options --------------------------------

option( BUILD_TESTS "Specifies whether to build the tests" OFF )
option( BUILD_SAMPLES "Specifies whether to build the samples" OFF )
option( BUILD_DOCUMENTATION "Specifies whether to build the documentation for the API and XML" OFF )
option( INCLUDE_CSHARP "Specifies whether to build libnpy with C# bindings" OFF )

Expand Down Expand Up @@ -89,19 +91,13 @@ if( BUILD_DOCUMENTATION )
find_package( Doxygen REQUIRED )
endif()

# -------------------- Testing ------------------------------------

include( CTest )

if( MSVC )
set( LIBNPY_CSHARP_DIR ${CMAKE_BINARY_DIR}/CSharpWrapper/$<CONFIG> )
endif()

# -------------------- Walk the subdirectories --------------------

add_subdirectory( src )
add_subdirectory( test )
add_subdirectory( samples )

if( BUILD_SAMPLES )
add_subdirectory( samples )
endif()

if( BUILD_DOCUMENTATION )
add_subdirectory( doc )
Expand All @@ -119,6 +115,18 @@ target_include_directories(npy
${CMAKE_CURRENT_SOURCE_DIR}/src
)

# -------------------- Testing ------------------------------------

if( BUILD_TESTS )
if( MSVC )
set( LIBNPY_CSHARP_DIR ${CMAKE_BINARY_DIR}/CSharpWrapper/$<CONFIG> )
endif()

include( CTest )
add_subdirectory( test )
endif()


# -------------------- Build settings -----------------------------

# use C++11
Expand Down Expand Up @@ -182,7 +190,6 @@ install( FILES ${PROJECT_FILES} DESTINATION "." )

if( MSVC )
# NuGet files
set( CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/nuget" CACHE PATH "..." FORCE )
set( LIBNPY_NUGET_NAME "npy-${SYSTEM_TOOLKIT}-${SYSTEM_BITS}-${CMAKE_BUILD_TYPE}" CACHE STRING "npy NuGet Name" FORCE )
file( READ RELEASE_NOTES LIBNPY_RELEASE_NOTES )

Expand Down
9 changes: 7 additions & 2 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
New Features:
- Updated CMake integration to make the library easier to use via `FetchContent`
Improvements:
- Further minor CMake changes to improve ease of use
- NPZ streams now have `is_open` methods to check for successful file opening
- Minor code style changes

Bug fixes:
- NPZ files will now correctly handle PKZIP versions after 2.0, both for reading and writing
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.1
1.4.0
16 changes: 11 additions & 5 deletions include/npy/npz.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class onpzstream
compression_method_t compression = compression_method_t::STORED,
endian_t endianness = npy::endian_t::NATIVE);

/** Whether the underlying stream has successfully been opened. */
bool is_open() const;

/** Closes this stream. This will write the directory and close
* the underlying stream as well. */
void close();
Expand All @@ -89,7 +92,7 @@ class onpzstream
template <typename> class TENSOR>
void write(const std::string &filename, const TENSOR<T> &tensor)
{
if (this->m_closed)
if (m_closed)
{
throw std::logic_error("Stream is closed");
}
Expand All @@ -104,7 +107,7 @@ class onpzstream
name += ".npy";
}

this->write_file(name, std::move(output.buf()));
write_file(name, std::move(output.buf()));
}

/** Write a tensor to the NPZ archive.
Expand All @@ -115,7 +118,7 @@ class onpzstream
template <typename T>
void write(const std::string &filename, const tensor<T> &tensor)
{
this->write<T, npy::tensor>(filename, tensor);
write<T, npy::tensor>(filename, tensor);
}

/** Destructor. This will call
Expand Down Expand Up @@ -147,6 +150,9 @@ class inpzstream
*/
inpzstream(const std::string &path);

/** Whether the underlying stream has successfully been opened. */
bool is_open() const;

/** Closes the underlying stream. */
void close();

Expand Down Expand Up @@ -175,7 +181,7 @@ class inpzstream
template <typename> class TENSOR>
TENSOR<T> read(const std::string &filename)
{
imemstream stream(this->read_file(filename));
imemstream stream(read_file(filename));
return load<T, TENSOR>(stream);
}

Expand All @@ -188,7 +194,7 @@ class inpzstream
template <typename T>
tensor<T> read(const std::string &filename)
{
return this->read<T, npy::tensor>(filename);
return read<T, npy::tensor>(filename);
}

private:
Expand Down
Loading

0 comments on commit 71f721a

Please sign in to comment.