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
10 changes: 7 additions & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ install:
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda info -a
- conda install pytest -c conda-forge
- conda install xtensor==0.8.0 pytest numpy pybind11==2.1.0 -c conda-forge
- xcopy /S %APPVEYOR_BUILD_FOLDER%\include %MINICONDA%\include
- conda install gtest cmake -c conda-forge
- conda install xtensor==0.8.1 pytest numpy pybind11==2.1.0 -c conda-forge
- cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -DBUILD_TESTS=ON .
- nmake test_xtensor_python
- nmake install

build_script:
- py.test -s
- cd test
- .\test_xtensor_python
38 changes: 24 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ env:
- MINCONDA_VERSION="latest"
- MINCONDA_LINUX="Linux-x86_64"
- MINCONDA_OSX="MacOSX-x86_64"
before_install:
- |
# Configure build variables
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
if [[ "$COMPILER" == "gcc" ]]; then
export CXX=g++-$GCC CC=gcc-$GCC;
fi
if [[ "$COMPILER" == "clang" ]]; then
export CXX=clang++-$CLANG CC=clang-$CLANG;
fi
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
export CXX=clang++ CC=clang PYTHONHOME=$HOME/miniconda;
fi

install:
# Define the version of miniconda to download
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
Expand All @@ -67,21 +81,17 @@ install:
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a
- conda install xtensor==0.8.0 pytest numpy pybind11==2.1.0 -c conda-forge
- cp -r $TRAVIS_BUILD_DIR/include/* $HOME/miniconda/include/
- conda install xtensor==0.8.1 pytest numpy pybind11==2.1.0 -c conda-forge
- cd test
- conda env create -f ./test-environment.yml
- source activate test-xtensor-python
- cd ..
- cmake -DBUILD_TESTS=ON -D CMAKE_INSTALL_PREFIX=$HOME/miniconda .
- make -j2 test_xtensor_python
- make install

script:
- |
# Configure build variables
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
if [[ "$COMPILER" == "gcc" ]]; then
export CXX=g++-$GCC CC=gcc-$GCC;
fi
if [[ "$COMPILER" == "clang" ]]; then
export CXX=clang++-$CLANG CC=clang-$CLANG;
fi
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
export CXX=clang++ CC=clang;
fi
- py.test -s
- cd test
- ./test_xtensor_python

3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ include_directories(${GTEST_INCLUDE_DIRS})

set(XTENSOR_PYTHON_TESTS
main.cpp
test_pytensor.cpp
test_pyarray.cpp
test_pytensor.cpp
test_pyvectorize.cpp
)

set(XTENSOR_PYTHON_TARGET test_xtensor_python)
Expand Down
2 changes: 1 addition & 1 deletion test/test-environment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test-xtensor
name: test-xtensor-python
channels:
- conda-forge
- defaults
Expand Down
80 changes: 80 additions & 0 deletions test/test_pyvectorize.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/***************************************************************************
* Copyright (c) 2016, Johan Mabille and Sylvain Corlay *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#include "gtest/gtest.h"
#include "test_common.hpp"
#include "xtensor-python/pytensor.hpp"
#include "xtensor-python/pyvectorize.hpp"
#include "pybind11/pybind11.h"
#include "pybind11/numpy.h"

namespace xt
{

double f1(double a, double b)
{
return a + b;
}

using shape_type = std::vector<std::size_t>;

TEST(pyvectorize, function)
{
auto vecf1 = pyvectorize(f1);
shape_type shape = { 3, 2 };
pyarray<double> a(shape, 1.5);
pyarray<double> b(shape, 2.3);
pyarray<double> c = vecf1(a, b);
EXPECT_EQ(a(0, 0) + b(0, 0), c(0, 0));
}

TEST(pyvectorize, lambda)
{
auto vecf1 = pyvectorize([](double a, double b) { return a + b; });
shape_type shape = { 3, 2 };
pyarray<double> a(shape, 1.5);
pyarray<double> b(shape, 2.3);
pyarray<double> c = vecf1(a, b);
EXPECT_EQ(a(0, 0) + b(0, 0), c(0, 0));
}

TEST(pyvectorize, complex)
{
using complex_t = std::complex<double>;
shape_type shape = { 3, 2 };
pyarray<complex_t> a(shape, complex_t(1.2, 2.5));
auto f = [](const pyarray<complex_t>& t) {
return std::make_tuple(pyvectorize([](complex_t x) { return std::abs(x); })(t),
pyvectorize([](complex_t x) { return std::arg(x); })(t));
};

auto res = f(a);
double expected_abs = std::abs(a(1, 1));
double expected_arg = std::arg(a(1, 1));
EXPECT_EQ(expected_abs, std::get<0>(res)(1, 1));
EXPECT_EQ(expected_arg, std::get<1>(res)(1, 1));
}

TEST(pyvectorize, complex_pybind)
{
using complex_t = std::complex<double>;
shape_type shape = { 3, 2 };
pyarray<complex_t> a(shape, complex_t(1.2, 2.5));
auto f = [](const pyarray<complex_t>& t) {
return pybind11::make_tuple(pyvectorize([](complex_t x) { return std::abs(x); })(t),
pyvectorize([](complex_t x) { return std::arg(x); })(t));
};

auto res = f(a);
double expected_abs = std::abs(a(1, 1));
double expected_arg = std::arg(a(1, 1));

EXPECT_EQ(expected_abs, res[0].cast<pyarray<double>>()(1, 1));
EXPECT_EQ(expected_arg, res[1].cast<pyarray<double>>()(1, 1));
}
}