Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Johnson <[email protected]>
  • Loading branch information
matajoh committed Nov 1, 2024
1 parent e3dc4f0 commit ed61d96
Show file tree
Hide file tree
Showing 18 changed files with 618 additions and 682 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/prgate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Run clang-format style check
uses: jidicula/[email protected]
with:
clang-format-version: '13'
clang-format-version: '18'
check-path: ${{matrix.path['check']}}
exclude-regex: ${{matrix.path['exclude']}}

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
.vscode
build*
assets/test/*_large*.npz
.cache
.cache
.env
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [2024-11-01 - Version 1.5.3](https://github.com/matajoh/libnpy/releases/tag/v1.5.3)

Improvements:
- Increased CHUNK size as per miniz instructions
- Added tests for very large arrays in NPZ files
- Added some CI tests to catch issues across platforms

Bugfixes:
- Fixed an issue where very large arrays in NPZ files would throw an error

## [2021-10-05 - Version 1.5.2](https://github.com/matajoh/libnpy/releases/tag/v1.5.2)

Removing `using namespace std` to simplify library use
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ if(CLANG_FORMAT_NOT_FOUND)
else()
file(GLOB ALL_SOURCE_FILES CONFIGURE_DEPENDS
src/*.cpp
src/*.h
include/libnpy/*.h
tests/*.cpp
tests/*.h
Expand Down
5 changes: 2 additions & 3 deletions src/zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
#ifndef _ZIP_H_
#define _ZIP_H_

#include <vector>
#include <cstdint>
#include <vector>

namespace npy
{
namespace npy {
/** Deflate the bytes and return the compressed result.
* \param bytes the raw bytes
* \return the compressed bytes
Expand Down
31 changes: 15 additions & 16 deletions test/crc32.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
#include <cstdint>
#include <fstream>
#include <sstream>
#include <cstdint>

#include "libnpy_tests.h"
#include "zip.h"

const static int BUF_SIZE = 4096;

int test_crc32()
{
int result = EXIT_SUCCESS;
std::ifstream stream(test::asset_path("float32.npy"), std::ios_base::in | std::ios_base::binary);
char buffer[BUF_SIZE];
std::vector<std::uint8_t> bytes;
while(stream.good())
{
stream.read(buffer, BUF_SIZE);
std::copy(buffer, buffer + stream.gcount(), std::back_inserter(bytes));
}
int test_crc32() {
int result = EXIT_SUCCESS;
std::ifstream stream(test::asset_path("float32.npy"),
std::ios_base::in | std::ios_base::binary);
char buffer[BUF_SIZE];
std::vector<std::uint8_t> bytes;
while (stream.good()) {
stream.read(buffer, BUF_SIZE);
std::copy(buffer, buffer + stream.gcount(), std::back_inserter(bytes));
}

int actual = npy::npy_crc32(bytes);
int expected = 928602993;
test::assert_equal(expected, actual, result, "crc32");
return result;
int actual = npy::npy_crc32(bytes);
int expected = 928602993;
test::assert_equal(expected, actual, result, "crc32");
return result;
}
167 changes: 83 additions & 84 deletions test/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,119 +3,118 @@
#include "npy/npz.h"
#include "npy/tensor.h"

namespace
{
npy::tensor<std::uint8_t> TENSOR(std::vector<size_t>({ 5, 2, 5 }));
namespace {
npy::tensor<std::uint8_t> TENSOR(std::vector<size_t>({5, 2, 5}));

void save_invalid_path()
{
npy::save(test::path_join({"does_not_exist", "bad.npy"}), TENSOR);
void save_invalid_path() {
npy::save(test::path_join({"does_not_exist", "bad.npy"}), TENSOR);
}

void load_invalid_path()
{
npy::load<std::uint8_t, npy::tensor>(test::path_join({"does_not_exist", "bad.npy"}));
void load_invalid_path() {
npy::load<std::uint8_t, npy::tensor>(
test::path_join({"does_not_exist", "bad.npy"}));
}

void peek_invalid_path()
{
npy::peek(test::path_join({"does_not_exist", "bad.npy"}));
void peek_invalid_path() {
npy::peek(test::path_join({"does_not_exist", "bad.npy"}));
}

void inpzstream_invalid_path()
{
npy::inpzstream(test::path_join({"does_not_exist", "bad.npz"}));
void inpzstream_invalid_path() {
npy::inpzstream(test::path_join({"does_not_exist", "bad.npz"}));
}

void inpzstream_read_invalid_filename()
{
npy::inpzstream stream(test::path_join({"assets", "test", "test.npz"}));
npy::tensor<std::uint8_t> tensor = stream.read<std::uint8_t>("not_there.npy");
void inpzstream_read_invalid_filename() {
npy::inpzstream stream(test::path_join({"assets", "test", "test.npz"}));
npy::tensor<std::uint8_t> tensor = stream.read<std::uint8_t>("not_there.npy");
}

void inpzstream_peek_invalid_filename()
{
npy::inpzstream stream(test::path_join({"assets", "test", "test.npz"}));
npy::header_info header = stream.peek("not_there.npy");
void inpzstream_peek_invalid_filename() {
npy::inpzstream stream(test::path_join({"assets", "test", "test.npz"}));
npy::header_info header = stream.peek("not_there.npy");
}

void onpzstream_compression()
{
npy::compression_method_t compression_method = static_cast<npy::compression_method_t>(99);
npy::onpzstream stream("test.npz", compression_method);
stream.write("test.npy", TENSOR);
void onpzstream_compression() {
npy::compression_method_t compression_method =
static_cast<npy::compression_method_t>(99);
npy::onpzstream stream("test.npz", compression_method);
stream.write("test.npy", TENSOR);
}

void tensor_copy_from_0()
{
std::vector<std::uint8_t> buffer;
TENSOR.copy_from(buffer.data(), buffer.size());
void tensor_copy_from_0() {
std::vector<std::uint8_t> buffer;
TENSOR.copy_from(buffer.data(), buffer.size());
}

void tensor_copy_from_1()
{
std::vector<std::uint8_t> buffer;
TENSOR.copy_from(buffer);
void tensor_copy_from_1() {
std::vector<std::uint8_t> buffer;
TENSOR.copy_from(buffer);
}

void tensor_move_from()
{
std::vector<std::uint8_t> buffer;
TENSOR.copy_from(std::move(buffer));
void tensor_move_from() {
std::vector<std::uint8_t> buffer;
TENSOR.copy_from(std::move(buffer));
}

void tensor_index_size()
{
std::uint8_t value = TENSOR(0, 0);
}
void tensor_index_size() { std::uint8_t value = TENSOR(0, 0); }

void tensor_index_range()
{
std::uint8_t value = TENSOR(2, 3, 3);
}
void tensor_index_range() { std::uint8_t value = TENSOR(2, 3, 3); }

void load_wrong_dtype()
{
npy::tensor<float> tensor = npy::load<float, npy::tensor>(test::path_join({"assets", "test", "uint8.npy"}));
void load_wrong_dtype() {
npy::tensor<float> tensor = npy::load<float, npy::tensor>(
test::path_join({"assets", "test", "uint8.npy"}));
}

void onpzstream_closed()
{
npy::onpzstream stream("test.npz");
stream.close();
stream.write("error.npy", TENSOR);
void onpzstream_closed() {
npy::onpzstream stream("test.npz");
stream.close();
stream.write("error.npy", TENSOR);
}

void inpzstream_invalid_file()
{
npy::inpzstream stream(test::path_join({"assets", "test", "uint8.npy"}));
void inpzstream_invalid_file() {
npy::inpzstream stream(test::path_join({"assets", "test", "uint8.npy"}));
}

} // namespace

int test_exceptions()
{
int result = EXIT_SUCCESS;

test::assert_throws<std::invalid_argument>(peek_invalid_path, result, "peek_invalid_path");
test::assert_throws<std::invalid_argument>(save_invalid_path, result, "save_invalid_path");
test::assert_throws<std::invalid_argument>(load_invalid_path, result, "load_invalid_path");
test::assert_throws<std::invalid_argument>(inpzstream_invalid_path, result, "inpzstream_invalid_path");
test::assert_throws<std::invalid_argument>(inpzstream_read_invalid_filename, result, "inpzstream_read_invalid_filename");
test::assert_throws<std::invalid_argument>(inpzstream_peek_invalid_filename, result, "inpzstream_peek_invalid_filename");
test::assert_throws<std::invalid_argument>(onpzstream_compression, result, "onpzstream_compression");
test::assert_throws<std::invalid_argument>(tensor_copy_from_0, result, "tensor_copy_from_0");
test::assert_throws<std::invalid_argument>(tensor_copy_from_1, result, "tensor_copy_from_1");
test::assert_throws<std::invalid_argument>(tensor_move_from, result, "tensor_move_from");
test::assert_throws<std::invalid_argument>(tensor_index_size, result, "tensor_index");

test::assert_throws<std::out_of_range>(tensor_index_range, result, "tensor_index_range");

test::assert_throws<std::logic_error>(load_wrong_dtype, result, "load_wrong_dtype");
test::assert_throws<std::logic_error>(onpzstream_closed, result, "onpzstream_closed");
test::assert_throws<std::logic_error>(inpzstream_invalid_file, result, "inpzstream_invalid_file");

std::remove("test.npz");

return result;
int test_exceptions() {
int result = EXIT_SUCCESS;

test::assert_throws<std::invalid_argument>(peek_invalid_path, result,
"peek_invalid_path");
test::assert_throws<std::invalid_argument>(save_invalid_path, result,
"save_invalid_path");
test::assert_throws<std::invalid_argument>(load_invalid_path, result,
"load_invalid_path");
test::assert_throws<std::invalid_argument>(inpzstream_invalid_path, result,
"inpzstream_invalid_path");
test::assert_throws<std::invalid_argument>(
inpzstream_read_invalid_filename, result,
"inpzstream_read_invalid_filename");
test::assert_throws<std::invalid_argument>(
inpzstream_peek_invalid_filename, result,
"inpzstream_peek_invalid_filename");
test::assert_throws<std::invalid_argument>(onpzstream_compression, result,
"onpzstream_compression");
test::assert_throws<std::invalid_argument>(tensor_copy_from_0, result,
"tensor_copy_from_0");
test::assert_throws<std::invalid_argument>(tensor_copy_from_1, result,
"tensor_copy_from_1");
test::assert_throws<std::invalid_argument>(tensor_move_from, result,
"tensor_move_from");
test::assert_throws<std::invalid_argument>(tensor_index_size, result,
"tensor_index");

test::assert_throws<std::out_of_range>(tensor_index_range, result,
"tensor_index_range");

test::assert_throws<std::logic_error>(load_wrong_dtype, result,
"load_wrong_dtype");
test::assert_throws<std::logic_error>(onpzstream_closed, result,
"onpzstream_closed");
test::assert_throws<std::logic_error>(inpzstream_invalid_file, result,
"inpzstream_invalid_file");

std::remove("test.npz");

return result;
}
Loading

0 comments on commit ed61d96

Please sign in to comment.