Skip to content
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
26 changes: 14 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ matrix:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
env: COMPILER=gcc GCC=6
- os: osx
osx_image: xcode8
compiler: clang
env:
global:
- MINCONDA_VERSION="latest"
- MINCONDA_LINUX="Linux-x86_64"
- MINCONDA_OSX="MacOSX-x86_64"
# before_install:

install:
# Define the version of miniconda to download
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
Expand All @@ -28,20 +26,24 @@ install:
fi
- wget "http://repo.continuum.io/miniconda/Miniconda3-$MINCONDA_VERSION-$MINCONDA_OS.sh" -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/miniconda
- export CONDA_PREFIX=$HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda info -a
# Start test environement
- conda env create -f ./test/test-environment.yml
- source activate test-xtensorio
- export CC=$CONDA_PREFIX/bin/gcc
- export CXX=$CONDA_PREFIX/bin/g++
# from conda toolchain package
- |
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
export CC=$CONDA_PREFIX/bin/gcc
export CXX=$CONDA_PREFIX/bin/g++
conda install gcc-7 -c QuantStack -c conda-forge
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
export CXX=clang++ CC=clang;
conda install libcxx clangdev -c QuantStack -c conda-forge
fi
- conda install cmake openimageio libsndfile boost zlib xtensor=0.15.5 -c QuantStack -c conda-forge
- export LDFLAGS="${LDFLAGS} -Wl,-rpath,$CONDA_PREFIX/lib"
- export LINKFLAGS="${LDFLAGS}"
# Testing
- mkdir build
- cd build
- cmake -DBUILD_TESTS=ON -DDOWNLOAD_GTEST=ON -DCMAKE_PREFIX_PATH=$CONDA_PREFIX ..;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Reading and writing image, sound and npz file formats to and from xtensor data s
conda install xtensor-io -c QuantStack -c conda-forge
```

- `xtensor-io` depends on `xtensor` `^0.13.2`.
- `xtensor-io` depends on `xtensor` `^0.15.5`.

- `OpenImageIO`, `libsndfile` and `zlib` are optional dependencies to `xtensor-io`

Expand Down
12 changes: 0 additions & 12 deletions test/test-environment.yml

This file was deleted.

51 changes: 15 additions & 36 deletions test/test_xnpz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,52 +33,31 @@ namespace xt
EXPECT_TRUE(xt::all(xt::equal(arr_0, xarr_0)));
}

bool compare_binary_files(std::string fn1, std::string fn2, std::size_t n_zipped_files)
{
std::ifstream stream1(fn1, std::ios::in | std::ios::binary);
std::vector<uint8_t> fn1_contents((std::istreambuf_iterator<char>(stream1)),
std::istreambuf_iterator<char>());

std::ifstream stream2(fn2, std::ios::in | std::ios::binary);
std::vector<uint8_t> fn2_contents((std::istreambuf_iterator<char>(stream2)),
std::istreambuf_iterator<char>());
std::size_t unequal = 0;

if (fn1_contents.size() != fn2_contents.size())
{
return false;
}

for (auto iter_fn1 = fn1_contents.begin(), iter_fn2 = fn2_contents.begin();
iter_fn1 != fn1_contents.end();
iter_fn1++, iter_fn2++)
{
if (*iter_fn1 != *iter_fn2)
{
unequal += 1;
}
}
// this is date + time == 4 bytes per file + once in global header
std::size_t unequal_allowed = (n_zipped_files + 2) * 3;
if (unequal > unequal_allowed)
{
return false;
}
}

TEST(xnpz, save_uncompressed)
{
dump_npz("files/dump_uncompressed.npz", "arr_0", linspace<double>(0, 100), false, false);
xt::xarray<int64_t> arr = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
dump_npz("files/dump_uncompressed.npz", "arr_1", arr);
EXPECT_TRUE(compare_binary_files("files/dump_uncompressed.npz", "files/uncompressed.npz", 2));
// Re-read
auto npz_map = xt::load_npz("files/dump_uncompressed.npz");
auto arr_0 = npz_map["arr_0"].cast<double>();
auto arr_1 = npz_map["arr_1"].cast<uint64_t>(false);
xt::xarray<uint64_t> xarr_1 = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
EXPECT_TRUE(xt::all(xt::isclose(arr_0, linspace<double>(0, 100))));
EXPECT_TRUE(xt::all(xt::equal(arr_1, xarr_1)));
}

TEST(xnpz, save_compressed)
{
xt::xarray<int64_t> arr = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
dump_npz("files/dump_compressed.npz", "arr_1", linspace<double>(0, 100), true, false );
dump_npz("files/dump_compressed.npz", "arr_0", arr, true);
EXPECT_TRUE(compare_binary_files("files/dump_compressed.npz", "files/compressed.npz", 2));
// Re-read
auto npz_map = xt::load_npz("files/dump_compressed.npz");
auto arr_0 = npz_map["arr_0"].cast<uint64_t>(false);
auto arr_1 = npz_map["arr_1"].cast<double>();
xt::xarray<uint64_t> xarr_0 = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
EXPECT_TRUE(xt::all(xt::isclose(arr_1, linspace<double>(0, 100))));
EXPECT_TRUE(xt::all(xt::equal(arr_0, xarr_0)));
}
}
}