From a6eea2dc74cd6727357722e28dc053cab98a3d8d Mon Sep 17 00:00:00 2001 From: Tom de Geus <tom@geus.me> Date: Thu, 23 Mar 2023 12:28:06 +0100 Subject: [PATCH] Applying clang-format --- .appveyor.yml | 42 +-- .../azure-pipelines-linux-clang.yml | 68 ++-- .../azure-pipelines-linux-gcc.yml | 57 ++-- .azure-pipelines/azure-pipelines-osx.yml | 50 +-- .azure-pipelines/unix-build.yml | 120 +++---- .clang-format | 90 +++++ .github/workflows/static-analysis.yml | 14 + .pre-commit-config.yaml | 47 +++ CMakeLists.txt | 5 +- azure-pipelines.yml | 9 +- benchmark/CMakeLists.txt | 1 - benchmark/main.cpp | 116 ++++--- cmake/FindNumPy.cmake | 6 +- docs/environment.yml | 4 +- docs/make.bat | 310 +++++++++--------- docs/source/array_tensor.rst | 1 - docs/source/basic_usage.rst | 1 - docs/source/conda.svg | 2 +- docs/source/conf.py | 1 - docs/source/cookiecutter.rst | 2 +- docs/source/debian.svg | 172 +++++----- docs/source/examples/copy_cast/main.cpp | 3 +- .../examples/readme_example_1/example.py | 1 - .../source/examples/readme_example_1/main.cpp | 3 +- docs/source/examples/sfinae/example.py | 1 - docs/source/examples/sfinae/main.cpp | 3 +- docs/source/examples/sfinae/mymodule.hpp | 49 +-- docs/source/examples/sfinae/python.cpp | 3 +- docs/source/numpy_capi.rst | 3 - docs/source/quantstack-white.svg | 2 +- docs/source/xtensor-python.svg | 120 +++---- environment-dev.yml | 13 +- include/xtensor-python/pyarray.hpp | 103 ++++-- .../xtensor-python/pyarray_backstrides.hpp | 59 ++-- include/xtensor-python/pycontainer.hpp | 100 ++++-- include/xtensor-python/pynative_casters.hpp | 26 +- include/xtensor-python/pystrides_adaptor.hpp | 41 ++- include/xtensor-python/pytensor.hpp | 103 +++--- include/xtensor-python/pyvectorize.hpp | 23 +- .../xtensor-python/xtensor_python_config.hpp | 14 +- .../xtensor_type_caster_base.hpp | 93 +++--- readthedocs.yml | 2 +- test/CMakeLists.txt | 1 - test/copyGTest.cmake.in | 1 - test/downloadGTest.cmake.in | 1 - test/main.cpp | 19 +- test/test_common.hpp | 122 ++++--- test/test_pyarray.cpp | 70 ++-- test/test_pyarray_traits.cpp | 35 +- test/test_pytensor.cpp | 48 ++- test/test_pyvectorize.cpp | 38 ++- test/test_sfinae.cpp | 21 +- test_python/main.cpp | 256 +++++++++++---- 53 files changed, 1470 insertions(+), 1025 deletions(-) create mode 100644 .clang-format create mode 100644 .github/workflows/static-analysis.yml create mode 100644 .pre-commit-config.yaml diff --git a/.appveyor.yml b/.appveyor.yml index 91cebe4..13f51e0 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -3,33 +3,33 @@ build: false os: Visual Studio 2015 platform: - - x64 +- x64 environment: matrix: - - MINICONDA: C:\xtensor-conda + - MINICONDA: C:\xtensor-conda init: - - "ECHO %MINICONDA%" - - C:\"Program Files (x86)"\"Microsoft Visual Studio 14.0"\VC\vcvarsall.bat %PLATFORM% - - ps: if($env:Platform -eq "x64"){Start-FileDownload 'http://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86_64.exe' C:\Miniconda.exe; echo "Done"} - - ps: if($env:Platform -eq "x86"){Start-FileDownload 'http://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86.exe' C:\Miniconda.exe; echo "Done"} - - cmd: C:\Miniconda.exe /S /D=C:\xtensor-conda - - "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%MINICONDA%\\Library\\bin;%PATH%" +- ECHO %MINICONDA% +- C:\"Program Files (x86)"\"Microsoft Visual Studio 14.0"\VC\vcvarsall.bat %PLATFORM% +- ps: if($env:Platform -eq "x64"){Start-FileDownload 'http://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86_64.exe' C:\Miniconda.exe; echo "Done"} +- ps: if($env:Platform -eq "x86"){Start-FileDownload 'http://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86.exe' C:\Miniconda.exe; echo "Done"} +- cmd: C:\Miniconda.exe /S /D=C:\xtensor-conda +- set PATH=%MINICONDA%;%MINICONDA%\Scripts;%MINICONDA%\Library\bin;%PATH% install: - - conda config --set always_yes yes --set changeps1 no - - conda update -q conda - - conda info -a - - conda install mamba -c conda-forge - - mamba install cmake pytest numpy pybind11 xtensor==0.24.0 -c conda-forge - - "set PYTHONHOME=%MINICONDA%" - - cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -D BUILD_TESTS=ON -D PYTHON_EXECUTABLE=%MINICONDA%\\python.exe -DDOWNLOAD_GTEST=ON . - - nmake test_xtensor_python - - nmake install - - rmdir /s/q "test/googletest-src" +- conda config --set always_yes yes --set changeps1 no +- conda update -q conda +- conda info -a +- conda install mamba -c conda-forge +- mamba install cmake pytest numpy pybind11 xtensor==0.24.0 -c conda-forge +- set PYTHONHOME=%MINICONDA% +- cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -D BUILD_TESTS=ON -D PYTHON_EXECUTABLE=%MINICONDA%\\python.exe -DDOWNLOAD_GTEST=ON . +- nmake test_xtensor_python +- nmake install +- rmdir /s/q "test/googletest-src" build_script: - - py.test -s - - cd test - - .\test_xtensor_python +- py.test -s +- cd test +- .\test_xtensor_python diff --git a/.azure-pipelines/azure-pipelines-linux-clang.yml b/.azure-pipelines/azure-pipelines-linux-clang.yml index 87d7592..54d3c8c 100644 --- a/.azure-pipelines/azure-pipelines-linux-clang.yml +++ b/.azure-pipelines/azure-pipelines-linux-clang.yml @@ -1,38 +1,38 @@ jobs: - - job: 'Linux_0' - strategy: - matrix: - clang_6: - llvm_version: '6.0' - clang_7: - llvm_version: '7' - clang_8: - llvm_version: '8' - clang_9: - llvm_version: '9' - pool: - vmImage: ubuntu-18.04 - variables: - CC: clang-$(llvm_version) - CXX: clang++-$(llvm_version) - timeoutInMinutes: 360 - steps: +- job: Linux_0 + strategy: + matrix: + clang_6: + llvm_version: '6.0' + clang_7: + llvm_version: '7' + clang_8: + llvm_version: '8' + clang_9: + llvm_version: '9' + pool: + vmImage: ubuntu-18.04 + variables: + CC: clang-$(llvm_version) + CXX: clang++-$(llvm_version) + timeoutInMinutes: 360 + steps: - - script: | - sudo add-apt-repository ppa:ubuntu-toolchain-r/test - if [[ $(llvm_version) == '4.0' || $(llvm_version) == '5.0' ]]; then - sudo apt-get update - sudo apt-get --no-install-suggests --no-install-recommends install gcc-4.9 clang-$(llvm_version) - else - LLVM_VERSION=$(llvm_version) - get -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - sudo add-apt-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-$LLVM_VERSION main" - sudo apt-get update - sudo apt-get --no-install-suggests --no-install-recommends install clang-$(llvm_version) - fi - displayName: Install build toolchain + - script: | + sudo add-apt-repository ppa:ubuntu-toolchain-r/test + if [[ $(llvm_version) == '4.0' || $(llvm_version) == '5.0' ]]; then + sudo apt-get update + sudo apt-get --no-install-suggests --no-install-recommends install gcc-4.9 clang-$(llvm_version) + else + LLVM_VERSION=$(llvm_version) + get -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo add-apt-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-$LLVM_VERSION main" + sudo apt-get update + sudo apt-get --no-install-suggests --no-install-recommends install clang-$(llvm_version) + fi + displayName: Install build toolchain - - bash: echo "##vso[task.prependpath]$CONDA/bin" - displayName: Add conda to PATH + - bash: echo "##vso[task.prependpath]$CONDA/bin" + displayName: Add conda to PATH - - template: unix-build.yml + - template: unix-build.yml diff --git a/.azure-pipelines/azure-pipelines-linux-gcc.yml b/.azure-pipelines/azure-pipelines-linux-gcc.yml index e0a6aa0..1e16b6a 100644 --- a/.azure-pipelines/azure-pipelines-linux-gcc.yml +++ b/.azure-pipelines/azure-pipelines-linux-gcc.yml @@ -1,33 +1,32 @@ jobs: - - job: 'Linux_1' - strategy: - matrix: - gcc_6: - gcc_version: '6' - gcc_7: - gcc_version: '7' - gcc_8: - gcc_version: '8' - gcc_9: - gcc_version: '9' - pool: - vmImage: ubuntu-18.04 - variables: - CC: gcc-$(gcc_version) - CXX: g++-$(gcc_version) - timeoutInMinutes: 360 - steps: +- job: Linux_1 + strategy: + matrix: + gcc_6: + gcc_version: '6' + gcc_7: + gcc_version: '7' + gcc_8: + gcc_version: '8' + gcc_9: + gcc_version: '9' + pool: + vmImage: ubuntu-18.04 + variables: + CC: gcc-$(gcc_version) + CXX: g++-$(gcc_version) + timeoutInMinutes: 360 + steps: - - script: | - if [[ $(gcc_version) == '4.9' || $(gcc_version) == '6' || $(gcc_version) == '7' || $(gcc_version) == '8' ]]; then - sudo add-apt-repository ppa:ubuntu-toolchain-r/test - sudo apt-get update - sudo apt-get --no-install-suggests --no-install-recommends install g++-$(gcc_version) - fi - displayName: Install build toolchain + - script: | + if [[ $(gcc_version) == '4.9' || $(gcc_version) == '6' || $(gcc_version) == '7' || $(gcc_version) == '8' ]]; then + sudo add-apt-repository ppa:ubuntu-toolchain-r/test + sudo apt-get update + sudo apt-get --no-install-suggests --no-install-recommends install g++-$(gcc_version) + fi + displayName: Install build toolchain - - bash: echo "##vso[task.prependpath]$CONDA/bin" - displayName: Add conda to PATH - - - template: unix-build.yml + - bash: echo "##vso[task.prependpath]$CONDA/bin" + displayName: Add conda to PATH + - template: unix-build.yml diff --git a/.azure-pipelines/azure-pipelines-osx.yml b/.azure-pipelines/azure-pipelines-osx.yml index beeafce..9da09c8 100644 --- a/.azure-pipelines/azure-pipelines-osx.yml +++ b/.azure-pipelines/azure-pipelines-osx.yml @@ -1,28 +1,28 @@ jobs: - - job: 'OSX' - strategy: - matrix: - macOS_10_15: - image_name: 'macOS-10.15' - macOS_11: - image_name: 'macOS-11' - pool: - vmImage: $(image_name) - variables: - CC: clang - CXX: clang++ - timeoutInMinutes: 360 - steps: - - script: | - echo "Removing homebrew for Azure to avoid conflicts with conda" - curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall > ~/uninstall_homebrew - chmod +x ~/uninstall_homebrew - ~/uninstall_homebrew -f -q - displayName: Remove homebrew +- job: OSX + strategy: + matrix: + macOS_10_15: + image_name: macOS-10.15 + macOS_11: + image_name: macOS-11 + pool: + vmImage: $(image_name) + variables: + CC: clang + CXX: clang++ + timeoutInMinutes: 360 + steps: + - script: | + echo "Removing homebrew for Azure to avoid conflicts with conda" + curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall > ~/uninstall_homebrew + chmod +x ~/uninstall_homebrew + ~/uninstall_homebrew -f -q + displayName: Remove homebrew - - bash: | - echo "##vso[task.prependpath]$CONDA/bin" - sudo chown -R $USER $CONDA - displayName: Add conda to PATH + - bash: | + echo "##vso[task.prependpath]$CONDA/bin" + sudo chown -R $USER $CONDA + displayName: Add conda to PATH - - template: unix-build.yml + - template: unix-build.yml diff --git a/.azure-pipelines/unix-build.yml b/.azure-pipelines/unix-build.yml index 97cb405..e5b9b4f 100644 --- a/.azure-pipelines/unix-build.yml +++ b/.azure-pipelines/unix-build.yml @@ -1,68 +1,68 @@ steps: - - script: | - conda config --set always_yes yes --set changeps1 no - conda update -q conda - conda env create --file environment-dev.yml - source activate xtensor-python - displayName: Install dependencies +- script: | + conda config --set always_yes yes --set changeps1 no + conda update -q conda + conda env create --file environment-dev.yml + source activate xtensor-python + displayName: Install dependencies - - script: | - source activate xtensor-python - mkdir build - cd build - cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DPYTHON_EXECUTABLE=`which python` -DDOWNLOAD_GTEST=ON $(Build.SourcesDirectory) - make install - displayName: Configure xtensor-python - workingDirectory: $(Build.BinariesDirectory) +- script: | + source activate xtensor-python + mkdir build + cd build + cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DPYTHON_EXECUTABLE=`which python` -DDOWNLOAD_GTEST=ON $(Build.SourcesDirectory) + make install + displayName: Configure xtensor-python + workingDirectory: $(Build.BinariesDirectory) - - script: | - source activate xtensor-python - make -j2 test_xtensor_python - displayName: Build xtensor-python - workingDirectory: $(Build.BinariesDirectory)/build +- script: | + source activate xtensor-python + make -j2 test_xtensor_python + displayName: Build xtensor-python + workingDirectory: $(Build.BinariesDirectory)/build - - script: | - source activate xtensor-python - cd test - ./test_xtensor_python - displayName: Test xtensor-python (C++) - workingDirectory: $(Build.BinariesDirectory)/build/test +- script: | + source activate xtensor-python + cd test + ./test_xtensor_python + displayName: Test xtensor-python (C++) + workingDirectory: $(Build.BinariesDirectory)/build/test - - script: | - source activate xtensor-python - py.test -s - displayName: Test xtensor-python (Python) - workingDirectory: $(Build.SourcesDirectory) +- script: | + source activate xtensor-python + py.test -s + displayName: Test xtensor-python (Python) + workingDirectory: $(Build.SourcesDirectory) - - script: | - source activate xtensor-python - cmake -Bbuild -DPython_EXECUTABLE=`which python` - cd build - cmake --build . - cp ../example.py . - python example.py - cd .. - displayName: Example - readme 1 - workingDirectory: $(Build.SourcesDirectory)/docs/source/examples/readme_example_1 +- script: | + source activate xtensor-python + cmake -Bbuild -DPython_EXECUTABLE=`which python` + cd build + cmake --build . + cp ../example.py . + python example.py + cd .. + displayName: Example - readme 1 + workingDirectory: $(Build.SourcesDirectory)/docs/source/examples/readme_example_1 - - script: | - source activate xtensor-python - cmake -Bbuild -DPython_EXECUTABLE=`which python` - cd build - cmake --build . - cp ../example.py . - python example.py - cd .. - displayName: Example - Copy 'cast' - workingDirectory: $(Build.SourcesDirectory)/docs/source/examples/copy_cast +- script: | + source activate xtensor-python + cmake -Bbuild -DPython_EXECUTABLE=`which python` + cd build + cmake --build . + cp ../example.py . + python example.py + cd .. + displayName: Example - Copy 'cast' + workingDirectory: $(Build.SourcesDirectory)/docs/source/examples/copy_cast - - script: | - source activate xtensor-python - cmake -Bbuild -DPython_EXECUTABLE=`which python` - cd build - cmake --build . - cp ../example.py . - python example.py - cd .. - displayName: Example - SFINAE - workingDirectory: $(Build.SourcesDirectory)/docs/source/examples/sfinae +- script: | + source activate xtensor-python + cmake -Bbuild -DPython_EXECUTABLE=`which python` + cd build + cmake --build . + cp ../example.py . + python example.py + cd .. + displayName: Example - SFINAE + workingDirectory: $(Build.SourcesDirectory)/docs/source/examples/sfinae diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d092c07 --- /dev/null +++ b/.clang-format @@ -0,0 +1,90 @@ +BasedOnStyle: Mozilla + +AccessModifierOffset: '-4' +AlignAfterOpenBracket: BlockIndent +AlignEscapedNewlines: Left +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +# Forbid one line lambdas because clang-format makes a weird split when +# single instructions lambdas are too long. +AllowShortLambdasOnASingleLine: Empty +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Allman +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: AfterComma +BreakStringLiterals: false +ColumnLimit: '110' +ConstructorInitializerIndentWidth: '4' +ContinuationIndentWidth: '4' +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Always +EmptyLineBeforeAccessModifier: Always +ExperimentalAutoDetectBinPacking: true +IncludeBlocks: Regroup +IncludeCategories: +- Regex: <[^.]+> + Priority: 1 +- Regex: <xtensor/.+> + Priority: 3 +- Regex: <.+> + Priority: 2 +- Regex: '"xtensor/.+"' + Priority: 4 +- Regex: '".+"' + Priority: 5 +IndentCaseLabels: true +IndentWidth: '4' +IndentWrappedFunctionNames: false +InsertBraces: true +InsertTrailingCommas: Wrapped +KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature +Language: Cpp +MaxEmptyLinesToKeep: '2' +NamespaceIndentation: All +ObjCBlockIndentWidth: '4' +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: false +PackConstructorInitializers: Never +PenaltyBreakAssignment: 100000 +PenaltyBreakBeforeFirstCallParameter: 0 +PenaltyBreakComment: 10 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakTemplateDeclaration: 0 +PenaltyExcessCharacter: 10 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 10 +PointerAlignment: Left +QualifierAlignment: Custom # Experimental +QualifierOrder: [inline, static, constexpr, const, volatile, type] +ReflowComments: true +SeparateDefinitionBlocks: Always +SortIncludes: CaseInsensitive +SortUsingDeclarations: true +SpaceAfterCStyleCast: true +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: '2' +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: c++14 +TabWidth: '4' +UseTab: Never diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..5441a33 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,14 @@ +name: Static Analysis + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: pre-commit/action@v3.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a0e9260 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,47 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: end-of-file-fixer + - id: trailing-whitespace + - id: mixed-line-ending + args: [--fix=lf] + exclude: \.bat$ + - id: check-json + - id: pretty-format-json + args: [--autofix, --top-keys=version] + - id: check-yaml + types: [file] + files: \.(yaml|yml|clang-format) + - id: detect-private-key + - id: check-merge-conflict +- repo: https://github.com/Lucas-C/pre-commit-hooks + rev: v1.4.2 + hooks: + - id: forbid-tabs + - id: remove-tabs + args: [--whitespaces-count, '4'] +- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.7.0 + hooks: + - id: pretty-format-yaml + args: [--autofix, --indent, '2'] + types: [file] + files: \.(yaml|yml|clang-format) +- repo: https://github.com/tdegeus/cpp_comment_format + rev: v0.2.0 + hooks: + - id: cpp_comment_format +- repo: https://github.com/tdegeus/conda_envfile + rev: v0.4.2 + hooks: + - id: conda_envfile_parse + files: environment.yaml +# Externally provided executables (so we can use them with editors as well). +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v15.0.7 + hooks: + - id: clang-format + files: .*\.[hc]pp$ diff --git a/CMakeLists.txt b/CMakeLists.txt index e1bd077..1b51174 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ foreach(ver ${xtensor_python_version_defines}) set(XTENSOR_PYTHON_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") endif() endforeach() -set(${PROJECT_NAME}_VERSION +set(${PROJECT_NAME}_VERSION ${XTENSOR_PYTHON_VERSION_MAJOR}.${XTENSOR_PYTHON_VERSION_MINOR}.${XTENSOR_PYTHON_VERSION_PATCH}) message(STATUS "xtensor-python v${${PROJECT_NAME}_VERSION}") @@ -45,7 +45,7 @@ else() find_package(xtensor ${xtensor_REQUIRED_VERSION} REQUIRED) message(STATUS "Found xtensor: ${xtensor_INCLUDE_DIRS}/xtensor") endif() - + # Currently no required version for pybind11 if(TARGET pybind11 OR TARGET pybind11::headers) # pybind11 has a variable that indicates its version already, so use that @@ -136,4 +136,3 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake install(EXPORT ${PROJECT_NAME}-targets FILE ${PROJECT_NAME}Targets.cmake DESTINATION ${XTENSOR_PYTHON_CMAKECONFIG_INSTALL_DIR}) - diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e930dbe..a7dcef7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,8 +1,7 @@ trigger: - - master +- master jobs: - - template: ./.azure-pipelines/azure-pipelines-linux-clang.yml - - template: ./.azure-pipelines/azure-pipelines-linux-gcc.yml - - template: ./.azure-pipelines/azure-pipelines-osx.yml - +- template: ./.azure-pipelines/azure-pipelines-linux-clang.yml +- template: ./.azure-pipelines/azure-pipelines-linux-gcc.yml +- template: ./.azure-pipelines/azure-pipelines-osx.yml diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 28589df..99253ff 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -95,4 +95,3 @@ add_custom_target(xbenchmark COMMAND "${PYTHON_EXECUTABLE}" "benchmark_pyvectorize.py" COMMAND "${PYTHON_EXECUTABLE}" "benchmark_pybind_vectorize.py" DEPENDS ${XTENSOR_PYTHON_BENCHMARK_TARGET}) - diff --git a/benchmark/main.cpp b/benchmark/main.cpp index d1d787e..92f188f 100644 --- a/benchmark/main.cpp +++ b/benchmark/main.cpp @@ -1,9 +1,11 @@ -#include "pybind11/pybind11.h" #include "pybind11/numpy.h" +#include "pybind11/pybind11.h" + #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION -#include "numpy/arrayobject.h" -#include "xtensor/xtensor.hpp" #include "xtensor/xarray.hpp" +#include "xtensor/xtensor.hpp" + +#include "numpy/arrayobject.h" #include "xtensor-python/pyarray.hpp" #include "xtensor-python/pytensor.hpp" #include "xtensor-python/pyvectorize.hpp" @@ -14,44 +16,84 @@ namespace py = pybind11; PYBIND11_MODULE(benchmark_xtensor_python, m) { - if(_import_array() < 0) + if (_import_array() < 0) { PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); } m.doc() = "Benchmark module for xtensor python bindings"; - m.def("sum_array", [](xt::pyarray<double> const& x) { - double sum = 0; - for(auto e : x) - sum += e; - return sum; - }); - - m.def("sum_tensor", [](xt::pytensor<double, 1> const& x) { - double sum = 0; - for(auto e : x) - sum += e; - return sum; - }); - - m.def("pybind_sum_array", [](py::array_t<double> const& x) { - double sum = 0; - size_t size = x.size(); - const double* data = x.data(0); - for(size_t i = 0; i < size; ++i) - sum += data[i]; - return sum; - }); - - m.def("rect_to_polar", [](xt::pyarray<complex_t> const& a) { - return py::vectorize([](complex_t x) { return std::abs(x); })(a); - }); - - m.def("pybind_rect_to_polar", [](py::array a) { - if (py::isinstance<py::array_t<complex_t>>(a)) - return py::vectorize([](complex_t x) { return std::abs(x); })(a); - else - throw py::type_error("rect_to_polar unhandled type"); - }); + m.def( + "sum_array", + [](const xt::pyarray<double>& x) + { + double sum = 0; + for (auto e : x) + { + sum += e; + } + return sum; + } + ); + + m.def( + "sum_tensor", + [](const xt::pytensor<double, 1>& x) + { + double sum = 0; + for (auto e : x) + { + sum += e; + } + return sum; + } + ); + + m.def( + "pybind_sum_array", + [](const py::array_t<double>& x) + { + double sum = 0; + size_t size = x.size(); + const double* data = x.data(0); + for (size_t i = 0; i < size; ++i) + { + sum += data[i]; + } + return sum; + } + ); + + m.def( + "rect_to_polar", + [](const xt::pyarray<complex_t>& a) + { + return py::vectorize( + [](complex_t x) + { + return std::abs(x); + } + )(a); + } + ); + + m.def( + "pybind_rect_to_polar", + [](py::array a) + { + if (py::isinstance<py::array_t<complex_t>>(a)) + { + return py::vectorize( + [](complex_t x) + { + return std::abs(x); + } + )(a); + } + else + { + throw py::type_error("rect_to_polar unhandled type"); + } + } + ); } diff --git a/cmake/FindNumPy.cmake b/cmake/FindNumPy.cmake index f043566..48a1046 100644 --- a/cmake/FindNumPy.cmake +++ b/cmake/FindNumPy.cmake @@ -24,10 +24,10 @@ # distribute, sublicense, and/or sell copies of the Software, and to permit # persons to whom the Software is furnished to do so, subject to # the following conditions: -# +# # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL @@ -35,7 +35,7 @@ # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. -# +# #============================================================================ # Finding NumPy involves calling the Python interpreter diff --git a/docs/environment.yml b/docs/environment.yml index 47e93f7..65d263f 100644 --- a/docs/environment.yml +++ b/docs/environment.yml @@ -1,7 +1,7 @@ name: xtensor-python-docs channels: - - conda-forge +- conda-forge dependencies: - - breathe +- breathe diff --git a/docs/make.bat b/docs/make.bat index 0df92b4..07de332 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -3,48 +3,48 @@ REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build + set SPHINXBUILD=sphinx-build ) set BUILDDIR=build set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source set I18NSPHINXOPTS=%SPHINXOPTS% source if NOT "%PAPER%" == "" ( - set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% - set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% ) if "%1" == "" goto help if "%1" == "help" ( - :help - echo.Please use `make ^<target^>` where ^<target^> is one of - echo. html to make standalone HTML files - echo. dirhtml to make HTML files named index.html in directories - echo. singlehtml to make a single large HTML file - echo. pickle to make pickle files - echo. json to make JSON files - echo. htmlhelp to make HTML files and a HTML help project - echo. qthelp to make HTML files and a qthelp project - echo. devhelp to make HTML files and a Devhelp project - echo. epub to make an epub - echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter - echo. text to make text files - echo. man to make manual pages - echo. texinfo to make Texinfo files - echo. gettext to make PO message catalogs - echo. changes to make an overview over all changed/added/deprecated items - echo. xml to make Docutils-native XML files - echo. pseudoxml to make pseudoxml-XML files for display purposes - echo. linkcheck to check all external links for integrity - echo. doctest to run all doctests embedded in the documentation if enabled - echo. coverage to run coverage check of the documentation if enabled - goto end + :help + echo.Please use `make ^<target^>` where ^<target^> is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + echo. coverage to run coverage check of the documentation if enabled + goto end ) if "%1" == "clean" ( - for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i - del /q /s %BUILDDIR%\* - goto end + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end ) @@ -58,15 +58,15 @@ goto sphinx_ok set SPHINXBUILD=python -m sphinx.__init__ %SPHINXBUILD% 2> nul if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 ) :sphinx_ok @@ -74,191 +74,191 @@ if errorlevel 9009 ( if "%1" == "html" ( doxygen - %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/html. - goto end + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end ) if "%1" == "dirhtml" ( - %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. - goto end + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end ) if "%1" == "singlehtml" ( - %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. - goto end + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end ) if "%1" == "pickle" ( - %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can process the pickle files. - goto end + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end ) if "%1" == "json" ( - %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can process the JSON files. - goto end + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end ) if "%1" == "htmlhelp" ( - %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can run HTML Help Workshop with the ^ + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ .hhp project file in %BUILDDIR%/htmlhelp. - goto end + goto end ) if "%1" == "qthelp" ( - %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can run "qcollectiongenerator" with the ^ + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in %BUILDDIR%/qthelp, like this: - echo.^> qcollectiongenerator %BUILDDIR%\qthelp\packagename.qhcp - echo.To view the help file: - echo.^> assistant -collectionFile %BUILDDIR%\qthelp\packagename.ghc - goto end + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\packagename.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\packagename.ghc + goto end ) if "%1" == "devhelp" ( - %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. - goto end + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end ) if "%1" == "epub" ( - %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The epub file is in %BUILDDIR%/epub. - goto end + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end ) if "%1" == "latex" ( - %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. - goto end + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end ) if "%1" == "latexpdf" ( - %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex - cd %BUILDDIR%/latex - make all-pdf - cd %~dp0 - echo. - echo.Build finished; the PDF files are in %BUILDDIR%/latex. - goto end + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end ) if "%1" == "latexpdfja" ( - %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex - cd %BUILDDIR%/latex - make all-pdf-ja - cd %~dp0 - echo. - echo.Build finished; the PDF files are in %BUILDDIR%/latex. - goto end + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end ) if "%1" == "text" ( - %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The text files are in %BUILDDIR%/text. - goto end + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end ) if "%1" == "man" ( - %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The manual pages are in %BUILDDIR%/man. - goto end + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end ) if "%1" == "texinfo" ( - %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. - goto end + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end ) if "%1" == "gettext" ( - %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The message catalogs are in %BUILDDIR%/locale. - goto end + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end ) if "%1" == "changes" ( - %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes - if errorlevel 1 exit /b 1 - echo. - echo.The overview file is in %BUILDDIR%/changes. - goto end + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end ) if "%1" == "linkcheck" ( - %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck - if errorlevel 1 exit /b 1 - echo. - echo.Link check complete; look for any errors in the above output ^ + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ or in %BUILDDIR%/linkcheck/output.txt. - goto end + goto end ) if "%1" == "doctest" ( - %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest - if errorlevel 1 exit /b 1 - echo. - echo.Testing of doctests in the sources finished, look at the ^ + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ results in %BUILDDIR%/doctest/output.txt. - goto end + goto end ) if "%1" == "coverage" ( - %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage - if errorlevel 1 exit /b 1 - echo. - echo.Testing of coverage in the sources finished, look at the ^ + %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage + if errorlevel 1 exit /b 1 + echo. + echo.Testing of coverage in the sources finished, look at the ^ results in %BUILDDIR%/coverage/python.txt. - goto end + goto end ) if "%1" == "xml" ( - %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The XML files are in %BUILDDIR%/xml. - goto end + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end ) if "%1" == "pseudoxml" ( - %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. - goto end + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end ) :end diff --git a/docs/source/array_tensor.rst b/docs/source/array_tensor.rst index e00889f..be45b40 100644 --- a/docs/source/array_tensor.rst +++ b/docs/source/array_tensor.rst @@ -24,4 +24,3 @@ pytensor Like ``xtensor``, ``pytensor`` has a static stack-allocated shape. This means that the shape of the numpy array is copied into the shape of the ``pytensor`` upon creation. As a consequence, reshapes are not reflected across languages. However, this drawback is offset by a more effective computation of shape and broadcast. - diff --git a/docs/source/basic_usage.rst b/docs/source/basic_usage.rst index c97c9ac..fd32012 100644 --- a/docs/source/basic_usage.rst +++ b/docs/source/basic_usage.rst @@ -99,4 +99,3 @@ Example 2: Create a numpy-style universal function from a C++ scalar function [[-0.540302, 1.257618, 1.89929 , 0.794764, -1.040465], [-1.499227, 0.136731, 1.646979, 1.643002, 0.128456], [-1.084323, -0.583843, 0.45342 , 1.073811, 0.706945]] - diff --git a/docs/source/conda.svg b/docs/source/conda.svg index 0755b2f..643a653 100644 --- a/docs/source/conda.svg +++ b/docs/source/conda.svg @@ -1 +1 @@ -<svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 127 127"><style>.st0{fill:#43b02a}</style><path class="st0" d="M13.8 81.2c-2.1 4.2-3.8 8.6-5.2 13.1 4.7 1.3 9.4 2.2 14.2 2.6.1-3.8.4-7.4.9-11-3.4-1.3-6.7-2.9-9.9-4.7zM33 32.8c-2.8 0-5.5.2-8.3.6.4 2.8.8 5.5 1.5 8.3 1.9-3.2 4.2-6.1 6.8-8.7v-.2zM10.5 98.7c3.6 5.5 8.1 10.4 13.2 14.5-.5-4.3-.9-8.4-.9-12.5-4.2-.4-8.3-1.1-12.3-2zM43 3.4c-5 1.7-9.6 4-14 6.8 3.3.6 6.5 1.3 9.7 2.3 1.2-3.1 2.7-6.1 4.3-9.1zM63.6 0c-2.5 0-4.9.2-7.3.4 3.4 2.4 6.6 4.9 9.7 7.7l2.5 2.3-2.5 2.5c-2.1 2-4.1 4.1-6 6.4v.1s-.4.4-1 1.1c1.5-.2 3-.2 4.6-.2 23.9 0 43.3 19.4 43.3 43.3s-19.4 43.3-43.3 43.3c-8.3 0-16.1-2.3-22.7-6.4-3.3.4-6.5.6-9.8.6-1.5 0-3 0-4.6-.1.1 4.9.6 10 1.4 15.3 10.2 6.9 22.4 10.9 35.6 10.9 35.1 0 63.6-28.5 63.6-63.6C127.2 28.5 98.7 0 63.6 0z"/><path class="st0" d="M55.1 15c1.3-1.5 2.6-3 3.9-4.4-3-2.5-6.1-4.9-9.4-6.9-2 3.4-3.8 7-5.3 10.6 2.9 1.1 5.7 2.3 8.4 3.6 1.3-1.6 2.2-2.6 2.4-2.9zM19.4 34.1c-4.7.8-9.3 2.1-13.8 3.7 1.8 4.6 4.1 9.1 6.7 13.3 3-2.1 6.1-4.1 9.3-5.8-1-3.7-1.7-7.4-2.2-11.2zM11.1 58.1c-3.4 2.8-6.6 5.8-9.6 9.2 3.3 2.9 6.8 5.5 10.5 7.9 1.7-3 3.6-6 5.6-8.8-2.2-2.6-4.4-5.4-6.5-8.3zM27.3 87.3c-.4 3.2-.7 6.5-.8 9.9 3.2.2 6.4.2 9.6 0-3.4-2.8-6.4-6.1-8.8-9.9zM36.6 18.1c-4-1.1-8.1-2-12.2-2.5-.4 4.2-.4 8.3-.1 12.4 3.3-.4 6.5-.6 9.8-.6.6-3.2 1.5-6.3 2.5-9.3zM42.3 19.9c-.8 2.4-1.5 4.8-2.1 7.2 2.8-1.8 5.8-3.3 8.9-4.4-2.2-1-4.5-1.9-6.8-2.8zM.5 72.1c.8 6.2 2.5 12.1 5 17.5C6.8 86 8.3 82.4 10 79c-3.3-2.1-6.4-4.4-9.5-6.9zM18.8 18.5c-3.8 3.8-7.1 8-9.9 12.6 3.3-1 6.6-1.8 10-2.4-.2-3.4-.3-6.8-.1-10.2zM15 55.2c1.6 2.3 3.4 4.6 5.3 6.8.2-4 .8-7.8 2-11.5-2.5 1.4-5 3-7.3 4.7zM15.8 77.3c2.7 1.5 5.4 2.9 8.3 4.1-1.7-3.7-2.8-7.6-3.4-11.8-1.8 2.5-3.4 5.1-4.9 7.7zM8.4 54.1c-2-3.2-3.8-6.5-5.4-10C1.2 49.7.1 55.7 0 61.8c2.7-2.8 5.5-5.4 8.4-7.7z"/></svg> \ No newline at end of file +<svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 127 127"><style>.st0{fill:#43b02a}</style><path class="st0" d="M13.8 81.2c-2.1 4.2-3.8 8.6-5.2 13.1 4.7 1.3 9.4 2.2 14.2 2.6.1-3.8.4-7.4.9-11-3.4-1.3-6.7-2.9-9.9-4.7zM33 32.8c-2.8 0-5.5.2-8.3.6.4 2.8.8 5.5 1.5 8.3 1.9-3.2 4.2-6.1 6.8-8.7v-.2zM10.5 98.7c3.6 5.5 8.1 10.4 13.2 14.5-.5-4.3-.9-8.4-.9-12.5-4.2-.4-8.3-1.1-12.3-2zM43 3.4c-5 1.7-9.6 4-14 6.8 3.3.6 6.5 1.3 9.7 2.3 1.2-3.1 2.7-6.1 4.3-9.1zM63.6 0c-2.5 0-4.9.2-7.3.4 3.4 2.4 6.6 4.9 9.7 7.7l2.5 2.3-2.5 2.5c-2.1 2-4.1 4.1-6 6.4v.1s-.4.4-1 1.1c1.5-.2 3-.2 4.6-.2 23.9 0 43.3 19.4 43.3 43.3s-19.4 43.3-43.3 43.3c-8.3 0-16.1-2.3-22.7-6.4-3.3.4-6.5.6-9.8.6-1.5 0-3 0-4.6-.1.1 4.9.6 10 1.4 15.3 10.2 6.9 22.4 10.9 35.6 10.9 35.1 0 63.6-28.5 63.6-63.6C127.2 28.5 98.7 0 63.6 0z"/><path class="st0" d="M55.1 15c1.3-1.5 2.6-3 3.9-4.4-3-2.5-6.1-4.9-9.4-6.9-2 3.4-3.8 7-5.3 10.6 2.9 1.1 5.7 2.3 8.4 3.6 1.3-1.6 2.2-2.6 2.4-2.9zM19.4 34.1c-4.7.8-9.3 2.1-13.8 3.7 1.8 4.6 4.1 9.1 6.7 13.3 3-2.1 6.1-4.1 9.3-5.8-1-3.7-1.7-7.4-2.2-11.2zM11.1 58.1c-3.4 2.8-6.6 5.8-9.6 9.2 3.3 2.9 6.8 5.5 10.5 7.9 1.7-3 3.6-6 5.6-8.8-2.2-2.6-4.4-5.4-6.5-8.3zM27.3 87.3c-.4 3.2-.7 6.5-.8 9.9 3.2.2 6.4.2 9.6 0-3.4-2.8-6.4-6.1-8.8-9.9zM36.6 18.1c-4-1.1-8.1-2-12.2-2.5-.4 4.2-.4 8.3-.1 12.4 3.3-.4 6.5-.6 9.8-.6.6-3.2 1.5-6.3 2.5-9.3zM42.3 19.9c-.8 2.4-1.5 4.8-2.1 7.2 2.8-1.8 5.8-3.3 8.9-4.4-2.2-1-4.5-1.9-6.8-2.8zM.5 72.1c.8 6.2 2.5 12.1 5 17.5C6.8 86 8.3 82.4 10 79c-3.3-2.1-6.4-4.4-9.5-6.9zM18.8 18.5c-3.8 3.8-7.1 8-9.9 12.6 3.3-1 6.6-1.8 10-2.4-.2-3.4-.3-6.8-.1-10.2zM15 55.2c1.6 2.3 3.4 4.6 5.3 6.8.2-4 .8-7.8 2-11.5-2.5 1.4-5 3-7.3 4.7zM15.8 77.3c2.7 1.5 5.4 2.9 8.3 4.1-1.7-3.7-2.8-7.6-3.4-11.8-1.8 2.5-3.4 5.1-4.9 7.7zM8.4 54.1c-2-3.2-3.8-6.5-5.4-10C1.2 49.7.1 55.7 0 61.8c2.7-2.8 5.5-5.4 8.4-7.7z"/></svg> diff --git a/docs/source/conf.py b/docs/source/conf.py index 3b428b8..08c3872 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -35,4 +35,3 @@ def setup(app): pygments_style = 'sphinx' todo_include_todos = False htmlhelp_basename = 'xtensorpythondoc' - diff --git a/docs/source/cookiecutter.rst b/docs/source/cookiecutter.rst index e725106..221f3bd 100644 --- a/docs/source/cookiecutter.rst +++ b/docs/source/cookiecutter.rst @@ -45,7 +45,7 @@ information: - ``python_package_name``: name of the Python package created by your extension, - ``cpp_namespace``: name for the cpp namespace holding the implementation of your extension, - ``project_short_description``: a short description for your project. - + This will produce a directory containing all the required content for a minimal extension project making use of xtensor with all the required boilerplate for package management, together with a few basic examples. diff --git a/docs/source/debian.svg b/docs/source/debian.svg index 50dcb70..9232651 100644 --- a/docs/source/debian.svg +++ b/docs/source/debian.svg @@ -1,86 +1,86 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Generator: Adobe Illustrator 10.0, SVG Export Plug-In . SVG Version: 3.0.0 Build 77) --> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [ - <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/"> - <!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/"> - <!ENTITY ns_ai "http://ns.adobe.com/AdobeIllustrator/10.0/"> - <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/"> - <!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/"> - <!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/"> - <!ENTITY ns_sfw "http://ns.adobe.com/SaveForWeb/1.0/"> - <!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/"> - <!ENTITY ns_adobe_xpath "http://ns.adobe.com/XPath/1.0/"> - <!ENTITY ns_svg "http://www.w3.org/2000/svg"> - <!ENTITY ns_xlink "http://www.w3.org/1999/xlink"> -]> -<svg - xmlns:x="&ns_extend;" xmlns:i="&ns_ai;" xmlns:graph="&ns_graphs;" i:viewOrigin="262 450" i:rulerOrigin="0 0" i:pageBounds="0 792 612 0" - xmlns="&ns_svg;" xmlns:xlink="&ns_xlink;" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" - width="87.041" height="108.445" viewBox="0 0 87.041 108.445" overflow="visible" enable-background="new 0 0 87.041 108.445" - xml:space="preserve"> - <metadata> - <variableSets xmlns="&ns_vars;"> - <variableSet varSetName="binding1" locked="none"> - <variables></variables> - <v:sampleDataSets xmlns="&ns_custom;" xmlns:v="&ns_vars;"></v:sampleDataSets> - </variableSet> - </variableSets> - <sfw xmlns="&ns_sfw;"> - <slices></slices> - <sliceSourceBounds y="341.555" x="262" width="87.041" height="108.445" bottomLeftOrigin="true"></sliceSourceBounds> - </sfw> - </metadata> - <g id="Layer_1" i:layer="yes" i:dimmedPercent="50" i:rgbTrio="#4F008000FFFF"> - <g> - <path i:knockout="Off" fill="#A80030" d="M51.986,57.297c-1.797,0.025,0.34,0.926,2.686,1.287 - c0.648-0.506,1.236-1.018,1.76-1.516C54.971,57.426,53.484,57.434,51.986,57.297"/> - <path i:knockout="Off" fill="#A80030" d="M61.631,54.893c1.07-1.477,1.85-3.094,2.125-4.766c-0.24,1.192-0.887,2.221-1.496,3.307 - c-3.359,2.115-0.316-1.256-0.002-2.537C58.646,55.443,61.762,53.623,61.631,54.893"/> - <path i:knockout="Off" fill="#A80030" d="M65.191,45.629c0.217-3.236-0.637-2.213-0.924-0.978 - C64.602,44.825,64.867,46.932,65.191,45.629"/> - <path i:knockout="Off" fill="#A80030" d="M45.172,1.399c0.959,0.172,2.072,0.304,1.916,0.533 - C48.137,1.702,48.375,1.49,45.172,1.399"/> - <path i:knockout="Off" fill="#A80030" d="M47.088,1.932l-0.678,0.14l0.631-0.056L47.088,1.932"/> - <path i:knockout="Off" fill="#A80030" d="M76.992,46.856c0.107,2.906-0.85,4.316-1.713,6.812l-1.553,0.776 - c-1.271,2.468,0.123,1.567-0.787,3.53c-1.984,1.764-6.021,5.52-7.313,5.863c-0.943-0.021,0.639-1.113,0.846-1.541 - c-2.656,1.824-2.131,2.738-6.193,3.846l-0.119-0.264c-10.018,4.713-23.934-4.627-23.751-17.371 - c-0.107,0.809-0.304,0.607-0.526,0.934c-0.517-6.557,3.028-13.143,9.007-15.832c5.848-2.895,12.704-1.707,16.893,2.197 - c-2.301-3.014-6.881-6.209-12.309-5.91c-5.317,0.084-10.291,3.463-11.951,7.131c-2.724,1.715-3.04,6.611-4.227,7.507 - C31.699,56.271,36.3,61.342,44.083,67.307c1.225,0.826,0.345,0.951,0.511,1.58c-2.586-1.211-4.954-3.039-6.901-5.277 - c1.033,1.512,2.148,2.982,3.589,4.137c-2.438-0.826-5.695-5.908-6.646-6.115c4.203,7.525,17.052,13.197,23.78,10.383 - c-3.113,0.115-7.068,0.064-10.566-1.229c-1.469-0.756-3.467-2.322-3.11-2.615c9.182,3.43,18.667,2.598,26.612-3.771 - c2.021-1.574,4.229-4.252,4.867-4.289c-0.961,1.445,0.164,0.695-0.574,1.971c2.014-3.248-0.875-1.322,2.082-5.609l1.092,1.504 - c-0.406-2.696,3.348-5.97,2.967-10.234c0.861-1.304,0.961,1.403,0.047,4.403c1.268-3.328,0.334-3.863,0.66-6.609 - c0.352,0.923,0.814,1.904,1.051,2.878c-0.826-3.216,0.848-5.416,1.262-7.285c-0.408-0.181-1.275,1.422-1.473-2.377 - c0.029-1.65,0.459-0.865,0.625-1.271c-0.324-0.186-1.174-1.451-1.691-3.877c0.375-0.57,1.002,1.478,1.512,1.562 - c-0.328-1.929-0.893-3.4-0.916-4.88c-1.49-3.114-0.527,0.415-1.736-1.337c-1.586-4.947,1.316-1.148,1.512-3.396 - c2.404,3.483,3.775,8.881,4.404,11.117c-0.48-2.726-1.256-5.367-2.203-7.922c0.73,0.307-1.176-5.609,0.949-1.691 - c-2.27-8.352-9.715-16.156-16.564-19.818c0.838,0.767,1.896,1.73,1.516,1.881c-3.406-2.028-2.807-2.186-3.295-3.043 - c-2.775-1.129-2.957,0.091-4.795,0.002c-5.23-2.774-6.238-2.479-11.051-4.217l0.219,1.023c-3.465-1.154-4.037,0.438-7.782,0.004 - c-0.228-0.178,1.2-0.644,2.375-0.815c-3.35,0.442-3.193-0.66-6.471,0.122c0.808-0.567,1.662-0.942,2.524-1.424 - c-2.732,0.166-6.522,1.59-5.352,0.295c-4.456,1.988-12.37,4.779-16.811,8.943l-0.14-0.933c-2.035,2.443-8.874,7.296-9.419,10.46 - l-0.544,0.127c-1.059,1.793-1.744,3.825-2.584,5.67c-1.385,2.36-2.03,0.908-1.833,1.278c-2.724,5.523-4.077,10.164-5.246,13.97 - c0.833,1.245,0.02,7.495,0.335,12.497c-1.368,24.704,17.338,48.69,37.785,54.228c2.997,1.072,7.454,1.031,11.245,1.141 - c-4.473-1.279-5.051-0.678-9.408-2.197c-3.143-1.48-3.832-3.17-6.058-5.102l0.881,1.557c-4.366-1.545-2.539-1.912-6.091-3.037 - l0.941-1.229c-1.415-0.107-3.748-2.385-4.386-3.646l-1.548,0.061c-1.86-2.295-2.851-3.949-2.779-5.23l-0.5,0.891 - c-0.567-0.973-6.843-8.607-3.587-6.83c-0.605-0.553-1.409-0.9-2.281-2.484l0.663-0.758c-1.567-2.016-2.884-4.6-2.784-5.461 - c0.836,1.129,1.416,1.34,1.99,1.533c-3.957-9.818-4.179-0.541-7.176-9.994l0.634-0.051c-0.486-0.732-0.781-1.527-1.172-2.307 - l0.276-2.75C4.667,58.121,6.719,47.409,7.13,41.534c0.285-2.389,2.378-4.932,3.97-8.92l-0.97-0.167 - c1.854-3.234,10.586-12.988,14.63-12.486c1.959-2.461-0.389-0.009-0.772-0.629c4.303-4.453,5.656-3.146,8.56-3.947 - c3.132-1.859-2.688,0.725-1.203-0.709c5.414-1.383,3.837-3.144,10.9-3.846c0.745,0.424-1.729,0.655-2.35,1.205 - c4.511-2.207,14.275-1.705,20.617,1.225c7.359,3.439,15.627,13.605,15.953,23.17l0.371,0.1 - c-0.188,3.802,0.582,8.199-0.752,12.238L76.992,46.856"/> - <path i:knockout="Off" fill="#A80030" d="M32.372,59.764l-0.252,1.26c1.181,1.604,2.118,3.342,3.626,4.596 - C34.661,63.502,33.855,62.627,32.372,59.764"/> - <path i:knockout="Off" fill="#A80030" d="M35.164,59.654c-0.625-0.691-0.995-1.523-1.409-2.352 - c0.396,1.457,1.207,2.709,1.962,3.982L35.164,59.654"/> - <path i:knockout="Off" fill="#A80030" d="M84.568,48.916l-0.264,0.662c-0.484,3.438-1.529,6.84-3.131,9.994 - C82.943,56.244,84.088,52.604,84.568,48.916"/> - <path i:knockout="Off" fill="#A80030" d="M45.527,0.537C46.742,0.092,48.514,0.293,49.803,0c-1.68,0.141-3.352,0.225-5.003,0.438 - L45.527,0.537"/> - <path i:knockout="Off" fill="#A80030" d="M2.872,23.219c0.28,2.592-1.95,3.598,0.494,1.889 - C4.676,22.157,2.854,24.293,2.872,23.219"/> - <path i:knockout="Off" fill="#A80030" d="M0,35.215c0.563-1.728,0.665-2.766,0.88-3.766C-0.676,33.438,0.164,33.862,0,35.215"/> - </g> - </g> -</svg> +<?xml version="1.0" encoding="utf-8"?> +<!-- Generator: Adobe Illustrator 10.0, SVG Export Plug-In . SVG Version: 3.0.0 Build 77) --> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [ + <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/"> + <!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/"> + <!ENTITY ns_ai "http://ns.adobe.com/AdobeIllustrator/10.0/"> + <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/"> + <!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/"> + <!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/"> + <!ENTITY ns_sfw "http://ns.adobe.com/SaveForWeb/1.0/"> + <!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/"> + <!ENTITY ns_adobe_xpath "http://ns.adobe.com/XPath/1.0/"> + <!ENTITY ns_svg "http://www.w3.org/2000/svg"> + <!ENTITY ns_xlink "http://www.w3.org/1999/xlink"> +]> +<svg + xmlns:x="&ns_extend;" xmlns:i="&ns_ai;" xmlns:graph="&ns_graphs;" i:viewOrigin="262 450" i:rulerOrigin="0 0" i:pageBounds="0 792 612 0" + xmlns="&ns_svg;" xmlns:xlink="&ns_xlink;" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" + width="87.041" height="108.445" viewBox="0 0 87.041 108.445" overflow="visible" enable-background="new 0 0 87.041 108.445" + xml:space="preserve"> + <metadata> + <variableSets xmlns="&ns_vars;"> + <variableSet varSetName="binding1" locked="none"> + <variables></variables> + <v:sampleDataSets xmlns="&ns_custom;" xmlns:v="&ns_vars;"></v:sampleDataSets> + </variableSet> + </variableSets> + <sfw xmlns="&ns_sfw;"> + <slices></slices> + <sliceSourceBounds y="341.555" x="262" width="87.041" height="108.445" bottomLeftOrigin="true"></sliceSourceBounds> + </sfw> + </metadata> + <g id="Layer_1" i:layer="yes" i:dimmedPercent="50" i:rgbTrio="#4F008000FFFF"> + <g> + <path i:knockout="Off" fill="#A80030" d="M51.986,57.297c-1.797,0.025,0.34,0.926,2.686,1.287 + c0.648-0.506,1.236-1.018,1.76-1.516C54.971,57.426,53.484,57.434,51.986,57.297"/> + <path i:knockout="Off" fill="#A80030" d="M61.631,54.893c1.07-1.477,1.85-3.094,2.125-4.766c-0.24,1.192-0.887,2.221-1.496,3.307 + c-3.359,2.115-0.316-1.256-0.002-2.537C58.646,55.443,61.762,53.623,61.631,54.893"/> + <path i:knockout="Off" fill="#A80030" d="M65.191,45.629c0.217-3.236-0.637-2.213-0.924-0.978 + C64.602,44.825,64.867,46.932,65.191,45.629"/> + <path i:knockout="Off" fill="#A80030" d="M45.172,1.399c0.959,0.172,2.072,0.304,1.916,0.533 + C48.137,1.702,48.375,1.49,45.172,1.399"/> + <path i:knockout="Off" fill="#A80030" d="M47.088,1.932l-0.678,0.14l0.631-0.056L47.088,1.932"/> + <path i:knockout="Off" fill="#A80030" d="M76.992,46.856c0.107,2.906-0.85,4.316-1.713,6.812l-1.553,0.776 + c-1.271,2.468,0.123,1.567-0.787,3.53c-1.984,1.764-6.021,5.52-7.313,5.863c-0.943-0.021,0.639-1.113,0.846-1.541 + c-2.656,1.824-2.131,2.738-6.193,3.846l-0.119-0.264c-10.018,4.713-23.934-4.627-23.751-17.371 + c-0.107,0.809-0.304,0.607-0.526,0.934c-0.517-6.557,3.028-13.143,9.007-15.832c5.848-2.895,12.704-1.707,16.893,2.197 + c-2.301-3.014-6.881-6.209-12.309-5.91c-5.317,0.084-10.291,3.463-11.951,7.131c-2.724,1.715-3.04,6.611-4.227,7.507 + C31.699,56.271,36.3,61.342,44.083,67.307c1.225,0.826,0.345,0.951,0.511,1.58c-2.586-1.211-4.954-3.039-6.901-5.277 + c1.033,1.512,2.148,2.982,3.589,4.137c-2.438-0.826-5.695-5.908-6.646-6.115c4.203,7.525,17.052,13.197,23.78,10.383 + c-3.113,0.115-7.068,0.064-10.566-1.229c-1.469-0.756-3.467-2.322-3.11-2.615c9.182,3.43,18.667,2.598,26.612-3.771 + c2.021-1.574,4.229-4.252,4.867-4.289c-0.961,1.445,0.164,0.695-0.574,1.971c2.014-3.248-0.875-1.322,2.082-5.609l1.092,1.504 + c-0.406-2.696,3.348-5.97,2.967-10.234c0.861-1.304,0.961,1.403,0.047,4.403c1.268-3.328,0.334-3.863,0.66-6.609 + c0.352,0.923,0.814,1.904,1.051,2.878c-0.826-3.216,0.848-5.416,1.262-7.285c-0.408-0.181-1.275,1.422-1.473-2.377 + c0.029-1.65,0.459-0.865,0.625-1.271c-0.324-0.186-1.174-1.451-1.691-3.877c0.375-0.57,1.002,1.478,1.512,1.562 + c-0.328-1.929-0.893-3.4-0.916-4.88c-1.49-3.114-0.527,0.415-1.736-1.337c-1.586-4.947,1.316-1.148,1.512-3.396 + c2.404,3.483,3.775,8.881,4.404,11.117c-0.48-2.726-1.256-5.367-2.203-7.922c0.73,0.307-1.176-5.609,0.949-1.691 + c-2.27-8.352-9.715-16.156-16.564-19.818c0.838,0.767,1.896,1.73,1.516,1.881c-3.406-2.028-2.807-2.186-3.295-3.043 + c-2.775-1.129-2.957,0.091-4.795,0.002c-5.23-2.774-6.238-2.479-11.051-4.217l0.219,1.023c-3.465-1.154-4.037,0.438-7.782,0.004 + c-0.228-0.178,1.2-0.644,2.375-0.815c-3.35,0.442-3.193-0.66-6.471,0.122c0.808-0.567,1.662-0.942,2.524-1.424 + c-2.732,0.166-6.522,1.59-5.352,0.295c-4.456,1.988-12.37,4.779-16.811,8.943l-0.14-0.933c-2.035,2.443-8.874,7.296-9.419,10.46 + l-0.544,0.127c-1.059,1.793-1.744,3.825-2.584,5.67c-1.385,2.36-2.03,0.908-1.833,1.278c-2.724,5.523-4.077,10.164-5.246,13.97 + c0.833,1.245,0.02,7.495,0.335,12.497c-1.368,24.704,17.338,48.69,37.785,54.228c2.997,1.072,7.454,1.031,11.245,1.141 + c-4.473-1.279-5.051-0.678-9.408-2.197c-3.143-1.48-3.832-3.17-6.058-5.102l0.881,1.557c-4.366-1.545-2.539-1.912-6.091-3.037 + l0.941-1.229c-1.415-0.107-3.748-2.385-4.386-3.646l-1.548,0.061c-1.86-2.295-2.851-3.949-2.779-5.23l-0.5,0.891 + c-0.567-0.973-6.843-8.607-3.587-6.83c-0.605-0.553-1.409-0.9-2.281-2.484l0.663-0.758c-1.567-2.016-2.884-4.6-2.784-5.461 + c0.836,1.129,1.416,1.34,1.99,1.533c-3.957-9.818-4.179-0.541-7.176-9.994l0.634-0.051c-0.486-0.732-0.781-1.527-1.172-2.307 + l0.276-2.75C4.667,58.121,6.719,47.409,7.13,41.534c0.285-2.389,2.378-4.932,3.97-8.92l-0.97-0.167 + c1.854-3.234,10.586-12.988,14.63-12.486c1.959-2.461-0.389-0.009-0.772-0.629c4.303-4.453,5.656-3.146,8.56-3.947 + c3.132-1.859-2.688,0.725-1.203-0.709c5.414-1.383,3.837-3.144,10.9-3.846c0.745,0.424-1.729,0.655-2.35,1.205 + c4.511-2.207,14.275-1.705,20.617,1.225c7.359,3.439,15.627,13.605,15.953,23.17l0.371,0.1 + c-0.188,3.802,0.582,8.199-0.752,12.238L76.992,46.856"/> + <path i:knockout="Off" fill="#A80030" d="M32.372,59.764l-0.252,1.26c1.181,1.604,2.118,3.342,3.626,4.596 + C34.661,63.502,33.855,62.627,32.372,59.764"/> + <path i:knockout="Off" fill="#A80030" d="M35.164,59.654c-0.625-0.691-0.995-1.523-1.409-2.352 + c0.396,1.457,1.207,2.709,1.962,3.982L35.164,59.654"/> + <path i:knockout="Off" fill="#A80030" d="M84.568,48.916l-0.264,0.662c-0.484,3.438-1.529,6.84-3.131,9.994 + C82.943,56.244,84.088,52.604,84.568,48.916"/> + <path i:knockout="Off" fill="#A80030" d="M45.527,0.537C46.742,0.092,48.514,0.293,49.803,0c-1.68,0.141-3.352,0.225-5.003,0.438 + L45.527,0.537"/> + <path i:knockout="Off" fill="#A80030" d="M2.872,23.219c0.28,2.592-1.95,3.598,0.494,1.889 + C4.676,22.157,2.854,24.293,2.872,23.219"/> + <path i:knockout="Off" fill="#A80030" d="M0,35.215c0.563-1.728,0.665-2.766,0.88-3.766C-0.676,33.438,0.164,33.862,0,35.215"/> + </g> + </g> +</svg> diff --git a/docs/source/examples/copy_cast/main.cpp b/docs/source/examples/copy_cast/main.cpp index 2e12609..f1c9f1f 100644 --- a/docs/source/examples/copy_cast/main.cpp +++ b/docs/source/examples/copy_cast/main.cpp @@ -1,6 +1,7 @@ #include <numeric> -#include <xtensor.hpp> + #include <pybind11/pybind11.h> +#include <xtensor.hpp> #define FORCE_IMPORT_ARRAY #include <xtensor-python/pyarray.hpp> diff --git a/docs/source/examples/readme_example_1/example.py b/docs/source/examples/readme_example_1/example.py index 1ae033d..b71f825 100644 --- a/docs/source/examples/readme_example_1/example.py +++ b/docs/source/examples/readme_example_1/example.py @@ -3,4 +3,3 @@ a = np.array([1, 2, 3]) assert np.isclose(np.sum(np.sin(a)), mymodule.sum_of_sines(a)) - diff --git a/docs/source/examples/readme_example_1/main.cpp b/docs/source/examples/readme_example_1/main.cpp index 6175ed8..d1af2ee 100644 --- a/docs/source/examples/readme_example_1/main.cpp +++ b/docs/source/examples/readme_example_1/main.cpp @@ -1,6 +1,7 @@ #include <numeric> -#include <xtensor.hpp> + #include <pybind11/pybind11.h> +#include <xtensor.hpp> #define FORCE_IMPORT_ARRAY #include <xtensor-python/pyarray.hpp> diff --git a/docs/source/examples/sfinae/example.py b/docs/source/examples/sfinae/example.py index 1929f0b..348fc93 100644 --- a/docs/source/examples/sfinae/example.py +++ b/docs/source/examples/sfinae/example.py @@ -5,4 +5,3 @@ b = np.array(a, copy=True) mymodule.times_dimension(b) # changing in-place! assert np.allclose(2 * a, b) - diff --git a/docs/source/examples/sfinae/main.cpp b/docs/source/examples/sfinae/main.cpp index a146cdd..2278f00 100644 --- a/docs/source/examples/sfinae/main.cpp +++ b/docs/source/examples/sfinae/main.cpp @@ -1,6 +1,7 @@ -#include "mymodule.hpp" #include <xtensor/xio.hpp> +#include "mymodule.hpp" + int main() { xt::xtensor<size_t, 2> a = xt::arange<size_t>(2 * 3).reshape({2, 3}); diff --git a/docs/source/examples/sfinae/mymodule.hpp b/docs/source/examples/sfinae/mymodule.hpp index 5127eff..ad3d004 100644 --- a/docs/source/examples/sfinae/mymodule.hpp +++ b/docs/source/examples/sfinae/mymodule.hpp @@ -1,32 +1,33 @@ #include <xtensor/xtensor.hpp> -namespace mymodule { - -template <class T> -struct is_std_vector +namespace mymodule { - static const bool value = false; -}; -template <class T> -struct is_std_vector<std::vector<T> > -{ - static const bool value = true; -}; + template <class T> + struct is_std_vector + { + static const bool value = false; + }; -// any xtensor object -template <class T, std::enable_if_t<xt::is_xexpression<T>::value, bool> = true> -void times_dimension(T& t) -{ - using value_type = typename T::value_type; - t *= (value_type)(t.dimension()); -} + template <class T> + struct is_std_vector<std::vector<T>> + { + static const bool value = true; + }; -// an std::vector -template <class T, std::enable_if_t<is_std_vector<T>::value, bool> = true> -void times_dimension(T& t) -{ - // do nothing -} + // any xtensor object + template <class T, std::enable_if_t<xt::is_xexpression<T>::value, bool> = true> + void times_dimension(T& t) + { + using value_type = typename T::value_type; + t *= (value_type) (t.dimension()); + } + + // an std::vector + template <class T, std::enable_if_t<is_std_vector<T>::value, bool> = true> + void times_dimension(T& t) + { + // do nothing + } } diff --git a/docs/source/examples/sfinae/python.cpp b/docs/source/examples/sfinae/python.cpp index 081f625..f719248 100644 --- a/docs/source/examples/sfinae/python.cpp +++ b/docs/source/examples/sfinae/python.cpp @@ -1,5 +1,6 @@ -#include "mymodule.hpp" #include <pybind11/pybind11.h> + +#include "mymodule.hpp" #define FORCE_IMPORT_ARRAY #include <xtensor-python/pyarray.hpp> diff --git a/docs/source/numpy_capi.rst b/docs/source/numpy_capi.rst index d489be2..a84364d 100644 --- a/docs/source/numpy_capi.rst +++ b/docs/source/numpy_capi.rst @@ -90,6 +90,3 @@ you can override the behavior of ``xtensor-python`` by explicitly defining ``PY_ // in every source file #define PY_ARRAY_UNIQUE_SYMBOL my_uniqe_array_api #include "xtensor-python/pyarray.hpp" - - - diff --git a/docs/source/quantstack-white.svg b/docs/source/quantstack-white.svg index d527db1..1f03ebb 100644 --- a/docs/source/quantstack-white.svg +++ b/docs/source/quantstack-white.svg @@ -49,4 +49,4 @@ d="m 85.3,16 c 1.2,0.6 2.4,1.3 3.4,2.2 l 0,22.2 c 0,9.2 -1.8,19.7 -14.2,19.7 l -1.9,0 C 60.1,60.1 58.4,49.6 58.4,40.4 l 0,-22.2 c 1,-0.9 2.2,-1.6 3.4,-2.2 l 0,23.4 c 0,10.4 1.5,17.7 11.4,17.7 l 0.9,0 c 9.8,0 11.4,-7.3 11.4,-17.7 L 85.5,16 Z M 133,38.1 c 0,15 -5.1,22.1 -18.1,22.1 -0.1,0 -0.6,0 -0.7,0 -11,0 -14.2,-5.1 -14.2,-12.4 0,-10.2 9.7,-12.6 29.5,-13.4 -0.6,-9.3 -3.7,-15.2 -14.6,-15.2 -3,0 -5.8,0.5 -8.6,1.8 l -1.5,-2.9 c 3.3,-1.7 6.7,-2.1 10.1,-2.1 13,0 18.1,7 18.1,22.1 z m -3.4,-0.7 c -16.6,0.8 -26.1,2.2 -26.1,10.5 0,2.8 0.5,4.9 1.9,6.4 0.4,0.5 1,0.9 1.7,1.2 2.6,1.1 5.2,1.5 7.9,1.5 12.2,0 14.7,-7.4 14.7,-18.9 -0.1,-0.3 -0.1,-0.5 -0.1,-0.7 z m 201.7,0.7 c 0,15 -5.1,22.1 -18.1,22.1 -0.1,0 -0.6,0 -0.7,0 -11,0 -14.2,-5.1 -14.2,-12.4 0,-10.2 9.7,-12.6 29.5,-13.4 -0.6,-9.3 -3.7,-15.2 -14.6,-15.2 -3,0 -5.8,0.5 -8.6,1.8 l -1.5,-2.9 c 3.3,-1.7 6.7,-2.1 10.1,-2.1 13,0 18.1,7 18.1,22.1 z m -3.4,-0.7 c -16.6,0.8 -26.1,2.2 -26.1,10.5 0,2.8 0.5,4.9 1.9,6.4 0.4,0.5 1,0.9 1.7,1.2 2.6,1.1 5.2,1.5 7.9,1.5 12.2,0 14.7,-7.4 14.7,-18.9 -0.1,-0.3 -0.1,-0.5 -0.1,-0.7 z M 57.2,82.2 c -0.9,0.9 -1.8,1.7 -2.9,2.3 C 45,79.7 38.3,71.4 34.9,60.6 31.7,62.2 27.8,63 23.1,63 6.5,63 0,53.3 0,32.3 0,11.4 6.5,1.6 23.1,1.6 c 16.6,0 23.1,9.7 23.1,30.7 0,13 -2.5,21.6 -8.4,26.4 3.2,10.9 10,19 19.4,23.5 z M 42.7,32.3 C 42.7,15.9 39.4,4.8 23,4.8 6.6,4.8 3.3,15.8 3.3,32.3 c 0,16.4 3.3,27.5 19.7,27.5 16.4,0 19.7,-11 19.7,-27.5 z m 366,-10.4 C 408,21 407.2,20.2 406.3,19.5 l -18.3,18.2 0,-22 -0.4,0 c -1.1,0.2 -2,0.5 -3,0.8 l 0,42.6 c 1.1,0.4 2.2,0.6 3.4,0.9 l 0,-21.3 17.8,17.8 c 0.9,-0.7 1.7,-1.4 2.5,-2.3 l -16,-16 16.4,-16.3 z M 360.6,57 c -12.2,0 -14.7,-7.4 -14.7,-18.9 0,-11.5 2.5,-18.9 14.7,-18.9 3.1,0 6,0.5 8.8,1.9 l 1.5,-2.9 c -3.4,-1.7 -6.9,-2.1 -10.2,-2.1 -13,0 -18.1,7 -18.1,22.1 0,15 5.1,22.1 18.1,22.1 3.4,0 6.9,-0.4 10.3,-2.1 l -1.5,-2.9 c -3,1.2 -5.9,1.7 -8.9,1.7 z m -198,-41.1 -1.9,0 c -12.5,0 -14.2,10.5 -14.2,19.7 l 0,22.2 c 1,0.9 2.2,1.6 3.4,2.2 l 0,-23.3 c 0,-10.4 1.5,-17.7 11.4,-17.7 l 0.9,0 c 9.8,0 11.4,7.3 11.4,17.7 l 0,23.4 c 1.2,-0.6 2.4,-1.3 3.4,-2.2 l 0,-22.2 c -0.2,-9.3 -2,-19.8 -14.4,-19.8 z m 127.7,4.3 -1.6,-3.1 -10.4,0 0,-10.9 -3.3,0 0,10.8 -10.5,0 -1.6,3.1 12.1,0 c 0,0 0,22.4 0,23.7 l 0,0 c -0.1,2.6 0.3,5.1 1.2,7.3 0,0.1 1,2.2 2.6,4.1 0.8,0.9 2.4,2.3 4.6,3.8 l 1.5,-3.1 c -1.7,-1.2 -2.9,-2.2 -3.5,-2.9 -1.3,-1.5 -2,-3.2 -2,-3.2 -0.7,-1.6 -1,-3.3 -1,-5 0,-1.2 0,-24.7 0,-24.7 l 11.9,0 z M 197.8,6 l -3.3,0 0,10.8 -12,0 1.6,3.1 10.4,0 c 0,0 0,12.2 0,13.5 l 0,0 c -0.1,2.6 0.3,5.1 1.2,7.3 0,0.1 1,2.2 2.6,4.1 0.8,0.9 2.3,2.2 4.4,3.7 l 1.6,-3.1 c -1.7,-1.2 -2.9,-2.2 -3.4,-2.9 -1.3,-1.5 -2,-3.2 -2,-3.2 -0.7,-1.6 -1,-3.3 -1,-5 0,-1.2 0,-14.5 0,-14.5 l 10.4,0 1.6,-3.1 -12.1,0 0,-10.7 z m 40.3,22.2 c -1.9,-0.7 -3.6,-1.3 -5.3,-2.1 l 0,0 c -5.1,-2.1 -8.7,-4.8 -8.7,-10.8 0,-9.2 6.4,-12.1 14.5,-12.1 3.8,0 7.5,0.4 11.2,1.7 L 251.3,2 c -4,-1.5 -8.3,-2 -12.8,-2 -9.4,0 -17.7,4.1 -17.7,15.4 0,6.7 3.4,10.4 8.6,12.9 l 0,0 c 0.8,0.3 1.4,0.6 2.1,0.9 0,0 0,0 0,0 l 0,0 c 1.9,0.8 3.3,1.4 5.1,2 8.4,3 12.3,3.5 15.1,6.6 0.2,0.2 4.1,4.8 3.1,10.4 -0.5,2.9 -2.2,5.5 -4.9,7.8 -6.2,5.1 -15.9,4 -25.2,0.9 l -1.6,3.1 c 5.1,1.8 10.4,3 15.4,3 5.1,0 9.7,-1.2 13.5,-4.3 4.2,-3.5 5.7,-7.2 6.1,-9.8 1.3,-7.1 -3.3,-12.6 -3.8,-13.2 -2.7,-2.9 -7.6,-4.4 -16.2,-7.5 z" id="path3" inkscape:connector-curvature="0" - style="fill:#ffffff" /></svg> \ No newline at end of file + style="fill:#ffffff" /></svg> diff --git a/docs/source/xtensor-python.svg b/docs/source/xtensor-python.svg index 181465f..7a29ffd 100644 --- a/docs/source/xtensor-python.svg +++ b/docs/source/xtensor-python.svg @@ -1,60 +1,60 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> -<svg version="1.1" id="Calque_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" - viewBox="0 0 238.8 81.3" width="710.714286" height="241.964286" style="enable-background:new 0 0 238.8 81.3;" xml:space="preserve"> -<style type="text/css"> - .st0{fill:#666666;} - .st1{fill:#7FD787;} - .st2{opacity:0.28;fill:#7FD787;enable-background:new ;} -</style> -<g> - <path class="st0" d="M177.8,62.3L177.8,62.3c-1.7,0-3.2,0.3-4.3,1c-0.5,0.3-0.9,0.6-1.3,1v15.7l2,0.7v-7.1c1.2,0.8,2.4,1.1,3.6,1.1 - c1.5,0,2.7-0.7,3.6-1.9c0.8-1.1,1.2-2.5,1.2-4.1h0c0-1.9-0.4-3.4-1.2-4.6C180.6,62.9,179.4,62.3,177.8,62.3z M177.4,73.4 - c-0.9,0.1-2-0.3-3.2-1v-7.8c0.2-0.2,0.6-0.4,1.1-0.6c0.7-0.3,1.4-0.4,2.2-0.4c1.9,0.1,2.8,1.8,2.8,5 - C180.3,71.7,179.3,73.3,177.4,73.4z M192.8,62.6h2v10.8c0,2.2-0.2,3.8-0.7,4.6c-0.4,0.9-1.3,1.5-2.6,2c-1,0.4-2.1,0.6-3.3,0.7 - l-0.3-1.3c1.2-0.2,2-0.3,2.5-0.5c1-0.3,1.6-0.8,2-1.5c0.3-0.5,0.4-1.6,0.4-3.1v-0.5c-1.4,0.6-2.8,0.9-4.3,0.9c-1,0-1.8-0.3-2.6-0.9 - c-0.8-0.7-1.3-1.5-1.3-2.6V63l2-0.7v8.3c0,0.9,0.3,1.6,0.9,2.1c0.6,0.5,1.3,0.7,2.2,0.7c0.9,0,1.9-0.4,2.9-1.1V62.6z M200.3,62.6 - h2.2v1.3h-2.2v7.8c0,0.7,0.2,1.3,0.6,1.6c0.3,0.3,0.9,0.4,1.6,0.4v1c-0.2,0-0.5,0-0.7,0c-1.1,0-2-0.3-2.6-0.8 - c-0.6-0.5-0.9-1.3-0.9-2.2v-7.8h-1.4v-1.3h1.4v-3.3l2-0.7V62.6z M213.6,63.6c0.7,0.7,1,1.6,1,2.6v8.3h-2v-7.7c0-0.8-0.2-1.5-0.5-2 - c-0.4-0.6-1-1-1.8-1c-0.9,0-2.1,0.5-3.4,1.4v9.2h-2V56.2l2-0.6v8.4c1.3-0.9,2.7-1.4,4.2-1.4C212.1,62.5,212.9,62.9,213.6,63.6z - M221.9,62.3c-1.7,0-3,0.6-4,1.8c-1,1.1-1.4,2.6-1.4,4.2c0,1.8,0.4,3.3,1.3,4.4c1,1.3,2.3,2,4.1,2c1.8,0,3.1-0.7,4.1-2 - c0.9-1.2,1.4-2.7,1.4-4.4c0-1.7-0.5-3.1-1.4-4.2C224.9,62.9,223.5,62.3,221.9,62.3z M221.9,73.5c-1.2,0-2-0.6-2.6-1.7 - c-0.5-0.9-0.7-2.1-0.7-3.4c0-3,1.1-4.6,3.3-4.7c1.2,0.1,2.1,0.6,2.6,1.6c0.5,0.8,0.7,1.8,0.7,3.1C225.2,71.8,224.1,73.5,221.9,73.5 - z M238.8,65.4v9.1h-2v-8.1c0-0.9-0.3-1.6-0.8-2.1c-0.5-0.5-1.3-0.7-2.1-0.7c-0.9,0-1.8,0.3-2.7,0.9v10h-2V64.3 - c1.1-0.8,2.2-1.4,3.2-1.6c0.9-0.2,1.7-0.4,2.4-0.4c0.5,0,0.9,0,1.3,0.1c0.8,0.2,1.4,0.5,1.9,1C238.5,64,238.8,64.6,238.8,65.4z - M149.7,68.3h6c1.7,0,3-1.4,3-3v-5.7c0-1.6-1.4-2.8-3-3.1c-1-0.2-2.1-0.2-3.1-0.2s-2,0.1-2.9,0.2c-2.5,0.4-3,1.4-3,3.1v2.3h6v0.8 - h-6h-2.2c-1.7,0-3.3,1-3.7,3c-0.6,2.3-0.6,3.7,0,6.1c0.4,1.8,1.4,3,3.2,3h2.1v-2.7C145.9,70.1,147.7,68.3,149.7,68.3z M149.3,60.4 - c-0.6,0-1.1-0.5-1.1-1.1c0-0.6,0.5-1.1,1.1-1.1c0.6,0,1.1,0.5,1.1,1.1C150.4,59.8,149.9,60.4,149.3,60.4z M161.7,62.6h-2.2v2.7 - c0,2.1-1.7,3.8-3.7,3.8h-6c-1.6,0-3,1.4-3,3v5.7c0,1.6,1.4,2.6,3,3c1.9,0.6,3.7,0.7,6,0c1.5-0.4,3-1.3,3-3v-2.3h-6v-0.8h6h3 - c1.7,0,2.4-1.2,3-3c0.6-1.9,0.6-3.7,0-6.1C164.2,63.9,163.4,62.6,161.7,62.6z M156,77.1c0.6,0,1.1,0.5,1.1,1.1 - c0,0.6-0.5,1.1-1.1,1.1c-0.6,0-1.1-0.5-1.1-1.1C154.9,77.6,155.4,77.1,156,77.1z"/> - <g> - <path class="st1" d="M79.7,15.9L79.7,15.9L79.7,15.9L79.7,15.9z M71.4,38.4c-0.5-1.2-0.8-2.5-0.8-3.8c0-0.9,0-18.8,0-18.8h9.1 - l-1.2-2.3h-7.9V5.2h-2.6v8.2h-8l-1.2,2.4h9.2c0,0,0,17.1,0,18c-0.1,1.9,0.2,3.9,0.9,5.5c0,0.1,0.8,1.6,1.9,3.1 - c0.6,0.6,1.8,1.7,3.5,2.9l1.2-2.4c-1.3-0.9-2.2-1.6-2.7-2.2C71.9,39.5,71.4,38.4,71.4,38.4z M42.3,4.9c-1.6,1-2.8,2.3-3.8,3.7 - C38.1,9.3,31.4,19.2,27.7,25C24.5,29.7,16.5,41.7,16,42.5c-1.3,2.2-3.1,4.1-5.2,5.5c0,0.1-2.3,1.4-5,2.3c-0.2,0-0.4,0.1-0.5,0.1 - H45c-0.1,0-0.2-0.1-0.4-0.1c-2.7-0.9-4.9-2.2-5-2.3c-2.1-1.4-3.9-3.3-5.2-5.5c-0.4-0.6-5.6-8.4-9.3-13.9c0.9-1.3,1.6-2.5,2.3-3.3 - c0,0.1,0.1,0.1,0.1,0.2c3.8,5.7,10.5,15.7,10.9,16.4c1,1.4,2.2,2.7,3.8,3.7c0,0,1.6,1.1,3.8,1.7c0.9,0.3,2.4,0.5,4.3,0.8v2.3h0.1 - V2.4c-1.9,0.2-3.5,0.4-4.3,0.8C44,3.8,42.3,4.9,42.3,4.9z M11.9,41.9c0.4-0.8,7.1-10.7,10.9-16.4c3.1-4.9,11.1-16.7,11.7-17.6 - c1.3-2.2,3.1-4.1,5.2-5.5c0-0.1,2.3-1.4,5-2.3C44.8,0.1,45,0,45.2,0H5.4c0.1,0,0.3,0.1,0.4,0.1c2.7,0.9,4.9,2.2,5,2.3 - c2.1,1.4,3.9,3.3,5.2,5.5c0.4,0.6,5.6,8.4,9.3,13.9c-0.9,1.3-1.6,2.5-2.3,3.3c0-0.1-0.1-0.1-0.1-0.2C19,19.3,12.3,9.3,11.9,8.5 - c-1-1.4-2.2-2.7-3.8-3.7c0,0-1.6-1.1-3.8-1.7C3.5,2.8,1.9,2.6,0,2.4v45.8c1.9-0.2,3.5-0.4,4.3-0.8c2.2-0.6,3.8-1.7,3.8-1.7 - C9.7,44.5,11,43.3,11.9,41.9z M201.3,12.7c-9.6,0-13.4,5.4-13.4,16.7c0,11.5,3.8,16.7,13.4,16.7c9.6,0,13.4-5.4,13.4-16.7 - C214.7,18,210.9,12.7,201.3,12.7z M201.3,44.1c-9.1,0-10.9-5.7-10.9-14.5s1.8-14.5,10.9-14.5c9.1,0,10.9,5.7,10.9,14.5 - C212.2,38.2,210.3,44,201.3,44.1z M237.7,12.7c-4.6,0.2-7.8,1.8-9.8,5v-4.5c-0.9,0.1-1.7,0.3-2.5,0.5v32.1 - c0.8,0.2,1.6,0.4,2.5,0.5v-17c0-8.8,1.8-14.5,10.9-14.5l0,0L237.7,12.7z M101,12.7c-5.8,0-12.7,2.2-12.7,16.9 - c0,13.6,5.9,16.7,13.3,16.7c4,0,7.5-0.8,10.4-2.5l-1-2.2c-3,1.7-5.8,2.4-9.4,2.4c-5.8,0-10.4-2.1-10.8-12.4v-1.3h22.5l0,0v-0.9 - C113.3,16.9,108.7,12.7,101,12.7z M90.6,28c0.2-11,5.1-13,10.3-13c5.7,0,9.7,3,9.7,13H90.6z M136.3,12.6h-1.4 - c-9.5,0-10.8,8-10.8,15v16.9c0.8,0.6,1.6,1.2,2.6,1.6V28.4c0-7.9,1.2-13.5,8.6-13.5h0.6c7.5,0,8.6,5.5,8.6,13.5v17.8 - c0.9-0.4,1.8-1,2.6-1.6V27.8C147.1,20.6,145.7,12.6,136.3,12.6z M168.9,28c-5-1.4-8-2.7-8-6.8c0-4.8,3.3-6.2,7.6-6.2 - c2.8,0,5.4,0.4,7.8,1.6l1-2.2c-2.8-1.4-5.8-1.7-8.8-1.7c-5.2,0-9.9,2.4-9.9,8.3s4.2,7.8,9.4,9.2c4.9,1.3,8.8,2.4,8.8,6.7 - c0,5.3-3.8,7-8,7c-3.8,0-7.5-1-10.2-2.8l-1.1,2.1c3.2,2.2,7.1,2.9,11.3,2.9c5.5,0,10.4-2.5,10.4-9.2 - C179.1,30.9,174.4,29.6,168.9,28z"/> - <path class="st2" d="M27.4,25.2c-0.6,0.9-1.4,2.1-2.3,3.3c3.7,5.5,8.8,13.3,9.3,13.9c1.3,2.2,3.1,4.1,5.2,5.5c0,0.1,2.3,1.4,5,2.3 - c0.2,0,0.4,0.1,0.5,0.1h5.2V48c-1.9-0.2-3.5-0.4-4.3-0.8c-2.2-0.6-3.8-1.7-3.8-1.7c-1.6-1-2.8-2.3-3.8-3.7 - c-0.4-0.8-7.1-10.7-10.9-16.4l0,0C27.5,25.4,27.5,25.3,27.4,25.2 M5.2,0H0v2.4c1.9,0.2,3.5,0.4,4.3,0.8c2.2,0.6,3.8,1.7,3.8,1.7 - c1.6,1,2.8,2.3,3.8,3.7C12.3,9.3,19,19.2,22.8,25l0,0c0,0.1,0.1,0.1,0.1,0.2c0.6-0.9,1.4-2.1,2.3-3.3c-3.7-5.5-8.8-13.3-9.3-13.9 - c-1.3-2.2-3.1-4.1-5.2-5.5c0-0.1-2.3-1.4-5-2.3C5.6,0.1,5.4,0,5.2,0"/> - </g> -</g> -</svg> +<?xml version="1.0" encoding="utf-8"?> +<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> +<svg version="1.1" id="Calque_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" + viewBox="0 0 238.8 81.3" width="710.714286" height="241.964286" style="enable-background:new 0 0 238.8 81.3;" xml:space="preserve"> +<style type="text/css"> + .st0{fill:#666666;} + .st1{fill:#7FD787;} + .st2{opacity:0.28;fill:#7FD787;enable-background:new ;} +</style> +<g> + <path class="st0" d="M177.8,62.3L177.8,62.3c-1.7,0-3.2,0.3-4.3,1c-0.5,0.3-0.9,0.6-1.3,1v15.7l2,0.7v-7.1c1.2,0.8,2.4,1.1,3.6,1.1 + c1.5,0,2.7-0.7,3.6-1.9c0.8-1.1,1.2-2.5,1.2-4.1h0c0-1.9-0.4-3.4-1.2-4.6C180.6,62.9,179.4,62.3,177.8,62.3z M177.4,73.4 + c-0.9,0.1-2-0.3-3.2-1v-7.8c0.2-0.2,0.6-0.4,1.1-0.6c0.7-0.3,1.4-0.4,2.2-0.4c1.9,0.1,2.8,1.8,2.8,5 + C180.3,71.7,179.3,73.3,177.4,73.4z M192.8,62.6h2v10.8c0,2.2-0.2,3.8-0.7,4.6c-0.4,0.9-1.3,1.5-2.6,2c-1,0.4-2.1,0.6-3.3,0.7 + l-0.3-1.3c1.2-0.2,2-0.3,2.5-0.5c1-0.3,1.6-0.8,2-1.5c0.3-0.5,0.4-1.6,0.4-3.1v-0.5c-1.4,0.6-2.8,0.9-4.3,0.9c-1,0-1.8-0.3-2.6-0.9 + c-0.8-0.7-1.3-1.5-1.3-2.6V63l2-0.7v8.3c0,0.9,0.3,1.6,0.9,2.1c0.6,0.5,1.3,0.7,2.2,0.7c0.9,0,1.9-0.4,2.9-1.1V62.6z M200.3,62.6 + h2.2v1.3h-2.2v7.8c0,0.7,0.2,1.3,0.6,1.6c0.3,0.3,0.9,0.4,1.6,0.4v1c-0.2,0-0.5,0-0.7,0c-1.1,0-2-0.3-2.6-0.8 + c-0.6-0.5-0.9-1.3-0.9-2.2v-7.8h-1.4v-1.3h1.4v-3.3l2-0.7V62.6z M213.6,63.6c0.7,0.7,1,1.6,1,2.6v8.3h-2v-7.7c0-0.8-0.2-1.5-0.5-2 + c-0.4-0.6-1-1-1.8-1c-0.9,0-2.1,0.5-3.4,1.4v9.2h-2V56.2l2-0.6v8.4c1.3-0.9,2.7-1.4,4.2-1.4C212.1,62.5,212.9,62.9,213.6,63.6z + M221.9,62.3c-1.7,0-3,0.6-4,1.8c-1,1.1-1.4,2.6-1.4,4.2c0,1.8,0.4,3.3,1.3,4.4c1,1.3,2.3,2,4.1,2c1.8,0,3.1-0.7,4.1-2 + c0.9-1.2,1.4-2.7,1.4-4.4c0-1.7-0.5-3.1-1.4-4.2C224.9,62.9,223.5,62.3,221.9,62.3z M221.9,73.5c-1.2,0-2-0.6-2.6-1.7 + c-0.5-0.9-0.7-2.1-0.7-3.4c0-3,1.1-4.6,3.3-4.7c1.2,0.1,2.1,0.6,2.6,1.6c0.5,0.8,0.7,1.8,0.7,3.1C225.2,71.8,224.1,73.5,221.9,73.5 + z M238.8,65.4v9.1h-2v-8.1c0-0.9-0.3-1.6-0.8-2.1c-0.5-0.5-1.3-0.7-2.1-0.7c-0.9,0-1.8,0.3-2.7,0.9v10h-2V64.3 + c1.1-0.8,2.2-1.4,3.2-1.6c0.9-0.2,1.7-0.4,2.4-0.4c0.5,0,0.9,0,1.3,0.1c0.8,0.2,1.4,0.5,1.9,1C238.5,64,238.8,64.6,238.8,65.4z + M149.7,68.3h6c1.7,0,3-1.4,3-3v-5.7c0-1.6-1.4-2.8-3-3.1c-1-0.2-2.1-0.2-3.1-0.2s-2,0.1-2.9,0.2c-2.5,0.4-3,1.4-3,3.1v2.3h6v0.8 + h-6h-2.2c-1.7,0-3.3,1-3.7,3c-0.6,2.3-0.6,3.7,0,6.1c0.4,1.8,1.4,3,3.2,3h2.1v-2.7C145.9,70.1,147.7,68.3,149.7,68.3z M149.3,60.4 + c-0.6,0-1.1-0.5-1.1-1.1c0-0.6,0.5-1.1,1.1-1.1c0.6,0,1.1,0.5,1.1,1.1C150.4,59.8,149.9,60.4,149.3,60.4z M161.7,62.6h-2.2v2.7 + c0,2.1-1.7,3.8-3.7,3.8h-6c-1.6,0-3,1.4-3,3v5.7c0,1.6,1.4,2.6,3,3c1.9,0.6,3.7,0.7,6,0c1.5-0.4,3-1.3,3-3v-2.3h-6v-0.8h6h3 + c1.7,0,2.4-1.2,3-3c0.6-1.9,0.6-3.7,0-6.1C164.2,63.9,163.4,62.6,161.7,62.6z M156,77.1c0.6,0,1.1,0.5,1.1,1.1 + c0,0.6-0.5,1.1-1.1,1.1c-0.6,0-1.1-0.5-1.1-1.1C154.9,77.6,155.4,77.1,156,77.1z"/> + <g> + <path class="st1" d="M79.7,15.9L79.7,15.9L79.7,15.9L79.7,15.9z M71.4,38.4c-0.5-1.2-0.8-2.5-0.8-3.8c0-0.9,0-18.8,0-18.8h9.1 + l-1.2-2.3h-7.9V5.2h-2.6v8.2h-8l-1.2,2.4h9.2c0,0,0,17.1,0,18c-0.1,1.9,0.2,3.9,0.9,5.5c0,0.1,0.8,1.6,1.9,3.1 + c0.6,0.6,1.8,1.7,3.5,2.9l1.2-2.4c-1.3-0.9-2.2-1.6-2.7-2.2C71.9,39.5,71.4,38.4,71.4,38.4z M42.3,4.9c-1.6,1-2.8,2.3-3.8,3.7 + C38.1,9.3,31.4,19.2,27.7,25C24.5,29.7,16.5,41.7,16,42.5c-1.3,2.2-3.1,4.1-5.2,5.5c0,0.1-2.3,1.4-5,2.3c-0.2,0-0.4,0.1-0.5,0.1 + H45c-0.1,0-0.2-0.1-0.4-0.1c-2.7-0.9-4.9-2.2-5-2.3c-2.1-1.4-3.9-3.3-5.2-5.5c-0.4-0.6-5.6-8.4-9.3-13.9c0.9-1.3,1.6-2.5,2.3-3.3 + c0,0.1,0.1,0.1,0.1,0.2c3.8,5.7,10.5,15.7,10.9,16.4c1,1.4,2.2,2.7,3.8,3.7c0,0,1.6,1.1,3.8,1.7c0.9,0.3,2.4,0.5,4.3,0.8v2.3h0.1 + V2.4c-1.9,0.2-3.5,0.4-4.3,0.8C44,3.8,42.3,4.9,42.3,4.9z M11.9,41.9c0.4-0.8,7.1-10.7,10.9-16.4c3.1-4.9,11.1-16.7,11.7-17.6 + c1.3-2.2,3.1-4.1,5.2-5.5c0-0.1,2.3-1.4,5-2.3C44.8,0.1,45,0,45.2,0H5.4c0.1,0,0.3,0.1,0.4,0.1c2.7,0.9,4.9,2.2,5,2.3 + c2.1,1.4,3.9,3.3,5.2,5.5c0.4,0.6,5.6,8.4,9.3,13.9c-0.9,1.3-1.6,2.5-2.3,3.3c0-0.1-0.1-0.1-0.1-0.2C19,19.3,12.3,9.3,11.9,8.5 + c-1-1.4-2.2-2.7-3.8-3.7c0,0-1.6-1.1-3.8-1.7C3.5,2.8,1.9,2.6,0,2.4v45.8c1.9-0.2,3.5-0.4,4.3-0.8c2.2-0.6,3.8-1.7,3.8-1.7 + C9.7,44.5,11,43.3,11.9,41.9z M201.3,12.7c-9.6,0-13.4,5.4-13.4,16.7c0,11.5,3.8,16.7,13.4,16.7c9.6,0,13.4-5.4,13.4-16.7 + C214.7,18,210.9,12.7,201.3,12.7z M201.3,44.1c-9.1,0-10.9-5.7-10.9-14.5s1.8-14.5,10.9-14.5c9.1,0,10.9,5.7,10.9,14.5 + C212.2,38.2,210.3,44,201.3,44.1z M237.7,12.7c-4.6,0.2-7.8,1.8-9.8,5v-4.5c-0.9,0.1-1.7,0.3-2.5,0.5v32.1 + c0.8,0.2,1.6,0.4,2.5,0.5v-17c0-8.8,1.8-14.5,10.9-14.5l0,0L237.7,12.7z M101,12.7c-5.8,0-12.7,2.2-12.7,16.9 + c0,13.6,5.9,16.7,13.3,16.7c4,0,7.5-0.8,10.4-2.5l-1-2.2c-3,1.7-5.8,2.4-9.4,2.4c-5.8,0-10.4-2.1-10.8-12.4v-1.3h22.5l0,0v-0.9 + C113.3,16.9,108.7,12.7,101,12.7z M90.6,28c0.2-11,5.1-13,10.3-13c5.7,0,9.7,3,9.7,13H90.6z M136.3,12.6h-1.4 + c-9.5,0-10.8,8-10.8,15v16.9c0.8,0.6,1.6,1.2,2.6,1.6V28.4c0-7.9,1.2-13.5,8.6-13.5h0.6c7.5,0,8.6,5.5,8.6,13.5v17.8 + c0.9-0.4,1.8-1,2.6-1.6V27.8C147.1,20.6,145.7,12.6,136.3,12.6z M168.9,28c-5-1.4-8-2.7-8-6.8c0-4.8,3.3-6.2,7.6-6.2 + c2.8,0,5.4,0.4,7.8,1.6l1-2.2c-2.8-1.4-5.8-1.7-8.8-1.7c-5.2,0-9.9,2.4-9.9,8.3s4.2,7.8,9.4,9.2c4.9,1.3,8.8,2.4,8.8,6.7 + c0,5.3-3.8,7-8,7c-3.8,0-7.5-1-10.2-2.8l-1.1,2.1c3.2,2.2,7.1,2.9,11.3,2.9c5.5,0,10.4-2.5,10.4-9.2 + C179.1,30.9,174.4,29.6,168.9,28z"/> + <path class="st2" d="M27.4,25.2c-0.6,0.9-1.4,2.1-2.3,3.3c3.7,5.5,8.8,13.3,9.3,13.9c1.3,2.2,3.1,4.1,5.2,5.5c0,0.1,2.3,1.4,5,2.3 + c0.2,0,0.4,0.1,0.5,0.1h5.2V48c-1.9-0.2-3.5-0.4-4.3-0.8c-2.2-0.6-3.8-1.7-3.8-1.7c-1.6-1-2.8-2.3-3.8-3.7 + c-0.4-0.8-7.1-10.7-10.9-16.4l0,0C27.5,25.4,27.5,25.3,27.4,25.2 M5.2,0H0v2.4c1.9,0.2,3.5,0.4,4.3,0.8c2.2,0.6,3.8,1.7,3.8,1.7 + c1.6,1,2.8,2.3,3.8,3.7C12.3,9.3,19,19.2,22.8,25l0,0c0,0.1,0.1,0.1,0.1,0.2c0.6-0.9,1.4-2.1,2.3-3.3c-3.7-5.5-8.8-13.3-9.3-13.9 + c-1.3-2.2-3.1-4.1-5.2-5.5c0-0.1-2.3-1.4-5-2.3C5.6,0.1,5.4,0,5.2,0"/> + </g> +</g> +</svg> diff --git a/environment-dev.yml b/environment-dev.yml index 6dff19f..7b55617 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -1,13 +1,12 @@ name: xtensor-python channels: - - conda-forge +- conda-forge dependencies: # Build dependencies - - cmake +- cmake # Host dependencies - - xtensor=0.24.0 - - numpy - - pybind11=2.4.3 +- xtensor=0.24.0 +- numpy +- pybind11=2.4.3 # Test dependencies - - pytest - +- pytest diff --git a/include/xtensor-python/pyarray.hpp b/include/xtensor-python/pyarray.hpp index 6df73cf..569da90 100644 --- a/include/xtensor-python/pyarray.hpp +++ b/include/xtensor-python/pyarray.hpp @@ -1,11 +1,11 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #ifndef PY_ARRAY_HPP #define PY_ARRAY_HPP @@ -20,10 +20,10 @@ #include "pyarray_backstrides.hpp" #include "pycontainer.hpp" -#include "pystrides_adaptor.hpp" #include "pynative_casters.hpp" -#include "xtensor_type_caster_base.hpp" +#include "pystrides_adaptor.hpp" #include "xtensor_python_config.hpp" +#include "xtensor_type_caster_base.hpp" namespace xt { @@ -35,7 +35,7 @@ namespace pybind11 { namespace detail { -#ifdef PYBIND11_DESCR // The macro is removed from pybind11 since 2.3 +#ifdef PYBIND11_DESCR // The macro is removed from pybind11 since 2.3 template <class T, xt::layout_type L> struct handle_type_name<xt::pyarray<T, L>> { @@ -69,7 +69,7 @@ namespace pybind11 return src.inc_ref(); } -#ifdef PYBIND11_DESCR // The macro is removed from pybind11 since 2.3 +#ifdef PYBIND11_DESCR // The macro is removed from pybind11 since 2.3 PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name()); #else PYBIND11_TYPE_CASTER(type, _("numpy.ndarray[") + npy_format_descriptor<T>::name + _("]")); @@ -99,8 +99,7 @@ namespace pybind11 namespace xt { template <class T, layout_type L> - struct xiterable_inner_types<pyarray<T, L>> - : xcontainer_iterable_types<pyarray<T, L>> + struct xiterable_inner_types<pyarray<T, L>> : xcontainer_iterable_types<pyarray<T, L>> { }; @@ -155,7 +154,7 @@ namespace xt using inner_shape_type = typename base_type::inner_shape_type; using inner_strides_type = typename base_type::inner_strides_type; using inner_backstrides_type = typename base_type::inner_backstrides_type; - constexpr static std::size_t rank = SIZE_MAX; + static constexpr std::size_t rank = SIZE_MAX; pyarray(); pyarray(const value_type& t); @@ -267,7 +266,8 @@ namespace xt : base_type() { base_type::resize(xt::shape<shape_type>(t), default_dynamic_layout()); - L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin<layout_type::row_major>(), t); + L == layout_type::row_major ? nested_copy(m_storage.begin(), t) + : nested_copy(this->template begin<layout_type::row_major>(), t); } template <class T, layout_type L> @@ -275,7 +275,8 @@ namespace xt : base_type() { base_type::resize(xt::shape<shape_type>(t), default_dynamic_layout()); - L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin<layout_type::row_major>(), t); + L == layout_type::row_major ? nested_copy(m_storage.begin(), t) + : nested_copy(this->template begin<layout_type::row_major>(), t); } template <class T, layout_type L> @@ -283,7 +284,8 @@ namespace xt : base_type() { base_type::resize(xt::shape<shape_type>(t), default_dynamic_layout()); - L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin<layout_type::row_major>(), t); + L == layout_type::row_major ? nested_copy(m_storage.begin(), t) + : nested_copy(this->template begin<layout_type::row_major>(), t); } template <class T, layout_type L> @@ -291,7 +293,8 @@ namespace xt : base_type() { base_type::resize(xt::shape<shape_type>(t), default_dynamic_layout()); - L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin<layout_type::row_major>(), t); + L == layout_type::row_major ? nested_copy(m_storage.begin(), t) + : nested_copy(this->template begin<layout_type::row_major>(), t); } template <class T, layout_type L> @@ -299,7 +302,8 @@ namespace xt : base_type() { base_type::resize(xt::shape<shape_type>(t), default_dynamic_layout()); - L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin<layout_type::row_major>(), t); + L == layout_type::row_major ? nested_copy(m_storage.begin(), t) + : nested_copy(this->template begin<layout_type::row_major>(), t); } template <class T, layout_type L> @@ -393,6 +397,7 @@ namespace xt auto shp = xtl::forward_sequence<shape_type, S>(shape); return self_type(shp); } + //@} /** @@ -404,10 +409,12 @@ namespace xt */ template <class T, layout_type L> inline pyarray<T, L>::pyarray(const self_type& rhs) - : base_type(), semantic_base(rhs) + : base_type() + , semantic_base(rhs) { auto tmp = pybind11::reinterpret_steal<pybind11::object>( - PyArray_NewLikeArray(rhs.python_array(), NPY_KEEPORDER, nullptr, 1)); + PyArray_NewLikeArray(rhs.python_array(), NPY_KEEPORDER, nullptr, 1) + ); if (!tmp) { @@ -445,7 +452,9 @@ namespace xt : base_type() { // TODO: prevent intermediary shape allocation - shape_type shape = xtl::forward_sequence<shape_type, decltype(e.derived_cast().shape())>(e.derived_cast().shape()); + shape_type shape = xtl::forward_sequence<shape_type, decltype(e.derived_cast().shape())>( + e.derived_cast().shape() + ); strides_type strides = xtl::make_sequence<strides_type>(shape.size(), size_type(0)); layout_type layout = default_dynamic_layout(); @@ -463,6 +472,7 @@ namespace xt { return semantic_base::operator=(e); } + //@} template <class T, layout_type L> @@ -482,8 +492,15 @@ namespace xt { strides_type adapted_strides(strides); - std::transform(strides.begin(), strides.end(), adapted_strides.begin(), - [](auto v) { return sizeof(T) * v; }); + std::transform( + strides.begin(), + strides.end(), + adapted_strides.begin(), + [](auto v) + { + return sizeof(T) * v; + } + ); int flags = NPY_ARRAY_ALIGNED; if (!std::is_const<T>::value) @@ -496,9 +513,16 @@ namespace xt npy_intp* shape_data = reinterpret_cast<npy_intp*>(const_cast<size_type*>(shape.data())); npy_intp* strides_data = reinterpret_cast<npy_intp*>(adapted_strides.data()); - auto tmp = pybind11::reinterpret_steal<pybind11::object>( - PyArray_NewFromDescr(&PyArray_Type, (PyArray_Descr*) dtype.release().ptr(), static_cast<int>(shape.size()), shape_data, strides_data, - nullptr, flags, nullptr)); + auto tmp = pybind11::reinterpret_steal<pybind11::object>(PyArray_NewFromDescr( + &PyArray_Type, + (PyArray_Descr*) dtype.release().ptr(), + static_cast<int>(shape.size()), + shape_data, + strides_data, + nullptr, + flags, + nullptr + )); if (!tmp) { @@ -517,11 +541,15 @@ namespace xt return; } - m_shape = inner_shape_type(reinterpret_cast<size_type*>(PyArray_SHAPE(this->python_array())), - static_cast<size_type>(PyArray_NDIM(this->python_array()))); - m_strides = inner_strides_type(reinterpret_cast<difference_type*>(PyArray_STRIDES(this->python_array())), - static_cast<size_type>(PyArray_NDIM(this->python_array())), - reinterpret_cast<size_type*>(PyArray_SHAPE(this->python_array()))); + m_shape = inner_shape_type( + reinterpret_cast<size_type*>(PyArray_SHAPE(this->python_array())), + static_cast<size_type>(PyArray_NDIM(this->python_array())) + ); + m_strides = inner_strides_type( + reinterpret_cast<difference_type*>(PyArray_STRIDES(this->python_array())), + static_cast<size_type>(PyArray_NDIM(this->python_array())), + reinterpret_cast<size_type*>(PyArray_SHAPE(this->python_array())) + ); if (L != layout_type::dynamic && !do_strides_match(m_shape, m_strides, L, 1)) { @@ -529,8 +557,10 @@ namespace xt } m_backstrides = backstrides_type(*this); - m_storage = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), - this->get_buffer_size()); + m_storage = storage_type( + reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), + this->get_buffer_size() + ); } template <class T, layout_type L> @@ -549,8 +579,9 @@ namespace xt inline auto pyarray<T, L>::backstrides_impl() const noexcept -> const inner_backstrides_type& { // m_backstrides wraps the numpy array backstrides, which is a raw pointer. - // The address of the raw pointer stored in the wrapper would be invalidated when the pyarray is copied. - // Hence, we build a new backstrides object (cheap wrapper around the underlying pointer) upon access. + // The address of the raw pointer stored in the wrapper would be invalidated when the pyarray is + // copied. Hence, we build a new backstrides object (cheap wrapper around the underlying pointer) upon + // access. m_backstrides = backstrides_type(*this); return m_backstrides; } diff --git a/include/xtensor-python/pyarray_backstrides.hpp b/include/xtensor-python/pyarray_backstrides.hpp index 4dfdab9..c672619 100644 --- a/include/xtensor-python/pyarray_backstrides.hpp +++ b/include/xtensor-python/pyarray_backstrides.hpp @@ -1,11 +1,11 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #ifndef PY_ARRAY_BACKSTRIDES_HPP #define PY_ARRAY_BACKSTRIDES_HPP @@ -62,28 +62,22 @@ namespace xt }; template <class B> - inline bool operator==(const pybackstrides_iterator<B>& lhs, - const pybackstrides_iterator<B>& rhs); + inline bool operator==(const pybackstrides_iterator<B>& lhs, const pybackstrides_iterator<B>& rhs); template <class B> - inline bool operator!=(const pybackstrides_iterator<B>& lhs, - const pybackstrides_iterator<B>& rhs); + inline bool operator!=(const pybackstrides_iterator<B>& lhs, const pybackstrides_iterator<B>& rhs); template <class B> - inline bool operator<(const pybackstrides_iterator<B>& lhs, - const pybackstrides_iterator<B>& rhs); + inline bool operator<(const pybackstrides_iterator<B>& lhs, const pybackstrides_iterator<B>& rhs); template <class B> - inline bool operator<=(const pybackstrides_iterator<B>& lhs, - const pybackstrides_iterator<B>& rhs); + inline bool operator<=(const pybackstrides_iterator<B>& lhs, const pybackstrides_iterator<B>& rhs); template <class B> - inline bool operator>(const pybackstrides_iterator<B>& lhs, - const pybackstrides_iterator<B>& rhs); + inline bool operator>(const pybackstrides_iterator<B>& lhs, const pybackstrides_iterator<B>& rhs); template <class B> - inline bool operator>=(const pybackstrides_iterator<B>& lhs, - const pybackstrides_iterator<B>& rhs); + inline bool operator>=(const pybackstrides_iterator<B>& lhs, const pybackstrides_iterator<B>& rhs); /*********************** * pyarray_backstrides * @@ -138,10 +132,11 @@ namespace xt /***************************************** * pybackstrides_iterator implementation * *****************************************/ - + template <class B> inline pybackstrides_iterator<B>::pybackstrides_iterator(const B* b, std::size_t offset) - : p_b(b), m_offset(offset) + : p_b(b) + , m_offset(offset) { } @@ -176,11 +171,11 @@ namespace xt inline auto pybackstrides_iterator<B>::operator--() -> self_type& { --m_offset; - return *this; + return *this; } template <class B> - inline auto pybackstrides_iterator<B>::operator++(int )-> self_type + inline auto pybackstrides_iterator<B>::operator++(int) -> self_type { self_type tmp(*this); ++m_offset; @@ -236,43 +231,37 @@ namespace xt } template <class B> - inline bool operator==(const pybackstrides_iterator<B>& lhs, - const pybackstrides_iterator<B>& rhs) + inline bool operator==(const pybackstrides_iterator<B>& lhs, const pybackstrides_iterator<B>& rhs) { return lhs.offset() == rhs.offset(); } template <class B> - inline bool operator!=(const pybackstrides_iterator<B>& lhs, - const pybackstrides_iterator<B>& rhs) + inline bool operator!=(const pybackstrides_iterator<B>& lhs, const pybackstrides_iterator<B>& rhs) { return !(lhs == rhs); } template <class B> - inline bool operator<(const pybackstrides_iterator<B>& lhs, - const pybackstrides_iterator<B>& rhs) + inline bool operator<(const pybackstrides_iterator<B>& lhs, const pybackstrides_iterator<B>& rhs) { return lhs.offset() < rhs.offset(); } template <class B> - inline bool operator<=(const pybackstrides_iterator<B>& lhs, - const pybackstrides_iterator<B>& rhs) + inline bool operator<=(const pybackstrides_iterator<B>& lhs, const pybackstrides_iterator<B>& rhs) { return (lhs < rhs) || (lhs == rhs); } template <class B> - inline bool operator>(const pybackstrides_iterator<B>& lhs, - const pybackstrides_iterator<B>& rhs) + inline bool operator>(const pybackstrides_iterator<B>& lhs, const pybackstrides_iterator<B>& rhs) { return !(lhs <= rhs); } template <class B> - inline bool operator>=(const pybackstrides_iterator<B>& lhs, - const pybackstrides_iterator<B>& rhs) + inline bool operator>=(const pybackstrides_iterator<B>& lhs, const pybackstrides_iterator<B>& rhs) { return !(lhs < rhs); } diff --git a/include/xtensor-python/pycontainer.hpp b/include/xtensor-python/pycontainer.hpp index 1617d03..13574bb 100644 --- a/include/xtensor-python/pycontainer.hpp +++ b/include/xtensor-python/pycontainer.hpp @@ -1,11 +1,11 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #ifndef PY_CONTAINER_HPP #define PY_CONTAINER_HPP @@ -16,8 +16,8 @@ #include <sstream> #include "pybind11/complex.h" -#include "pybind11/pybind11.h" #include "pybind11/numpy.h" +#include "pybind11/pybind11.h" #ifndef FORCE_IMPORT_ARRAY #define NO_IMPORT_ARRAY @@ -32,6 +32,7 @@ #undef copysign #include <cmath> + #include "xtensor/xcontainer.hpp" #include "xtl/xsequence.hpp" @@ -151,7 +152,9 @@ namespace xt struct numpy_traits; template <class T> - struct numpy_traits<T, std::enable_if_t<pybind11::detail::satisfies_any_of<T, std::is_arithmetic, xtl::is_complex>::value>> + struct numpy_traits< + T, + std::enable_if_t<pybind11::detail::satisfies_any_of<T, std::is_arithmetic, xtl::is_complex>::value>> { private: @@ -161,12 +164,22 @@ namespace xt // On Linux x64, NPY_INT64 != NPY_LONGLONG and NPY_UINT64 != NPY_ULONGLONG, // we use the values of NPY_INT64 and NPY_UINT64 which are consistent with the // values of NPY_LONG and NPY_ULONG. - constexpr static const int value_list[15] = { + static constexpr const int value_list[15] = { NPY_BOOL, - NPY_BYTE, NPY_UBYTE, NPY_SHORT, NPY_USHORT, - NPY_INT32, NPY_UINT32, NPY_INT64, NPY_UINT64, - NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE, - NPY_CFLOAT, NPY_CDOUBLE, NPY_CLONGDOUBLE}; + NPY_BYTE, + NPY_UBYTE, + NPY_SHORT, + NPY_USHORT, + NPY_INT32, + NPY_UINT32, + NPY_INT64, + NPY_UINT64, + NPY_FLOAT, + NPY_DOUBLE, + NPY_LONGDOUBLE, + NPY_CFLOAT, + NPY_CDOUBLE, + NPY_CLONGDOUBLE}; public: @@ -181,7 +194,7 @@ namespace xt template <bool> struct numpy_enum_adjuster { - static inline int pyarray_type(PyArrayObject* obj) + inline static int pyarray_type(PyArrayObject* obj) { return PyArray_TYPE(obj); } @@ -190,10 +203,10 @@ namespace xt template <> struct numpy_enum_adjuster<true> { - static inline int pyarray_type(PyArrayObject* obj) + inline static int pyarray_type(PyArrayObject* obj) { int res = PyArray_TYPE(obj); - if(res == NPY_LONGLONG || res == NPY_ULONGLONG) + if (res == NPY_LONGLONG || res == NPY_ULONGLONG) { res -= 2; } @@ -235,14 +248,18 @@ namespace xt template <class T> bool check_array_type(const pybind11::handle& src, std::false_type) { - return PyArray_EquivTypes((PyArray_Descr*) pybind11::detail::array_proxy(src.ptr())->descr, - (PyArray_Descr*) pybind11::dtype::of<T>().ptr()); + return PyArray_EquivTypes( + (PyArray_Descr*) pybind11::detail::array_proxy(src.ptr())->descr, + (PyArray_Descr*) pybind11::dtype::of<T>().ptr() + ); } template <class T> bool check_array(const pybind11::handle& src) { - using is_arithmetic_type = std::integral_constant<bool, bool(pybind11::detail::satisfies_any_of<T, std::is_arithmetic, xtl::is_complex>::value)>; + using is_arithmetic_type = std::integral_constant< + bool, + bool(pybind11::detail::satisfies_any_of<T, std::is_arithmetic, xtl::is_complex>::value)>; return PyArray_Check(src.ptr()) && check_array_type<T>(src, is_arithmetic_type{}); } } @@ -305,8 +322,14 @@ namespace xt } auto dtype = pybind11::detail::npy_format_descriptor<value_type>::dtype(); - auto res = PyArray_FromAny(ptr, (PyArray_Descr *) dtype.release().ptr(), 0, 0, - NPY_ARRAY_ENSUREARRAY | NPY_ARRAY_FORCECAST, nullptr); + auto res = PyArray_FromAny( + ptr, + (PyArray_Descr*) dtype.release().ptr(), + 0, + 0, + NPY_ARRAY_ENSUREARRAY | NPY_ARRAY_FORCECAST, + nullptr + ); return res; } @@ -320,11 +343,16 @@ namespace xt inline auto pycontainer<D>::get_buffer_size() const -> size_type { const size_type& (*min)(const size_type&, const size_type&) = std::min<size_type>; - size_type min_stride = this->strides().empty() ? size_type(1) : - std::max(size_type(1), std::accumulate(this->strides().cbegin(), - this->strides().cend(), - std::numeric_limits<size_type>::max(), - min)); + size_type min_stride = this->strides().empty() ? size_type(1) + : std::max( + size_type(1), + std::accumulate( + this->strides().cbegin(), + this->strides().cend(), + std::numeric_limits<size_type>::max(), + min + ) + ); return min_stride * static_cast<size_type>(PyArray_SIZE(this->python_array())); } @@ -356,11 +384,11 @@ namespace xt { static bool run(std::size_t new_dim) { - if(new_dim != N) + if (new_dim != N) { std::ostringstream err_msg; - err_msg << "Invalid conversion to pycontainer, expecting a container of dimension " - << N << ", got a container of dimension " << new_dim << "."; + err_msg << "Invalid conversion to pycontainer, expecting a container of dimension " << N + << ", got a container of dimension " << new_dim << "."; throw std::runtime_error(err_msg.str()); } return new_dim == N; @@ -376,7 +404,8 @@ namespace xt template <class S> inline void pycontainer<D>::resize(const S& shape) { - if (shape.size() != this->dimension() || !std::equal(std::begin(shape), std::end(shape), std::begin(this->shape()))) + if (shape.size() != this->dimension() + || !std::equal(std::begin(shape), std::end(shape), std::begin(this->shape()))) { resize(shape, layout_type::row_major); } @@ -416,7 +445,10 @@ namespace xt { if (compute_size(shape) != this->size()) { - throw std::runtime_error("Cannot reshape with incorrect number of elements (" + std::to_string(this->size()) + " vs " + std::to_string(compute_size(shape)) + ")"); + throw std::runtime_error( + "Cannot reshape with incorrect number of elements (" + std::to_string(this->size()) + " vs " + + std::to_string(compute_size(shape)) + ")" + ); } detail::check_dims<shape_type>::run(shape.size()); layout = default_assignable_layout(layout); @@ -436,7 +468,9 @@ namespace xt } using shape_ptr = typename std::decay_t<S>::pointer; - PyArray_Dims dims = {reinterpret_cast<npy_intp*>(const_cast<shape_ptr>(shape.data())), static_cast<int>(shape.size())}; + PyArray_Dims dims = { + reinterpret_cast<npy_intp*>(const_cast<shape_ptr>(shape.data())), + static_cast<int>(shape.size())}; auto new_ptr = PyArray_Newshape((PyArrayObject*) this->ptr(), &dims, npy_layout); auto old_ptr = this->ptr(); this->ptr() = new_ptr; diff --git a/include/xtensor-python/pynative_casters.hpp b/include/xtensor-python/pynative_casters.hpp index aa19604..89cebea 100644 --- a/include/xtensor-python/pynative_casters.hpp +++ b/include/xtensor-python/pynative_casters.hpp @@ -1,11 +1,11 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #ifndef PYNATIVE_CASTERS_HPP #define PYNATIVE_CASTERS_HPP @@ -30,25 +30,29 @@ namespace pybind11 // Type caster for casting xt::xtensor_fixed to ndarray template <class T, class FSH, xt::layout_type L> - struct type_caster<xt::xtensor_fixed<T, FSH, L>> : xtensor_type_caster_base<xt::xtensor_fixed<T, FSH, L>> + struct type_caster<xt::xtensor_fixed<T, FSH, L>> + : xtensor_type_caster_base<xt::xtensor_fixed<T, FSH, L>> { }; // Type caster for casting xt::xstrided_view to ndarray template <class CT, class S, xt::layout_type L, class FST> - struct type_caster<xt::xstrided_view<CT, S, L, FST>> : xtensor_type_caster_base<xt::xstrided_view<CT, S, L, FST>> + struct type_caster<xt::xstrided_view<CT, S, L, FST>> + : xtensor_type_caster_base<xt::xstrided_view<CT, S, L, FST>> { }; // Type caster for casting xt::xarray_adaptor to ndarray template <class EC, xt::layout_type L, class SC, class Tag> - struct type_caster<xt::xarray_adaptor<EC, L, SC, Tag>> : xtensor_type_caster_base<xt::xarray_adaptor<EC, L, SC, Tag>> + struct type_caster<xt::xarray_adaptor<EC, L, SC, Tag>> + : xtensor_type_caster_base<xt::xarray_adaptor<EC, L, SC, Tag>> { }; // Type caster for casting xt::xtensor_adaptor to ndarray template <class EC, std::size_t N, xt::layout_type L, class Tag> - struct type_caster<xt::xtensor_adaptor<EC, N, L, Tag>> : xtensor_type_caster_base<xt::xtensor_adaptor<EC, N, L, Tag>> + struct type_caster<xt::xtensor_adaptor<EC, N, L, Tag>> + : xtensor_type_caster_base<xt::xtensor_adaptor<EC, N, L, Tag>> { }; } diff --git a/include/xtensor-python/pystrides_adaptor.hpp b/include/xtensor-python/pystrides_adaptor.hpp index fde929a..5031e0e 100644 --- a/include/xtensor-python/pystrides_adaptor.hpp +++ b/include/xtensor-python/pystrides_adaptor.hpp @@ -1,11 +1,11 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #ifndef PYSTRIDES_ADAPTOR_HPP #define PYSTRIDES_ADAPTOR_HPP @@ -172,7 +172,10 @@ namespace xt return p_current - rhs.p_current; } - pointer get_pointer() const { return p_current; } + pointer get_pointer() const + { + return p_current; + } private: @@ -181,43 +184,37 @@ namespace xt }; template <std::size_t N> - inline bool operator==(const pystrides_iterator<N>& lhs, - const pystrides_iterator<N>& rhs) + inline bool operator==(const pystrides_iterator<N>& lhs, const pystrides_iterator<N>& rhs) { return lhs.get_pointer() == rhs.get_pointer(); } template <std::size_t N> - inline bool operator!=(const pystrides_iterator<N>& lhs, - const pystrides_iterator<N>& rhs) + inline bool operator!=(const pystrides_iterator<N>& lhs, const pystrides_iterator<N>& rhs) { return !(lhs == rhs); } template <std::size_t N> - inline bool operator<(const pystrides_iterator<N>& lhs, - const pystrides_iterator<N>& rhs) + inline bool operator<(const pystrides_iterator<N>& lhs, const pystrides_iterator<N>& rhs) { return lhs.get_pointer() < rhs.get_pointer(); } template <std::size_t N> - inline bool operator<=(const pystrides_iterator<N>& lhs, - const pystrides_iterator<N>& rhs) + inline bool operator<=(const pystrides_iterator<N>& lhs, const pystrides_iterator<N>& rhs) { return (lhs < rhs) || (lhs == rhs); } template <std::size_t N> - inline bool operator>(const pystrides_iterator<N>& lhs, - const pystrides_iterator<N>& rhs) + inline bool operator>(const pystrides_iterator<N>& lhs, const pystrides_iterator<N>& rhs) { return !(lhs <= rhs); } template <std::size_t N> - inline bool operator>=(const pystrides_iterator<N>& lhs, - const pystrides_iterator<N>& rhs) + inline bool operator>=(const pystrides_iterator<N>& lhs, const pystrides_iterator<N>& rhs) { return !(lhs < rhs); } @@ -228,7 +225,9 @@ namespace xt template <std::size_t N> inline pystrides_adaptor<N>::pystrides_adaptor(const_pointer data, size_type size, shape_type shape) - : p_data(data), m_size(size), p_shape(shape) + : p_data(data) + , m_size(size) + , p_shape(shape) { } diff --git a/include/xtensor-python/pytensor.hpp b/include/xtensor-python/pytensor.hpp index acf05b8..e047e81 100644 --- a/include/xtensor-python/pytensor.hpp +++ b/include/xtensor-python/pytensor.hpp @@ -1,11 +1,11 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #ifndef PY_TENSOR_HPP #define PY_TENSOR_HPP @@ -20,10 +20,10 @@ #include "xtensor/xutils.hpp" #include "pycontainer.hpp" -#include "pystrides_adaptor.hpp" #include "pynative_casters.hpp" -#include "xtensor_type_caster_base.hpp" +#include "pystrides_adaptor.hpp" #include "xtensor_python_config.hpp" +#include "xtensor_type_caster_base.hpp" namespace xt { @@ -35,7 +35,7 @@ namespace pybind11 { namespace detail { -#ifdef PYBIND11_DESCR // The macro is removed from pybind11 since 2.3 +#ifdef PYBIND11_DESCR // The macro is removed from pybind11 since 2.3 template <class T, std::size_t N, xt::layout_type L> struct handle_type_name<xt::pytensor<T, N, L>> { @@ -77,7 +77,7 @@ namespace pybind11 return src.inc_ref(); } -#ifdef PYBIND11_DESCR // The macro is removed from pybind11 since 2.3 +#ifdef PYBIND11_DESCR // The macro is removed from pybind11 since 2.3 PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name()); #else PYBIND11_TYPE_CASTER(type, _("numpy.ndarray[") + npy_format_descriptor<T>::name + _("]")); @@ -101,12 +101,13 @@ namespace pybind11 } }; - } // namespace detail + } // namespace detail } namespace xt { - namespace detail { + namespace detail + { template <std::size_t N> struct numpy_strides @@ -120,11 +121,10 @@ namespace xt npy_intp* value = nullptr; }; - } // namespace detail + } // namespace detail template <class T, std::size_t N, layout_type L> - struct xiterable_inner_types<pytensor<T, N, L>> - : xcontainer_iterable_types<pytensor<T, N, L>> + struct xiterable_inner_types<pytensor<T, N, L>> : xcontainer_iterable_types<pytensor<T, N, L>> { }; @@ -180,7 +180,7 @@ namespace xt using inner_shape_type = typename base_type::inner_shape_type; using inner_strides_type = typename base_type::inner_strides_type; using inner_backstrides_type = typename base_type::inner_backstrides_type; - constexpr static std::size_t rank = N; + static constexpr std::size_t rank = N; pytensor(); pytensor(nested_initializer_list_t<T, N> t); @@ -326,9 +326,7 @@ namespace xt * @param l the layout_type of the pytensor */ template <class T, std::size_t N, layout_type L> - inline pytensor<T, N, L>::pytensor(const shape_type& shape, - const_reference value, - layout_type l) + inline pytensor<T, N, L>::pytensor(const shape_type& shape, const_reference value, layout_type l) { compute_strides(shape, l, m_strides); init_tensor(shape, m_strides); @@ -343,9 +341,7 @@ namespace xt * @param value the value of the elements */ template <class T, std::size_t N, layout_type L> - inline pytensor<T, N, L>::pytensor(const shape_type& shape, - const strides_type& strides, - const_reference value) + inline pytensor<T, N, L>::pytensor(const shape_type& shape, const strides_type& strides, const_reference value) { init_tensor(shape, strides); std::fill(m_storage.begin(), m_storage.end(), value); @@ -357,8 +353,7 @@ namespace xt * @param strides the strides of the pytensor */ template <class T, std::size_t N, layout_type L> - inline pytensor<T, N, L>::pytensor(const shape_type& shape, - const strides_type& strides) + inline pytensor<T, N, L>::pytensor(const shape_type& shape, const strides_type& strides) { init_tensor(shape, strides); } @@ -375,6 +370,7 @@ namespace xt auto shp = xtl::forward_sequence<shape_type, S>(shape); return self_type(shp); } + //@} /** @@ -386,7 +382,8 @@ namespace xt */ template <class T, std::size_t N, layout_type L> inline pytensor<T, N, L>::pytensor(const self_type& rhs) - : base_type(), semantic_base(rhs) + : base_type() + , semantic_base(rhs) { init_tensor(rhs.shape(), rhs.strides()); std::copy(rhs.storage().cbegin(), rhs.storage().cend(), this->storage().begin()); @@ -402,6 +399,7 @@ namespace xt *this = std::move(tmp); return *this; } + //@} /** @@ -416,7 +414,9 @@ namespace xt inline pytensor<T, N, L>::pytensor(const xexpression<E>& e) : base_type() { - shape_type shape = xtl::forward_sequence<shape_type, decltype(e.derived_cast().shape())>(e.derived_cast().shape()); + shape_type shape = xtl::forward_sequence<shape_type, decltype(e.derived_cast().shape())>( + e.derived_cast().shape() + ); strides_type strides = xtl::make_sequence<strides_type>(N, size_type(0)); compute_strides(shape, layout_type::row_major, strides); init_tensor(shape, strides); @@ -432,6 +432,7 @@ namespace xt { return semantic_base::operator=(e); } + //@} template <class T, std::size_t N, layout_type L> @@ -450,8 +451,15 @@ namespace xt inline void pytensor<T, N, L>::init_tensor(const shape_type& shape, const strides_type& strides) { detail::numpy_strides<N> python_strides; - std::transform(strides.begin(), strides.end(), python_strides.value, - [](auto v) { return sizeof(T) * v; }); + std::transform( + strides.begin(), + strides.end(), + python_strides.value, + [](auto v) + { + return sizeof(T) * v; + } + ); int flags = NPY_ARRAY_ALIGNED; if (!std::is_const<T>::value) { @@ -459,10 +467,16 @@ namespace xt } auto dtype = pybind11::detail::npy_format_descriptor<T>::dtype(); - auto tmp = pybind11::reinterpret_steal<pybind11::object>( - PyArray_NewFromDescr(&PyArray_Type, (PyArray_Descr*) dtype.release().ptr(), static_cast<int>(shape.size()), - const_cast<npy_intp*>(shape.data()), python_strides.value, - nullptr, flags, nullptr)); + auto tmp = pybind11::reinterpret_steal<pybind11::object>(PyArray_NewFromDescr( + &PyArray_Type, + (PyArray_Descr*) dtype.release().ptr(), + static_cast<int>(shape.size()), + const_cast<npy_intp*>(shape.data()), + python_strides.value, + nullptr, + flags, + nullptr + )); if (!tmp) { @@ -473,8 +487,10 @@ namespace xt m_shape = shape; m_strides = strides; adapt_strides(m_shape, m_strides, m_backstrides); - m_storage = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), - static_cast<size_type>(PyArray_SIZE(this->python_array()))); + m_storage = storage_type( + reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), + static_cast<size_type>(PyArray_SIZE(this->python_array())) + ); } template <class T, std::size_t N, layout_type L> @@ -491,8 +507,15 @@ namespace xt } std::copy(PyArray_DIMS(this->python_array()), PyArray_DIMS(this->python_array()) + N, m_shape.begin()); - std::transform(PyArray_STRIDES(this->python_array()), PyArray_STRIDES(this->python_array()) + N, m_strides.begin(), - [](auto v) { return v / sizeof(T); }); + std::transform( + PyArray_STRIDES(this->python_array()), + PyArray_STRIDES(this->python_array()) + N, + m_strides.begin(), + [](auto v) + { + return v / sizeof(T); + } + ); adapt_strides(m_shape, m_strides, m_backstrides); if (L != layout_type::dynamic && !do_strides_match(m_shape, m_strides, L, 1)) @@ -500,8 +523,10 @@ namespace xt throw std::runtime_error("NumPy: passing container with bad strides for layout (is it a view?)."); } - m_storage = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), - this->get_buffer_size()); + m_storage = storage_type( + reinterpret_cast<pointer>(PyArray_DATA(this->python_array())), + this->get_buffer_size() + ); } template <class T, std::size_t N, layout_type L> diff --git a/include/xtensor-python/pyvectorize.hpp b/include/xtensor-python/pyvectorize.hpp index 9c7d107..97d6600 100644 --- a/include/xtensor-python/pyvectorize.hpp +++ b/include/xtensor-python/pyvectorize.hpp @@ -1,20 +1,21 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #ifndef PY_VECTORIZE_HPP #define PY_VECTORIZE_HPP #include <type_traits> -#include "pyarray.hpp" #include "xtensor/xvectorize.hpp" +#include "pyarray.hpp" + namespace xt { @@ -53,10 +54,12 @@ namespace xt } template <class F> - inline auto pyvectorize(F&& f) -> decltype(pyvectorize(std::forward<F>(f), (detail::get_function_type<F>*)nullptr)) + inline auto pyvectorize(F&& f) + -> decltype(pyvectorize(std::forward<F>(f), (detail::get_function_type<F>*) nullptr)) { - return pyvectorize(std::forward<F>(f), (detail::get_function_type<F>*)nullptr); + return pyvectorize(std::forward<F>(f), (detail::get_function_type<F>*) nullptr); } + /// @endcond } diff --git a/include/xtensor-python/xtensor_python_config.hpp b/include/xtensor-python/xtensor_python_config.hpp index 7466f14..492b963 100644 --- a/include/xtensor-python/xtensor_python_config.hpp +++ b/include/xtensor-python/xtensor_python_config.hpp @@ -1,11 +1,11 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #ifndef XTENSOR_PYTHON_CONFIG_HPP #define XTENSOR_PYTHON_CONFIG_HPP diff --git a/include/xtensor-python/xtensor_type_caster_base.hpp b/include/xtensor-python/xtensor_type_caster_base.hpp index 840e28c..1c1f85b 100644 --- a/include/xtensor-python/xtensor_type_caster_base.hpp +++ b/include/xtensor-python/xtensor_type_caster_base.hpp @@ -1,25 +1,25 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #ifndef XTENSOR_TYPE_CASTER_HPP #define XTENSOR_TYPE_CASTER_HPP -#include <cstddef> #include <algorithm> +#include <cstddef> #include <vector> -#include "xtensor/xtensor.hpp" -#include "xtensor/xfixed.hpp" - #include <pybind11/numpy.h> #include <pybind11/pybind11.h> +#include "xtensor/xfixed.hpp" +#include "xtensor/xtensor.hpp" + namespace pybind11 { namespace detail @@ -102,7 +102,6 @@ namespace pybind11 } }; - template <class T> struct pybind_array_dim_checker { @@ -133,7 +132,6 @@ namespace pybind11 } }; - template <class T> struct pybind_array_shape_checker { @@ -163,10 +161,15 @@ namespace pybind11 { // TODO: make use of xt::pyarray instead of array. std::vector<std::size_t> python_strides(src.strides().size()); - std::transform(src.strides().begin(), src.strides().end(), - python_strides.begin(), [](auto v) { - return sizeof(typename Type::value_type) * v; - }); + std::transform( + src.strides().begin(), + src.strides().end(), + python_strides.begin(), + [](auto v) + { + return sizeof(typename Type::value_type) * v; + } + ); std::vector<std::size_t> python_shape(src.shape().size()); std::copy(src.shape().begin(), src.shape().end(), python_shape.begin()); @@ -181,10 +184,10 @@ namespace pybind11 return a.release(); } - // Takes an lvalue ref to some strided expression type and a (python) base object, creating a numpy array that - // reference the expression object's data with `base` as the python-registered base class (if omitted, - // the base will be set to None, and lifetime management is up to the caller). The numpy array is - // non-writeable if the given type is const. + // Takes an lvalue ref to some strided expression type and a (python) base object, creating a numpy + // array that reference the expression object's data with `base` as the python-registered base class + // (if omitted, the base will be set to None, and lifetime management is up to the caller). The numpy + // array is non-writeable if the given type is const. template <typename Type, typename CType> handle xtensor_ref_array(CType& src, handle parent = none()) { @@ -198,7 +201,13 @@ namespace pybind11 template <typename Type, typename CType> handle xtensor_encapsulate(CType* src) { - capsule base(src, [](void* o) { delete static_cast<CType*>(o); }); + capsule base( + src, + [](void* o) + { + delete static_cast<CType*>(o); + } + ); return xtensor_ref_array<Type>(*src, base); } @@ -206,7 +215,6 @@ namespace pybind11 template <class Type> struct xtensor_type_caster_base { - private: // Cast implementation @@ -215,26 +223,29 @@ namespace pybind11 { switch (policy) { - case return_value_policy::take_ownership: - case return_value_policy::automatic: - return xtensor_encapsulate<Type>(src); - case return_value_policy::move: - return xtensor_encapsulate<Type>(new CType(std::move(*src))); - case return_value_policy::copy: - return xtensor_array_cast<Type>(*src); - case return_value_policy::reference: - case return_value_policy::automatic_reference: - return xtensor_ref_array<Type>(*src); - case return_value_policy::reference_internal: - return xtensor_ref_array<Type>(*src, parent); - default: - throw cast_error("unhandled return_value_policy: should not happen!"); + case return_value_policy::take_ownership: + case return_value_policy::automatic: + return xtensor_encapsulate<Type>(src); + case return_value_policy::move: + return xtensor_encapsulate<Type>(new CType(std::move(*src))); + case return_value_policy::copy: + return xtensor_array_cast<Type>(*src); + case return_value_policy::reference: + case return_value_policy::automatic_reference: + return xtensor_ref_array<Type>(*src); + case return_value_policy::reference_internal: + return xtensor_ref_array<Type>(*src, parent); + default: + throw cast_error("unhandled return_value_policy: should not happen!"); }; } public: - PYBIND11_TYPE_CASTER(Type, _("numpy.ndarray[") + npy_format_descriptor<typename Type::value_type>::name + _("]")); + PYBIND11_TYPE_CASTER( + Type, + _("numpy.ndarray[") + npy_format_descriptor<typename Type::value_type>::name + _("]") + ); bool load(handle src, bool convert) { @@ -284,7 +295,8 @@ namespace pybind11 // lvalue reference return; default (automatic) becomes copy static handle cast(Type& src, return_value_policy policy, handle parent) { - if (policy == return_value_policy::automatic || policy == return_value_policy::automatic_reference) + if (policy == return_value_policy::automatic + || policy == return_value_policy::automatic_reference) { policy = return_value_policy::copy; } @@ -295,7 +307,8 @@ namespace pybind11 // const lvalue reference return; default (automatic) becomes copy static handle cast(const Type& src, return_value_policy policy, handle parent) { - if (policy == return_value_policy::automatic || policy == return_value_policy::automatic_reference) + if (policy == return_value_policy::automatic + || policy == return_value_policy::automatic_reference) { policy = return_value_policy::copy; } diff --git a/readthedocs.yml b/readthedocs.yml index 02f0e7b..004a03a 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -1,2 +1,2 @@ conda: - file: docs/environment.yml + file: docs/environment.yml diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0c77b0d..91bebfd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -100,4 +100,3 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) endif() add_custom_target(xtest COMMAND ./test_xtensor_python DEPENDS test_xtensor_python) - diff --git a/test/copyGTest.cmake.in b/test/copyGTest.cmake.in index 8341a74..aeb2e2a 100644 --- a/test/copyGTest.cmake.in +++ b/test/copyGTest.cmake.in @@ -21,4 +21,3 @@ ExternalProject_Add(googletest INSTALL_COMMAND "" TEST_COMMAND "" ) - diff --git a/test/downloadGTest.cmake.in b/test/downloadGTest.cmake.in index 2d5cc5b..ba525b7 100644 --- a/test/downloadGTest.cmake.in +++ b/test/downloadGTest.cmake.in @@ -22,4 +22,3 @@ ExternalProject_Add(googletest INSTALL_COMMAND "" TEST_COMMAND "" ) - diff --git a/test/main.cpp b/test/main.cpp index d3cc6c4..37a5ac4 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,19 +1,19 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ // Required to avoid the error "std does not have member copysign" #include <cmath> -#include "gtest/gtest.h" - #include <pybind11/embed.h> +#include "gtest/gtest.h" + #define FORCE_IMPORT_ARRAY #include "xtensor-python/pyarray.hpp" @@ -32,4 +32,3 @@ int main(int argc, char* argv[]) // Return test results return ret; } - diff --git a/test/test_common.hpp b/test/test_common.hpp index 07a0992..ff2b49b 100644 --- a/test/test_common.hpp +++ b/test/test_common.hpp @@ -1,11 +1,11 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #ifndef TEST_COMMON_HPP #define TEST_COMMON_HPP @@ -62,12 +62,35 @@ namespace xt layout_type m_layout; assigner_type m_assigner; - inline size_type size() const { return m_data.size(); } - inline const shape_type& shape() const { return m_shape; } - inline const strides_type& strides() const { return m_strides; } - inline const strides_type& backstrides() const { return m_backstrides; } - inline layout_type layout() const { return m_layout; } - inline const vector_type& data() const { return m_data; } + inline size_type size() const + { + return m_data.size(); + } + + inline const shape_type& shape() const + { + return m_shape; + } + + inline const strides_type& strides() const + { + return m_strides; + } + + inline const strides_type& backstrides() const + { + return m_backstrides; + } + + inline layout_type layout() const + { + return m_layout; + } + + inline const vector_type& data() const + { + return m_data; + } }; template <class C = std::vector<std::size_t>> @@ -77,9 +100,8 @@ namespace xt { this->m_strides = {8, 4, 1}; this->m_backstrides = {16, 4, 3}; - this->m_data = {-1, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23}; + this->m_data = { + -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}; this->m_layout = layout_type::row_major; } }; @@ -91,10 +113,8 @@ namespace xt { this->m_strides = {1, 3, 6}; this->m_backstrides = {2, 3, 18}; - this->m_data = {-1, 8, 16, 4, 12, 20, - 1, 9, 17, 5, 13, 21, - 2, 10, 18, 6, 14, 22, - 3, 11, 19, 7, 15, 23}; + this->m_data = { + -1, 8, 16, 4, 12, 20, 1, 9, 17, 5, 13, 21, 2, 10, 18, 6, 14, 22, 3, 11, 19, 7, 15, 23}; this->m_layout = layout_type::column_major; } }; @@ -106,9 +126,8 @@ namespace xt { this->m_strides = {8, 1, 2}; this->m_backstrides = {16, 1, 6}; - this->m_data = {-1, 4, 1, 5, 2, 6, 3, 7, - 8, 12, 9, 13, 10, 14, 11, 15, - 16, 20, 17, 21, 18, 22, 19, 23}; + this->m_data = { + -1, 4, 1, 5, 2, 6, 3, 7, 8, 12, 9, 13, 10, 14, 11, 15, 16, 20, 17, 21, 18, 22, 19, 23}; this->m_layout = layout_type::dynamic; } }; @@ -147,12 +166,35 @@ namespace xt layout_type m_layout; assigner_type m_assigner; - inline size_type size() const { return m_data.size(); } - inline const shape_type& shape() const { return m_shape; } - inline const strides_type& strides() const { return m_strides; } - inline const strides_type& backstrides() const { return m_backstrides; } - inline layout_type layout() const { return m_layout; } - inline const vector_type& data() const { return m_data; } + inline size_type size() const + { + return m_data.size(); + } + + inline const shape_type& shape() const + { + return m_shape; + } + + inline const strides_type& strides() const + { + return m_strides; + } + + inline const strides_type& backstrides() const + { + return m_backstrides; + } + + inline layout_type layout() const + { + return m_layout; + } + + inline const vector_type& data() const + { + return m_data; + } }; template <class V, class R> @@ -160,7 +202,9 @@ namespace xt { EXPECT_TRUE(std::equal(vec.shape().cbegin(), vec.shape().cend(), result.shape().cbegin())); EXPECT_TRUE(std::equal(vec.strides().cbegin(), vec.strides().cend(), result.strides().cbegin())); - EXPECT_TRUE(std::equal(vec.backstrides().cbegin(), vec.backstrides().cend(), result.backstrides().cbegin())); + EXPECT_TRUE( + std::equal(vec.backstrides().cbegin(), vec.backstrides().cend(), result.backstrides().cbegin()) + ); EXPECT_EQ(vec.size(), result.size()); if (compare_layout) { @@ -245,14 +289,10 @@ namespace xt EXPECT_EQ(vt.shape(), shape_new); EXPECT_TRUE(std::equal(vt.storage().cbegin(), vt.storage().cend(), rm.m_data.cbegin())); - strides_type new_strides = {rm.m_strides[2], - rm.m_strides[1], - rm.m_strides[0]}; + strides_type new_strides = {rm.m_strides[2], rm.m_strides[1], rm.m_strides[0]}; EXPECT_EQ(vt.strides(), new_strides); - strides_type new_backstrides = {rm.m_backstrides[2], - rm.m_backstrides[1], - rm.m_backstrides[0]}; + strides_type new_backstrides = {rm.m_backstrides[2], rm.m_backstrides[1], rm.m_backstrides[0]}; EXPECT_EQ(vt.backstrides(), new_backstrides); EXPECT_EQ(vec_copy(0, 0, 0), vt(0, 0, 0)); @@ -278,9 +318,7 @@ namespace xt EXPECT_TRUE(std::equal(vt.shape().cbegin(), vt.shape().cend(), shape_new.begin())); EXPECT_TRUE(std::equal(vt.storage().cbegin(), vt.storage().cend(), rm.m_data.cbegin())); - strides_type new_strides = {rm.m_strides[1], - rm.m_strides[0], - rm.m_strides[2]}; + strides_type new_strides = {rm.m_strides[1], rm.m_strides[0], rm.m_strides[2]}; EXPECT_EQ(vt.strides(), new_strides); // strides_type new_backstrides = {rm.m_backstrides[1], @@ -331,7 +369,7 @@ namespace xt #ifdef XTENSOR_ENABLE_ASSERT EXPECT_ANY_THROW(vec(10, 10, 10)); #else - (void)vec; + (void) vec; #endif } @@ -582,7 +620,7 @@ namespace xt vecrm.resize(rm.m_shape, layout_type::row_major); std::copy(rm.data().cbegin(), rm.data().cend(), vecrm.template begin<layout_type::row_major>()); EXPECT_TRUE(std::equal(rm.data().cbegin(), rm.data().cend(), vecrm.storage().cbegin())); - //EXPECT_EQ(vecrm.template end<layout_type::row_major>(), vecrm.data().end()); + // EXPECT_EQ(vecrm.template end<layout_type::row_major>(), vecrm.data().end()); } { @@ -591,7 +629,7 @@ namespace xt veccm.resize(cm.m_shape, layout_type::column_major); std::copy(cm.data().cbegin(), cm.data().cend(), veccm.template begin<layout_type::column_major>()); EXPECT_TRUE(std::equal(cm.data().cbegin(), cm.data().cend(), veccm.storage().cbegin())); - //EXPECT_EQ(veccm.template end<layout_type::column_major>(), veccm.data().end()); + // EXPECT_EQ(veccm.template end<layout_type::column_major>(), veccm.data().end()); } } diff --git a/test/test_pyarray.cpp b/test/test_pyarray.cpp index 3f509e3..73e295d 100644 --- a/test/test_pyarray.cpp +++ b/test/test_pyarray.cpp @@ -1,20 +1,18 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#include "gtest/gtest.h" - -#include "xtensor-python/pyarray.hpp" + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #include "xtensor/xarray.hpp" #include "xtensor/xview.hpp" +#include "gtest/gtest.h" #include "test_common.hpp" +#include "xtensor-python/pyarray.hpp" namespace xt { @@ -23,53 +21,39 @@ namespace xt template <class T> using ndarray = pyarray<T, xt::layout_type::row_major>; - void test1 (ndarray<int>const& x) + void test1(const ndarray<int>& x) { ndarray<int> y = x; ndarray<int> z = xt::zeros<int>({10}); } - double compute(ndarray<double> const& xs) + double compute(const ndarray<double>& xs) { - auto v = xt::view (xs, 0, xt::all()); + auto v = xt::view(xs, 0, xt::all()); return v(0); } TEST(pyarray, initializer_constructor) { - pyarray<int> r - {{{ 0, 1, 2}, - { 3, 4, 5}, - { 6, 7, 8}}, - {{ 9, 10, 11}, - {12, 13, 14}, - {15, 16, 17}}}; + pyarray<int> r{{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}, {{9, 10, 11}, {12, 13, 14}, {15, 16, 17}}}; EXPECT_EQ(r.layout(), xt::layout_type::row_major); EXPECT_EQ(r.dimension(), 3); EXPECT_EQ(r(0, 0, 1), 1); EXPECT_EQ(r.shape()[0], 2); - pyarray<int, xt::layout_type::column_major> c - {{{ 0, 1, 2}, - { 3, 4, 5}, - { 6, 7, 8}}, - {{ 9, 10, 11}, - {12, 13, 14}, - {15, 16, 17}}}; + pyarray<int, xt::layout_type::column_major> c{ + {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}, + {{9, 10, 11}, {12, 13, 14}, {15, 16, 17}}}; EXPECT_EQ(c.layout(), xt::layout_type::column_major); EXPECT_EQ(c.dimension(), 3); EXPECT_EQ(c(0, 0, 1), 1); EXPECT_EQ(c.shape()[0], 2); - pyarray<int, xt::layout_type::dynamic> d - {{{ 0, 1, 2}, - { 3, 4, 5}, - { 6, 7, 8}}, - {{ 9, 10, 11}, - {12, 13, 14}, - {15, 16, 17}}}; + pyarray<int, xt::layout_type::dynamic> d{ + {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}, + {{9, 10, 11}, {12, 13, 14}, {15, 16, 17}}}; EXPECT_EQ(d.layout(), xt::layout_type::row_major); EXPECT_EQ(d.dimension(), 3); @@ -86,7 +70,7 @@ namespace xt compare_shape(ra, rm); EXPECT_EQ(layout_type::row_major, ra.layout()); } - + { SCOPED_TRACE("column_major constructor"); column_major_result<> cm; @@ -150,7 +134,7 @@ namespace xt central_major_result<> res; int value = 2; pyarray<int> a(res.m_shape, res.m_strides, value); - + { SCOPED_TRACE("copy constructor"); pyarray<int> b(a); @@ -201,8 +185,8 @@ namespace xt TEST(pyarray, extended_constructor) { - xt::xarray<int> a1 = { { 1, 2 },{ 3, 4 } }; - xt::xarray<int> a2 = { { 1, 2 },{ 3, 4 } }; + xt::xarray<int> a1 = {{1, 2}, {3, 4}}; + xt::xarray<int> a2 = {{1, 2}, {3, 4}}; pyarray<int> c = a1 + a2; EXPECT_EQ(c(0, 0), a1(0, 0) + a2(0, 0)); EXPECT_EQ(c(0, 1), a1(0, 1) + a2(0, 1)); @@ -227,7 +211,7 @@ namespace xt pyarray<int> a; test_resize(a); - pyarray<int> b = { {1, 2}, {3, 4} }; + pyarray<int> b = {{1, 2}, {3, 4}}; a.resize(b.shape()); EXPECT_EQ(a.shape(), b.shape()); } @@ -277,7 +261,7 @@ namespace xt EXPECT_EQ(2, a1(1)); EXPECT_EQ(4, a2(1, 1)); } - + TEST(pyarray, zerod) { pyarray<int> a; @@ -286,7 +270,7 @@ namespace xt TEST(pyarray, reshape) { - pyarray<int> a = {{1,2,3}, {4,5,6}}; + pyarray<int> a = {{1, 2, 3}, {4, 5, 6}}; auto ptr = a.data(); a.reshape({1, 6}); std::vector<std::size_t> sc1({1, 6}); @@ -300,7 +284,7 @@ namespace xt TEST(pyarray, view) { - xt::pyarray<int> arr = xt::zeros<int>({ 10 }); + xt::pyarray<int> arr = xt::zeros<int>({10}); auto v = xt::view(arr, xt::all()); EXPECT_EQ(v(0), 0.); } diff --git a/test/test_pyarray_traits.cpp b/test/test_pyarray_traits.cpp index fe9ef6a..a4d2b25 100644 --- a/test/test_pyarray_traits.cpp +++ b/test/test_pyarray_traits.cpp @@ -1,26 +1,23 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #include "gtest/gtest.h" - #include "xtensor-python/pyarray.hpp" - - namespace xt { namespace testing { - class pyarray_traits: public ::testing::Test + class pyarray_traits : public ::testing::Test { protected: - + using dynamic_type = xt::pyarray<double>; using row_major_type = xt::pyarray<double, xt::layout_type::row_major>; using column_major_type = xt::pyarray<double, xt::layout_type::column_major>; @@ -35,13 +32,13 @@ namespace xt column_major_type c2 = {{0., 2.}, {0., 20.}, {0., 200.}}; template <class T> - bool test_has_strides(T const&) + bool test_has_strides(const T&) { return xt::has_strides<T>::value; } template <class T> - xt::layout_type test_result_layout(T const& a1, T const& a2) + xt::layout_type test_result_layout(const T& a1, const T& a2) { auto tmp1 = pow(sin((a2 - a1) / 2.), 2.); auto tmp2 = cos(a1); @@ -49,7 +46,7 @@ namespace xt } template <class T> - bool test_linear_assign(T const& a1, T const& a2) + bool test_linear_assign(const T& a1, const T& a2) { auto tmp1 = pow(sin((a2 - a1) / 2.), 2.); auto tmp2 = cos(a1); @@ -58,7 +55,7 @@ namespace xt } template <class T> - bool test_static_simd_linear_assign(T const& a1, T const& a2) + bool test_static_simd_linear_assign(const T& a1, const T& a2) { auto tmp1 = pow(sin((a2 - a1) / 2.), 2.); auto tmp2 = cos(a1); @@ -66,7 +63,7 @@ namespace xt } template <class T> - bool test_dynamic_simd_linear_assign(T const& a1, T const& a2) + bool test_dynamic_simd_linear_assign(const T& a1, const T& a2) { auto tmp1 = pow(sin((a2 - a1) / 2.), 2.); auto tmp2 = cos(a1); @@ -74,7 +71,7 @@ namespace xt } template <class T> - bool test_linear_static_layout(T const& a1, T const& a2) + bool test_linear_static_layout(const T& a1, const T& a2) { auto tmp1 = pow(sin((a2 - a1) / 2.), 2.); auto tmp2 = cos(a1); @@ -82,7 +79,7 @@ namespace xt } template <class T> - bool test_contiguous_layout(T const& a1, T const& a2) + bool test_contiguous_layout(const T& a1, const T& a2) { auto tmp1 = pow(sin((a2 - a1) / 2.), 2.); auto tmp2 = cos(a1); diff --git a/test/test_pytensor.cpp b/test/test_pytensor.cpp index f2ac013..e1aa4f3 100644 --- a/test/test_pytensor.cpp +++ b/test/test_pytensor.cpp @@ -1,20 +1,18 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#include "gtest/gtest.h" - -#include "xtensor-python/pytensor.hpp" + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #include "xtensor/xtensor.hpp" #include "xtensor/xview.hpp" +#include "gtest/gtest.h" #include "test_common.hpp" +#include "xtensor-python/pytensor.hpp" namespace xt { @@ -22,13 +20,7 @@ namespace xt TEST(pytensor, initializer_constructor) { - pytensor<int, 3> t - {{{ 0, 1, 2}, - { 3, 4, 5}, - { 6, 7, 8}}, - {{ 9, 10, 11}, - {12, 13, 14}, - {15, 16, 17}}}; + pytensor<int, 3> t{{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}, {{9, 10, 11}, {12, 13, 14}, {15, 16, 17}}}; EXPECT_EQ(t.dimension(), 3); EXPECT_EQ(t(0, 0, 1), 1); EXPECT_EQ(t.shape()[0], 2); @@ -170,8 +162,8 @@ namespace xt TEST(pytensor, extended_constructor) { - xt::xtensor<int, 2> a1 = { {1, 2}, {3, 4} }; - xt::xtensor<int, 2> a2 = { {1, 2}, {3, 4} }; + xt::xtensor<int, 2> a1 = {{1, 2}, {3, 4}}; + xt::xtensor<int, 2> a2 = {{1, 2}, {3, 4}}; pytensor<int, 2> c = a1 + a2; EXPECT_EQ(c(0, 0), a1(0, 0) + a2(0, 0)); EXPECT_EQ(c(0, 1), a1(0, 1) + a2(0, 1)); @@ -184,7 +176,7 @@ namespace xt pytensor<int, 3> a; test_resize<pytensor<int, 3>, container_type>(a); - pytensor<int, 3> b = { { { 1, 2 },{ 3, 4 } } }; + pytensor<int, 3> b = {{{1, 2}, {3, 4}}}; a.resize(b.shape()); EXPECT_EQ(a.shape(), b.shape()); } @@ -232,9 +224,9 @@ namespace xt TEST(pytensor, reshape) { - pytensor<int, 2> a = {{1,2,3}, {4,5,6}}; + pytensor<int, 2> a = {{1, 2, 3}, {4, 5, 6}}; auto ptr = a.data(); - a.reshape(a.shape()); // compilation check + a.reshape(a.shape()); // compilation check a.reshape({1, 6}); EXPECT_EQ(ptr, a.data()); EXPECT_THROW(a.reshape(std::vector<std::size_t>{6}), std::runtime_error); @@ -245,16 +237,16 @@ namespace xt TEST(pytensor, view) { - xt::pytensor<int, 1> arr = xt::zeros<int>({ 10 }); + xt::pytensor<int, 1> arr = xt::zeros<int>({10}); auto v = xt::view(arr, xt::all()); EXPECT_EQ(v(0), 0.); } TEST(pytensor, unary) { - pytensor<int, 1> a = { 1, 2, 3 }; + pytensor<int, 1> a = {1, 2, 3}; pytensor<int, 1> res = -a; - pytensor<int, 1> ref = { -1, -2, -3 }; + pytensor<int, 1> ref = {-1, -2, -3}; EXPECT_EQ(ref(0), res(0)); EXPECT_EQ(ref(1), res(1)); EXPECT_EQ(ref(1), res(1)); @@ -264,9 +256,9 @@ namespace xt { // pybind11 overrrides a number of operators in pybind11::object. // This is testing that the right overload is picked up. - pytensor<double, 1> a = { 1.0, 2.0, 3.0 }; + pytensor<double, 1> a = {1.0, 2.0, 3.0}; a /= 2; - pytensor<double, 1> ref = { 0.5, 1.0, 1.5 }; + pytensor<double, 1> ref = {0.5, 1.0, 1.5}; EXPECT_EQ(ref(0), a(0)); EXPECT_EQ(ref(1), a(1)); EXPECT_EQ(ref(1), a(1)); diff --git a/test/test_pyvectorize.cpp b/test/test_pyvectorize.cpp index 30378e6..f11133a 100644 --- a/test/test_pyvectorize.cpp +++ b/test/test_pyvectorize.cpp @@ -1,18 +1,18 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #include "gtest/gtest.h" +#include "pybind11/numpy.h" +#include "pybind11/pybind11.h" #include "test_common.hpp" #include "xtensor-python/pytensor.hpp" #include "xtensor-python/pyvectorize.hpp" -#include "pybind11/pybind11.h" -#include "pybind11/numpy.h" namespace xt { @@ -27,7 +27,7 @@ namespace xt TEST(pyvectorize, function) { auto vecf1 = pyvectorize(f1); - shape_type shape = { 3, 2 }; + shape_type shape = {3, 2}; pyarray<double> a(shape, 1.5); pyarray<double> b(shape, 2.3); pyarray<double> c = vecf1(a, b); @@ -36,8 +36,13 @@ namespace xt TEST(pyvectorize, lambda) { - auto vecf1 = pyvectorize([](double a, double b) { return a + b; }); - shape_type shape = { 3, 2 }; + auto vecf1 = pyvectorize( + [](double a, double b) + { + return a + b; + } + ); + shape_type shape = {3, 2}; pyarray<double> a(shape, 1.5); pyarray<double> b(shape, 2.3); pyarray<double> c = vecf1(a, b); @@ -47,9 +52,14 @@ namespace xt TEST(pyvectorize, complex) { using complex_t = std::complex<double>; - shape_type shape = { 3, 2 }; + shape_type shape = {3, 2}; pyarray<complex_t> a(shape, complex_t(1.2, 2.5)); - auto f = pyvectorize([](complex_t x) { return std::abs(x); }); + auto f = pyvectorize( + [](complex_t x) + { + return std::abs(x); + } + ); auto res = f(a); double exp = std::abs(a(1, 1)); EXPECT_EQ(exp, res(1, 1)); diff --git a/test/test_sfinae.cpp b/test/test_sfinae.cpp index a614485..4577afd 100644 --- a/test/test_sfinae.cpp +++ b/test/test_sfinae.cpp @@ -1,20 +1,21 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #include <limits> -#include "gtest/gtest.h" -#include "xtensor-python/pytensor.hpp" -#include "xtensor-python/pyarray.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xtensor.hpp" +#include "gtest/gtest.h" +#include "xtensor-python/pyarray.hpp" +#include "xtensor-python/pytensor.hpp" + namespace xt { template <class E, std::enable_if_t<!xt::has_fixed_rank_t<E>::value, int> = 0> diff --git a/test_python/main.cpp b/test_python/main.cpp index 7a0c524..961df4e 100644 --- a/test_python/main.cpp +++ b/test_python/main.cpp @@ -1,23 +1,24 @@ /*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ + * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * + * Copyright (c) QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ #include <numeric> -#include "xtensor/xmath.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xfixed.hpp" +#include "xtensor/xmath.hpp" #define FORCE_IMPORT_ARRAY +#include "xtensor/xadapt.hpp" +#include "xtensor/xstrided_view.hpp" + #include "xtensor-python/pyarray.hpp" #include "xtensor-python/pytensor.hpp" #include "xtensor-python/pyvectorize.hpp" -#include "xtensor/xadapt.hpp" -#include "xtensor/xstrided_view.hpp" namespace py = pybind11; using complex_t = std::complex<double>; @@ -39,8 +40,8 @@ xt::xarray<int> example3_xarray(const xt::xarray<int>& m) return xt::transpose(m) + 2; } -xt::xarray<int, xt::layout_type::column_major> example3_xarray_colmajor( - const xt::xarray<int, xt::layout_type::column_major>& m) +xt::xarray<int, xt::layout_type::column_major> +example3_xarray_colmajor(const xt::xarray<int, xt::layout_type::column_major>& m) { return xt::transpose(m) + 2; } @@ -55,13 +56,14 @@ xt::xtensor<int, 2> example3_xtensor2(const xt::xtensor<int, 2>& m) return xt::transpose(m) + 2; } -xt::xtensor<int, 2, xt::layout_type::column_major> example3_xtensor2_colmajor( - const xt::xtensor<int, 2, xt::layout_type::column_major>& m) +xt::xtensor<int, 2, xt::layout_type::column_major> +example3_xtensor2_colmajor(const xt::xtensor<int, 2, xt::layout_type::column_major>& m) { return xt::transpose(m) + 2; } -xt::xtensor_fixed<int, xt::xshape<4, 3, 2>> example3_xfixed3(const xt::xtensor_fixed<int, xt::xshape<2, 3, 4>>& m) +xt::xtensor_fixed<int, xt::xshape<4, 3, 2>> +example3_xfixed3(const xt::xtensor_fixed<int, xt::xshape<2, 3, 4>>& m) { return xt::transpose(m) + 2; } @@ -71,8 +73,8 @@ xt::xtensor_fixed<int, xt::xshape<3, 2>> example3_xfixed2(const xt::xtensor_fixe return xt::transpose(m) + 2; } -xt::xtensor_fixed<int, xt::xshape<3, 2>, xt::layout_type::column_major> example3_xfixed2_colmajor( - const xt::xtensor_fixed<int, xt::xshape<2, 3>, xt::layout_type::column_major>& m) +xt::xtensor_fixed<int, xt::xshape<3, 2>, xt::layout_type::column_major> +example3_xfixed2_colmajor(const xt::xtensor_fixed<int, xt::xshape<2, 3>, xt::layout_type::column_major>& m) { return xt::transpose(m) + 2; } @@ -87,13 +89,14 @@ double readme_example1(xt::pyarray<double>& m) double readme_example2(double i, double j) { - return std::sin(i) - std::cos(j); + return std::sin(i) - std::cos(j); } auto complex_overload(const xt::pyarray<std::complex<double>>& a) { return a; } + auto no_complex_overload(const xt::pyarray<double>& a) { return a; @@ -108,6 +111,7 @@ auto no_complex_overload_reg(const double& a) { return a; } + // // Operator examples // @@ -138,15 +142,59 @@ int add(int i, int j) return i + j; } -template <class T> std::string typestring() { return "Unknown"; } -template <> std::string typestring<uint8_t>() { return "uint8"; } -template <> std::string typestring<int8_t>() { return "int8"; } -template <> std::string typestring<uint16_t>() { return "uint16"; } -template <> std::string typestring<int16_t>() { return "int16"; } -template <> std::string typestring<uint32_t>() { return "uint32"; } -template <> std::string typestring<int32_t>() { return "int32"; } -template <> std::string typestring<uint64_t>() { return "uint64"; } -template <> std::string typestring<int64_t>() { return "int64"; } +template <class T> +std::string typestring() +{ + return "Unknown"; +} + +template <> +std::string typestring<uint8_t>() +{ + return "uint8"; +} + +template <> +std::string typestring<int8_t>() +{ + return "int8"; +} + +template <> +std::string typestring<uint16_t>() +{ + return "uint16"; +} + +template <> +std::string typestring<int16_t>() +{ + return "int16"; +} + +template <> +std::string typestring<uint32_t>() +{ + return "uint32"; +} + +template <> +std::string typestring<int32_t>() +{ + return "int32"; +} + +template <> +std::string typestring<uint64_t>() +{ + return "uint64"; +} + +template <> +std::string typestring<int64_t>() +{ + return "int64"; +} template <class T> inline std::string int_overload(xt::pyarray<T>& m) @@ -194,10 +242,21 @@ struct B class C { public: + using array_type = xt::xarray<double, xt::layout_type::row_major>; - C() : m_array{0, 0, 0, 0} {} - array_type & array() { return m_array; } + + C() + : m_array{0, 0, 0, 0} + { + } + + array_type& array() + { + return m_array; + } + private: + array_type m_array; }; @@ -206,7 +265,7 @@ struct test_native_casters using array_type = xt::xarray<double>; array_type a = xt::ones<double>({50, 50}); - const auto & get_array() + const auto& get_array() { return a; } @@ -235,7 +294,7 @@ struct test_native_casters auto get_owning_array_adapter() { size_t size = 100; - int * data = new int[size]; + int* data = new int[size]; std::fill(data, data + size, 1); using shape_type = std::vector<size_t>; @@ -301,7 +360,7 @@ xt::pytensor<int, 0> xscalar(const xt::pytensor<int, 1>& arg) template <class T> using ndarray = xt::pyarray<T, xt::layout_type::row_major>; -void test_rm(ndarray<int>const& x) +void test_rm(const ndarray<int>& x) { ndarray<int> y = x; ndarray<int> z = xt::zeros<int>({10}); @@ -336,14 +395,26 @@ PYBIND11_MODULE(xtensor_python_test, m) m.def("array_subtraction", array_subtraction); m.def("array_multiplication", array_multiplication); m.def("array_division", array_division); - + m.def("vectorize_example1", xt::pyvectorize(add)); - m.def("rect_to_polar", xt::pyvectorize([](complex_t x) { return std::abs(x); })); + m.def( + "rect_to_polar", + xt::pyvectorize( + [](complex_t x) + { + return std::abs(x); + } + ) + ); - m.def("compare_shapes", [](const xt::pyarray<double>& a, const xt::pyarray<double>& b) { - return a.shape() == b.shape(); - }); + m.def( + "compare_shapes", + [](const xt::pyarray<double>& a, const xt::pyarray<double>& b) + { + return a.shape() == b.shape(); + } + ); m.def("test_rm", test_rm); @@ -375,28 +446,101 @@ PYBIND11_MODULE(xtensor_python_test, m) .def(py::init<>()) .def_property_readonly( "copy", - [](C & self) { return self.array(); } + [](C& self) + { + return self.array(); + } ) .def_property_readonly( "ref", - [](C & self) -> C::array_type & { return self.array(); } - ) - ; - - m.def("simple_array", [](xt::pyarray<int>) { return 1; } ); - m.def("simple_tensor", [](xt::pytensor<int, 1>) { return 2; } ); - - m.def("diff_shape_overload", [](xt::pytensor<int, 1> a) { return 1; }); - m.def("diff_shape_overload", [](xt::pytensor<int, 2> a) { return 2; }); + [](C& self) -> C::array_type& + { + return self.array(); + } + ); + + m.def( + "simple_array", + [](xt::pyarray<int>) + { + return 1; + } + ); + m.def( + "simple_tensor", + [](xt::pytensor<int, 1>) + { + return 2; + } + ); + + m.def( + "diff_shape_overload", + [](xt::pytensor<int, 1> a) + { + return 1; + } + ); + m.def( + "diff_shape_overload", + [](xt::pytensor<int, 2> a) + { + return 2; + } + ); py::class_<test_native_casters>(m, "test_native_casters") - .def(py::init<>()) - .def("get_array", &test_native_casters::get_array, py::return_value_policy::reference_internal) // memory managed by the class instance - .def("get_strided_view", &test_native_casters::get_strided_view, py::keep_alive<0, 1>()) // keep_alive<0, 1>() => do not free "self" before the returned view - .def("get_array_adapter", &test_native_casters::get_array_adapter, py::keep_alive<0, 1>()) // keep_alive<0, 1>() => do not free "self" before the returned adapter - .def("get_tensor_adapter", &test_native_casters::get_tensor_adapter, py::keep_alive<0, 1>()) // keep_alive<0, 1>() => do not free "self" before the returned adapter - .def("get_owning_array_adapter", &test_native_casters::get_owning_array_adapter) // auto memory management as the adapter owns its memory - .def("view_keep_alive_member_function", [](test_native_casters & self, xt::pyarray<double> & a) // keep_alive<0, 2>() => do not free second parameter before the returned view - {return xt::reshape_view(a, {a.size(), });}, - py::keep_alive<0, 2>()); + .def(py::init<>()) + .def("get_array", &test_native_casters::get_array, py::return_value_policy::reference_internal) // memory + // managed + // by + // the + // class + // instance + .def("get_strided_view", &test_native_casters::get_strided_view, py::keep_alive<0, 1>()) // keep_alive<0, + // 1>() => + // do not + // free + // "self" + // before + // the + // returned + // view + .def("get_array_adapter", &test_native_casters::get_array_adapter, py::keep_alive<0, 1>()) // keep_alive<0, + // 1>() => + // do not + // free + // "self" + // before + // the + // returned + // adapter + .def("get_tensor_adapter", &test_native_casters::get_tensor_adapter, py::keep_alive<0, 1>()) // keep_alive<0, + // 1>() + // => do + // not + // free + // "self" + // before + // the + // returned + // adapter + .def("get_owning_array_adapter", &test_native_casters::get_owning_array_adapter) // auto memory + // management as the + // adapter owns its + // memory + .def( + "view_keep_alive_member_function", + [](test_native_casters& self, xt::pyarray<double>& a) // keep_alive<0, 2>() => do not free second + // parameter before the returned view + { + return xt::reshape_view( + a, + { + a.size(), + } + ); + }, + py::keep_alive<0, 2>() + ); }