diff --git a/.gitignore b/.gitignore index 64a6a583..0edbcde6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,15 +18,10 @@ version.py tests/ndarray tests/ndarray-eigen tests/ndarray-fft -tests/swig_test_mod.py -include/ndarray/buildOptions.h include/ndarray/Array.h include/ndarray/ArrayBaseN.h include/ndarray/ArrayRef.h include/ndarray/Vector.h include/ndarray/fft/FFTWTraits.h include/ndarray/operators.h -include/ndarray/bp/auto/*.h -include/ndarray/eigen/bp/auto/*.h -tests/.*.succeeded build/ diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 612e2c90..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "Boost.NumPy"] - path = Boost.NumPy - url = git://github.com/ndarray/Boost.NumPy.git diff --git a/.travis.yml b/.travis.yml index 91298410..8ed6668d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,10 +22,8 @@ install: - conda update -q conda # Useful for debugging any issues with conda - conda info -a - - conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION boost fftw numpy pybind11 swig cmake gxx_linux-64 + - conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION boost fftw numpy pybind11 cmake gxx_linux-64 eigen - source activate test-environment - - echo "eigen 3.2.*" > $CONDA_PREFIX/conda-meta/pinned - - conda install eigen - export BOOST_DIR=$CONDA_PREFIX - export EIGEN_DIR=$CONDA_PREFIX - export FFTW_DIR=$CONDA_PREFIX @@ -40,7 +38,7 @@ script: - make test ARGS="-V" - rm CMakeCache.txt - - cmake -DNDARRAY_PYBIND11=ON -DNDARRAY_EIGENVIEW=ON .. + - cmake -DNDARRAY_PYBIND11=ON .. - make - make test ARGS="-V" diff --git a/Boost.NumPy b/Boost.NumPy deleted file mode 160000 index a0e849ed..00000000 --- a/Boost.NumPy +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a0e849ed91fbd19e96f1eb7f69d5d89a565e5d79 diff --git a/CMakeLists.txt b/CMakeLists.txt index fd4d423c..5809b3a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,6 @@ project(ndarray) # only executed if NDARRAY_TEST is enabled. option(NDARRAY_TEST "Enable tests?" ON) option(NDARRAY_EIGEN "Enable Eigen tests?" ON) -option(NDARRAY_EIGENVIEW "Enable ndarray::EigenView (requires Eigen < 3.3)?" OFF) -option(NDARRAY_STDPYBIND11EIGEN "Enable standard pybind11 Eigen wrappers (requires Eigen > 3.2.5)?" OFF) option(NDARRAY_FFTW "Enable FFTW tests?" ON) option(NDARRAY_PYBIND11 "Enable Pybind11 tests?" OFF) @@ -42,10 +40,6 @@ if(DOXYGEN_FOUND) ) endif(DOXYGEN_FOUND) -if(NDARRAY_EIGENVIEW AND NDARRAY_STDPYBIND11EIGEN) - message(FATAL_ERROR "NDARRAY_EIGENVIEW and NDARRAY_STDPYBIND11EIGEN cannot both be enabled") -endif() - if(NDARRAY_TEST) enable_testing() add_subdirectory(tests) diff --git a/README.md b/README.md index 2564652b..5e7fe9bf 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,10 @@ More information can be found in the [documentation at ndarray.github.io/ndarray](http://ndarray.github.io/ndarray/). -Building from Git ------------------ +Installation +------------ -CMake is the supported way to build ndarray. - -To build with cmake, do: +ndarray can be built and tested with CMake: mkdir build cd build @@ -29,37 +27,11 @@ EIGEN_DIR, and FFTW_DIR environment variables. For example, to build with an alternate Eigen3 install location and disable FFTW testing replace `cmake ..` with `EIGEN_DIR=/opt/local cmake -DNDARRY_FFTW=OFF ..`. -ndarray::EigenView is not compatible with Eigen >= 3.3, -nor is it compatible with pybind11's default Eigen wrappers. -To build without ndarray::EigenView use cmake option `-DNDARRAY_EIGENVIEW=OFF` - -ndarray's build system does not produce the correct suffixes for pybind11 outputs under pybind11 2.1.x (due to a bug in pybind11 itself). To avoid this problem, please upgrade to pybind11 2.2.x, or try the (now reverted) patch from ndarray commit f46c0f0ff876ceab5aaa3286e5f6e86902e72feb. - -However, the cmake build does not support Boost.NumPy library -and Boost.Python wrappers, which are deprecated in favor of pybind11. -If you are keen to use Boost.Python you can try the older -scons build files, as follows - -ndarray includes the Boost.NumPy library using git's "submodules" -feature. When you clone the ndarray repository with git, you'll get -an empty Boost.NumPy directory. Even if you don't plan to use -Boost.NumPy (which is required only if you want to build the -Boost.Python bindings for ndarray), it *is* necessary to checkout the -Boost.NumPy source (as parts of the build system is shared). So, -immediately after cloning ndarray, you'll need to run: - -git submodule update --init --recursive - -From there, you'll be able to build ndarray and (optionally) -Boost.NumPy together just by running "scons" from the root of the -ndarray clone. +ndarray's build system does not produce the correct suffixes for pybind11 +outputs under pybind11 2.1.x (due to a bug in pybind11 itself). To avoid this +problem, please upgrade to pybind11 2.2.x, or try the (now reverted) patch from +ndarray commit f46c0f0ff876ceab5aaa3286e5f6e86902e72feb. Version 1.4.2 of ndarray is the last version to support SWIG. - -Building from Compressed Source -------------------------------- - -GitHub's automatically generated tarballs and zip files don't include -the Boost.NumPy submodule or the git metadata needed to run "git -submodule", so these features can't be used from release tarball. Please download from git if you want to use the Boost.NumPy interface. +Version 1.5.3 of ndarray is the last verison to support Boost.Python. diff --git a/SConstruct b/SConstruct deleted file mode 100644 index 0b80e5c5..00000000 --- a/SConstruct +++ /dev/null @@ -1,95 +0,0 @@ -# -*- python -*- -# -# Copyright (c) 2010-2012, Jim Bosch -# All rights reserved. -# -# ndarray is distributed under a simple BSD-like license; -# see the LICENSE file that should be present in the root -# of the source distribution, or alternately available at: -# https://github.com/ndarray/ndarray -# -import os -import sys -sys.path.insert(0, os.path.abspath('Boost.NumPy')) -from SConsChecks import AddLibOptions, GetLibChecks - -setupOptions, makeEnvironment, setupTargets, checks, libs = SConscript("Boost.NumPy/SConscript") -libs.extend(['swig', 'eigen', 'boost.test', 'fftw', 'boost.preprocessor']) -checks = GetLibChecks(libs) - -variables = setupOptions() - -AddOption("--with-eigen", dest="eigen_prefix", type="string", nargs=1, action="store", - metavar="DIR", default=os.environ.get("EIGEN_DIR"), - help="prefix for Eigen libraries; should have an 'include' subdirectory") -AddOption("--with-eigen-include", dest="eigen_include", type="string", nargs=1, action="store", - metavar="DIR", help="location of Eigen header files") -AddOption("--with-fftw", dest="fftw_prefix", type="string", nargs=1, action="store", - metavar="DIR", default=os.environ.get("FFTW_DIR"), - help="prefix for FFTW libraries; should have 'include' and 'lib' subdirectories") -AddOption("--with-fftw-include", dest="fftw_include", type="string", nargs=1, action="store", - metavar="DIR", help="location of FFTW header files") -AddOption("--with-fftw-lib", dest="fftw_lib", type="string", nargs=1, action="store", - metavar="DIR", help="location of FFTW library") -building = not GetOption("help") and not GetOption("clean") - -env = makeEnvironment(variables) -env.Tool('m4') -env.AppendUnique(CPPPATH=["#include"]) - -if building: - config = env.Configure(custom_tests=checks) - haveEigen = config.CheckEigen() - haveFFTW = config.CheckFFTW() - env = config.Finish() -else: - haveEigen = False - haveFFTW = False -env.haveEigen = haveEigen -env.haveFFTW = haveFFTW - -testEnv = env.Clone() -if building: - config = testEnv.Configure(custom_tests=checks) - haveBoostTest = config.CheckBoostTest() - testEnv = config.Finish() -else: - haveBoostTest = False -testEnv.haveBoostTest = haveBoostTest - -pyEnv = env.Clone() -if building: - config = pyEnv.Configure(custom_tests=checks) - havePython = config.CheckPython() and config.CheckNumPy() - config.CheckBoostPP() - pyEnv = config.Finish() -else: - havePython = False -pyEnv.havePython = havePython - -bpEnv = pyEnv.Clone() -if building: - config = bpEnv.Configure(custom_tests=checks) - haveBoostPython = config.CheckBoostPython() - bpEnv = config.Finish() -else: - haveBoostPython = False -bpEnv.haveBoostPython = haveBoostPython - -bpEnv.AppendUnique(CPPPATH=["#Boost.NumPy"]) -if haveBoostPython: - setupTargets(bpEnv, root="Boost.NumPy") -elif building: - print("Not building Boost.NumPy component.") - -headers = SConscript(os.path.join("include", "SConscript"), exports="env") - -prefix = Dir(GetOption("prefix")).abspath -install_headers = GetOption("install_headers") -if not install_headers: - install_headers = os.path.join(prefix, "include") -for header in Flatten(headers): - relative = os.path.relpath(header.abspath, Dir("#include").abspath) - env.Alias("install", env.InstallAs(os.path.join(install_headers, relative), header)) - -tests = SConscript(os.path.join("tests", "SConscript"), exports=["env", "testEnv", "pyEnv", "bpEnv"]) diff --git a/doc/SConscript b/doc/SConscript deleted file mode 100644 index 2028ebcd..00000000 --- a/doc/SConscript +++ /dev/null @@ -1,3 +0,0 @@ -# -*- python -*- -from lsst.sconsUtils import scripts -scripts.BasicSConscript.doc(inputs=["#include"]) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index c86cc992..494b45b0 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -23,7 +23,7 @@ endforeach(FILENAME) foreach(FILENAME ${PREPROCESS_FILES1}) add_custom_command ( OUTPUT ${FILENAME} - DEPENDS ${FILENAME}.m4 "ndarray/buildOptions.h.in" + DEPENDS ${FILENAME}.m4 COMMAND m4 ${FILENAME}.m4 > ${FILENAME} ) endforeach(FILENAME) @@ -36,9 +36,6 @@ foreach(FILENAME ${PREPROCESS_FILES2}) ) endforeach(FILENAME) -# record certain build options -configure_file(ndarray/buildOptions.h.in "${CMAKE_CURRENT_SOURCE_DIR}/ndarray/buildOptions.h") - add_custom_target(preprocess_includes1 ALL DEPENDS ${PREPROCESS_FILES1}) add_custom_target(preprocess_includes2 ALL DEPENDS ${PREPROCESS_FILES2}) add_dependencies(preprocess_includes2 preprocess_includes1) diff --git a/include/SConscript b/include/SConscript deleted file mode 100644 index 5585249c..00000000 --- a/include/SConscript +++ /dev/null @@ -1,39 +0,0 @@ -# -*- python -*- -# -# Copyright (c) 2010-2012, Jim Bosch -# All rights reserved. -# -# ndarray is distributed under a simple BSD-like license; -# see the LICENSE file that should be present in the root -# of the source distribution, or alternately available at: -# https://github.com/ndarray/ndarray -# -Import("env") -import os - -generated = ["ndarray/ArrayRef.h", - "ndarray/ArrayBaseN.h", - "ndarray/operators.h", - "ndarray/Vector.h", - "ndarray/fft/FFTWTraits.h", - "ndarray/bp/auto/Array.h", - "ndarray/bp/auto/ArrayRef.h", - "ndarray/bp/auto/Vector.h", - "ndarray/eigen/bp/auto/EigenView.h", - "ndarray/eigen/bp/auto/Array.h", - "ndarray/eigen/bp/auto/Matrix.h", - ] -m4include = Dir("../m4").abspath -m4flags = "-I%s" % m4include -headers = [env.M4(filename, "%s.m4" % filename, M4FLAGS=[m4flags]) for filename in generated] - -for header in headers: - env.Depends(header, Glob(os.path.join(m4include, "*.m4"))) - -headers += env.Glob("*.h") -headers += env.Glob("*/*.h") -headers += env.Glob("*/*/*.h") -headers += env.Glob("*/*/*/*.h") -headers += env.Glob("*.i") - -Return("headers") diff --git a/include/ndarray/ArrayBase.h b/include/ndarray/ArrayBase.h index ede9b80b..79325028 100644 --- a/include/ndarray/ArrayBase.h +++ b/include/ndarray/ArrayBase.h @@ -28,13 +28,6 @@ #include "ndarray/detail/ArrayAccess.h" #include "ndarray/detail/ViewBuilder.h" #include "ndarray/ArrayTraits.h" -#include "ndarray/buildOptions.h" - -#ifdef NDARRAY_EIGENVIEW - -#include "ndarray/eigen_fwd.h" - -#endif // NDARRAY_EIGENVIEW namespace ndarray { @@ -196,32 +189,6 @@ class ArrayBase : public ExpressionBase { /// @brief Return an ArrayRef view to this. Deep const deep() const { return Deep(this->getSelf()); } - -#ifdef NDARRAY_EIGENVIEW - - //@{ - /** - * @name Eigen3 Interface - * - * These methods return Eigen3 views to the array. Template - * parameters optionally control the expression type (Matrix/Array) and - * the compile-time dimensions. - * - * The inline implementation is included by ndarray/eigen.h. - */ - template - EigenView asEigen() const; - - template - EigenView asEigen() const; - - template - EigenView asEigen() const; - - EigenView asEigen() const; - //@} - -#endif // NDARRAY_EIGENVIEW /// @brief A template metafunction class to determine the result of a view indexing operation. template diff --git a/include/ndarray/EigenView.h b/include/ndarray/EigenView.h deleted file mode 100644 index 55453863..00000000 --- a/include/ndarray/EigenView.h +++ /dev/null @@ -1,437 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_EigenView_h_INCLUDED -#define NDARRAY_EigenView_h_INCLUDED - -/** - * @file ndarray/EigenView.h - * @brief ndarray::EigenView presents a reference-counted Eigen view into an ndarray::Array. - * - * \note This file is not included by the main "ndarray.h" header file. - */ - -#if defined __GNUC__ && __GNUC__>=6 - #pragma GCC diagnostic ignored "-Wignored-attributes" - #pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -#include "Eigen/Core" -#include "ndarray.h" -#include "ndarray/eigen_fwd.h" -#include "ndarray/buildOptions.h" - -#ifdef NDARRAY_EIGENVIEW - -namespace ndarray { -namespace detail { - -template -struct EigenStrideTraits<1,0,Rows,1> { - enum { - InnerStride = Eigen::Dynamic, - OuterStride = Eigen::Dynamic, - IsVector = 1, - Flags = Eigen::LinearAccessBit, - Options = Eigen::ColMajor | Eigen::AutoAlign - }; - static int getInnerStride(Core<1> const & core) { return core.getStride(); } - static int getOuterStride(Core<1> const & core) { return core.getSize() * core.getStride(); } - static int getRowStride(Core<1> const & core) { return core.getStride(); } - static int getColStride(Core<1> const & core) { return core.getSize() * core.getStride(); } - static int getRows(Core<1> const & core) { return core.getSize(); } - static int getCols(Core<1> const & core) { return 1; } -}; - -template -struct EigenStrideTraits<1,0,1,Cols> { - enum { - InnerStride = Eigen::Dynamic, - OuterStride = Eigen::Dynamic, - IsVector = 1, - Flags = Eigen::LinearAccessBit | Eigen::RowMajorBit, - Options = Eigen::RowMajor | Eigen::AutoAlign - }; - static int getInnerStride(Core<1> const & core) { return core.getStride(); } - static int getOuterStride(Core<1> const & core) { return core.getSize() * core.getStride(); } - static int getRowStride(Core<1> const & core) { return core.getSize() * core.getStride(); } - static int getColStride(Core<1> const & core) { return core.getStride(); } - static int getRows(Core<1> const & core) { return 1; } - static int getCols(Core<1> const & core) { return core.getSize(); } -}; - -template -struct EigenStrideTraits<1,C,1,1> { - enum { - InnerStride = Eigen::Dynamic, - OuterStride = Eigen::Dynamic, - IsVector = 1, - Flags = Eigen::LinearAccessBit, - Options = Eigen::ColMajor | Eigen::AutoAlign - }; - static int getInnerStride(Core<1> const & core) { return core.getStride(); } - static int getOuterStride(Core<1> const & core) { return core.getStride(); } - static int getRowStride(Core<1> const & core) { return core.getStride(); } - static int getColStride(Core<1> const & core) { return core.getStride(); } - static int getRows(Core<1> const & core) { return 1; } - static int getCols(Core<1> const & core) { return 1; } -}; - -template -struct EigenStrideTraits<1,C,Rows,1> { - enum { - InnerStride = 1, - OuterStride = Eigen::Dynamic, - IsVector = 1, - Flags = Eigen::LinearAccessBit | Eigen::PacketAccessBit, - Options = Eigen::ColMajor | Eigen::AutoAlign - }; - static int getInnerStride(Core<1> const & core) { return 1; } - static int getOuterStride(Core<1> const & core) { return core.getSize(); } - static int getRowStride(Core<1> const & core) { return 1; } - static int getColStride(Core<1> const & core) { return core.getSize(); } - static int getRows(Core<1> const & core) { return core.getSize(); } - static int getCols(Core<1> const & core) { return 1;} -}; - -template -struct EigenStrideTraits<1,C,1,Cols> { - enum { - InnerStride = 1, - OuterStride = Eigen::Dynamic, - IsVector = 1, - Flags = Eigen::LinearAccessBit | Eigen::RowMajorBit | Eigen::PacketAccessBit, - Options = Eigen::RowMajor | Eigen::AutoAlign - }; - static int getInnerStride(Core<1> const & core) { return 1; } - static int getOuterStride(Core<1> const & core) { return core.getSize(); } - static int getRowStride(Core<1> const & core) { return core.getSize(); } - static int getColStride(Core<1> const & core) { return 1; } - static int getRows(Core<1> const & core) { return 1; } - static int getCols(Core<1> const & core) { return core.getSize(); } -}; - -template -struct EigenStrideTraits<2,0,Rows,Cols> { - enum { - InnerStride = Eigen::Dynamic, - OuterStride = Eigen::Dynamic, - IsVector = 0, - Flags = 0, - Options = Eigen::ColMajor | Eigen::AutoAlign - }; - static int getInnerStride(Core<2> const & core) { return core.getStride(); } - static int getOuterStride(Core<1> const & core) { return core.getStride(); } - static int getRowStride(Core<2> const & core) { return core.getStride(); } - static int getColStride(Core<1> const & core) { return core.getStride(); } - static int getRows(Core<2> const & core) { return core.getSize(); } - static int getCols(Core<1> const & core) { return core.getSize(); } -}; - -template -struct EigenStrideTraits<2,1,Rows,Cols> { - enum { - InnerStride = 1, - OuterStride = Eigen::Dynamic, - IsVector = 0, - Flags = Eigen::RowMajorBit | Eigen::PacketAccessBit, - Options = Eigen::RowMajor | Eigen::AutoAlign - }; - static int getInnerStride(Core<1> const & core) { return 1; } - static int getOuterStride(Core<2> const & core) { return core.getStride(); } - static int getRowStride(Core<2> const & core) { return core.getStride(); } - static int getColStride(Core<1> const & core) { return 1; } - static int getRows(Core<2> const & core) { return core.getSize(); } - static int getCols(Core<1> const & core) { return core.getSize(); } -}; - -template -struct EigenStrideTraits<2,2,Rows,Cols> : public EigenStrideTraits<2,1,Rows,Cols> {}; - -template -struct EigenStrideTraits<2,-1,Rows,Cols> { - enum { - InnerStride = 1, - OuterStride = Eigen::Dynamic, - IsVector = 0, - Flags = Eigen::PacketAccessBit, - Options = Eigen::ColMajor | Eigen::AutoAlign - }; - static int getInnerStride(Core<2> const & core) { return 1; } - static int getOuterStride(Core<1> const & core) { return core.getStride(); } - static int getRowStride(Core<2> const & core) { return 1; } - static int getColStride(Core<1> const & core) { return core.getStride(); } - static int getRows(Core<2> const & core) { return core.getSize(); } - static int getCols(Core<1> const & core) { return core.getSize(); } -}; - -template -struct EigenStrideTraits<2,-2,Rows,Cols> : public EigenStrideTraits<2,-1,Rows,Cols> {}; - -} // namespace detail -} // namespace ndarray - - -namespace Eigen { -namespace internal { - -template -struct traits< ndarray::EigenView > { - typedef DenseIndex Index; - typedef Dense StorageKind; - typedef XprKind_ XprKind; - typedef typename boost::remove_const::type Scalar; - enum { - RowsAtCompileTime = Rows, - ColsAtCompileTime = Cols, - MaxRowsAtCompileTime = Rows, - MaxColsAtCompileTime = Cols, - InnerStrideAtCompileTime = ndarray::detail::EigenStrideTraits::InnerStride, - OuterStrideAtCompileTime = ndarray::detail::EigenStrideTraits::OuterStride, - IsVectorAtCompileTime = ndarray::detail::EigenStrideTraits::IsVector, - Flags = ndarray::detail::EigenStrideTraits::Flags - | Eigen::NestByRefBit | Eigen::DirectAccessBit - | (boost::is_const::value ? 0 : Eigen::LvalueBit), - CoeffReadCost = NumTraits::ReadCost - }; -}; - -} // namespace internal -} // namespace Eigen - -namespace ndarray { - -/** - * @brief Eigen3 view into an ndarray::Array. - * - * EigenView provides an Eigen DenseBase-derived object based on an ndarray::Array internally. - * Any one or two dimensional Array can be viewed as an Eigen object. - * - * Assignment to an EigenView is deep, and uses the Eigen assignment operators, but construction - * from an ndarray::Array or ArrayRef is shallow with reference counting. Block and transpose - * operations use the standard Eigen Block and Transpose classes, and do not do reference counting - * (in fact, they hold a plain C++ reference to the EigenView, so they should be considered extremely - * temporary). - * - * @todo Add reference-counted share and transpose operations that return EigenViews. - * - * @ingroup EigenGroup - */ -template -class EigenView - : public Eigen::internal::dense_xpr_base< EigenView >::type -{ - typedef detail::EigenStrideTraits ST; - typedef detail::ArrayAccess< Array > Access; - - void checkDimensions() { - NDARRAY_ASSERT( Rows_ == Eigen::Dynamic || Rows_ == rows() ); - NDARRAY_ASSERT( Cols_ == Eigen::Dynamic || Cols_ == cols() ); - } - -public: - - typedef typename Eigen::internal::dense_xpr_base< EigenView >::type Base; - - EIGEN_DENSE_PUBLIC_INTERFACE(EigenView) - - enum { Options = ST::Options }; - - typedef typename boost::mpl::if_< - boost::is_same, - Eigen::Matrix, - Eigen::Array - >::type PlainEigenType; - - typedef T * PointerType; - - EigenView() : _array() {} - - EigenView(EigenView const & other) : _array(other._array) {} - - explicit EigenView(Array const & array) : _array(array) { checkDimensions(); } - - EigenView & operator=(EigenView const & other) { - // Weird behavior to please SWIG: if we're default-constructed, and it's an exact match, - // do shallow assignment; otherwise all assignment is deep. - if (_array.getData() == 0) { - _array = other._array; - } else { - Base::operator=(other); - } - return *this; - } - - template - EigenView & operator=(Eigen::DenseBase const & other) { - return Base::operator=(other); - } - - template - EigenView & operator=(Eigen::EigenBase const & other) { - return Base::operator=(other); - } - - template - EigenView & operator=(Eigen::ReturnByValue const & other) { - return Base::operator=(other); - } - - inline Index innerStride() const { return ST::getInnerStride(*Access::getCore(_array)); } - inline Index outerStride() const { return ST::getOuterStride(*Access::getCore(_array)); } - - inline Index rowStride() const { return ST::getRowStride(*Access::getCore(_array)); } - inline Index colStride() const { return ST::getColStride(*Access::getCore(_array)); } - - inline Index rows() const { return ST::getRows(*Access::getCore(_array)); } - inline Index cols() const { return ST::getCols(*Access::getCore(_array)); } - - inline T* data() const { return _array.getData(); } - - inline T* data() { return _array.getData(); } - - inline T& coeff(Index row, Index col) const { - return _array.getData()[row * rowStride() + col * colStride()]; - } - - inline T& coeff(Index index) const { - return _array.getData()[index * innerStride()]; - } - - inline T& coeffRef(Index row, Index col) const { - return _array.getData()[row * rowStride() + col * colStride()]; - } - - inline T& coeffRef(Index row, Index col) { - return _array.getData()[row * rowStride() + col * colStride()]; - } - - inline T& coeffRef(Index index) const { - return _array.getData()[index * innerStride()]; - } - - inline T& coeffRef(Index index) { - return _array.getData()[index * innerStride()]; - } - - template - inline PacketScalar packet(Index row, Index col) const { - return Eigen::internal::ploadt( - _array.getData() + (col * colStride() + row * rowStride()) - ); - } - - template - inline PacketScalar packet(Index index) const { - BOOST_STATIC_ASSERT( N == 1 ); - return Eigen::internal::ploadt( - _array.getData() + index * innerStride() - ); - } - - template - inline void writePacket(Index row, Index col, const PacketScalar& x) { - BOOST_STATIC_ASSERT( !boost::is_const::value ); - Eigen::internal::pstoret( - _array.getData() + (col * colStride() + row * rowStride()), x - ); - } - - template - inline void writePacket(Index index, const PacketScalar& x) { - BOOST_STATIC_ASSERT( !boost::is_const::value ); - BOOST_STATIC_ASSERT( N == 1 ); - Eigen::internal::pstoret( - _array.getData() + index * innerStride(), x - ); - } - - Array const & shallow() const { return _array; } - ArrayRef deep() const { return _array.deep(); } - - void reset(Array const & array = Array()) { _array = array; checkDimensions(); } - void reset(ArrayRef const & array) { reset(array.shallow()); } - - void swap(EigenView & other) { _array.swap(other._array); } - - using Base::swap; - -private: - Array _array; -}; - -/// @brief A metafunction that computes the EigenView instantiation that most closely matches an Eigen type. -template -struct SelectEigenView { - typedef Eigen::internal::traits Traits; - typedef typename Traits::Scalar Scalar; - typedef typename boost::mpl::if_< boost::is_const, Scalar const, Scalar >::type Element; - typedef typename Traits::XprKind XprKind; - enum { - N = 2, - C = ((contiguous) ? ((Traits::Flags & Eigen::RowMajorBit) ? 2 : -2) : 0), - Rows = Traits::RowsAtCompileTime, - Cols = Traits::ColsAtCompileTime - }; - typedef Array Shallow; - typedef ArrayRef Deep; - typedef EigenView Type; -}; - -/// @brief Copy an arbitrary Eigen expression into a new EigenView. -template -inline typename SelectEigenView::Type copy(Eigen::EigenBase const & other) { - typename SelectEigenView::Type result( - typename SelectEigenView::Shallow(allocate(other.rows(), other.cols())) - ); - result = other.derived(); - return result; -} - -template -template -inline EigenView::Element, ArrayBase::ND::value, - ArrayBase::RMC::value, XprKind, Rows, Cols - > -ArrayBase::asEigen() const { - return EigenView::Element, ArrayBase::ND::value, - ArrayBase::RMC::value, XprKind, Rows, Cols>(this->getSelf()); -} - -template -template -inline EigenView::Element, ArrayBase::ND::value, - ArrayBase::RMC::value, XprKind> -ArrayBase::asEigen() const { - return EigenView::Element, ArrayBase::ND::value, - ArrayBase::RMC::value, XprKind>(this->getSelf()); -} - -template -template -inline EigenView::Element, ArrayBase::ND::value, - ArrayBase::RMC::value, Eigen::MatrixXpr, Rows, Cols> -ArrayBase::asEigen() const { - return EigenView::Element, ArrayBase::ND::value, - ArrayBase::RMC::value, Eigen::MatrixXpr, Rows, Cols>(this->getSelf()); -} - -template -inline EigenView::Element, ArrayBase::ND::value, - ArrayBase::RMC::value, Eigen::MatrixXpr> -ArrayBase::asEigen() const { - return EigenView::Element, ArrayBase::ND::value, - ArrayBase::RMC::value>(this->getSelf()); -} - -} // namespace ndarray - -#endif // NDARRAY_EIGENVIEW -#endif // !NDARRAY_EigenView_h_INCLUDED diff --git a/include/ndarray/bp.h b/include/ndarray/bp.h deleted file mode 100644 index 9cb9cd09..00000000 --- a/include/ndarray/bp.h +++ /dev/null @@ -1,18 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_bp_h_INCLUDED -#define NDARRAY_bp_h_INCLUDED - -#include "ndarray/bp/Array.h" -#include "ndarray/bp/ArrayRef.h" -#include "ndarray/bp/Vector.h" - -#endif // !NDARRAY_bp_h_INCLUDED diff --git a/include/ndarray/bp/Array.h b/include/ndarray/bp/Array.h deleted file mode 100644 index d8560813..00000000 --- a/include/ndarray/bp/Array.h +++ /dev/null @@ -1,160 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_BP_Array_h_INCLUDED -#define NDARRAY_BP_Array_h_INCLUDED - -#include "boost/numpy.hpp" -#include "ndarray.h" -#include "ndarray/bp_fwd.h" -#include - -namespace ndarray { -namespace detail { - -inline void destroyManagerCObject(void * p) { -#if PY_MAJOR_VERSION == 2 - Manager::Ptr * b = reinterpret_cast(p); -#else - Manager::Ptr * b = reinterpret_cast(PyCapsule_GetPointer(reinterpret_cast(p), 0)); -#endif - delete b; -} - -inline boost::python::object makePyObject(Manager::Ptr const & x) { - boost::intrusive_ptr< ExternalManager > y - = boost::dynamic_pointer_cast< ExternalManager >(x); - if (y) { - return y->getOwner(); - } -#if PY_MAJOR_VERSION == 2 - boost::python::handle<> h(::PyCObject_FromVoidPtr(new Manager::Ptr(x), &destroyManagerCObject)); -#else - boost::python::handle<> h(::PyCapsule_New(new Manager::Ptr(x), 0, (PyCapsule_Destructor)&destroyManagerCObject)); -#endif - return boost::python::object(h); -} - -} // namespace detail - -template -class ToBoostPython< Array > { -public: - - typedef boost::numpy::ndarray result_type; - - static boost::numpy::ndarray apply(Array const & array) { - boost::numpy::dtype dtype - = boost::numpy::dtype::get_builtin::type>(); - boost::python::object owner = detail::makePyObject(array.getManager()); - Py_ssize_t itemsize = dtype.get_itemsize(); - ndarray::Vector shape_elements = array.getShape(); - ndarray::Vector strides_elements = array.getStrides(); - std::vector shape_bytes(N); - std::vector strides_bytes(N); - for (int n=0; n -class FromBoostPython< Array > { -public: - - explicit FromBoostPython(boost::python::object const & input_) : input(input_) {} - - bool convertible() { - if (input.is_none()) return true; - try { - boost::numpy::ndarray array = boost::python::extract(input); - boost::numpy::dtype dtype - = boost::numpy::dtype::get_builtin::type>(); - boost::numpy::ndarray::bitflag flags = array.get_flags(); - if (dtype != array.get_dtype()) return false; - if (N != array.get_nd()) return false; - if (!boost::is_const::value && !(flags & boost::numpy::ndarray::WRITEABLE)) return false; - if (C > 0) { - Offset requiredStride = sizeof(T); - for (int i = 0; i < C; ++i) { - if ((array.shape(N-i-1) > 1) && (array.strides(N-i-1) != requiredStride)) { - return false; - } - requiredStride *= array.shape(N-i-1); - } - } else if (C < 0) { - Offset requiredStride = sizeof(T); - for (int i = 0; i < -C; ++i) { - if ((array.shape(i) > 1) && (array.strides(i) != requiredStride)) { - return false; - } - requiredStride *= array.shape(i); - } - } - } catch (boost::python::error_already_set) { - boost::python::handle_exception(); - PyErr_Clear(); - return false; - } - return true; - } - - Array operator()() { - if (input.is_none()) return Array(); - boost::numpy::ndarray array = boost::python::extract(input); - boost::numpy::dtype dtype = array.get_dtype(); - Py_ssize_t itemsize = dtype.get_itemsize(); - for (int i = 0; i < N; ++i) { - if ((array.shape(i) > 1) && (array.strides(i) % itemsize != 0)) { - PyErr_SetString( - PyExc_TypeError, - "Cannot convert array to C++: strides must be an integer multiple of the element size" - ); - boost::python::throw_error_already_set(); - } - } - boost::python::object obj_owner = array.get_base(); - if (obj_owner.is_none()) { - obj_owner = array; - } - Vector shape; - Vector strides; - for (int i=0; i 1) { - strides[i] = array.strides(i) / itemsize; - } else { - strides[i] = 1; - } - } - Array r = ndarray::external( - reinterpret_cast(array.get_data()), shape, strides, obj_owner - ); - return r; - } - - boost::python::object input; -}; - -} // namespace ndarray - -namespace boost { namespace numpy { - -template -numpy::ndarray array(::ndarray::Array const & arg) { - return ::ndarray::ToBoostPython< ::ndarray::Array >::apply(arg); -} - -}} // namespace boost::numpy - -#endif // !NDARRAY_BP_Array_h_INCLUDED diff --git a/include/ndarray/bp/ArrayRef.h b/include/ndarray/bp/ArrayRef.h deleted file mode 100644 index e7ab913f..00000000 --- a/include/ndarray/bp/ArrayRef.h +++ /dev/null @@ -1,55 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_BP_ArrayRef_h_INCLUDED -#define NDARRAY_BP_ArrayRef_h_INCLUDED - -#include "ndarray/bp/Array.h" - -namespace ndarray { - -template -class ToBoostPython< ArrayRef > { -public: - - typedef boost::numpy::ndarray result_type; - - static boost::numpy::ndarray apply(ArrayRef const & array) { - return ToBoostPython< Array >::apply(array); - } - -}; - -template -class FromBoostPython< ArrayRef > { -public: - - explicit FromBoostPython(boost::python::object const & input) : _impl(input) {} - - bool convertible() { return _impl.convertible(); } - - ArrayRef operator()() { return ArrayRef(_impl()); } - -private: - FromBoostPython< Array > _impl; -}; - -} // namespace ndarray - -namespace boost { namespace numpy { - -template -numpy::ndarray array(::ndarray::ArrayRef const & arg) { - return ::ndarray::ToBoostPython< ::ndarray::ArrayRef >::apply(arg); -} - -}} // namespace boost::numpy - -#endif // !NDARRAY_BP_ArrayRef_h_INCLUDED diff --git a/include/ndarray/bp/Vector.h b/include/ndarray/bp/Vector.h deleted file mode 100644 index bc86e278..00000000 --- a/include/ndarray/bp/Vector.h +++ /dev/null @@ -1,75 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_BP_Vector_h_INCLUDED -#define NDARRAY_BP_Vector_h_INCLUDED - -#include "boost/python.hpp" -#include "ndarray/Vector.h" -#include "ndarray/bp_fwd.h" - -namespace ndarray { - -template -class ToBoostPython< Vector > { -public: - - typedef boost::python::tuple result_type; - - static boost::python::tuple apply(Vector const & x) { - boost::python::handle<> t(PyTuple_New(N)); - for (int n=0; n -class FromBoostPython< Vector > { -public: - - explicit FromBoostPython(boost::python::object const & input_) : input(input_) {} - - bool convertible() { - try { - boost::python::tuple t(input); - if (len(t) != N) return false; - input = t; - } catch (boost::python::error_already_set) { - boost::python::handle_exception(); - PyErr_Clear(); - return false; - } - return true; - } - - Vector operator()() { - boost::python::tuple t = boost::python::extract(input); - if (len(t) != N) { - PyErr_SetString(PyExc_ValueError, "Incorrect size for ndarray::Vector."); - boost::python::throw_error_already_set(); - } - Vector r; - for (int n=0; n(t[n]); - } - return r; - } - - boost::python::object input; -}; - -} // namespace ndarray - -#endif // !NDARRAY_BP_Vector_h_INCLUDED diff --git a/include/ndarray/bp/auto.h b/include/ndarray/bp/auto.h deleted file mode 100644 index ed093547..00000000 --- a/include/ndarray/bp/auto.h +++ /dev/null @@ -1,18 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_BP_auto_h_INCLUDED -#define NDARRAY_BP_auto_h_INCLUDED - -#include "ndarray/bp/auto/Array.h" -#include "ndarray/bp/auto/ArrayRef.h" -#include "ndarray/bp/auto/Vector.h" - -#endif // !NDARRAY_BP_auto_h_INCLUDED diff --git a/include/ndarray/bp/auto/Array.h.m4 b/include/ndarray/bp/auto/Array.h.m4 deleted file mode 100644 index f27766da..00000000 --- a/include/ndarray/bp/auto/Array.h.m4 +++ /dev/null @@ -1,22 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -// THIS FILE IS MACHINE GENERATED BY SCONS. DO NOT EDIT MANUALLY. -include(`auto_bp_converters.m4')dnl -changecom(`###')dnl -#ifndef NDARRAY_BP_AUTO_Array_h_INCLUDED -#define NDARRAY_BP_AUTO_Array_h_INCLUDED - -#include "boost/numpy.hpp" -#include "ndarray/bp/Array.h" - -BP_AUTO_CONVERTERS(`typename T, int N, int C', `ndarray::Array')dnl - -#endif // !NDARRAY_BP_AUTO_Array_h_INCLUDED diff --git a/include/ndarray/bp/auto/ArrayRef.h.m4 b/include/ndarray/bp/auto/ArrayRef.h.m4 deleted file mode 100644 index 06c7addc..00000000 --- a/include/ndarray/bp/auto/ArrayRef.h.m4 +++ /dev/null @@ -1,22 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -// THIS FILE IS MACHINE GENERATED BY SCONS. DO NOT EDIT MANUALLY. -include(`auto_bp_converters.m4')dnl -changecom(`###')dnl -#ifndef NDARRAY_BP_AUTO_ArrayRef_h_INCLUDED -#define NDARRAY_BP_AUTO_ArrayRef_h_INCLUDED - -#include "boost/numpy.hpp" -#include "ndarray/bp/ArrayRef.h" - -BP_AUTO_CONVERTERS(`typename T, int N, int C', `ndarray::ArrayRef')dnl - -#endif // !NDARRAY_BP_AUTO_ArrayRef_h_INCLUDED diff --git a/include/ndarray/bp/auto/Vector.h.m4 b/include/ndarray/bp/auto/Vector.h.m4 deleted file mode 100644 index 72d6327e..00000000 --- a/include/ndarray/bp/auto/Vector.h.m4 +++ /dev/null @@ -1,22 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -// THIS FILE IS MACHINE GENERATED BY SCONS. DO NOT EDIT MANUALLY. -include(`auto_bp_converters.m4')dnl -changecom(`###')dnl -#ifndef NDARRAY_BP_AUTO_Vector_h_INCLUDED -#define NDARRAY_BP_AUTO_Vector_h_INCLUDED - -#include "boost/numpy.hpp" -#include "ndarray/bp/Vector.h" - -BP_AUTO_CONVERTERS(`typename T, int N', `ndarray::Vector')dnl - -#endif // !NDARRAY_BP_AUTO_Vector_h_INCLUDED diff --git a/include/ndarray/bp/eigen b/include/ndarray/bp/eigen deleted file mode 120000 index b2c030d0..00000000 --- a/include/ndarray/bp/eigen +++ /dev/null @@ -1 +0,0 @@ -../eigen/bp \ No newline at end of file diff --git a/include/ndarray/bp/eigen.h b/include/ndarray/bp/eigen.h deleted file mode 100644 index b8527b6c..00000000 --- a/include/ndarray/bp/eigen.h +++ /dev/null @@ -1,16 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_BP_eigen_h_INCLUDED -#define NDARRAY_BP_eigen_h_INCLUDED - -#include "ndarray/eigen/bp.h" - -#endif // !NDARRAY_BP_eigen_h_INCLUDED diff --git a/include/ndarray/bp_fwd.h b/include/ndarray/bp_fwd.h deleted file mode 100644 index 557c2626..00000000 --- a/include/ndarray/bp_fwd.h +++ /dev/null @@ -1,21 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_bp_fwd_h_INCLUDED -#define NDARRAY_bp_fwd_h_INCLUDED - -namespace ndarray { - -template class ToBoostPython; -template class FromBoostPython; - -} // namespace ndarray - -#endif // !NDARRAY_bp_fwd_h_INCLUDED diff --git a/include/ndarray/buildOptions.h.in b/include/ndarray/buildOptions.h.in deleted file mode 100644 index 38ccd2be..00000000 --- a/include/ndarray/buildOptions.h.in +++ /dev/null @@ -1,5 +0,0 @@ -// Build options that need to be remembered -// so they can be used when other packages build against ndarray - -#cmakedefine NDARRAY_EIGENVIEW -#cmakedefine NDARRAY_STDPYBIND11EIGEN diff --git a/include/ndarray/eigen.h b/include/ndarray/eigen.h index afd6ec30..26ee65a2 100644 --- a/include/ndarray/eigen.h +++ b/include/ndarray/eigen.h @@ -26,7 +26,6 @@ #include "Eigen/Core" #include "ndarray.h" #include "ndarray/eigen_fwd.h" -#include "ndarray/EigenView.h" namespace ndarray { namespace detail { diff --git a/include/ndarray/eigen/bp.h b/include/ndarray/eigen/bp.h deleted file mode 100644 index ce77f8dd..00000000 --- a/include/ndarray/eigen/bp.h +++ /dev/null @@ -1,19 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_EIGEN_bp_h_INCLUDED -#define NDARRAY_EIGEN_bp_h_INCLUDED - -#include "ndarray/eigen/bp/EigenView.h" -#include "ndarray/eigen/bp/Array.h" -#include "ndarray/eigen/bp/Matrix.h" -#include "ndarray/eigen/bp/ReturnInternal.h" - -#endif // !NDARRAY_EIGEN_bp_h_INCLUDED diff --git a/include/ndarray/eigen/bp/Array.h b/include/ndarray/eigen/bp/Array.h deleted file mode 100644 index a6233366..00000000 --- a/include/ndarray/eigen/bp/Array.h +++ /dev/null @@ -1,59 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_EIGEN_BP_Array_h_INCLUDED -#define NDARRAY_EIGEN_BP_Array_h_INCLUDED - -#include "ndarray/eigen/bp/EigenView.h" -#include "buildOptions.h" - -#ifdef NDARRAY_EIGENVIEW - -namespace ndarray { - -template -class ToBoostPython< Eigen::Array > { -public: - - typedef Eigen::Array Input; - - typedef boost::numpy::ndarray result_type; - - typedef typename SelectEigenView::Type View; - - static boost::numpy::ndarray apply(Input const & input) { - return ToBoostPython< View >::apply(ndarray::copy(input)); - } - -}; - -template -class FromBoostPython< Eigen::Array > { -public: - - typedef Eigen::Array Output; - - // Use noncontiguous EigenView ('false' below) because we don't care about the input strides. - typedef typename SelectEigenView::Type View; - - explicit FromBoostPython(boost::python::object const & input) : _impl(input) {} - - bool convertible() { return _impl.convertible(); } - - Output operator()() { return Output(_impl()); } - -private: - FromBoostPython< View > _impl; -}; - -} // namespace ndarray - -#endif // NDARRAY_EIGENVIEW -#endif // !NDARRAY_EIGEN_BP_Matrix_h_INCLUDED diff --git a/include/ndarray/eigen/bp/EigenView.h b/include/ndarray/eigen/bp/EigenView.h deleted file mode 100644 index fa2bdbf0..00000000 --- a/include/ndarray/eigen/bp/EigenView.h +++ /dev/null @@ -1,84 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_EIGEN_BP_EigenView_h_INCLUDED -#define NDARRAY_EIGEN_BP_EigenView_h_INCLUDED - -#include "boost/numpy.hpp" -#include "ndarray/bp/Array.h" -#include "ndarray/eigen.h" -#include "ndarray/buildOptions.h" - -#ifdef NDARRAY_EIGENVIEW - -namespace ndarray { - -template -class ToBoostPython< EigenView > { -public: - - typedef boost::numpy::ndarray result_type; - - static boost::numpy::ndarray apply(EigenView const & input) { - boost::numpy::ndarray result = ToBoostPython< Array >::apply(input.shallow()); - if (Rows_ == 1 || Cols_ == 1) return result.squeeze(); - return result; - } - -}; - -template -class FromBoostPython< EigenView > { -public: - - BOOST_STATIC_ASSERT( N == 1 || N == 2 ); - - BOOST_STATIC_ASSERT( N != 1 || Rows_ == 1 || Cols_ == 1 ); - - explicit FromBoostPython(boost::python::object const & input) : _impl(input) {} - - bool convertible() { - try { - boost::numpy::ndarray array = boost::python::extract(_impl.input); - if (N == 2) { - if (Rows_ == 1) { - array = array.reshape(boost::python::make_tuple(1, -1)); - } else if (Cols_ == 1) { - array = array.reshape(boost::python::make_tuple(-1, 1)); - } - if (Rows_ != Eigen::Dynamic && array.shape(0) != Rows_) return false; - if (Cols_ != Eigen::Dynamic && array.shape(1) != Cols_) return false; - } else if (N == 1) { - array = array.squeeze(); - int requiredSize = Rows_ * Cols_; - if (requiredSize != Eigen::Dynamic && array.shape(0) != requiredSize) return false; - } - _impl.input = array; - if (!_impl.convertible()) return false; - } catch (boost::python::error_already_set) { - boost::python::handle_exception(); - PyErr_Clear(); - return false; - } - return true; - } - - EigenView operator()() { - return EigenView(_impl()); - } - -private: - FromBoostPython< Array > _impl; -}; - -} // namespace ndarray - -#endif // NDARRAY_EIGENVIEW -#endif // !NDARRAY_EIGEN_BP_EigenView_h_INCLUDED diff --git a/include/ndarray/eigen/bp/Matrix.h b/include/ndarray/eigen/bp/Matrix.h deleted file mode 100644 index 895115b0..00000000 --- a/include/ndarray/eigen/bp/Matrix.h +++ /dev/null @@ -1,59 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_EIGEN_BP_Matrix_h_INCLUDED -#define NDARRAY_EIGEN_BP_Matrix_h_INCLUDED - -#include "ndarray/eigen/bp/EigenView.h" -#include "ndarray/buildOptions.h" - -#ifdef NDARRAY_EIGENVIEW - -namespace ndarray { - -template -class ToBoostPython< Eigen::Matrix > { -public: - - typedef Eigen::Matrix Input; - - typedef boost::numpy::ndarray result_type; - - typedef typename SelectEigenView::Type View; - - static boost::numpy::ndarray apply(Input const & input) { - return ToBoostPython< View >::apply(ndarray::copy(input)); - } - -}; - -template -class FromBoostPython< Eigen::Matrix > { -public: - - typedef Eigen::Matrix Output; - - // Use noncontiguous EigenView ('false' below) because we don't care about the input strides. - typedef typename SelectEigenView::Type View; - - explicit FromBoostPython(boost::python::object const & input) : _impl(input) {} - - bool convertible() { return _impl.convertible(); } - - Output operator()() { return Output(_impl()); } - -private: - FromBoostPython< View > _impl; -}; - -} // namespace ndarray - -#endif // NDARRAY_EIGENVIEW -#endif // !NDARRAY_EIGEN_BP_Matrix_h_INCLUDED diff --git a/include/ndarray/eigen/bp/ReturnInternal.h b/include/ndarray/eigen/bp/ReturnInternal.h deleted file mode 100644 index 96580d56..00000000 --- a/include/ndarray/eigen/bp/ReturnInternal.h +++ /dev/null @@ -1,131 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_EIGEN_BP_ReturnInternal_h_INCLUDED -#define NDARRAY_EIGEN_BP_ReturnInternal_h_INCLUDED - -#if defined __GNUC__ && __GNUC__>=6 - #pragma GCC diagnostic ignored "-Wignored-attributes" - #pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -#include "boost/numpy.hpp" -#include - -namespace ndarray { namespace detail { - -template -struct ShallowToBoostPython { - - typedef boost::numpy::ndarray result_type; - - typedef typename Input::Scalar Scalar; - - static boost::numpy::ndarray apply(Input const & input, bool writeable=true) { - boost::numpy::dtype dtype = boost::numpy::dtype::get_builtin(); - int itemsize = dtype.get_itemsize(); - std::vector shape(2); - shape[0] = input.rows(); - shape[1] = input.cols(); - std::vector strides(2, itemsize); - strides[0] *= input.rowStride(); - strides[1] *= input.colStride(); - boost::python::object none; - boost::numpy::ndarray result = (writeable) ? - boost::numpy::from_data(const_cast(input.data()), dtype, shape, strides, none) : - boost::numpy::from_data(const_cast(input.data()), dtype, shape, strides, none); - if (Input::RowsAtCompileTime == 1 || Input::ColsAtCompileTime == 1) return result.squeeze(); - return result; - } -}; - -} // namespace detail - -template -struct ReturnInternal : public Base { - - /** - * \brief A model of ResultConverter that creates a numpy.matrix view into an Eigen object. - * - * Note that the returned view does not own its own data, and doesn't (yet) own a reference - * to the object that does. For this reason, this result converter should ONLY be used by - * return_internal_matrix or with another model of CallPolicies with a postcall operations - * that installs a reference to the owning object. - */ - template - struct MakeShallowMatrix { - - inline bool convertible() const { return true; } - - inline PyObject * operator()(Input const & x) const { - try { - boost::python::object r = detail::ShallowToBoostPython< Input >::apply(x, writeable); - Py_INCREF(r.ptr()); - return r.ptr(); - } catch (boost::python::error_already_set & exc) { - boost::python::handle_exception(); - return NULL; - } - } - - inline PyTypeObject const * get_pytype() const { - return boost::python::converter::object_manager_traits< - typename detail::ShallowToBoostPython< Input >::result_type - >::get_pytype(); - } - - }; - - /// \brief Model of ResultConverterGenerator for make_shallow_matrix. - struct result_converter { - template - struct apply { - typedef typename boost::remove_reference::type dereferenced; - - typedef MakeShallowMatrix< - typename boost::remove_const::type, - boost::is_const::value - > type; - }; - }; - - template - static PyObject * postcall(ArgumentPackage const & args_, PyObject * result) { - std::size_t arity_ = boost::python::detail::arity(args_); - if (owner_arg > arity_ || owner_arg < 1) { - PyErr_SetString(PyExc_IndexError, - "ndarray::ReturnInternal: argument out of range."); - return NULL; - } - PyObject * owner_ref = boost::python::detail::get_prev::execute(args_, result); - if (owner_ref == NULL) return 0; - result = Base::postcall(args_, result); - if (result == NULL) return 0; - try { - boost::python::object owner( - reinterpret_cast(owner_ref) - ); - boost::numpy::ndarray array( - reinterpret_cast(result) - ); - array.set_base(owner); - Py_INCREF(array.ptr()); - result = array.ptr(); - } catch (boost::python::error_already_set & err) { - boost::python::handle_exception(); - return NULL; - } - return result; - } -}; - -} // namespace ndarray - -#endif // !NDARRAY_EIGEN_BP_ReturnInternal_h_INCLUDED diff --git a/include/ndarray/eigen/bp/auto.h b/include/ndarray/eigen/bp/auto.h deleted file mode 100644 index b1cefbd5..00000000 --- a/include/ndarray/eigen/bp/auto.h +++ /dev/null @@ -1,19 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#ifndef NDARRAY_EIGEN_BP_auto_h_INCLUDED -#define NDARRAY_EIGEN_BP_auto_h_INCLUDED - -#include "ndarray/eigen/bp/auto/EigenView.h" -#include "ndarray/eigen/bp/auto/Array.h" -#include "ndarray/eigen/bp/auto/Matrix.h" -#include "ndarray/eigen/bp.h" - -#endif // !NDARRAY_EIGEN_BP_auto_h_INCLUDED diff --git a/include/ndarray/eigen/bp/auto/Array.h.m4 b/include/ndarray/eigen/bp/auto/Array.h.m4 deleted file mode 100644 index 8202b295..00000000 --- a/include/ndarray/eigen/bp/auto/Array.h.m4 +++ /dev/null @@ -1,23 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -// THIS FILE IS MACHINE GENERATED BY SCONS. DO NOT EDIT MANUALLY. -include(`auto_bp_converters.m4')dnl -changecom(`###')dnl -#ifndef NDARRAY_EIGEN_BP_AUTO_Array_h_INCLUDED -#define NDARRAY_EIGEN_BP_AUTO_Array_h_INCLUDED - -#include "boost/numpy.hpp" -#include "ndarray/eigen/bp/Array.h" - -BP_AUTO_CONVERTERS(`typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols', - `Eigen::Array')dnl - -#endif // !NDARRAY_EIGEN_BP_AUTO_Array_h_INCLUDED diff --git a/include/ndarray/eigen/bp/auto/EigenView.h.m4 b/include/ndarray/eigen/bp/auto/EigenView.h.m4 deleted file mode 100644 index 994a4502..00000000 --- a/include/ndarray/eigen/bp/auto/EigenView.h.m4 +++ /dev/null @@ -1,27 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -// THIS FILE IS MACHINE GENERATED BY SCONS. DO NOT EDIT MANUALLY. -include(`auto_bp_converters.m4')dnl -changecom(`###')dnl -#ifndef NDARRAY_EIGEN_BP_AUTO_EigenView_h_INCLUDED -#define NDARRAY_EIGEN_BP_AUTO_EigenView_h_INCLUDED - -#include "boost/numpy.hpp" -#include "ndarray/eigen/bp/EigenView.h" -#include "ndarray/buildOptions.h" - -#ifdef NDARRAY_EIGENVIEW - -BP_AUTO_CONVERTERS(`typename T, int N, int C, typename XprKind_, int Rows_, int Cols_', - `ndarray::EigenView')dnl - -#endif // NDARRAY_EIGENVIEW -#endif // !NDARRAY_EIGEN_BP_AUTO_EigenView_h_INCLUDED diff --git a/include/ndarray/eigen/bp/auto/Matrix.h.m4 b/include/ndarray/eigen/bp/auto/Matrix.h.m4 deleted file mode 100644 index adadb29f..00000000 --- a/include/ndarray/eigen/bp/auto/Matrix.h.m4 +++ /dev/null @@ -1,23 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -// THIS FILE IS MACHINE GENERATED BY SCONS. DO NOT EDIT MANUALLY. -include(`auto_bp_converters.m4')dnl -changecom(`###')dnl -#ifndef NDARRAY_EIGEN_BP_AUTO_Matrix_h_INCLUDED -#define NDARRAY_EIGEN_BP_AUTO_Matrix_h_INCLUDED - -#include "boost/numpy.hpp" -#include "ndarray/eigen/bp/Matrix.h" - -BP_AUTO_CONVERTERS(`typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols', - `Eigen::Matrix')dnl - -#endif // !NDARRAY_EIGEN_BP_AUTO_Matrix_h_INCLUDED diff --git a/include/ndarray/eigen_fwd.h b/include/ndarray/eigen_fwd.h index 76831b93..fdb362fe 100644 --- a/include/ndarray/eigen_fwd.h +++ b/include/ndarray/eigen_fwd.h @@ -11,14 +11,12 @@ #ifndef NDARRAY_eigen_fwd_h_INCLUDED #define NDARRAY_eigen_fwd_h_INCLUDED -#include "ndarray/buildOptions.h" - /** * @file ndarray/eigen_fwd.h * @brief Forward declarations for ndarray/eigen interface. */ -/** +/** * \defgroup ndarrayEigenGroup Eigen * Interoperability with the Eigen 3 linear algebra library. */ @@ -35,19 +33,6 @@ namespace detail { template struct EigenStrideTraits; } // namespace detail - -#ifdef NDARRAY_EIGENVIEW - -template < - typename T, int N, int C, - typename XprKind_=Eigen::MatrixXpr, - int Rows_=-1, - int Cols_=((N == 1) ? 1 : -1) - > -class EigenView; - -#endif // NDARRAY_EIGENVIEW - } // namespace ndarray #endif // !NDARRAY_eigen_fwd_h_INCLUDED diff --git a/include/ndarray/pybind11.h b/include/ndarray/pybind11.h index 3101eec5..09eefac8 100644 --- a/include/ndarray/pybind11.h +++ b/include/ndarray/pybind11.h @@ -44,14 +44,8 @@ #include "pybind11.h" #include "pybind11/numpy.h" -#include "ndarray/buildOptions.h" -#ifdef NDARRAY_STDPYBIND11EIGEN -#include "pybind11/eigen.h" -#endif // NDARRAY_STDPYBIND11EIGEN - #include "ndarray.h" #include "ndarray/eigen.h" -#include "ndarray/buildOptions.h" namespace ndarray { @@ -248,193 +242,6 @@ class type_caster< ndarray::Array > { Helper _helper; }; -#ifdef NDARRAY_EIGENVIEW - -/* @brief A pybind11 type_caster for ndarray::EigenView - */ -template -class type_caster< ndarray::EigenView > { - using Helper = ndarray::Pybind11Helper; -public: - - bool load(handle src, bool) { - if (!_helper.init(src)) { - return false; - } - if (_helper.isNone) { - return true; - } - if ((Rows == 1 || Cols == 1) && N == 2) { - int shape[2] = { -1, -1 }; - if (Rows == 1) { - shape[0] = 1; - } else { - shape[1] = 1; - } - try { - _helper.wrapper = _helper.wrapper.attr("reshape")(shape[0], shape[1]); - } catch (error_already_set &) { - return false; - } - } else if (N == 1) { - _helper.wrapper = _helper.wrapper.squeeze(); - } - if (!_helper.check()) { - return false; - } - // check whether the shape is correct if it's static - if (N == 2) { - if (Rows != Eigen::Dynamic && _helper.wrapper.shape(0) != static_cast(Rows)) { - return false; - } - if (Cols != Eigen::Dynamic && _helper.wrapper.shape(1) != static_cast(Cols)) { - return false; - } - } else { - auto requiredSize = Rows * Cols; - if (requiredSize != Eigen::Dynamic && _helper.wrapper.size() != static_cast(requiredSize)) { - return false; - } - } - return true; - } - - void set_value() { - _value.reset(_helper.convert()); - } - - bool isNone() const { return _helper.isNone; } - - static handle cast(const ndarray::EigenView &src, return_value_policy /* policy */, handle /* parent */) { - using Wrapper = typename Helper::Wrapper; - Wrapper wrapper = reinterpret_steal(Helper::toPython(src.shallow())); - return wrapper.squeeze().release(); - } - - static PYBIND11_DESCR name() { return type_descr(_>()); } - - static handle cast(const ndarray::EigenView *src, return_value_policy policy, handle parent) { - return cast(*src, policy, parent); - } - - operator ndarray::EigenView * () { - if (isNone()) { - return nullptr; - } else { - set_value(); - return &_value; - } - } - - operator ndarray::EigenView & () { - set_value(); - return _value; - } - - template using cast_op_type = pybind11::detail::cast_op_type<_T>; - -private: - ndarray::EigenView _value; - Helper _helper; -}; - - -template -class type_caster< Eigen::Array > { - using OutputView = typename ndarray::SelectEigenView< Eigen::Array >::Type; - using InputView = typename ndarray::SelectEigenView< Eigen::Array const, false>::Type; -public: - - bool load(handle src, bool convert) { - return _nested.load(src, convert); - } - - void set_value() { - InputView & v = _nested; - _value = v; - } - - static handle cast(const Eigen::Array &src, return_value_policy policy, handle parent) { - OutputView v = ndarray::copy(src); - return type_caster< OutputView >::cast(v, policy, parent); - } - - static PYBIND11_DESCR name() { return type_descr(_>()); } - - static handle cast(const Eigen::Array *src, return_value_policy policy, handle parent) { - return cast(*src, policy, parent); - } - - operator Eigen::Array * () { - if (_nested.isNone()) { - return nullptr; - } else { - set_value(); - return &_value; - } - } - - operator Eigen::Array & () { - set_value(); - return _value; - } - - template using cast_op_type = pybind11::detail::cast_op_type<_T>; - -private: - Eigen::Array _value; - type_caster< InputView > _nested; -}; - - -template -class type_caster< Eigen::Matrix > { - using OutputView = typename ndarray::SelectEigenView< Eigen::Matrix >::Type; - using InputView = typename ndarray::SelectEigenView< Eigen::Matrix const, false>::Type; -public: - - bool load(handle src, bool convert) { - return _nested.load(src, convert); - } - - void set_value() { - InputView & v = _nested; - _value = v; - } - - static handle cast(const Eigen::Matrix &src, return_value_policy policy, handle parent) { - OutputView v = ndarray::copy(src); - return type_caster< OutputView >::cast(v, policy, parent); - } - - static PYBIND11_DESCR name() { return type_descr(_>()); } - - static handle cast(const Eigen::Matrix *src, return_value_policy policy, handle parent) { - return cast(*src, policy, parent); - } - - operator Eigen::Matrix * () { - if (_nested.isNone()) { - return nullptr; - } else { - set_value(); - return &_value; - } - } - - operator Eigen::Matrix & () { - set_value(); return _value; - } - - template using cast_op_type = pybind11::detail::cast_op_type<_T>; - -private: - Eigen::Matrix _value; - type_caster< InputView > _nested; -}; - -#endif // NDARRAY_EIGENVIEW - NAMESPACE_END(detail) NAMESPACE_END(pybind11) diff --git a/m4/auto_bp_converters.m4 b/m4/auto_bp_converters.m4 deleted file mode 100644 index d07d5709..00000000 --- a/m4/auto_bp_converters.m4 +++ /dev/null @@ -1,73 +0,0 @@ -define(`BP_AUTO_CONVERTERS', -` -namespace boost { namespace python { - -template <$1> -struct to_python_value< $2 const & > : public detail::builtin_to_python { - inline PyObject * operator()($2 const & x) const { - object result = ndarray::ToBoostPython< $2 >::apply(x); - Py_INCREF(result.ptr()); - return result.ptr(); - } - inline PyTypeObject const * get_pytype() const { - return converter::object_manager_traits< - typename ndarray::ToBoostPython< $2 >::result_type - >::get_pytype(); - } -}; - -template <$1> -struct to_python_value< $2 & > : public detail::builtin_to_python { - inline PyObject * operator()($2 & x) const { - object result = ndarray::ToBoostPython< $2 >::apply(x); - Py_INCREF(result.ptr()); - return result.ptr(); - } - inline PyTypeObject const * get_pytype() const { - return converter::object_manager_traits< - typename ndarray::ToBoostPython< $2 >::result_type - >::get_pytype(); - } -}; - -namespace converter { - -template <$1> -struct arg_to_python< $2 > : public handle<> { - inline arg_to_python($2 const & v) : - handle<>(to_python_value<$2 const &>()(v)) {} -}; - -template <$1> -struct arg_rvalue_from_python< $2 const & > { - typedef $2 result_type; - arg_rvalue_from_python(PyObject * p) : - _converter(boost::python::object(boost::python::handle<>(boost::python::borrowed(p)))) {} - bool convertible() const { return _converter.convertible(); } - result_type operator()() const { return _converter(); } -private: - mutable ndarray::FromBoostPython< $2 > _converter; -}; - -template <$1> -struct arg_rvalue_from_python< $2 > : public arg_rvalue_from_python< $2 const &> { - arg_rvalue_from_python(PyObject * p) : arg_rvalue_from_python< $2 const & >(p) {} -}; - -template <$1> -struct arg_rvalue_from_python< $2 const > : public arg_rvalue_from_python< $2 const &> { - arg_rvalue_from_python(PyObject * p) : arg_rvalue_from_python< $2 const & >(p) {} -}; - -template <$1> -struct extract_rvalue< $2 > : private noncopyable { - typedef $2 result_type; - extract_rvalue(PyObject * x) : m_converter(x) {} - bool check() const { return m_converter.convertible(); } - result_type operator()() const { return m_converter(); } -private: - arg_rvalue_from_python< result_type const & > m_converter; -}; - -}}} // namespace boost::python::converter -')dnl diff --git a/tests/SConscript b/tests/SConscript deleted file mode 100644 index 5e2371a7..00000000 --- a/tests/SConscript +++ /dev/null @@ -1,85 +0,0 @@ -# -*- python -*- -# -# Copyright (c) 2010-2012, Jim Bosch -# All rights reserved. -# -# ndarray is distributed under a simple BSD-like license; -# see the LICENSE file that should be present in the root -# of the source distribution, or alternately available at: -# https://github.com/ndarray/ndarray -# -import os -import sys - -def RunBinaryUnitTest(target, source, env): - if not env.Execute(source[0].abspath): - env.Execute(Touch(target)) - -def BinaryUnitTest(env, source, dependencies=None): - if os.name != 'nt': - bin = env.Program(target="%s.test" % source, source=source) - else: - bin = env.Program(source) - run = env.Command(".%s.succeeded" % str(source), bin, RunBinaryUnitTest) - if dependencies: - env.Depends(run, dependencies) - env.Alias("tests", run) - return run - -def RunPythonUnitTest(target, source, env): - if not env.Execute('%s %s' % (sys.executable, source[0].abspath)): - env.Execute(Touch(target)) - -def PythonUnitTest(env, script, dependencies): - run = env.Command(".%s.succeeded" % str(script), script, RunPythonUnitTest) - env.Depends(run, dependencies) - env.Alias("tests", run) - return run - -Import("env", "testEnv", "pyEnv", "bpEnv") - -if testEnv.haveBoostTest: - BinaryUnitTest(testEnv, "ndarray.cc") - BinaryUnitTest(testEnv, "views.cc") - if testEnv.haveEigen: - BinaryUnitTest(testEnv, "ndarray-eigen.cc") - if testEnv.haveFFTW: - fftwEnv = testEnv.Clone() - BinaryUnitTest(fftwEnv, "ndarray-fft.cc") - -if pyEnv.havePython: - mod = pyEnv.LoadableModule("python_test_mod", "python_test_mod.cc", SHLIBPREFIX="") - if os.name == 'nt': - # Move the module to have the correct name. - mod = env.Command(os.path.join(Dir('.').srcnode().abspath, "python_test_mod.pyd"), - mod, - Move(os.path.join(Dir('.').srcnode().abspath, "python_test_mod.pyd"), mod[0])) - PythonUnitTest(pyEnv, "python_test.py", mod) - -if bpEnv.haveBoostPython: - libs = bpEnv.get("LIBS", []) + ["boost_numpy"] - libpath = bpEnv.get("LIBPATH", []) + [Dir("#Boost.NumPy/libs/numpy/src").abspath] - rpath = bpEnv.get("RPATH", []) + [Dir("#Boost.NumPy/libs/numpy/src").abspath] - bpEnv.Append( LINKFLAGS = ["$__RPATH"] ) # workaround for SCons bug #1644 - mod = bpEnv.LoadableModule("bp_test_mod", "bp_test_mod.cc", SHLIBPREFIX="", - LIBS=libs, LIBPATH=libpath, RPATH=rpath) - if os.name == 'nt': - # Move the module to have the correct name. - mod = env.Command(os.path.join(Dir('.').srcnode().abspath, "bp_test_mod.pyd"), - mod, - Move(os.path.join(Dir('.').srcnode().abspath, "bp_test_mod.pyd"), mod[0])) - PythonUnitTest(bpEnv, "bp_test.py", mod) - if bpEnv.haveEigen: - mod = bpEnv.LoadableModule("eigen_bp_test_mod", "eigen_bp_test_mod.cc", SHLIBPREFIX="", - LIBS=libs, LIBPATH=libpath, RPATH=rpath) - if os.name == 'nt': - # Move the module to have the correct name. - mod = env.Command(os.path.join(Dir('.').srcnode().abspath, "eigen_bp_test_mod.pyd"), - mod, - Move(os.path.join(Dir('.').srcnode().abspath, "eigen_bp_test_mod.pyd"), mod[0])) - PythonUnitTest(bpEnv, "eigen_bp_test.py", mod) - - -env.Clean("tests", Glob("*.os")) -env.Clean("tests", Glob("*.pyc")) -env.Clean("tests", Glob("*.so")) diff --git a/tests/bp_test.py b/tests/bp_test.py deleted file mode 100755 index 714c8f5a..00000000 --- a/tests/bp_test.py +++ /dev/null @@ -1,94 +0,0 @@ -# -*- python -*- -# -# Copyright (c) 2010-2012, Jim Bosch -# All rights reserved. -# -# ndarray is distributed under a simple BSD-like license; -# see the LICENSE file that should be present in the root -# of the source distribution, or alternately available at: -# https://github.com/ndarray/ndarray -# -import bp_test_mod -import unittest -import numpy - -class TestNdArrayWrappers(unittest.TestCase): - - def testReturnArray(self): - for suffix in ("11","10","22","21","20","33","32","31","30"): - func = getattr(bp_test_mod, "returnArray_d%s" % suffix) - cfunc = getattr(bp_test_mod, "returnArray_dc%s" % suffix) - array = func() - carray = cfunc() - self.assert_((array == numpy.arange(0, array.size).reshape(array.shape)).all()) - self.assert_((carray == numpy.arange(0, carray.size).reshape(carray.shape)).all()) - self.assert_(array.flags["WRITEABLE"]) - self.assert_(not carray.flags["WRITEABLE"]) - - def testAcceptArray(self): - for suffix in ("11","10","22","21","20","33","32","31","30"): - func = getattr(bp_test_mod, "acceptArray_d%s" % suffix) - cfunc = getattr(bp_test_mod, "acceptArray_dc%s" % suffix) - nd = int(suffix[0]) - shape = tuple(int(i) for i in numpy.random.randint(low=2,high=5,size=nd)) - array = numpy.zeros(shape, dtype=float) - array[:] = numpy.arange(0, array.size).reshape(array.shape) - self.assert_(func(array)) - self.assert_(cfunc(array)) - - def testAcceptArrayVal(self): - for suffix in ("11","10","22","21","20","33","32","31","30"): - func = getattr(bp_test_mod, "acceptArrayVal_d%s" % suffix) - cfunc = getattr(bp_test_mod, "acceptArrayVal_dc%s" % suffix) - nd = int(suffix[0]) - shape = tuple(int(i) for i in numpy.random.randint(low=2,high=5,size=nd)) - array = numpy.zeros(shape, dtype=float) - array[:] = numpy.arange(0, array.size).reshape(array.shape) - self.assert_(func(array)) - self.assert_(cfunc(array)) - - def testExtractArray(self): - for suffix in ("11","10","22","21","20","33","32","31","30"): - func = getattr(bp_test_mod, "extractArray_d%s" % suffix) - cfunc = getattr(bp_test_mod, "extractArray_dc%s" % suffix) - nd = int(suffix[0]) - shape = tuple(int(i) for i in numpy.random.randint(low=2,high=5,size=nd)) - array = numpy.zeros(shape, dtype=float) - array[:] = numpy.arange(0, array.size).reshape(array.shape) - self.assert_(func(array)) - self.assert_(cfunc(array)) - - def testReturnVector(self): - for suffix in ("2","3"): - func = getattr(bp_test_mod, "returnVector_d%s" % suffix) - vector = func() - self.assertEqual(vector, tuple(numpy.arange(len(vector), dtype=float))) - - def testAcceptVector(self): - for suffix in ("2","3"): - func = getattr(bp_test_mod, "acceptVector_d%s" % suffix) - nd = int(suffix[0]) - vector = tuple(numpy.arange(nd, dtype=float)) - self.assert_(func(vector)) - - def testStrideHandling(self): - # in NumPy 1.8+ 1- and 0-sized arrays can have arbitrary strides; we should - # be able to handle those - array = numpy.zeros(1, dtype=float) - self.assert_(bp_test_mod.acceptArray_d11(array)) - self.assert_(bp_test_mod.acceptArray_d10(array)) - array = numpy.zeros(0, dtype=float) - self.assert_(bp_test_mod.acceptArray_d11(array)) - self.assert_(bp_test_mod.acceptArray_d10(array)) - # test that we gracefully fail when the strides are not multiples of the itemsize - dtype = numpy.dtype([("f1", numpy.float64), ("f2", numpy.int16)]) - table = numpy.zeros(3, dtype=dtype) - self.assertRaises(TypeError, bp_test_mod.acceptArray_d10, table['f1']) - - def _testMemory(self): - shape = (400, 400, 10) - for n in range(1000000): - a = bp_test_mod.makeArray_d33(shape) - -if __name__=="__main__": - unittest.main() diff --git a/tests/bp_test_mod.cc b/tests/bp_test_mod.cc deleted file mode 100644 index cce9795f..00000000 --- a/tests/bp_test_mod.cc +++ /dev/null @@ -1,190 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ - -#include "ndarray/bp/auto.h" - -#include "boost/random/mersenne_twister.hpp" -#include "boost/random/uniform_int.hpp" - -static boost::mt19937 engine; -static boost::uniform_int<> random_int(2, 5); - -template -ndarray::Array makeArray(ndarray::Vector const & shape) { - ndarray::Array::type,N,N> a = ndarray::allocate(shape); - ndarray::Array::type,1,1> flat = ndarray::flatten<1>(a); - for (int n=0; n < flat.template getSize<0>(); ++n) { - flat[n] = n; - } - return a; -} - -template -ndarray::Vector makeShape() { - ndarray::Vector shape; - for (int n=0; n -ndarray::Array returnArray() { - ndarray::Array::type,N,N> a = ndarray::allocate(makeShape()); - ndarray::Array::type,1,1> flat = ndarray::flatten<1>(a); - for (int n=0; n < flat.template getSize<0>(); ++n) { - flat[n] = n; - } - return a; -} - -template -bool acceptArray(ndarray::Array const & p) { - ndarray::Array::type,N,N> a = ndarray::allocate(p.getShape()); - a.deep() = p; - ndarray::Array::type,1,1> flat = ndarray::flatten<1>(a); - for (int n=0; n < flat.template getSize<0>(); ++n) { - if (flat[n] != n) return false; - } - return true; -} - -template -bool acceptArrayVal(ndarray::Array p) { - ndarray::Array::type,N,N> a = ndarray::allocate(p.getShape()); - a.deep() = p; - ndarray::Array::type,1,1> flat = ndarray::flatten<1>(a); - for (int n=0; n < flat.template getSize<0>(); ++n) { - if (flat[n] != n) return false; - } - return true; -} - -template -bool extractArray(boost::python::object const & obj) { - ndarray::Array p = boost::python::extract< ndarray::Array >(obj); - ndarray::Array::type,N,N> a = ndarray::allocate(p.getShape()); - a.deep() = p; - ndarray::Array::type,1,1> flat = ndarray::flatten<1>(a); - for (int n=0; n < flat.template getSize<0>(); ++n) { - if (flat[n] != n) return false; - } - return true; -} - -template -ndarray::Vector returnVector() { - ndarray::Vector r; - for (int n=0; n -bool acceptVector(ndarray::Vector const & p) { - for (int n=0; n -bool extractVector(boost::python::object const & obj) { - ndarray::Vector p = boost::python::extract< ndarray::Vector >(obj); - for (int n=0; n); - boost::python::def("returnArray_d11", returnArray); - boost::python::def("returnArray_d10", returnArray); - boost::python::def("returnArray_d22", returnArray); - boost::python::def("returnArray_d21", returnArray); - boost::python::def("returnArray_d20", returnArray); - boost::python::def("returnArray_d33", returnArray); - boost::python::def("returnArray_d32", returnArray); - boost::python::def("returnArray_d31", returnArray); - boost::python::def("returnArray_d30", returnArray); - boost::python::def("returnArray_dc11", returnArray); - boost::python::def("returnArray_dc10", returnArray); - boost::python::def("returnArray_dc22", returnArray); - boost::python::def("returnArray_dc21", returnArray); - boost::python::def("returnArray_dc20", returnArray); - boost::python::def("returnArray_dc33", returnArray); - boost::python::def("returnArray_dc32", returnArray); - boost::python::def("returnArray_dc31", returnArray); - boost::python::def("returnArray_dc30", returnArray); - boost::python::def("acceptArray_d11", acceptArray); - boost::python::def("acceptArray_d10", acceptArray); - boost::python::def("acceptArray_d22", acceptArray); - boost::python::def("acceptArray_d21", acceptArray); - boost::python::def("acceptArray_d20", acceptArray); - boost::python::def("acceptArray_d33", acceptArray); - boost::python::def("acceptArray_d32", acceptArray); - boost::python::def("acceptArray_d31", acceptArray); - boost::python::def("acceptArray_d30", acceptArray); - boost::python::def("acceptArray_dc11", acceptArray); - boost::python::def("acceptArray_dc10", acceptArray); - boost::python::def("acceptArray_dc22", acceptArray); - boost::python::def("acceptArray_dc21", acceptArray); - boost::python::def("acceptArray_dc20", acceptArray); - boost::python::def("acceptArray_dc33", acceptArray); - boost::python::def("acceptArray_dc32", acceptArray); - boost::python::def("acceptArray_dc31", acceptArray); - boost::python::def("acceptArray_dc30", acceptArray); - boost::python::def("acceptArrayVal_d11", acceptArrayVal); - boost::python::def("acceptArrayVal_d10", acceptArrayVal); - boost::python::def("acceptArrayVal_d22", acceptArrayVal); - boost::python::def("acceptArrayVal_d21", acceptArrayVal); - boost::python::def("acceptArrayVal_d20", acceptArrayVal); - boost::python::def("acceptArrayVal_d33", acceptArrayVal); - boost::python::def("acceptArrayVal_d32", acceptArrayVal); - boost::python::def("acceptArrayVal_d31", acceptArrayVal); - boost::python::def("acceptArrayVal_d30", acceptArrayVal); - boost::python::def("acceptArrayVal_dc11", acceptArrayVal); - boost::python::def("acceptArrayVal_dc10", acceptArrayVal); - boost::python::def("acceptArrayVal_dc22", acceptArrayVal); - boost::python::def("acceptArrayVal_dc21", acceptArrayVal); - boost::python::def("acceptArrayVal_dc20", acceptArrayVal); - boost::python::def("acceptArrayVal_dc33", acceptArrayVal); - boost::python::def("acceptArrayVal_dc32", acceptArrayVal); - boost::python::def("acceptArrayVal_dc31", acceptArrayVal); - boost::python::def("acceptArrayVal_dc30", acceptArrayVal); - boost::python::def("extractArray_d11", extractArray); - boost::python::def("extractArray_d10", extractArray); - boost::python::def("extractArray_d22", extractArray); - boost::python::def("extractArray_d21", extractArray); - boost::python::def("extractArray_d20", extractArray); - boost::python::def("extractArray_d33", extractArray); - boost::python::def("extractArray_d32", extractArray); - boost::python::def("extractArray_d31", extractArray); - boost::python::def("extractArray_d30", extractArray); - boost::python::def("extractArray_dc11", extractArray); - boost::python::def("extractArray_dc10", extractArray); - boost::python::def("extractArray_dc22", extractArray); - boost::python::def("extractArray_dc21", extractArray); - boost::python::def("extractArray_dc20", extractArray); - boost::python::def("extractArray_dc33", extractArray); - boost::python::def("extractArray_dc32", extractArray); - boost::python::def("extractArray_dc31", extractArray); - boost::python::def("extractArray_dc30", extractArray); - boost::python::def("returnVector_d3", returnVector); - boost::python::def("returnVector_d2", returnVector); - boost::python::def("acceptVector_d3", acceptVector); - boost::python::def("acceptVector_d2", acceptVector); - boost::python::def("extractVector_d3", extractVector); - boost::python::def("extractVector_d2", extractVector); -} diff --git a/tests/eigen_bp_test.py b/tests/eigen_bp_test.py deleted file mode 100755 index 45c014cd..00000000 --- a/tests/eigen_bp_test.py +++ /dev/null @@ -1,87 +0,0 @@ -# -*- python -*- -# -# Copyright (c) 2010-2012, Jim Bosch -# All rights reserved. -# -# ndarray is distributed under a simple BSD-like license; -# see the LICENSE file that should be present in the root -# of the source distribution, or alternately available at: -# https://github.com/ndarray/ndarray -# -import eigen_bp_test_mod -import unittest -import numpy - -class TestEigenWrappers(unittest.TestCase): - - def setUp(self): - self.matrix_p_i = numpy.array([[1,2,3],[4,5,6]], dtype=numpy.int32, order="C") - self.matrix_p_d = numpy.array([[1,2,3],[4,5,6]], dtype=numpy.float64, order="C") - self.matrix_m_i = numpy.array([[1,2,3],[4,5,6]], dtype=numpy.int32, order="F") - self.matrix_m_d = numpy.array([[1,2,3],[4,5,6]], dtype=numpy.float64, order="F") - self.vector_i = numpy.array([1,2,3,4], dtype=numpy.int32) - self.vector_d = numpy.array([1,2,3,4], dtype=numpy.float64) - - def testEigenView(self): - for typechar in ("d", "i"): - for name1 in ("M23", "MX3", "M2X", "MXX", "A23", "AX3", "A2X", "AXX"): - for name2 in ("2p2", "2p1", "2p0"): - m = getattr(self, "matrix_p_%s" % typechar) - accept = getattr(eigen_bp_test_mod, "acceptEigenView_%s%s_%s" % (name1, typechar, name2)) - ret = getattr(eigen_bp_test_mod, "returnEigenView_%s%s_%s" % (name1, typechar, name2)) - self.assert_(accept(m)) - self.assert_((ret() == m).all()) - for name2 in ("2m2", "2m1", "2p0"): - m = getattr(self, "matrix_m_%s" % typechar) - accept = getattr(eigen_bp_test_mod, "acceptEigenView_%s%s_%s" % (name1, typechar, name2)) - ret = getattr(eigen_bp_test_mod, "returnEigenView_%s%s_%s" % (name1, typechar, name2)) - self.assert_(accept(m)) - self.assert_((ret() == m).all()) - - def testAcceptMatrix(self): - self.assert_(eigen_bp_test_mod.acceptMatrix_23d_cref(self.matrix_p_d)) - self.assert_(eigen_bp_test_mod.acceptMatrix_X3d_cref(self.matrix_p_d)) - self.assert_(eigen_bp_test_mod.acceptMatrix_2Xd_cref(self.matrix_p_d)) - self.assert_(eigen_bp_test_mod.acceptMatrix_XXd_cref(self.matrix_p_d)) - self.assert_(eigen_bp_test_mod.acceptMatrix_23d_cref(self.matrix_m_d)) - self.assert_(eigen_bp_test_mod.acceptMatrix_X3d_cref(self.matrix_m_d)) - self.assert_(eigen_bp_test_mod.acceptMatrix_2Xd_cref(self.matrix_m_d)) - self.assert_(eigen_bp_test_mod.acceptMatrix_XXd_cref(self.matrix_m_d)) - - def testAcceptVector(self): - self.assert_(eigen_bp_test_mod.acceptVector_41d_cref(self.vector_d)) - self.assert_(eigen_bp_test_mod.acceptVector_X1d_cref(self.vector_d)) - self.assert_(eigen_bp_test_mod.acceptVector_14d_cref(self.vector_d)) - self.assert_(eigen_bp_test_mod.acceptVector_1Xd_cref(self.vector_d)) - - def testReturnMatrix(self): - self.assert_((eigen_bp_test_mod.returnMatrix_23d() == self.matrix_p_d).all()) - self.assert_((eigen_bp_test_mod.returnMatrix_X3d() == self.matrix_p_d).all()) - self.assert_((eigen_bp_test_mod.returnMatrix_2Xd() == self.matrix_p_d).all()) - self.assert_((eigen_bp_test_mod.returnMatrix_XXd() == self.matrix_p_d).all()) - self.assert_((eigen_bp_test_mod.returnMatrix_23d_c() == self.matrix_p_d).all()) - self.assert_((eigen_bp_test_mod.returnMatrix_X3d_c() == self.matrix_p_d).all()) - self.assert_((eigen_bp_test_mod.returnMatrix_2Xd_c() == self.matrix_p_d).all()) - self.assert_((eigen_bp_test_mod.returnMatrix_XXd_c() == self.matrix_p_d).all()) - - def testReturnObject(self): - self.assert_((eigen_bp_test_mod.returnObject_23d() == self.matrix_p_d).all()) - self.assert_((eigen_bp_test_mod.returnObject_X3d() == self.matrix_p_d).all()) - self.assert_((eigen_bp_test_mod.returnObject_2Xd() == self.matrix_p_d).all()) - self.assert_((eigen_bp_test_mod.returnObject_XXd() == self.matrix_p_d).all()) - - def testMatrixOwner(self): - for suffix in ("23d", "X3d", "2Xd", "XXd"): - cls = getattr(eigen_bp_test_mod, "MatrixOwner_%s" % suffix) - obj = cls() - self.assert_(obj.getMatrix_ref().base is obj) - self.assert_(obj.getMatrix_cref().base is obj) - self.assert_((obj.getMatrix_ref() == self.matrix_p_d).all()) - self.assert_((obj.getMatrix_cref() == self.matrix_p_d).all()) - self.assert_(obj.getMatrix_ref().flags["WRITEABLE"]) - self.assert_(not obj.getMatrix_cref().flags["WRITEABLE"]) - self.assert_(not obj.getMatrix_ref().flags["OWNDATA"]) - self.assert_(not obj.getMatrix_cref().flags["OWNDATA"]) - -if __name__=="__main__": - unittest.main() diff --git a/tests/eigen_bp_test_mod.cc b/tests/eigen_bp_test_mod.cc deleted file mode 100644 index 7ae6224c..00000000 --- a/tests/eigen_bp_test_mod.cc +++ /dev/null @@ -1,191 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#include "ndarray/buildOptions.h" -#include "ndarray/eigen/bp/auto.h" - -namespace bp = boost::python; -namespace bn = boost::numpy; - -template -bool acceptMatrix(M m) { - return (m(0,0) == 1) && (m(0,1) == 2) && (m(0,2) == 3) - && (m(1,0) == 4) && (m(1,1) == 5) && (m(1,2) == 6); -} - -template -bool acceptVector(M m) { - return (m[0] == 1) && (m[1] == 2) && (m[2] == 3) && (m[3] == 4); -} - - -template -void fillMatrix(M & m) { - m(0,0) = 1; - m(0,1) = 2; - m(0,2) = 3; - m(1,0) = 4; - m(1,1) = 5; - m(1,2) = 6; -} - -#ifdef NDARRAY_EIGENVIEW - -template -M returnEigenView() { - static typename boost::remove_const::type>::type m( - ndarray::allocate(2,3) - ); - fillMatrix(m); - return m; -} - -#endif NDARRAY_EIGENVIEW - -template -M returnMatrix() { - static typename boost::remove_const::type>::type m(2,3); - fillMatrix(m); - return m; -} - -template -void fillVector(M & m) { - m[0] = 1; - m[1] = 2; - m[2] = 3; - m[3] = 4; -} - -template -M returnVector() { - static typename boost::remove_const::type>::type m(4); - fillVector(m); - return m; -} - -template -bp::object returnObject() { - static typename boost::remove_const::type>::type m(2,3); - fillMatrix(m); - bp::object o(m); - return o; -} - -template -class MatrixOwner { - M _matrix; -public: - MatrixOwner() : _matrix(2,3) { fillMatrix(_matrix); } - - M const & getMatrix_cref() const { return _matrix; } - M & getMatrix_ref() { return _matrix; } - - bool compareData(bn::matrix const & mp) const { - return _matrix.data() == reinterpret_cast(mp.get_data()); - } - - EIGEN_MAKE_ALIGNED_OPERATOR_NEW; - - static void declare(char const * name) { - bp::class_< MatrixOwner >(name) - .def("getMatrix_cref", &MatrixOwner::getMatrix_cref, - ndarray::ReturnInternal<>()) - .def("getMatrix_ref", &MatrixOwner::getMatrix_ref, - ndarray::ReturnInternal<>()) - .def("compareData", &MatrixOwner::compareData) - ; - } -}; - -static const int X = Eigen::Dynamic; - -#ifdef NDARRAY_EIGENVIEW - -template -void wrapEigenView(std::string const & name) { - bp::def(("accept" + name + "_2p2").c_str(), - acceptMatrix const &>); - bp::def(("accept" + name + "_2p1").c_str(), - acceptMatrix const &>); - bp::def(("accept" + name + "_2p0").c_str(), - acceptMatrix const &>); - bp::def(("accept" + name + "_2m1").c_str(), - acceptMatrix const &>); - bp::def(("accept" + name + "_2m2").c_str(), - acceptMatrix const &>); - bp::def(("return" + name + "_2p2").c_str(), - returnEigenView >); - bp::def(("return" + name + "_2p1").c_str(), - returnEigenView >); - bp::def(("return" + name + "_2p0").c_str(), - returnEigenView >); - bp::def(("return" + name + "_2m1").c_str(), - returnEigenView >); - bp::def(("return" + name + "_2m2").c_str(), - returnEigenView >); -} - -#endif // NDARRAY_EIGENVIEW - -BOOST_PYTHON_MODULE(eigen_bp_test_mod) { - bn::initialize(); - -#ifdef NDARRAY_EIGENVIEW - - wrapEigenView("EigenView_M23d"); - wrapEigenView("EigenView_MX3d"); - wrapEigenView("EigenView_M2Xd"); - wrapEigenView("EigenView_MXXd"); - wrapEigenView("EigenView_M23i"); - wrapEigenView("EigenView_MX3i"); - wrapEigenView("EigenView_M2Xi"); - wrapEigenView("EigenView_MXXi"); - - wrapEigenView("EigenView_A23d"); - wrapEigenView("EigenView_AX3d"); - wrapEigenView("EigenView_A2Xd"); - wrapEigenView("EigenView_AXXd"); - wrapEigenView("EigenView_A23i"); - wrapEigenView("EigenView_AX3i"); - wrapEigenView("EigenView_A2Xi"); - wrapEigenView("EigenView_AXXi"); - -#endif // NDARRAY_EIGENVIEW - - bp::def("acceptMatrix_23d_cref", acceptMatrix< Eigen::Matrix const & >); - bp::def("acceptMatrix_X3d_cref", acceptMatrix< Eigen::Matrix const & >); - bp::def("acceptMatrix_2Xd_cref", acceptMatrix< Eigen::Matrix const & >); - bp::def("acceptMatrix_XXd_cref", acceptMatrix< Eigen::Matrix const & >); - bp::def("acceptVector_41d_cref", acceptVector< Eigen::Matrix const & >); - bp::def("acceptVector_X1d_cref", acceptVector< Eigen::Matrix const & >); - bp::def("acceptVector_14d_cref", acceptVector< Eigen::Matrix const & >); - bp::def("acceptVector_1Xd_cref", acceptVector< Eigen::Matrix const & >); - bp::def("returnVector_41d", returnVector< Eigen::Matrix >); - bp::def("returnVector_14d", returnVector< Eigen::Matrix >); - bp::def("returnVector_X1d", returnVector< Eigen::Matrix >); - bp::def("returnVector_1Xd", returnVector< Eigen::Matrix >); - bp::def("returnMatrix_23d", returnMatrix< Eigen::Matrix >); - bp::def("returnMatrix_X3d", returnMatrix< Eigen::Matrix >); - bp::def("returnMatrix_2Xd", returnMatrix< Eigen::Matrix >); - bp::def("returnMatrix_XXd", returnMatrix< Eigen::Matrix >); - bp::def("returnMatrix_23d_c", returnMatrix< Eigen::Matrix const>); - bp::def("returnMatrix_X3d_c", returnMatrix< Eigen::Matrix const>); - bp::def("returnMatrix_2Xd_c", returnMatrix< Eigen::Matrix const>); - bp::def("returnMatrix_XXd_c", returnMatrix< Eigen::Matrix const>); - bp::def("returnObject_23d", returnObject< Eigen::Matrix >); - bp::def("returnObject_X3d", returnObject< Eigen::Matrix >); - bp::def("returnObject_2Xd", returnObject< Eigen::Matrix >); - bp::def("returnObject_XXd", returnObject< Eigen::Matrix >); - MatrixOwner< Eigen::Matrix >::declare("MatrixOwner_23d"); - MatrixOwner< Eigen::Matrix >::declare("MatrixOwner_X3d"); - MatrixOwner< Eigen::Matrix >::declare("MatrixOwner_2Xd"); - MatrixOwner< Eigen::Matrix >::declare("MatrixOwner_XXd"); -} diff --git a/tests/ndarray-eigen.cc b/tests/ndarray-eigen.cc index 475c7a63..7d4785dd 100644 --- a/tests/ndarray-eigen.cc +++ b/tests/ndarray-eigen.cc @@ -9,7 +9,6 @@ * https://github.com/ndarray/ndarray */ #include "ndarray/eigen.h" -#include "ndarray/buildOptions.h" #include "Eigen/SVD" #define BOOST_TEST_DYN_LINK @@ -133,140 +132,6 @@ BOOST_AUTO_TEST_CASE(AsEigen) { invokeAsEigenTests(); } -#ifdef NDARRAY_EIGENVIEW - -template -void testEigenView(ndarray::EigenView b) { - ndarray::Array a(b.shallow()); - b.setRandom(); - testElements2(a, b); - Eigen::Matrix m1(b.rows(), 6); - m1.setRandom(b.rows(), 6); - Eigen::Matrix m2(6, b.cols()); - m2.setRandom(6, b.cols()); - b.matrix() = m1 * m2; - Eigen::Matrix m3 = m1 * m2; - for (int i = 0; i < b.rows(); ++i) { - for (int j = 0; j < b.cols(); ++j) { - BOOST_CHECK(a[i][j] == m3(i,j)); - } - } - Eigen::Array m4(b.rows(), b.cols()); - m4.setRandom(); - Eigen::Array m5 = m4 * b; - Eigen::Array m6 = m4 * m3.array(); - BOOST_CHECK( (m5 == m6).all() ); -} - -template -void testEigenView(ndarray::EigenView b) { - ndarray::Array a(b.shallow()); - b.setRandom(); - testElements1(a, b); - Eigen::Matrix m1(b.rows(), 6); - m1.setRandom(b.rows(), 6); - Eigen::Matrix m2(6, b.cols()); - m2.setRandom(6, b.cols()); - b.matrix() = m1 * m2; - Eigen::Matrix m3 = m1 * m2; - for (int i = 0; i < b.rows(); ++i) { - BOOST_CHECK(a[i] == m3[i]); - } - Eigen::Array m4(b.rows(), b.cols()); - m4.setRandom(); - Eigen::Array m5 = m4 * b; - Eigen::Array m6 = m4 * m3.array(); - BOOST_CHECK( (m5 == m6).all() ); -} - -template -void testEigenView(ndarray::EigenView b) { - ndarray::Array a(b.shallow()); - b.setRandom(); - testElements2(a, b); - Eigen::Matrix m1(b.rows(), 6); - m1.setRandom(b.rows(), 6); - Eigen::Matrix m2(6, b.cols()); - m2.setRandom(6, b.cols()); - b = m1 * m2; - Eigen::Matrix m3 = m1 * m2; - for (int i = 0; i < b.rows(); ++i) { - for (int j = 0; j < b.cols(); ++j) { - BOOST_CHECK(a[i][j] == m3(i,j)); - } - } - Eigen::Array m4(b.rows(), b.cols()); - m4.setRandom(); - Eigen::Array m5 = m4 * b.array(); - Eigen::Array m6 = m4 * m3.array(); - BOOST_CHECK( (m5 == m6).all() ); -} - -template -void testEigenView(ndarray::EigenView b) { - ndarray::Array a(b.shallow()); - b.setRandom(); - testElements1(a, b); - Eigen::Matrix m1(b.rows(), 6); - m1.setRandom(b.rows(), 6); - Eigen::Matrix m2(6, b.cols()); - m2.setRandom(6, b.cols()); - b = m1 * m2; - Eigen::Matrix m3 = m1 * m2; - for (int i = 0; i < b.rows(); ++i) { - BOOST_CHECK(a[i] == m3[i]); - } - Eigen::Array m4(b.rows(), b.cols()); - m4.setRandom(); - Eigen::Array m5 = m4 * b.array(); - Eigen::Array m6 = m4 * m3.array(); - BOOST_CHECK( (m5 == m6).all() ); -} - -template -void invokeEigenViewTests() { - ndarray::Array a22(ndarray::allocate(5,4)); - testEigenView(a22.asEigen()); - testEigenView(a22.asEigen()); - testEigenView(a22.transpose().asEigen()); - testEigenView(a22.transpose().asEigen()); - ndarray::Array a21(a22[ndarray::view()(0,3)]); - testEigenView(a21.asEigen()); - testEigenView(a21.asEigen()); - testEigenView(a21.transpose().asEigen()); - testEigenView(a21.transpose().asEigen()); - ndarray::Array a20(a22[ndarray::view()(0,4,2)]); - testEigenView(a20.asEigen()); - testEigenView(a20.asEigen()); - testEigenView(a20.transpose().asEigen()); - testEigenView(a20.transpose().asEigen()); - ndarray::Array a11(ndarray::allocate(4)); - testEigenView(a11.asEigen()); - testEigenView(a11.asEigen()); - testEigenView(a11.asEigen()); - testEigenView(a11.transpose().asEigen()); - testEigenView(a11.transpose().asEigen()); - testEigenView(a11.transpose().asEigen()); - ndarray::Array a10(a11[ndarray::view(0,4,2)]); - testEigenView(a10.asEigen()); - testEigenView(a10.asEigen()); - testEigenView(a10.asEigen()); - testEigenView(a10.transpose().asEigen()); - testEigenView(a10.transpose().asEigen()); - testEigenView(a10.transpose().asEigen()); -} - -BOOST_AUTO_TEST_CASE(EigenView) { - invokeEigenViewTests(); - invokeEigenViewTests(); - - Eigen::MatrixXd m(Eigen::MatrixXd::Random(5,6)); - ndarray::SelectEigenView::Type v(ndarray::copy(m)); - BOOST_CHECK( (v.array() == m.array()).all() ); -} - -#endif // NDARRAY_EIGENVIEW - template void testSVD(Matrix const & a, Vector const & b, Vector & x) { SVD svd(a, Eigen::ComputeThinU | Eigen::ComputeThinV); diff --git a/tests/pybind11_test.py b/tests/pybind11_test.py old mode 100755 new mode 100644 index b3f1e263..1c913ed6 --- a/tests/pybind11_test.py +++ b/tests/pybind11_test.py @@ -13,25 +13,9 @@ import pybind11_test_mod -HasEigenView = hasattr(pybind11_test_mod, "returnMatrixXd") - class TestNumpyPybind11(unittest.TestCase): - @unittest.skipIf(not HasEigenView, "No EigenView") - def testMatrixXd(self): - m1 = pybind11_test_mod.returnMatrixXd() - m2 = numpy.matrix(numpy.arange(15, dtype=float).reshape(3, 5).transpose()) - self.assertTrue((m1 == m2).all()) - self.assertTrue(pybind11_test_mod.acceptMatrixXd(m2)) - - @unittest.skipIf(not HasEigenView, "No EigenView") - def testMatrix2d(self): - m1 = pybind11_test_mod.returnMatrix2d() - m2 = numpy.matrix([[0.0, 2.0], [1.0, 3.0]]) - self.assertTrue((m1 == m2).all()) - self.assertTrue(pybind11_test_mod.acceptMatrix2d(m2)) - def testArray1(self): a1 = pybind11_test_mod.returnArray1() a2 = numpy.arange(6, dtype=float) @@ -50,22 +34,6 @@ def testArray3(self): self.assertTrue((a1 == a3).all()) self.assertFalse(a3.flags["WRITEABLE"]) - @unittest.skipIf(not HasEigenView, "No EigenView") - def testClass(self): - a = pybind11_test_mod.MatrixOwner() - m1 = a.member - m2 = a.getMember() - self.assertTrue((m1 == 0).all()) - self.assertTrue((m2 == 0).all()) - self.assertEqual(m1.shape, (2, 2)) - self.assertEqual(m2.shape, (2, 2)) - - @unittest.skipIf(not HasEigenView, "No EigenView") - def testOverloads(self): - self.assertEqual(pybind11_test_mod.acceptOverload(1), 0) - self.assertEqual(pybind11_test_mod.acceptOverload(numpy.zeros((2, 2), dtype=float)), 2) - self.assertEqual(pybind11_test_mod.acceptOverload(numpy.zeros((3, 3), dtype=float)), 3) - def testStrideHandling(self): # in NumPy 1.8+ 1- and 0-sized arrays can have arbitrary strides; we should # be able to handle those @@ -87,24 +55,6 @@ def testNone(self): self.assertEqual(pybind11_test_mod.acceptNoneArray(None), 1) self.assertEqual(pybind11_test_mod.acceptNoneArray(), 1) - if HasEigenView: - m1 = pybind11_test_mod.returnMatrixXd() - self.assertEqual(pybind11_test_mod.acceptNoneMatrixXd(m1), 2) - self.assertEqual(pybind11_test_mod.acceptNoneMatrixXd(None), 3) - self.assertEqual(pybind11_test_mod.acceptNoneMatrixXd(), 3) - - m2 = pybind11_test_mod.returnMatrix2d() - self.assertEqual(pybind11_test_mod.acceptNoneMatrix2d(m2), 4) - self.assertEqual(pybind11_test_mod.acceptNoneMatrix2d(None), 5) - self.assertEqual(pybind11_test_mod.acceptNoneMatrix2d(), 5) - - @unittest.skipIf(not HasEigenView, "No EigenView") - def testFullySpecifiedMatrix(self): - # Failure on this specific case was not caught by other unit tests - a = numpy.array([[1., 0.], [0., 1.]]) - b = numpy.array([0., 0.]) - self.assertTrue(pybind11_test_mod.acceptFullySpecifiedMatrix(a, b)) - def testNonNativeByteOrder(self): d1 = numpy.dtype("f8") diff --git a/tests/pybind11_test_mod.cc b/tests/pybind11_test_mod.cc index 9489f24e..b1d0fb73 100644 --- a/tests/pybind11_test_mod.cc +++ b/tests/pybind11_test_mod.cc @@ -1,29 +1,10 @@ #include "pybind11/pybind11.h" #include "ndarray/pybind11.h" -#include "ndarray/buildOptions.h" namespace py = pybind11; using namespace py::literals; -#ifdef NDARRAY_EIGENVIEW -Eigen::MatrixXd returnMatrixXd() { - Eigen::MatrixXd r(5, 3); - for (int n = 0; n < r.size(); ++n) { - r.data()[n] = n; - } - return r; -} - -Eigen::Matrix2d returnMatrix2d() { - Eigen::Matrix2d r; - for (int n = 0; n < r.size(); ++n) { - r.data()[n] = n; - } - return r; -} -#endif // NDARRAY_EIGENVIEW - ndarray::Array returnArray1() { ndarray::Array r(ndarray::allocate(ndarray::makeVector(6))); for (int n = 0; n < r.getSize<0>(); ++n) { @@ -49,18 +30,6 @@ ndarray::Array returnConstArray3() { return returnArray3(); } -#ifdef NDARRAY_EIGENVIEW -bool acceptMatrixXd(Eigen::MatrixXd const & m1) { - Eigen::MatrixXd m2 = returnMatrixXd(); - return m1 == m2; -} - -bool acceptMatrix2d(Eigen::Matrix2d const & m1) { - Eigen::Matrix2d m2 = returnMatrix2d(); - return m1 == m2; -} -#endif // NDARRAY_EIGENVIEW - bool acceptArray1(ndarray::Array const & a1) { ndarray::Array a2 = returnArray1(); #ifndef GCC_45 @@ -86,20 +55,6 @@ bool acceptArray3(ndarray::Array const & a1) { #endif } -#ifdef NDARRAY_EIGENVIEW -int acceptOverload(int n) { - return 0; -} - -int acceptOverload(Eigen::Matrix3d const & m) { - return 3; -} - -int acceptOverload(Eigen::Matrix2d const & m) { - return 2; -} -#endif // NDARRAY_EIGENVIEW - int acceptNoneArray(ndarray::Array const * array = nullptr) { if (array) { return 0; @@ -108,71 +63,17 @@ int acceptNoneArray(ndarray::Array const * array = nullptr) { } } -#ifdef NDARRAY_EIGENVIEW -int acceptNoneMatrixXd(Eigen::MatrixXd const * matrix = nullptr) { - if (matrix) { - return 2; - } else { - return 3; - } -} - -int acceptNoneMatrix2d(Eigen::Matrix2d const * matrix = nullptr) { - if (matrix) { - return 4; - } else { - return 5; - } -} - -struct MatrixOwner { - typedef Eigen::Matrix MemberMatrix; - MemberMatrix member; - MemberMatrix & getMember() { return member; } - explicit MatrixOwner() : member(MemberMatrix::Zero()) {} -}; - -bool acceptFullySpecifiedMatrix(Eigen::Matrix const & a, Eigen::Matrix const & b) { - return true; -}; -#endif // NDARRAY_EIGENVIEW - PYBIND11_PLUGIN(pybind11_test_mod) { pybind11::module mod("pybind11_test_mod", "Tests for the ndarray library"); -#ifdef NDARRAY_EIGENVIEW - py::class_ cls(mod, "MatrixOwner"); - cls.def(py::init<>()); - - py::class_(cls, "MemberMatrix"); - - cls.def_readwrite("member", &MatrixOwner::member); - cls.def("getMember", &MatrixOwner::getMember); - mod.def("returnMatrixXd", returnMatrixXd); - mod.def("returnMatrix2d", returnMatrix2d); -#endif // NDARRAY_EIGENVIEW mod.def("returnArray1", returnArray1); mod.def("returnConstArray1", returnConstArray1); mod.def("returnArray3", returnArray3); mod.def("returnConstArray3", returnConstArray3); -#ifdef NDARRAY_EIGENVIEW - mod.def("acceptMatrixXd", acceptMatrixXd); - mod.def("acceptMatrix2d", acceptMatrix2d); -#endif // NDARRAY_EIGENVIEW mod.def("acceptArray1", acceptArray1); mod.def("acceptArray10", acceptArray10); mod.def("acceptArray3", acceptArray3); -#ifdef NDARRAY_EIGENVIEW - mod.def("acceptOverload", (int (*)(int)) acceptOverload); - mod.def("acceptOverload", (int (*)(Eigen::Matrix2d const &)) acceptOverload); - mod.def("acceptOverload", (int (*)(Eigen::Matrix3d const &)) acceptOverload); -#endif // NDARRAY_EIGENVIEW mod.def("acceptNoneArray", acceptNoneArray, "array"_a = nullptr); -#ifdef NDARRAY_EIGENVIEW - mod.def("acceptNoneMatrixXd", acceptNoneMatrixXd, "matrix"_a = nullptr); - mod.def("acceptNoneMatrix2d", acceptNoneMatrix2d, "matrix"_a = nullptr); - mod.def("acceptFullySpecifiedMatrix", acceptFullySpecifiedMatrix); -#endif // NDARRAY_EIGENVIEW return mod.ptr(); } \ No newline at end of file diff --git a/tests/python_test.py b/tests/python_test.py deleted file mode 100755 index 2f02b05c..00000000 --- a/tests/python_test.py +++ /dev/null @@ -1,117 +0,0 @@ -# -*- python -*- -# -# Copyright (c) 2010-2012, Jim Bosch -# All rights reserved. -# -# ndarray is distributed under a simple BSD-like license; -# see the LICENSE file that should be present in the root -# of the source distribution, or alternately available at: -# https://github.com/ndarray/ndarray -# -import numpy -import python_test_mod -import unittest - -class TestNDArray(unittest.TestCase): - - def testIntArrayConversion(self): - a1 = numpy.zeros((5,3,4),dtype=numpy.int32) - a2 = a1[:,:,:2] - self.assertTrue(a1.flags["WRITEABLE"]) - self.assertTrue(a2.flags["WRITEABLE"]) - - ua1 = numpy.zeros((5,3,4),dtype=numpy.uint32) - self.assertTrue(ua1.flags["WRITEABLE"]) - - b1 = python_test_mod.passIntArray33(a1) - self.assertTrue(b1.flags["WRITEABLE"]) - self.assertEqual(a1.shape,b1.shape) - self.assertEqual(a1.strides,b1.strides) - - ub1 = python_test_mod.passUIntArray33(ua1) - self.assertTrue(ub1.flags["WRITEABLE"]) - self.assertEqual(a1.shape,ub1.shape) - self.assertEqual(a1.strides,ub1.strides) - - c1 = python_test_mod.passIntArray30(a1) - self.assertTrue(c1.flags["WRITEABLE"]) - self.assertEqual(a1.shape,c1.shape) - self.assertEqual(a1.strides,c1.strides) - - d1 = python_test_mod.passConstIntArray33(a1) - self.assertEqual(a1.shape,d1.shape) - self.assertEqual(a1.strides,d1.strides) - self.assertTrue(not d1.flags.writeable) - - self.assertRaises(ValueError, python_test_mod.passIntArray33, a2) - - c2 = python_test_mod.passIntArray30(a2) - self.assertTrue(c2.flags["WRITEABLE"]) - self.assertEqual(a2.shape,c2.shape) - self.assertEqual(a2.strides,c2.strides) - - # test to be sure a tuple of tuples does not work - self.assertRaises(TypeError, python_test_mod.passIntArray30, ((1,1,1),(2,2,2),(3,3,3))) - - # test to be sure an array of the wrong type does not work - self.assertRaises(ValueError, python_test_mod.passIntArray30, - numpy.zeros((4,3,4),dtype=numpy.float)) - - def testVectorConversion(self): - a = (3.5,6.7,1.2) - b = python_test_mod.passFloatVector3(a) - self.assertEqual(a,b) - - def testArrayConversion(self): - a1 = numpy.zeros((5,3,4),dtype=float) - a2 = a1[:,:,:2] - self.assertTrue(a1.flags["WRITEABLE"]) - self.assertTrue(a2.flags["WRITEABLE"]) - - b1 = python_test_mod.passFloatArray33(a1) - self.assertTrue(b1.flags["WRITEABLE"]) - self.assertEqual(a1.shape,b1.shape) - self.assertEqual(a1.strides,b1.strides) - - - c1 = python_test_mod.passFloatArray30(a1) - self.assertTrue(c1.flags["WRITEABLE"]) - self.assertEqual(a1.shape,c1.shape) - self.assertEqual(a1.strides,c1.strides) - - d1 = python_test_mod.passConstFloatArray33(a1) - self.assertEqual(a1.shape,d1.shape) - self.assertEqual(a1.strides,d1.strides) - self.assertTrue(not d1.flags.writeable) - - self.assertRaises(ValueError, python_test_mod.passFloatArray33, a2) - - c2 = python_test_mod.passFloatArray30(a2) - self.assertTrue(c2.flags["WRITEABLE"]) - self.assertEqual(a2.shape,c2.shape) - self.assertEqual(a2.strides,c2.strides) - - # test to be sure a tuple of tuples does not work - self.assertRaises(TypeError, python_test_mod.passFloatArray30, - ((1.0,1.0,1.0),(2.0,2.0,2.0),(3.0,3.0,3.0))) - - # test to be sure an array of the wrong type does not work - self.assertRaises(ValueError, python_test_mod.passFloatArray30, - numpy.zeros((4,3,4),dtype=numpy.int32)) - - # test to be sure a tuple of tuples does not work - self.assertRaises(TypeError, python_test_mod.passFloatArray30, - ((1.0,1.0,1.0),(2.0,2.0,2.0),(3.0,3.0,3.0))) - - # test to be sure an array of the wrong type does not work - self.assertRaises(ValueError, python_test_mod.passFloatArray30, - numpy.zeros((4,3,4),dtype=numpy.int32)) - - def testFloatArrayCreation(self): - a = python_test_mod.makeFloatArray3((3,4,5)) - - def testIntArrayCreation(self): - a = python_test_mod.makeIntArray3((3,4,5)) - -if __name__ == "__main__": - unittest.main() diff --git a/tests/python_test_mod.cc b/tests/python_test_mod.cc deleted file mode 100644 index e73bee88..00000000 --- a/tests/python_test_mod.cc +++ /dev/null @@ -1,98 +0,0 @@ -// -*- c++ -*- -/* - * Copyright (c) 2010-2012, Jim Bosch - * All rights reserved. - * - * ndarray is distributed under a simple BSD-like license; - * see the LICENSE file that should be present in the root - * of the source distribution, or alternately available at: - * https://github.com/ndarray/ndarray - */ -#include "Python.h" -#include "numpy/arrayobject.h" -#include "ndarray/swig.h" -#include -#ifndef _MSC_VER -#pragma GCC diagnostic ignored "-Wuninitialized" -#endif - -/* Define macros for things that changed between Python V2.7 and V3.2 */ -#if PY_MAJOR_VERSION >= 3 -#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) -#define RETURN(value) return value -#else -#define MOD_INIT(name) PyMODINIT_FUNC init##name(void) -#define RETURN(value) return -#endif - -template -static PyObject * passVector(PyObject * self, PyObject * args) { - ndarray::Vector vector; - if (!PyArg_ParseTuple(args,"O&",ndarray::PyConverter< ndarray::Vector >::fromPython,&vector)) - return NULL; - return ndarray::PyConverter< ndarray::Vector >::toPython(vector); -} - -template -static PyObject * passArray(PyObject * self, PyObject * args) { - ndarray::Array array; - if (!PyArg_ParseTuple(args,"O&",ndarray::PyConverter< ndarray::Array >::fromPython,&array)) - return NULL; - return ndarray::PyConverter< ndarray::Array >::toPython(array); -} - -template -static PyObject * makeArray(PyObject * self, PyObject * args) { - ndarray::Vector shape; - if (!PyArg_ParseTuple( - args, - "O&", - ndarray::PyConverter< ndarray::Vector >::fromPython, - &shape) - ) { - return NULL; - } - ndarray::Array array = ndarray::allocate(shape); - array.deep() = static_cast(0); - return ndarray::PyConverter< ndarray::Array >::toPython(array); -} - -static PyMethodDef methods[] = { - {"passFloatVector3",&passVector,METH_VARARGS,NULL}, - {"passFloatArray33",&passArray,METH_VARARGS,NULL}, - {"passConstFloatArray33",&passArray,METH_VARARGS,NULL}, - {"passFloatArray30",&passArray,METH_VARARGS,NULL}, - {"makeFloatArray3",&makeArray,METH_VARARGS,NULL}, - {"passIntVector3",&passVector,METH_VARARGS,NULL}, - {"passIntArray33",&passArray,METH_VARARGS,NULL}, - {"passUIntArray33",&passArray,METH_VARARGS,NULL}, - {"passConstIntArray33",&passArray,METH_VARARGS,NULL}, - {"passIntArray30",&passArray,METH_VARARGS,NULL}, - {"makeIntArray3",&makeArray,METH_VARARGS,NULL}, - {NULL} -}; - -/* Describe the properties of the module. */ -#if PY_MAJOR_VERSION >= 3 -static struct PyModuleDef testmodule = { - PyModuleDef_HEAD_INIT, - "ndarray_python_test", - "Test the ndarray python interface", - -1, - methods, - NULL, NULL, NULL, NULL -}; -#endif - -MOD_INIT(ndarray_python_test) { - import_array(); - PyObject * module = Py_InitModule("python_test_mod",methods); - if (module == NULL) return; -#if PY_MAJOR_VERSION >= 3 - PyObject * module; - module = PyModule_Create(&testmodule); -#else - Py_InitModule3("ndarray_python_test", methods, "Test ndarray python interface"); -#endif - RETURN(module); -}