├── .clang-format ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── gh-pages.yml │ ├── issue-close.yml │ ├── linux.yml │ ├── osx.yml │ ├── static-analysis.yml │ └── windows.yml ├── .gitignore ├── .pre-commit-config.yaml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── benchmark ├── CMakeLists.txt ├── benchmark_adapter.cpp ├── benchmark_assign.cpp ├── benchmark_builder.cpp ├── benchmark_container.cpp ├── benchmark_creation.cpp ├── benchmark_increment_stepper.cpp ├── benchmark_lambda_expressions.cpp ├── benchmark_math.cpp ├── benchmark_random.cpp ├── benchmark_reducer.cpp ├── benchmark_view_access.cpp ├── benchmark_view_adapt.cpp ├── benchmark_view_assignment.cpp ├── benchmark_views.cpp ├── benchmark_xshape.cpp ├── copyGBenchmark.cmake.in ├── downloadGBenchmark.cmake.in └── main.cpp ├── cmake └── FindTBB.cmake ├── docs ├── Doxyfile ├── Makefile ├── ghp_environment.yml ├── make.bat ├── rtd_environment.yml └── source │ ├── _static │ ├── goatcounter.js │ └── main_stylesheet.css │ ├── adaptor.rst │ ├── api │ ├── accumulating_functions.rst │ ├── basic_functions.rst │ ├── classif_functions.rst │ ├── container_index.rst │ ├── error_functions.rst │ ├── exponential_functions.rst │ ├── expression_index.rst │ ├── function_index.rst │ ├── hyperbolic_functions.rst │ ├── index_related.rst │ ├── io_index.rst │ ├── iterator_index.rst │ ├── nan_functions.rst │ ├── nearint_operations.rst │ ├── operators.rst │ ├── power_functions.rst │ ├── reducing_functions.rst │ ├── shape.rst │ ├── trigonometric_functions.rst │ ├── xaccumulator.rst │ ├── xadapt.rst │ ├── xarray.rst │ ├── xarray_adaptor.rst │ ├── xaxis_iterator.rst │ ├── xaxis_slice_iterator.rst │ ├── xbroadcast.rst │ ├── xbuilder.rst │ ├── xchunked_array.rst │ ├── xcontainer.rst │ ├── xcontainer_semantic.rst │ ├── xcsv.rst │ ├── xeval.rst │ ├── xexpression.rst │ ├── xfixed.rst │ ├── xfunction.rst │ ├── xfunctor_view.rst │ ├── xgenerator.rst │ ├── xhistogram.rst │ ├── xindex_view.rst │ ├── xio.rst │ ├── xiterable.rst │ ├── xjson.rst │ ├── xmanipulation.rst │ ├── xmasked_view.rst │ ├── xmath.rst │ ├── xnpy.rst │ ├── xoptional_assembly.rst │ ├── xoptional_assembly_adaptor.rst │ ├── xoptional_assembly_base.rst │ ├── xpad.rst │ ├── xrandom.rst │ ├── xreducer.rst │ ├── xrepeat.rst │ ├── xsemantic_base.rst │ ├── xset_operation.rst │ ├── xshape.rst │ ├── xsort.rst │ ├── xstrided_view.rst │ ├── xstrides.rst │ ├── xtensor.rst │ ├── xtensor_adaptor.rst │ ├── xview.rst │ └── xview_semantic.rst │ ├── binder-logo.svg │ ├── bindings.rst │ ├── build-options.rst │ ├── builder.rst │ ├── changelog.rst │ ├── closure-semantics.rst │ ├── cmake.svg │ ├── compilers.rst │ ├── conda.svg │ ├── conf.py │ ├── container.rst │ ├── debian.svg │ ├── dev-build-options.rst │ ├── developer │ ├── assign_xexpression.svg │ ├── assignment.rst │ ├── computed_assign.svg │ ├── concepts.rst │ ├── expression_tree.rst │ ├── extended_copy_semantic.svg │ ├── implementation_classes.rst │ ├── iterating_expression.rst │ ├── iteration.svg │ ├── stepper_basic.svg │ ├── stepper_broadcasting.svg │ ├── stepper_iterating.svg │ ├── stepper_to_end.svg │ ├── xarray_uml.svg │ ├── xcontainer_classes.svg │ ├── xfunction_tree.svg │ ├── xsemantic_classes.svg │ └── xtensor_internals.rst │ ├── expression.rst │ ├── external-structures.rst │ ├── file_loading.rst │ ├── getting_started.rst │ ├── histogram.rst │ ├── index.rst │ ├── indices.rst │ ├── installation.rst │ ├── missing.rst │ ├── numpy-differences.rst │ ├── numpy.rst │ ├── numpy.svg │ ├── operator.rst │ ├── pitfall.rst │ ├── quantstack-white.svg │ ├── quickref │ ├── basic.rst │ ├── builder.rst │ ├── chunked_arrays.rst │ ├── iterator.rst │ ├── manipulation.rst │ ├── math.rst │ ├── operator.rst │ └── reducer.rst │ ├── random.rst │ ├── rank.rst │ ├── related.rst │ ├── releasing.rst │ ├── scalar.rst │ ├── spack.svg │ ├── view.rst │ ├── xeus-cling-screenshot.png │ ├── xfft.rst │ ├── xframe.svg │ ├── xsimd-small.svg │ ├── xsimd.svg │ ├── xtensor-blas-small.svg │ ├── xtensor-blas.svg │ ├── xtensor-cookiecutter.svg │ ├── xtensor-fftw.svg │ ├── xtensor-io-small.svg │ ├── xtensor-io.svg │ ├── xtensor-julia-small.svg │ ├── xtensor-julia.svg │ ├── xtensor-python-small.svg │ ├── xtensor-python.svg │ ├── xtensor-r-small.svg │ ├── xtensor-r.svg │ ├── xtensor-ros.svg │ ├── xtensor.svg │ └── xtl.svg ├── environment-dev.yml ├── environment.yml ├── include └── xtensor │ ├── chunk │ ├── xchunked_array.hpp │ ├── xchunked_assign.hpp │ └── xchunked_view.hpp │ ├── containers │ ├── xadapt.hpp │ ├── xarray.hpp │ ├── xbuffer_adaptor.hpp │ ├── xcontainer.hpp │ ├── xfixed.hpp │ ├── xscalar.hpp │ ├── xstorage.hpp │ └── xtensor.hpp │ ├── core │ ├── xaccessible.hpp │ ├── xassign.hpp │ ├── xeval.hpp │ ├── xexpression.hpp │ ├── xexpression_traits.hpp │ ├── xfunction.hpp │ ├── xiterable.hpp │ ├── xiterator.hpp │ ├── xlayout.hpp │ ├── xmath.hpp │ ├── xmultiindex_iterator.hpp │ ├── xnoalias.hpp │ ├── xoperation.hpp │ ├── xsemantic.hpp │ ├── xshape.hpp │ ├── xstrides.hpp │ ├── xtensor_config.hpp │ ├── xtensor_forward.hpp │ └── xvectorize.hpp │ ├── generators │ ├── xbuilder.hpp │ ├── xgenerator.hpp │ └── xrandom.hpp │ ├── io │ ├── xcsv.hpp │ ├── xinfo.hpp │ ├── xio.hpp │ ├── xjson.hpp │ ├── xmime.hpp │ └── xnpy.hpp │ ├── misc │ ├── xcomplex.hpp │ ├── xexpression_holder.hpp │ ├── xfft.hpp │ ├── xhistogram.hpp │ ├── xmanipulation.hpp │ ├── xpad.hpp │ ├── xset_operation.hpp │ ├── xsort.hpp │ └── xtl_concepts.hpp │ ├── optional │ ├── xoptional.hpp │ ├── xoptional_assembly.hpp │ ├── xoptional_assembly_base.hpp │ └── xoptional_assembly_storage.hpp │ ├── reducers │ ├── xaccumulator.hpp │ ├── xblockwise_reducer.hpp │ ├── xblockwise_reducer_functors.hpp │ ├── xnorm.hpp │ └── xreducer.hpp │ ├── utils │ ├── xexception.hpp │ ├── xtensor_simd.hpp │ └── xutils.hpp │ └── views │ ├── xaxis_iterator.hpp │ ├── xaxis_slice_iterator.hpp │ ├── xbroadcast.hpp │ ├── xdynamic_view.hpp │ ├── xfunctor_view.hpp │ ├── xindex_view.hpp │ ├── xmasked_view.hpp │ ├── xoffset_view.hpp │ ├── xrepeat.hpp │ ├── xslice.hpp │ ├── xstrided_view.hpp │ ├── xstrided_view_base.hpp │ ├── xview.hpp │ └── xview_utils.hpp ├── notebooks ├── images │ ├── xtensor-blas.png │ └── xtensor.png └── xtensor.ipynb ├── readthedocs.yml ├── test ├── CMakeLists.txt ├── files │ ├── cppy_source │ │ ├── test_extended_broadcast_view.cppy │ │ ├── test_extended_xhistogram.cppy │ │ ├── test_extended_xmath_interp.cppy │ │ ├── test_extended_xmath_reducers.cppy │ │ └── test_extended_xsort.cppy │ ├── generate.py │ ├── preprocess.py │ ├── xio_expected_results.hpp │ ├── xio_expected_results │ │ ├── big_exp.txt │ │ ├── bool_fn.txt │ │ ├── complex_numbers.txt │ │ ├── complex_zero_erasing.txt │ │ ├── custom_formatter_result.txt │ │ ├── cut_4d.txt │ │ ├── cut_both.txt │ │ ├── cut_high.txt │ │ ├── cut_long.txt │ │ ├── float_leading_zero.txt │ │ ├── long_strings.txt │ │ ├── precision.txt │ │ ├── print_options_result.txt │ │ ├── random_nan_inf.txt │ │ ├── random_strings.txt │ │ ├── threed_double.txt │ │ └── twod_double.txt │ └── xnpy_files │ │ ├── bool.be.npy │ │ ├── bool.le.npy │ │ ├── bool_fortran.be.npy │ │ ├── bool_fortran.le.npy │ │ ├── double.be.npy │ │ ├── double.le.npy │ │ ├── double_fortran.be.npy │ │ ├── double_fortran.le.npy │ │ ├── int.be.npy │ │ ├── int.le.npy │ │ ├── unsignedlong.be.npy │ │ ├── unsignedlong.le.npy │ │ ├── unsignedlong_fortran.be.npy │ │ └── unsignedlong_fortran.le.npy ├── main.cpp ├── set_compiler_flag.cmake ├── test_common.hpp ├── test_common_macros.hpp ├── test_extended_broadcast_view.cpp ├── test_extended_xhistogram.cpp ├── test_extended_xmath_interp.cpp ├── test_extended_xmath_reducers.cpp ├── test_extended_xsort.cpp ├── test_sfinae.cpp ├── test_strided_assign.cpp ├── test_utils.hpp ├── test_xaccumulator.cpp ├── test_xadapt.cpp ├── test_xadaptor_semantic.cpp ├── test_xarray.cpp ├── test_xarray_adaptor.cpp ├── test_xassign.cpp ├── test_xaxis_iterator.cpp ├── test_xaxis_slice_iterator.cpp ├── test_xblockwise_reducer.cpp ├── test_xbroadcast.cpp ├── test_xbuffer_adaptor.cpp ├── test_xbuilder.cpp ├── test_xchunked_array.cpp ├── test_xchunked_view.cpp ├── test_xcomplex.cpp ├── test_xcontainer_semantic.cpp ├── test_xcsv.cpp ├── test_xdatesupport.cpp ├── test_xdynamic_view.cpp ├── test_xeval.cpp ├── test_xexception.cpp ├── test_xexpression.cpp ├── test_xexpression_holder.cpp ├── test_xexpression_traits.cpp ├── test_xfft.cpp ├── test_xfixed.cpp ├── test_xfunc_on_xexpression.cpp ├── test_xfunction.cpp ├── test_xfunctor_adaptor.cpp ├── test_xhistogram.cpp ├── test_xindex_view.cpp ├── test_xinfo.cpp ├── test_xio.cpp ├── test_xiterator.cpp ├── test_xjson.cpp ├── test_xlayout.cpp ├── test_xmanipulation.cpp ├── test_xmasked_view.cpp ├── test_xmath.cpp ├── test_xmath_result_type.cpp ├── test_xmime.cpp ├── test_xmultiindex_iterator.cpp ├── test_xnan_functions.cpp ├── test_xnoalias.cpp ├── test_xnorm.cpp ├── test_xnpy.cpp ├── test_xoperation.cpp ├── test_xoptional.cpp ├── test_xoptional_assembly.cpp ├── test_xoptional_assembly_adaptor.cpp ├── test_xoptional_assembly_storage.cpp ├── test_xpad.cpp ├── test_xrandom.cpp ├── test_xreducer.cpp ├── test_xrepeat.cpp ├── test_xscalar.cpp ├── test_xscalar_semantic.cpp ├── test_xsemantic.hpp ├── test_xset_operation.cpp ├── test_xshape.cpp ├── test_xsimd.cpp ├── test_xsimd8.cpp ├── test_xsort.cpp ├── test_xstorage.cpp ├── test_xstrided_view.cpp ├── test_xstrides.cpp ├── test_xtensor.cpp ├── test_xtensor_adaptor.cpp ├── test_xtensor_semantic.cpp ├── test_xutils.cpp ├── test_xvectorize.cpp ├── test_xview.cpp └── test_xview_semantic.cpp ├── tools └── check_circular.py ├── xtensor.pc.in └── xtensorConfig.cmake.in /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Mozilla 2 | 3 | AccessModifierOffset: '-4' 4 | AlignAfterOpenBracket: BlockIndent 5 | AlignEscapedNewlines: Left 6 | AllowAllArgumentsOnNextLine: false 7 | AllowAllParametersOfDeclarationOnNextLine: false 8 | AllowShortBlocksOnASingleLine: false 9 | AllowShortCaseLabelsOnASingleLine: false 10 | AllowShortFunctionsOnASingleLine: false 11 | AllowShortIfStatementsOnASingleLine: false 12 | # Forbid one line lambdas because clang-format makes a weird split when 13 | # single instructions lambdas are too long. 14 | AllowShortLambdasOnASingleLine: Empty 15 | AllowShortLoopsOnASingleLine: false 16 | AlwaysBreakAfterDefinitionReturnType: None 17 | AlwaysBreakAfterReturnType: None 18 | AlwaysBreakTemplateDeclarations: Yes 19 | BinPackArguments: false 20 | BinPackParameters: false 21 | BreakBeforeBinaryOperators: NonAssignment 22 | BreakBeforeBraces: Allman 23 | BreakBeforeTernaryOperators: true 24 | BreakConstructorInitializers: BeforeComma 25 | BreakInheritanceList: AfterComma 26 | BreakStringLiterals: false 27 | ColumnLimit: '110' 28 | ConstructorInitializerIndentWidth: '4' 29 | ContinuationIndentWidth: '4' 30 | Cpp11BracedListStyle: true 31 | DerivePointerAlignment: false 32 | DisableFormat: false 33 | EmptyLineAfterAccessModifier: Always 34 | EmptyLineBeforeAccessModifier: Always 35 | ExperimentalAutoDetectBinPacking: true 36 | IncludeBlocks: Regroup 37 | IncludeCategories: 38 | - Regex: <[^.]+> 39 | Priority: 1 40 | - Regex: 41 | Priority: 3 42 | - Regex: <.+> 43 | Priority: 2 44 | - Regex: '"xtensor/.+"' 45 | Priority: 4 46 | - Regex: '".+"' 47 | Priority: 5 48 | IndentCaseLabels: true 49 | IndentWidth: '4' 50 | IndentWrappedFunctionNames: false 51 | InsertBraces: true 52 | InsertTrailingCommas: Wrapped 53 | KeepEmptyLinesAtTheStartOfBlocks: false 54 | LambdaBodyIndentation: Signature 55 | Language: Cpp 56 | MaxEmptyLinesToKeep: '2' 57 | NamespaceIndentation: All 58 | ObjCBlockIndentWidth: '4' 59 | ObjCSpaceAfterProperty: false 60 | ObjCSpaceBeforeProtocolList: false 61 | PackConstructorInitializers: Never 62 | PenaltyBreakAssignment: 100000 63 | PenaltyBreakBeforeFirstCallParameter: 0 64 | PenaltyBreakComment: 10 65 | PenaltyBreakOpenParenthesis: 0 66 | PenaltyBreakTemplateDeclaration: 0 67 | PenaltyExcessCharacter: 10 68 | PenaltyIndentedWhitespace: 0 69 | PenaltyReturnTypeOnItsOwnLine: 10 70 | PointerAlignment: Left 71 | QualifierAlignment: Custom # Experimental 72 | QualifierOrder: [inline, static, constexpr, const, volatile, type] 73 | ReflowComments: true 74 | SeparateDefinitionBlocks: Always 75 | SortIncludes: CaseInsensitive 76 | SortUsingDeclarations: true 77 | SpaceAfterCStyleCast: true 78 | SpaceAfterTemplateKeyword: true 79 | SpaceBeforeAssignmentOperators: true 80 | SpaceBeforeParens: ControlStatements 81 | SpaceInEmptyParentheses: false 82 | SpacesBeforeTrailingComments: '2' 83 | SpacesInAngles: false 84 | SpacesInCStyleCastParentheses: false 85 | SpacesInContainerLiterals: false 86 | SpacesInParentheses: false 87 | SpacesInSquareBrackets: false 88 | Standard: c++20 89 | TabWidth: '4' 90 | UseTab: Never 91 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Checklist 2 | 3 | - [ ] The title and commit message(s) are descriptive. 4 | - [ ] Small commits made to fix your PR have been squashed to avoid history pollution. 5 | - [ ] Tests have been added for new features or bug fixes. 6 | - [ ] API of new functions and classes are documented. 7 | 8 | # Description 9 | 10 | 14 | -------------------------------------------------------------------------------- /.github/workflows/gh-pages.yml: -------------------------------------------------------------------------------- 1 | name: gh-pages 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | defaults: 9 | run: 10 | shell: bash -l {0} 11 | 12 | jobs: 13 | 14 | publish: 15 | 16 | runs-on: ubuntu-latest 17 | 18 | defaults: 19 | run: 20 | shell: bash -l {0} 21 | 22 | steps: 23 | 24 | - name: Basic GitHub action setup 25 | uses: actions/checkout@v2 26 | 27 | - name: Set mamba environment 28 | uses: mamba-org/setup-micromamba@main 29 | with: 30 | environment-file: docs/ghp_environment.yml 31 | environment-name: xtensor-doc 32 | init-shell: bash 33 | cache-downloads: true 34 | 35 | - name: Run doxygen 36 | working-directory: docs 37 | run: doxygen 38 | 39 | - name: Deploy to GitHub Pages 40 | if: success() 41 | uses: crazy-max/ghaction-github-pages@v2 42 | with: 43 | target_branch: gh-pages 44 | build_dir: docs/html 45 | jekyll: false 46 | keep_history: false 47 | env: 48 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 49 | -------------------------------------------------------------------------------- /.github/workflows/issue-close.yml: -------------------------------------------------------------------------------- 1 | name: Close inactive issues and PRs 2 | on: 3 | schedule: 4 | - cron: 30 1 * * * 5 | 6 | jobs: 7 | close-issues: 8 | runs-on: ubuntu-latest 9 | permissions: 10 | issues: write 11 | pull-requests: write 12 | steps: 13 | - uses: actions/stale@v8 14 | with: 15 | any-of-issue-labels: Needs clarification, Answered, Stale? 16 | days-before-issue-stale: 30 17 | days-before-issue-close: 14 18 | stale-issue-label: Stale 19 | stale-issue-message: | 20 | This issue is stale because it has been open for 30 days with no activity. 21 | It will be automatically closed in 14 days. 22 | close-issue-message: | 23 | This issue was closed because it has been inactive for 14 days since being marked as stale. 24 | any-of-pr-labels: Needs clarification, Answered, Needs revision, Stale? 25 | days-before-pr-stale: 60 26 | days-before-pr-close: 14 27 | stale-pr-label: Stale 28 | stale-pr-message: | 29 | This pr is stale because it has been open for 60 days with no activity. 30 | It will be automatically closed in 14 days. 31 | close-pr-message: | 32 | This issue was closed because it has been inactive for 14 days since being marked as stale. 33 | repo-token: ${{ secrets.GITHUB_TOKEN }} 34 | -------------------------------------------------------------------------------- /.github/workflows/osx.yml: -------------------------------------------------------------------------------- 1 | name: OSX 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | push: 6 | branches: [master] 7 | concurrency: 8 | group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }} 9 | cancel-in-progress: true 10 | defaults: 11 | run: 12 | shell: bash -e -l {0} 13 | jobs: 14 | build: 15 | runs-on: macos-${{ matrix.os }} 16 | name: macos-${{ matrix.os }} 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | os: 21 | - 13 22 | - 14 23 | - 15 24 | 25 | steps: 26 | 27 | - name: Checkout code 28 | uses: actions/checkout@v3 29 | 30 | - name: Set conda environment 31 | uses: mamba-org/setup-micromamba@main 32 | with: 33 | environment-name: myenv 34 | environment-file: environment-dev.yml 35 | init-shell: bash 36 | cache-downloads: true 37 | 38 | - name: Configure using CMake 39 | run: cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON 40 | 41 | - name: Install 42 | working-directory: build 43 | run: cmake --install . 44 | 45 | - name: Build 46 | working-directory: build 47 | run: cmake --build . --target test_xtensor_lib --parallel 8 48 | 49 | - name: Run tests 50 | working-directory: build 51 | run: ctest -R ^xtest$ --output-on-failure 52 | -------------------------------------------------------------------------------- /.github/workflows/static-analysis.yml: -------------------------------------------------------------------------------- 1 | name: Static Analysis 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | pull_request: 7 | branches: [master] 8 | 9 | jobs: 10 | pre-commit: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: pre-commit/action@v3.0.0 15 | -------------------------------------------------------------------------------- /.github/workflows/windows.yml: -------------------------------------------------------------------------------- 1 | name: Windows 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | push: 6 | branches: [master] 7 | concurrency: 8 | group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }} 9 | cancel-in-progress: true 10 | defaults: 11 | run: 12 | shell: bash -e -l {0} 13 | jobs: 14 | build: 15 | runs-on: ${{ matrix.runs-on }} 16 | name: ${{ matrix.sys.compiler }} 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | runs-on: [windows-latest] 21 | sys: 22 | - {compiler: default} 23 | # Enable again and fix remaining issues after refactoring 24 | #- {compiler: clang} 25 | 26 | steps: 27 | 28 | - name: Setup MSVC 29 | if: matrix.sys.compiler == 'default' 30 | uses: ilammy/msvc-dev-cmd@v1 31 | 32 | - name: Setup clang 33 | if: matrix.sys.compiler == 'clang' 34 | run: | 35 | echo "CC=clang" >> $GITHUB_ENV 36 | echo "CXX=clang++" >> $GITHUB_ENV 37 | 38 | - name: Checkout code 39 | uses: actions/checkout@v3 40 | 41 | - name: Set conda environment 42 | uses: mamba-org/setup-micromamba@main 43 | with: 44 | environment-name: myenv 45 | environment-file: environment-dev.yml 46 | init-shell: bash 47 | cache-downloads: true 48 | create-args: | 49 | ninja 50 | 51 | - name: Configure using CMake 52 | run: cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON -G Ninja 53 | 54 | - name: Install 55 | working-directory: build 56 | run: cmake --install . 57 | 58 | - name: Build 59 | working-directory: build 60 | run: cmake --build . --target test_xtensor_lib --parallel 8 61 | 62 | - name: Run tests 63 | working-directory: build 64 | run: ctest -R ^xtest$ --output-on-failure 65 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Doxygen output 2 | docs/html/ 3 | docs/xml/ 4 | 5 | # Prerequisites 6 | *.d 7 | 8 | # Compiled Object files 9 | *.slo 10 | *.lo 11 | *.o 12 | *.obj 13 | 14 | # Precompiled Headers 15 | *.gch 16 | *.pch 17 | 18 | # Compiled Dynamic libraries 19 | *.so 20 | *.dylib 21 | *.dll 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # Vim tmp files 35 | *.swp 36 | *~ 37 | 38 | # Generated directory 39 | include/tmp/ 40 | 41 | # Build directory 42 | build/ 43 | 44 | # Test build artefacts 45 | test/test_xtensor 46 | test/CMakeCache.txt 47 | test/Makefile 48 | test/CMakeFiles/ 49 | test/cmake_install.cmake 50 | 51 | # Documentation build artefacts 52 | docs/CMakeCache.txt 53 | docs/xml/ 54 | docs/build/ 55 | docs/*.tmp 56 | 57 | # Jupyter artefacts 58 | .ipynb_checkpoints/ 59 | 60 | # Pytho artefacts 61 | __pycache__ 62 | 63 | # Generated files 64 | *.pc 65 | .vscode/settings.json 66 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v4.5.0 4 | hooks: 5 | - id: check-added-large-files 6 | - id: check-case-conflict 7 | - id: end-of-file-fixer 8 | - id: trailing-whitespace 9 | - id: mixed-line-ending 10 | args: [--fix=lf] 11 | exclude: \.bat$ 12 | - id: check-json 13 | - id: pretty-format-json 14 | args: [--autofix, --top-keys=version] 15 | - id: check-yaml 16 | types: [file] 17 | files: \.(yaml|yml|clang-format) 18 | - id: detect-private-key 19 | - id: check-merge-conflict 20 | - repo: https://github.com/Lucas-C/pre-commit-hooks 21 | rev: v1.5.4 22 | hooks: 23 | - id: forbid-tabs 24 | - id: remove-tabs 25 | args: [--whitespaces-count, '4'] 26 | - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks 27 | rev: v2.11.0 28 | hooks: 29 | - id: pretty-format-yaml 30 | args: [--autofix, --indent, '2'] 31 | types: [file] 32 | files: \.(yaml|yml|clang-format) 33 | - repo: https://github.com/tdegeus/cpp_comment_format 34 | rev: v0.2.1 35 | hooks: 36 | - id: cpp_comment_format 37 | - repo: https://github.com/tdegeus/conda_envfile 38 | rev: v0.4.2 39 | hooks: 40 | - id: conda_envfile_parse 41 | files: environment.yaml 42 | # Externally provided executables (so we can use them with editors as well). 43 | - repo: https://github.com/pre-commit/mirrors-clang-format 44 | rev: v17.0.6 45 | hooks: 46 | - id: clang-format 47 | files: .*\.[hc]pp$ 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | Copyright (c) 2016, QuantStack 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /benchmark/benchmark_creation.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #include 10 | 11 | #include "xtensor/containers/xarray.hpp" 12 | #include "xtensor/containers/xfixed.hpp" 13 | #include "xtensor/containers/xtensor.hpp" 14 | #include "xtensor/generators/xbuilder.hpp" 15 | 16 | namespace xt 17 | { 18 | void benchmark_empty(benchmark::State& state) 19 | { 20 | for (auto _ : state) 21 | { 22 | auto e = xt::empty({5, 5}); 23 | } 24 | } 25 | 26 | template 27 | void benchmark_from_shape(benchmark::State& state) 28 | { 29 | for (auto _ : state) 30 | { 31 | T e = T::from_shape({5, 5}); 32 | } 33 | } 34 | 35 | template 36 | void benchmark_creation(benchmark::State& state) 37 | { 38 | for (auto _ : state) 39 | { 40 | T e(typename T::shape_type({5, 5})); 41 | } 42 | } 43 | 44 | void benchmark_empty_to_xtensor(benchmark::State& state) 45 | { 46 | for (auto _ : state) 47 | { 48 | xtensor e = xt::empty({5, 5}); 49 | } 50 | } 51 | 52 | void benchmark_empty_to_xarray(benchmark::State& state) 53 | { 54 | for (auto _ : state) 55 | { 56 | xarray e = xt::empty({5, 5}); 57 | } 58 | } 59 | 60 | BENCHMARK(benchmark_empty); 61 | BENCHMARK(benchmark_empty_to_xtensor); 62 | BENCHMARK(benchmark_empty_to_xarray); 63 | BENCHMARK_TEMPLATE(benchmark_from_shape, xarray); 64 | BENCHMARK_TEMPLATE(benchmark_from_shape, xtensor); 65 | BENCHMARK_TEMPLATE(benchmark_creation, xarray); 66 | BENCHMARK_TEMPLATE(benchmark_creation, xtensor); 67 | } 68 | -------------------------------------------------------------------------------- /benchmark/benchmark_increment_stepper.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #include 10 | 11 | #include "xtensor/containers/xarray.hpp" 12 | #include "xtensor/generators/xrandom.hpp" 13 | 14 | #define SHAPE 30, 30 15 | #define RANGE 3, 100 16 | 17 | namespace xt 18 | { 19 | namespace benchmark_xstepper 20 | { 21 | void stepper_stepper(benchmark::State& state) 22 | { 23 | std::vector shape = {SHAPE, std::size_t(state.range(0))}; 24 | xt::xarray a = xt::random::rand(shape); 25 | xt::xarray b = xt::random::rand(shape); 26 | volatile double c = 0; 27 | for (auto _ : state) 28 | { 29 | auto end = compute_size(shape); 30 | auto it = a.stepper_begin(shape); 31 | auto bit = b.stepper_begin(shape); 32 | 33 | xindex index(shape.size()); 34 | xindex bindex(shape.size()); 35 | 36 | for (std::size_t i = 0; i < end; ++i) 37 | { 38 | c += *it + *bit; 39 | stepper_tools::increment_stepper(bit, bindex, shape); 40 | stepper_tools::increment_stepper(it, index, shape); 41 | } 42 | benchmark::DoNotOptimize(c); 43 | } 44 | } 45 | 46 | BENCHMARK(stepper_stepper)->Range(RANGE); 47 | 48 | void stepper_stepper_ref(benchmark::State& state) 49 | { 50 | std::vector shape = {SHAPE, std::size_t(state.range(0))}; 51 | xt::xarray a = xt::random::rand(shape); 52 | xt::xarray b = xt::random::rand(shape); 53 | xindex index; 54 | xindex bindex; 55 | volatile double c = 0; 56 | for (auto _ : state) 57 | { 58 | auto it = a.storage().begin(); 59 | auto bit = b.storage().begin(); 60 | auto end = a.storage().end(); 61 | for (; it != end; ++it) 62 | { 63 | c += *it + *bit; 64 | ++bit; 65 | } 66 | benchmark::DoNotOptimize(c); 67 | } 68 | } 69 | 70 | BENCHMARK(stepper_stepper_ref)->Range(RANGE); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /benchmark/benchmark_lambda_expressions.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #include 10 | 11 | #include "xtensor/containers/xarray.hpp" 12 | #include "xtensor/containers/xtensor.hpp" 13 | #include "xtensor/core/xmath.hpp" 14 | #include "xtensor/core/xnoalias.hpp" 15 | #include "xtensor/generators/xbuilder.hpp" 16 | 17 | namespace xt 18 | { 19 | void lambda_cube(benchmark::State& state) 20 | { 21 | xtensor x = empty({state.range(0), state.range(0)}); 22 | for (auto _ : state) 23 | { 24 | xtensor res = xt::cube(x); 25 | benchmark::DoNotOptimize(res.data()); 26 | } 27 | } 28 | 29 | void xexpression_cube(benchmark::State& state) 30 | { 31 | xtensor x = empty({state.range(0), state.range(0)}); 32 | for (auto _ : state) 33 | { 34 | xtensor res = x * x * x; 35 | benchmark::DoNotOptimize(res.data()); 36 | } 37 | } 38 | 39 | void lambda_higher_pow(benchmark::State& state) 40 | { 41 | xtensor x = empty({state.range(0), state.range(0)}); 42 | for (auto _ : state) 43 | { 44 | xtensor res = xt::pow<16>(x); 45 | benchmark::DoNotOptimize(res.data()); 46 | } 47 | } 48 | 49 | void xsimd_higher_pow(benchmark::State& state) 50 | { 51 | xtensor x = empty({state.range(0), state.range(0)}); 52 | for (auto _ : state) 53 | { 54 | xtensor res = xt::pow(x, 16); 55 | benchmark::DoNotOptimize(res.data()); 56 | } 57 | } 58 | 59 | void xexpression_higher_pow(benchmark::State& state) 60 | { 61 | xtensor x = empty({state.range(0), state.range(0)}); 62 | for (auto _ : state) 63 | { 64 | xtensor res = x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x; 65 | benchmark::DoNotOptimize(res.data()); 66 | } 67 | } 68 | 69 | BENCHMARK(lambda_cube)->Range(32, 32 << 3); 70 | BENCHMARK(xexpression_cube)->Range(32, 32 << 3); 71 | BENCHMARK(lambda_higher_pow)->Range(32, 32 << 3); 72 | BENCHMARK(xsimd_higher_pow)->Range(32, 32 << 3); 73 | BENCHMARK(xexpression_higher_pow)->Range(32, 32 << 3); 74 | } 75 | -------------------------------------------------------------------------------- /benchmark/benchmark_random.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef BENCHMARK_RANDOM_HPP 10 | #define BENCHMARK_RANDOM_HPP 11 | 12 | #include 13 | 14 | #include "xtensor/containers/xarray.hpp" 15 | #include "xtensor/containers/xtensor.hpp" 16 | #include "xtensor/core/xnoalias.hpp" 17 | #include "xtensor/generators/xrandom.hpp" 18 | 19 | namespace xt 20 | { 21 | namespace random_bench 22 | { 23 | void random_assign_xtensor(benchmark::State& state) 24 | { 25 | for (auto _ : state) 26 | { 27 | xtensor result = xt::random::rand({20, 20}); 28 | benchmark::DoNotOptimize(result.data()); 29 | } 30 | } 31 | 32 | void random_assign_forloop(benchmark::State& state) 33 | { 34 | for (auto _ : state) 35 | { 36 | xtensor result; 37 | result.resize({20, 20}); 38 | std::uniform_real_distribution dist(0, 1); 39 | auto& engine = xt::random::get_default_random_engine(); 40 | for (auto& el : result.storage()) 41 | { 42 | el = dist(engine); 43 | } 44 | benchmark::DoNotOptimize(result.data()); 45 | } 46 | } 47 | 48 | void random_assign_xarray(benchmark::State& state) 49 | { 50 | for (auto _ : state) 51 | { 52 | xarray result = xt::random::rand({20, 20}); 53 | benchmark::DoNotOptimize(result.data()); 54 | } 55 | } 56 | 57 | BENCHMARK(random_assign_xarray); 58 | BENCHMARK(random_assign_xtensor); 59 | BENCHMARK(random_assign_forloop); 60 | } 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /benchmark/benchmark_view_adapt.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef BENCHMARK_VIEW_ADAPT_HPP 10 | #define BENCHMARK_VIEW_ADAPT_HPP 11 | 12 | #include 13 | 14 | #include "xtensor/containers/xadapt.hpp" 15 | #include "xtensor/containers/xfixed.hpp" 16 | #include "xtensor/containers/xtensor.hpp" 17 | #include "xtensor/core/xnoalias.hpp" 18 | #include "xtensor/generators/xrandom.hpp" 19 | #include "xtensor/views/xview.hpp" 20 | 21 | namespace xt 22 | { 23 | namespace benchmark_view_adapt 24 | { 25 | using T2 = xt::xtensor_fixed>; 26 | 27 | T2 foo(const T2& A) 28 | { 29 | return 2. * A; 30 | } 31 | 32 | void random_view(benchmark::State& state) 33 | { 34 | xt::xtensor A = xt::random::randn({2000, 8, 2, 2}); 35 | xt::xtensor B = xt::empty(A.shape()); 36 | 37 | for (auto _ : state) 38 | { 39 | for (size_t i = 0; i < A.shape()[0]; ++i) 40 | { 41 | for (size_t j = 0; j < A.shape()[1]; ++j) 42 | { 43 | auto a = xt::view(A, i, j); 44 | auto b = xt::view(B, i, j); 45 | 46 | xt::noalias(b) = foo(a); 47 | } 48 | } 49 | benchmark::DoNotOptimize(B.data()); 50 | } 51 | } 52 | 53 | void random_adapt(benchmark::State& state) 54 | { 55 | xt::xtensor A = xt::random::randn({2000, 8, 2, 2}); 56 | xt::xtensor B = xt::empty(A.shape()); 57 | 58 | for (auto _ : state) 59 | { 60 | for (size_t i = 0; i < A.shape()[0]; ++i) 61 | { 62 | for (size_t j = 0; j < A.shape()[1]; ++j) 63 | { 64 | auto a = xt::adapt(&A(i, j, 0, 0), xt::xshape<2, 2>()); 65 | auto b = xt::adapt(&B(i, j, 0, 0), xt::xshape<2, 2>()); 66 | 67 | xt::noalias(b) = foo(a); 68 | } 69 | } 70 | benchmark::DoNotOptimize(B.data()); 71 | } 72 | } 73 | 74 | BENCHMARK(random_view); 75 | BENCHMARK(random_adapt); 76 | } 77 | } 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /benchmark/benchmark_xshape.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | 10 | #ifndef BENCHMARK_SHAPE_HPP 11 | #define BENCHMARK_SHAPE_HPP 12 | 13 | #include 14 | 15 | #include "xtensor/containers/xstorage.hpp" 16 | #include "xtensor/core/xshape.hpp" 17 | 18 | namespace xt 19 | { 20 | namespace benchmark_xshape 21 | { 22 | template 23 | void xshape_initializer(benchmark::State& state) 24 | { 25 | for (auto _ : state) 26 | { 27 | T sv({2, 3, 1}); 28 | benchmark::DoNotOptimize(sv.data()); 29 | } 30 | } 31 | 32 | template 33 | void xshape_initializer_long(benchmark::State& state) 34 | { 35 | for (auto _ : state) 36 | { 37 | T sv({2, 3, 1, 2, 6, 1, 2, 3, 45, 6, 12, 3, 5, 45, 5, 6}); 38 | benchmark::DoNotOptimize(sv.data()); 39 | } 40 | } 41 | 42 | template 43 | void xshape_access(benchmark::State& state) 44 | { 45 | T a({3, 2, 1, 3}); 46 | for (auto _ : state) 47 | { 48 | a[0] = a[1] * a[2] + a[3]; 49 | a[3] = a[1]; 50 | a[1] = a[2] + a[3]; 51 | a[2] = a[3]; 52 | benchmark::DoNotOptimize(a.data()); 53 | } 54 | } 55 | 56 | BENCHMARK_TEMPLATE(xshape_initializer, std::vector); 57 | BENCHMARK_TEMPLATE(xshape_initializer, xt::svector); 58 | BENCHMARK_TEMPLATE(xshape_initializer, std::array); 59 | BENCHMARK_TEMPLATE(xshape_initializer_long, xt::svector); 60 | BENCHMARK_TEMPLATE(xshape_initializer_long, xt::uvector); 61 | BENCHMARK_TEMPLATE(xshape_initializer_long, std::vector); 62 | BENCHMARK_TEMPLATE(xshape_access, xt::uvector); 63 | BENCHMARK_TEMPLATE(xshape_access, std::vector); 64 | BENCHMARK_TEMPLATE(xshape_access, xt::svector); 65 | BENCHMARK_TEMPLATE(xshape_access, std::array); 66 | } 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /benchmark/copyGBenchmark.cmake.in: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht # 3 | # # 4 | # Distributed under the terms of the BSD 3-Clause License. # 5 | # # 6 | # The full license is in the file LICENSE, distributed with this software. # 7 | ############################################################################ 8 | 9 | cmake_minimum_required(VERSION 2.8.2) 10 | 11 | project(googlebenchmark-download NONE) 12 | 13 | include(ExternalProject) 14 | ExternalProject_Add(benchmark 15 | URL "${googlebenchmark_SRC_DIR}" 16 | SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-src" 17 | BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-build" 18 | CONFIGURE_COMMAND "" 19 | BUILD_COMMAND "" 20 | INSTALL_COMMAND "" 21 | TEST_COMMAND "" 22 | ) 23 | -------------------------------------------------------------------------------- /benchmark/downloadGBenchmark.cmake.in: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht # 3 | # # 4 | # Distributed under the terms of the BSD 3-Clause License. # 5 | # # 6 | # The full license is in the file LICENSE, distributed with this software. # 7 | ############################################################################ 8 | 9 | cmake_minimum_required(VERSION 2.8.2) 10 | 11 | project(googlebenchmark-download NONE) 12 | 13 | include(ExternalProject) 14 | ExternalProject_Add(googlebenchmark 15 | GIT_REPOSITORY https://github.com/google/benchmark.git 16 | GIT_TAG v1.3.0 17 | SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-src" 18 | BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-build" 19 | CONFIGURE_COMMAND "" 20 | BUILD_COMMAND "" 21 | INSTALL_COMMAND "" 22 | TEST_COMMAND "" 23 | ) 24 | -------------------------------------------------------------------------------- /benchmark/main.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include "xtensor/containers/xarray.hpp" 14 | #include "xtensor/containers/xtensor.hpp" 15 | 16 | #ifdef XTENSOR_USE_XSIMD 17 | #ifdef __GNUC__ 18 | template 19 | void print_type(T&& /*t*/) 20 | { 21 | std::cout << __PRETTY_FUNCTION__ << std::endl; 22 | } 23 | #endif 24 | void print_stats() 25 | { 26 | std::cout << "USING XSIMD\nSIMD SIZE: " << xsimd::simd_traits::size << "\n\n"; 27 | #ifdef __GNUC__ 28 | print_type(xt::xarray()); 29 | print_type(xt::xtensor()); 30 | #endif 31 | } 32 | #else 33 | void print_stats() 34 | { 35 | std::cout << "NOT USING XSIMD\n\n"; 36 | }; 37 | #endif 38 | 39 | 40 | // Custom main function to print SIMD config 41 | int main(int argc, char** argv) 42 | { 43 | print_stats(); 44 | benchmark::Initialize(&argc, argv); 45 | if (benchmark::ReportUnrecognizedArguments(argc, argv)) 46 | { 47 | return 1; 48 | } 49 | benchmark::RunSpecifiedBenchmarks(); 50 | } 51 | -------------------------------------------------------------------------------- /docs/Doxyfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "xtensor" 2 | XML_OUTPUT = xml 3 | INPUT = ../include 4 | GENERATE_LATEX = NO 5 | GENERATE_MAN = NO 6 | GENERATE_RTF = NO 7 | CASE_SENSE_NAMES = NO 8 | GENERATE_HTML = YES 9 | GENERATE_XML = YES 10 | RECURSIVE = YES 11 | QUIET = YES 12 | JAVADOC_AUTOBRIEF = YES 13 | WARN_IF_UNDOCUMENTED = NO 14 | MACRO_EXPANSION = YES 15 | PREDEFINED = IN_DOXYGEN 16 | EXCLUDE_SYMBOLS = detail 17 | GENERATE_TREEVIEW = YES 18 | SOURCE_BROWSER = YES 19 | # WARN_IF_UNDOCUMENTED = YES 20 | 21 | # Allow for rst directives and advanced functions e.g. grid tables 22 | ALIASES = "rst=\verbatim embed:rst:leading-asterisk" 23 | ALIASES += "endrst=\endverbatim" 24 | -------------------------------------------------------------------------------- /docs/ghp_environment.yml: -------------------------------------------------------------------------------- 1 | channels: 2 | - conda-forge 3 | dependencies: 4 | - doxygen 5 | -------------------------------------------------------------------------------- /docs/rtd_environment.yml: -------------------------------------------------------------------------------- 1 | name: xtensor-docs 2 | 3 | channels: 4 | - conda-forge 5 | 6 | dependencies: 7 | - breathe 8 | - sphinx_rtd_theme 9 | -------------------------------------------------------------------------------- /docs/source/_static/goatcounter.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | window.counter = 'https://xtensor_readthedocs_io.goatcounter.com/count' 3 | 4 | var script = document.createElement('script'); 5 | script.async = 1; 6 | script.src = '//gc.zgo.at/count.js'; 7 | var ins = document.getElementsByTagName('script')[0]; 8 | ins.parentNode.insertBefore(script, ins) 9 | })(); 10 | -------------------------------------------------------------------------------- /docs/source/_static/main_stylesheet.css: -------------------------------------------------------------------------------- 1 | .wy-nav-content{ 2 | max-width: 1000px; 3 | margin: auto; 4 | } 5 | -------------------------------------------------------------------------------- /docs/source/api/accumulating_functions.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Accumulating functions 8 | ====================== 9 | 10 | **xtensor** provides the following accumulating functions for xexpressions: 11 | 12 | Defined in ``xtensor/core/xmath.hpp`` 13 | 14 | .. doxygenfunction:: cumsum(E&&) 15 | 16 | .. doxygenfunction:: cumsum(E&&, std::ptrdiff_t) 17 | 18 | .. doxygenfunction:: cumprod(E&&) 19 | 20 | .. doxygenfunction:: cumprod(E&&, std::ptrdiff_t) 21 | -------------------------------------------------------------------------------- /docs/source/api/basic_functions.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Basic functions 8 | =============== 9 | 10 | **xtensor** provides the following basic functions for xexpressions and scalars: 11 | 12 | Defined in ``xtensor/core/xmath.hpp`` 13 | 14 | .. doxygenfunction:: abs(E&&) 15 | 16 | .. doxygenfunction:: fabs(E&&) 17 | 18 | .. doxygenfunction:: fmod(E1&&, E2&&) 19 | 20 | .. doxygenfunction:: remainder(E1&&, E2&&) 21 | 22 | .. doxygenfunction:: fma(E1&&, E2&&, E3&&) 23 | 24 | .. doxygenfunction:: maximum(E1&&, E2&&) 25 | 26 | .. doxygenfunction:: minimum(E1&&, E2&&) 27 | 28 | .. doxygenfunction:: fmax(E1&&, E2&&) 29 | 30 | .. doxygenfunction:: fmin(E1&&, E2&&) 31 | 32 | .. doxygenfunction:: fdim(E1&&, E2&&) 33 | 34 | .. doxygenfunction:: clip(E1&&, E2&&, E3&&) 35 | 36 | .. doxygenfunction:: sign(E&&) 37 | -------------------------------------------------------------------------------- /docs/source/api/classif_functions.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Classification functions 8 | ======================== 9 | 10 | **xtensor** provides the following classification functions for xexpressions and scalars: 11 | 12 | Defined in ``xtensor/core/xmath.hpp`` 13 | 14 | .. doxygenfunction:: isfinite(E&&) 15 | 16 | .. doxygenfunction:: isinf(E&&) 17 | 18 | .. doxygenfunction:: isnan(E&&) 19 | 20 | .. doxygenfunction:: isclose(E1&&, E2&&, double, double, bool) 21 | 22 | .. doxygenfunction:: allclose(E1&&, E2&, double, double) 23 | -------------------------------------------------------------------------------- /docs/source/api/container_index.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Containers and views 8 | ==================== 9 | 10 | Containers are in-memory expressions that share a common implementation of most of the methods of the xexpression API. 11 | The final container classes (:cpp:type:`xt::xarray`, :cpp:type:`xt::xtensor`) mainly implement constructors and value semantic, most of the 12 | xexpression API is actually implemented in ``xstrided_container`` and ``xcontainer``. 13 | 14 | .. toctree:: 15 | 16 | xcontainer 17 | xaccessible 18 | xiterable 19 | xarray 20 | xarray_adaptor 21 | xchunked_array 22 | xtensor 23 | xtensor_adaptor 24 | xfixed 25 | xadapt 26 | xoptional_assembly_base 27 | xoptional_assembly 28 | xoptional_assembly_adaptor 29 | xmasked_view 30 | xview 31 | xstrided_view 32 | xbroadcast 33 | xindex_view 34 | xfunctor_view 35 | xrepeat 36 | xfft 37 | -------------------------------------------------------------------------------- /docs/source/api/error_functions.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Error and gamma functions 8 | ========================= 9 | 10 | **xtensor** provides the following error and gamma functions for xexpressions: 11 | 12 | Defined in ``xtensor/core/xmath.hpp`` 13 | 14 | .. doxygenfunction:: erf(E&&) 15 | 16 | .. doxygenfunction:: erfc(E&&) 17 | 18 | .. doxygenfunction:: tgamma(E&&) 19 | 20 | .. doxygenfunction:: lgamma(E&&) 21 | -------------------------------------------------------------------------------- /docs/source/api/exponential_functions.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Exponential functions 8 | ===================== 9 | 10 | **xtensor** provides the following exponential functions for xexpressions: 11 | 12 | Defined in ``xtensor/core/xmath.hpp`` 13 | 14 | .. doxygenfunction:: exp(E&&) 15 | 16 | .. doxygenfunction:: exp2(E&&) 17 | 18 | .. doxygenfunction:: expm1(E&&) 19 | 20 | .. doxygenfunction:: log(E&&) 21 | 22 | .. doxygenfunction:: log2(E&&) 23 | 24 | .. doxygenfunction:: log10(E&&) 25 | 26 | .. doxygenfunction:: log1p(E&&) 27 | -------------------------------------------------------------------------------- /docs/source/api/expression_index.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Expressions and semantic 8 | ======================== 9 | 10 | :cpp:type:`xt::xexpression` and the semantic classes contain all the methods required to perform evaluation and 11 | assignment of expressions. They define the computed assignment operators, the assignment methods for 12 | ``noalias`` and the downcast methods. 13 | 14 | .. toctree:: 15 | 16 | xexpression 17 | xsemantic_base 18 | xcontainer_semantic 19 | xview_semantic 20 | xeval 21 | -------------------------------------------------------------------------------- /docs/source/api/function_index.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Functions and generators 8 | ======================== 9 | 10 | .. toctree:: 11 | 12 | xfunction 13 | xreducer 14 | xaccumulator 15 | xgenerator 16 | xbuilder 17 | xmanipulation 18 | xsort 19 | xset_operation 20 | xrandom 21 | xhistogram 22 | xpad 23 | -------------------------------------------------------------------------------- /docs/source/api/hyperbolic_functions.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Hyperbolic functions 8 | ==================== 9 | 10 | **xtensor** provides the following hyperbolic functions for xexpressions: 11 | 12 | Defined in ``xtensor/core/xmath.hpp`` 13 | 14 | .. _sinh-function-reference: 15 | .. doxygenfunction:: sinh(E&&) 16 | 17 | .. _cosh-function-reference: 18 | .. doxygenfunction:: cosh(E&&) 19 | 20 | .. _tanh-function-reference: 21 | .. doxygenfunction:: tanh(E&&) 22 | 23 | .. _asinh-func-ref: 24 | .. doxygenfunction:: asinh(E&&) 25 | 26 | .. _acosh-func-ref: 27 | .. doxygenfunction:: acosh(E&&) 28 | 29 | .. _atanh-func-ref: 30 | .. doxygenfunction:: atanh(E&&) 31 | -------------------------------------------------------------------------------- /docs/source/api/index_related.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Index related functions 8 | ======================= 9 | 10 | Defined in ``xtensor/core/xoperation.hpp`` 11 | 12 | .. doxygenfunction:: where(const T&) 13 | 14 | .. doxygenfunction:: nonzero(const T&) 15 | 16 | .. doxygenfunction:: argwhere 17 | 18 | .. doxygenfunction:: from_indices 19 | -------------------------------------------------------------------------------- /docs/source/api/io_index.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | IO Operations 8 | ============= 9 | 10 | .. toctree:: 11 | 12 | xio 13 | xnpy 14 | xcsv 15 | xjson 16 | -------------------------------------------------------------------------------- /docs/source/api/iterator_index.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Iterators 8 | ========= 9 | 10 | In addition to the iterators defined in the different types of expressions, *xtensor* provides 11 | classes that allow to iterate over slices of an expression along a specified axis. 12 | 13 | .. toctree:: 14 | 15 | xaxis_iterator 16 | xaxis_slice_iterator 17 | -------------------------------------------------------------------------------- /docs/source/api/nan_functions.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | NaN functions 8 | ============= 9 | 10 | **xtensor** provides the following functions that deal with NaNs in xexpressions: 11 | 12 | Defined in ``xtensor/core/xmath.hpp`` 13 | 14 | .. doxygenfunction:: nan_to_num(E&&) 15 | 16 | .. doxygenfunction:: nanmin(E&&, X&&, EVS) 17 | 18 | .. doxygenfunction:: nanmax(E&&, X&&, EVS) 19 | 20 | .. doxygenfunction:: nansum(E&&, X&&, EVS) 21 | 22 | .. doxygenfunction:: nanmean(E&&, X&&, EVS) 23 | 24 | .. doxygenfunction:: nanvar(E&&, X&&, EVS) 25 | 26 | .. doxygenfunction:: nanstd(E&&, X&&, EVS) 27 | 28 | .. doxygenfunction:: nanprod(E&&, X&&, EVS) 29 | 30 | .. doxygenfunction:: nancumsum(E&&) 31 | 32 | .. doxygenfunction:: nancumsum(E&&, std::ptrdiff_t) 33 | 34 | .. doxygenfunction:: nancumprod(E&&) 35 | 36 | .. doxygenfunction:: nancumprod(E&&, std::ptrdiff_t) 37 | -------------------------------------------------------------------------------- /docs/source/api/nearint_operations.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Nearest integer floating point operations 8 | ========================================= 9 | 10 | **xtensor** provides the following rounding operations for xexpressions: 11 | 12 | Defined in ``xtensor/core/xmath.hpp`` 13 | 14 | .. doxygenfunction:: ceil(E&&) 15 | 16 | .. doxygenfunction:: floor(E&&) 17 | 18 | .. doxygenfunction:: trunc(E&&) 19 | 20 | .. doxygenfunction:: round(E&&) 21 | 22 | .. doxygenfunction:: nearbyint(E&&) 23 | 24 | .. doxygenfunction:: rint(E&&) 25 | -------------------------------------------------------------------------------- /docs/source/api/operators.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Operators and related functions 8 | =============================== 9 | 10 | Defined in ``xtensor/core/xmath.hpp`` and ``xtensor/core/xoperation.hpp`` 11 | 12 | .. doxygenfunction:: operator+(E&&) 13 | 14 | .. doxygenfunction:: operator-(E&&) 15 | 16 | .. doxygenfunction:: operator+(E1&&, E2&&) 17 | 18 | .. doxygenfunction:: operator-(E1&&, E2&&) 19 | 20 | .. doxygenfunction:: operator*(E1&&, E2&&) 21 | 22 | .. doxygenfunction:: operator/(E1&&, E2&&) 23 | 24 | .. doxygenfunction:: operator||(E1&&, E2&&) 25 | 26 | .. doxygenfunction:: operator&&(E1&&, E2&&) 27 | 28 | .. doxygenfunction:: operator!(E&&) 29 | 30 | .. doxygenfunction:: where(E1&&, E2&&, E3&&) 31 | 32 | .. doxygenfunction:: any(E&&) 33 | 34 | .. doxygenfunction:: all(E&&) 35 | 36 | .. doxygenfunction:: operator<(E1&&, E2&&) 37 | 38 | .. doxygenfunction:: operator<=(E1&&, E2&&) 39 | 40 | .. doxygenfunction:: operator>(E1&&, E2&&) 41 | 42 | .. doxygenfunction:: operator>=(E1&&, E2&&) 43 | 44 | .. doxygenfunction:: operator==(const xexpression&, const xexpression&) 45 | 46 | .. doxygenfunction:: operator!=(const xexpression&, const xexpression&) 47 | 48 | .. doxygenfunction:: equal(E1&&, E2&&) 49 | 50 | .. doxygenfunction:: not_equal(E1&&, E2&&) 51 | 52 | .. doxygenfunction:: less(E1&& e1, E2&& e2) 53 | 54 | .. doxygenfunction:: less_equal(E1&& e1, E2&& e2) 55 | 56 | .. doxygenfunction:: greater(E1&& e1, E2&& e2) 57 | 58 | .. doxygenfunction:: greater_equal(E1&& e1, E2&& e2) 59 | 60 | .. doxygenfunction:: operator&(E1&&, E2&&) 61 | 62 | .. doxygenfunction:: operator|(E1&&, E2&&) 63 | 64 | .. doxygenfunction:: operator^(E1&&, E2&&) 65 | 66 | .. doxygenfunction:: operator~(E&&) 67 | 68 | .. doxygenfunction:: left_shift(E1&&, E2&&) 69 | 70 | .. doxygenfunction:: right_shift(E1&&, E2&&) 71 | 72 | .. doxygenfunction:: operator<<(E1&&, E2&&) 73 | 74 | .. doxygenfunction:: operator>>(E1&&, E2&&) 75 | 76 | .. doxygenfunction:: cast(E&&) 77 | -------------------------------------------------------------------------------- /docs/source/api/power_functions.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | 8 | Power functions 9 | =============== 10 | 11 | **xtensor** provides the following power functions for xexpressions and scalars: 12 | 13 | Defined in ``xtensor/core/xmath.hpp`` 14 | 15 | .. doxygenfunction:: pow(E1&&, E2&&) 16 | 17 | .. doxygenfunction:: pow(E&&) 18 | 19 | .. doxygenfunction:: square(E1&&) 20 | 21 | .. doxygenfunction:: cube(E1&&) 22 | 23 | .. doxygenfunction:: sqrt(E&&) 24 | 25 | .. doxygenfunction:: cbrt(E&&) 26 | 27 | .. doxygenfunction:: hypot(E1&&, E2&&) 28 | -------------------------------------------------------------------------------- /docs/source/api/reducing_functions.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Reducing functions 8 | ================== 9 | 10 | **xtensor** provides the following reducing functions for xexpressions: 11 | 12 | Defined in ``xtensor/core/xmath.hpp`` 13 | 14 | .. doxygenfunction:: sum(E&&, EVS) 15 | 16 | .. doxygenfunction:: sum(E&&, X&&, EVS) 17 | 18 | .. doxygenfunction:: prod(E&&, EVS) 19 | 20 | .. doxygenfunction:: prod(E&&, X&&, EVS) 21 | 22 | .. doxygenfunction:: mean(E&&, EVS) 23 | 24 | .. doxygenfunction:: mean(E&&, X&&, EVS) 25 | 26 | .. doxygenfunction:: average(E&&, EVS) 27 | 28 | .. doxygenfunction:: variance(E&&, EVS) 29 | 30 | .. doxygenfunction:: variance(E&&, X&&, EVS) 31 | 32 | .. doxygenfunction:: variance(E&&, X&&, const D&, EVS) 33 | 34 | .. doxygenfunction:: stddev(E&&, EVS) 35 | 36 | .. doxygenfunction:: stddev(E&&, X&&, EVS) 37 | 38 | .. doxygenfunction:: diff(const xexpression&, unsigned int, std::ptrdiff_t) 39 | 40 | .. doxygenfunction:: amax(E&&, EVS) 41 | 42 | .. doxygenfunction:: amax(E&&, X&&, EVS) 43 | 44 | .. doxygenfunction:: amin(E&&, EVS) 45 | 46 | .. doxygenfunction:: amin(E&&, X&&, EVS) 47 | 48 | .. doxygenfunction:: trapz(const xexpression&, double, std::ptrdiff_t) 49 | 50 | .. doxygenfunction:: trapz(const xexpression&, const xexpression&, std::ptrdiff_t) 51 | 52 | Defined in ``xtensor/reducers/xnorm.hpp`` 53 | 54 | .. doxygenfunction:: norm_l0(E&&, X&&, EVS) 55 | 56 | .. doxygenfunction:: norm_l1(E&&, X&&, EVS) 57 | 58 | .. doxygenfunction:: norm_sq(E&&, X&&, EVS) 59 | 60 | .. doxygenfunction:: norm_l2(E&&, X&&, EVS) 61 | 62 | .. doxygenfunction:: norm_linf(E&&, X&&, EVS) 63 | 64 | .. doxygenfunction:: norm_lp_to_p(E&&, double, X&&, EVS) 65 | 66 | .. doxygenfunction:: norm_lp(E&&, double, X&&, EVS) 67 | 68 | .. doxygenfunction:: norm_induced_l1(E&&, EVS) 69 | 70 | .. doxygenfunction:: norm_induced_linf(E&&, EVS) 71 | -------------------------------------------------------------------------------- /docs/source/api/shape.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Shape/index manipulation 8 | ======================== 9 | 10 | .. toctree:: 11 | 12 | xshape 13 | xstrides 14 | -------------------------------------------------------------------------------- /docs/source/api/trigonometric_functions.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Trigonometric functions 8 | ======================= 9 | 10 | **xtensor** provides the following trigonometric functions for xexpressions and scalars: 11 | 12 | Defined in ``xtensor/core/xmath.hpp`` 13 | 14 | .. doxygenfunction:: sin(E&&) 15 | 16 | .. doxygenfunction:: cos(E&&) 17 | 18 | .. doxygenfunction:: tan(E&&) 19 | 20 | .. doxygenfunction:: asin(E&&) 21 | 22 | .. doxygenfunction:: acos(E&&) 23 | 24 | .. doxygenfunction:: atan(E&&) 25 | 26 | .. doxygenfunction:: atan2(E1&&, E2&&) 27 | -------------------------------------------------------------------------------- /docs/source/api/xaccumulator.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xaccumulator 8 | ============ 9 | 10 | Defined in ``xtensor/reducers/xaccumulator.hpp`` 11 | 12 | .. doxygenfunction:: xt::accumulate(F&&, E&&, EVS) 13 | 14 | .. doxygenfunction:: xt::accumulate(F&&, E&&, std::ptrdiff_t, EVS) 15 | -------------------------------------------------------------------------------- /docs/source/api/xadapt.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xadapt 8 | ====== 9 | 10 | Defined in ``xtensor/containers/xadapt.hpp`` 11 | 12 | .. cpp:namespace-push:: xt 13 | 14 | .. doxygengroup:: xt_xadapt 15 | 16 | .. cpp:namespace-pop:: 17 | -------------------------------------------------------------------------------- /docs/source/api/xarray.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xarray 8 | ====== 9 | 10 | Defined in ``xtensor/containers/xarray.hpp`` 11 | 12 | .. doxygenclass:: xt::xarray_container 13 | :members: 14 | 15 | .. doxygentypedef:: xt::xarray 16 | 17 | .. doxygentypedef:: xt::xarray_optional 18 | -------------------------------------------------------------------------------- /docs/source/api/xarray_adaptor.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xarray_adaptor 8 | ============== 9 | 10 | Defined in ``xtensor/containers/xarray.hpp`` 11 | 12 | .. doxygenclass:: xt::xarray_adaptor 13 | :members: 14 | -------------------------------------------------------------------------------- /docs/source/api/xaxis_iterator.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xaxis_iterator 8 | ============== 9 | 10 | Defined in ``xtensor/views/xaxis_iterator.hpp`` 11 | 12 | .. doxygenclass:: xt::xaxis_iterator 13 | :members: 14 | 15 | .. doxygenfunction:: operator==(const xaxis_iterator&, const xaxis_iterator&) 16 | 17 | 18 | .. doxygenfunction:: operator!=(const xaxis_iterator&, const xaxis_iterator&) 19 | 20 | .. doxygenfunction:: axis_begin(E&&) 21 | 22 | .. doxygenfunction:: axis_begin(E&&, typename std::decay_t::size_type) 23 | 24 | .. doxygenfunction:: axis_end(E&&) 25 | 26 | .. doxygenfunction:: axis_end(E&&, typename std::decay_t::size_type) 27 | -------------------------------------------------------------------------------- /docs/source/api/xaxis_slice_iterator.rst: -------------------------------------------------------------------------------- 1 | 2 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 3 | 4 | Distributed under the terms of the BSD 3-Clause License. 5 | 6 | The full license is in the file LICENSE, distributed with this software. 7 | 8 | xaxis_slice_iterator 9 | ==================== 10 | 11 | Defined in ``xtensor/views/xaxis_slice_iterator.hpp`` 12 | 13 | .. doxygenclass:: xt::xaxis_slice_iterator 14 | :members: 15 | 16 | .. doxygenfunction:: operator==(const xaxis_slice_iterator&, const xaxis_slice_iterator&) 17 | 18 | 19 | .. doxygenfunction:: operator!=(const xaxis_slice_iterator&, const xaxis_slice_iterator&) 20 | 21 | .. doxygenfunction:: axis_slice_begin(E&&) 22 | 23 | .. doxygenfunction:: axis_slice_begin(E&&, typename std::decay_t::size_type) 24 | 25 | .. doxygenfunction:: axis_slice_end(E&&) 26 | 27 | .. doxygenfunction:: axis_slice_end(E&&, typename std::decay_t::size_type) 28 | -------------------------------------------------------------------------------- /docs/source/api/xbroadcast.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xbroadcast 8 | ========== 9 | 10 | Defined in ``xtensor/views/xbroadcast.hpp`` 11 | 12 | .. doxygenclass:: xt::xbroadcast 13 | :members: 14 | 15 | .. doxygenfunction:: xt::broadcast(E&&, const S&) 16 | -------------------------------------------------------------------------------- /docs/source/api/xbuilder.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xbuilder 8 | ======== 9 | 10 | Defined in ``xtensor/generators/xbuilder.hpp`` 11 | 12 | .. doxygenfunction:: xt::ones(S) 13 | 14 | .. doxygenfunction:: xt::ones(const I (&)[L]) 15 | 16 | .. doxygenfunction:: xt::zeros(S) 17 | 18 | .. doxygenfunction:: xt::zeros(const I (&)[L]) 19 | 20 | .. doxygenfunction:: xt::empty(const S&) 21 | 22 | .. doxygenfunction:: xt::full_like(const xexpression&) 23 | 24 | .. doxygenfunction:: xt::empty_like(const xexpression&) 25 | 26 | .. doxygenfunction:: xt::zeros_like(const xexpression&) 27 | 28 | .. doxygenfunction:: xt::ones_like(const xexpression&) 29 | 30 | .. doxygenfunction:: xt::eye(const std::vector&, int) 31 | 32 | .. doxygenfunction:: xt::eye(std::size_t, int) 33 | 34 | .. doxygenfunction:: xt::arange(T, T, S) 35 | 36 | .. doxygenfunction:: xt::arange(T) 37 | 38 | .. doxygenfunction:: xt::linspace 39 | 40 | .. doxygenfunction:: xt::logspace 41 | 42 | .. doxygenfunction:: xt::concatenate(std::tuple&&, std::size_t) 43 | 44 | .. doxygenfunction:: xt::stack 45 | 46 | .. doxygenfunction:: xt::hstack 47 | 48 | .. doxygenfunction:: xt::vstack 49 | 50 | .. doxygenfunction:: xt::meshgrid 51 | 52 | .. doxygenfunction:: xt::diag 53 | 54 | .. doxygenfunction:: xt::diagonal 55 | 56 | .. doxygenfunction:: xt::tril 57 | 58 | .. doxygenfunction:: xt::triu 59 | -------------------------------------------------------------------------------- /docs/source/api/xchunked_array.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvaidan Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xchunked_array 8 | ============== 9 | 10 | .. cpp:namespace-push:: xt 11 | 12 | .. doxygengroup:: xt_xchunked_array 13 | 14 | .. cpp:namespace-pop:: 15 | -------------------------------------------------------------------------------- /docs/source/api/xcontainer.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | layout 8 | ====== 9 | 10 | Defined in ``xtensor/core/xlayout.hpp`` 11 | 12 | .. doxygenenum:: xt::layout_type 13 | 14 | .. doxygenfunction:: xt::compute_layout(Args... args) 15 | 16 | xcontainer 17 | ========== 18 | 19 | Defined in ``xtensor/containers/xcontainer.hpp`` 20 | 21 | .. doxygenclass:: xt::xcontainer 22 | :members: 23 | 24 | xstrided_container 25 | ================== 26 | 27 | Defined in ``xtensor/containers/xcontainer.hpp`` 28 | 29 | .. doxygenclass:: xt::xstrided_container 30 | :members: 31 | -------------------------------------------------------------------------------- /docs/source/api/xcontainer_semantic.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xcontainer_semantic 8 | =================== 9 | 10 | Defined in ``xtensor/core/xsemantic.hpp`` 11 | 12 | .. doxygenclass:: xt::xcontainer_semantic 13 | :members: 14 | -------------------------------------------------------------------------------- /docs/source/api/xcsv.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xcsv: read/write CSV files 8 | ========================== 9 | 10 | Defined in ``xtensor/io/xcsv.hpp`` 11 | 12 | .. doxygenfunction:: xt::load_csv 13 | 14 | .. doxygenfunction:: xt::dump_csv 15 | -------------------------------------------------------------------------------- /docs/source/api/xeval.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xeval 8 | ===== 9 | 10 | .. cpp:namespace-push:: xt 11 | 12 | .. doxygengroup:: xt_xeval 13 | 14 | .. cpp:namespace-pop:: 15 | -------------------------------------------------------------------------------- /docs/source/api/xexpression.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xexpression 8 | =========== 9 | 10 | Defined in ``xtensor/core/xexpression.hpp`` 11 | 12 | .. doxygenclass:: xt::xexpression 13 | :members: 14 | 15 | .. doxygenclass:: xt::xshared_expression 16 | :members: 17 | 18 | .. doxygenfunction:: make_xshared 19 | 20 | .. doxygenfunction:: share(xexpression&) 21 | 22 | .. doxygenfunction:: share(xexpression&&) 23 | -------------------------------------------------------------------------------- /docs/source/api/xfixed.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xtensor_fixed 8 | ============= 9 | 10 | Defined in ``xtensor/containers/xfixed.hpp`` 11 | 12 | .. doxygenclass:: xt::xfixed_container 13 | :members: 14 | 15 | .. doxygentypedef:: xt::xtensor_fixed 16 | -------------------------------------------------------------------------------- /docs/source/api/xfunction.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xfunction 8 | ========= 9 | 10 | Defined in ``xtensor/core/xfunction.hpp`` 11 | 12 | .. doxygenclass:: xt::xfunction 13 | :members: 14 | 15 | Defined in ``xtensor/core/xmath.hpp`` 16 | 17 | .. doxygenfunction:: make_lambda_xfunction 18 | -------------------------------------------------------------------------------- /docs/source/api/xfunctor_view.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xfunctor_view 8 | ============= 9 | 10 | .. cpp:namespace-push:: xt 11 | 12 | .. doxygengroup:: xt_xfunctor_view 13 | :members: 14 | :undoc-members: 15 | 16 | .. doxygengroup:: xt_xcomplex 17 | 18 | .. cpp:namespace-pop:: 19 | -------------------------------------------------------------------------------- /docs/source/api/xgenerator.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xgenerator 8 | ========== 9 | 10 | Defined in ``xtensor/generators/xgenerator.hpp`` 11 | 12 | .. doxygenclass:: xt::xgenerator 13 | :members: 14 | -------------------------------------------------------------------------------- /docs/source/api/xhistogram.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xhistogram 8 | ========== 9 | 10 | Defined in ``xtensor/misc/xhistogram.hpp`` 11 | 12 | .. doxygenenum:: xt::histogram_algorithm 13 | 14 | .. doxygenfunction:: xt::histogram(E1&&, E2&&, E3&&, bool) 15 | 16 | .. doxygenfunction:: xt::bincount(E1&&, E2&&, std::size_t) 17 | 18 | .. doxygenfunction:: xt::histogram_bin_edges(E1&&, E2&&, E3, E3, std::size_t, histogram_algorithm) 19 | 20 | .. doxygenfunction:: xt::digitize(E1&&, E2&&, E3&&, bool, bool) 21 | 22 | .. doxygenfunction:: xt::bin_items(size_t, E&&) 23 | 24 | Further overloads 25 | ----------------- 26 | 27 | .. doxygenfunction:: xt::histogram(E1&&, E2&&, bool) 28 | 29 | .. doxygenfunction:: xt::histogram(E1&&, std::size_t, bool) 30 | 31 | .. doxygenfunction:: xt::histogram(E1&&, std::size_t, E2, E2, bool) 32 | 33 | .. doxygenfunction:: xt::histogram(E1&&, std::size_t, E2&&, bool) 34 | 35 | .. doxygenfunction:: xt::histogram(E1&&, std::size_t, E2&&, E3, E3, bool) 36 | 37 | .. doxygenfunction:: xt::histogram_bin_edges(E1&&, E2, E2, std::size_t, histogram_algorithm) 38 | 39 | .. doxygenfunction:: xt::histogram_bin_edges(E1&&, E2&&, std::size_t, histogram_algorithm) 40 | 41 | .. doxygenfunction:: xt::histogram_bin_edges(E1&&, std::size_t, histogram_algorithm) 42 | 43 | .. doxygenfunction:: xt::bin_items(size_t, size_t) 44 | -------------------------------------------------------------------------------- /docs/source/api/xindex_view.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xindex_view 8 | =========== 9 | 10 | Defined in ``xtensor/views/xindex_view.hpp`` 11 | 12 | .. doxygenclass:: xt::xindex_view 13 | :members: 14 | 15 | .. doxygenclass:: xt::xfiltration 16 | :members: 17 | 18 | .. doxygenfunction:: xt::index_view(E&&, I&&) 19 | 20 | .. doxygenfunction:: xt::filter 21 | 22 | .. doxygenfunction:: xt::filtration 23 | -------------------------------------------------------------------------------- /docs/source/api/xio.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xio: pretty printing 8 | ==================== 9 | 10 | Defined in ``xtensor/io/xio.hpp`` 11 | 12 | This file defines functions for pretty printing xexpressions. It defines appropriate 13 | overloads for the ``<<`` operator for std::ostreams and xexpressions. 14 | 15 | .. code:: 16 | 17 | #include 18 | #include 19 | 20 | int main() 21 | { 22 | xt::xarray a = {{1,2,3}, {4,5,6}}; 23 | std::cout << a << std::endl; 24 | return 0; 25 | } 26 | 27 | Will print 28 | 29 | .. code:: 30 | 31 | {{ 1., 2., 3.}, 32 | { 4., 5., 6.}} 33 | 34 | With the following functions, the global print options can be set: 35 | 36 | .. doxygenfunction:: xt::print_options::set_line_width 37 | 38 | .. doxygenfunction:: xt::print_options::set_threshold 39 | 40 | .. doxygenfunction:: xt::print_options::set_edge_items 41 | 42 | .. doxygenfunction:: xt::print_options::set_precision 43 | 44 | On can also locally overwrite the print options with io manipulators: 45 | 46 | .. doxygenclass:: xt::print_options::line_width 47 | 48 | .. doxygenclass:: xt::print_options::threshold 49 | 50 | .. doxygenclass:: xt::print_options::edge_items 51 | 52 | .. doxygenclass:: xt::print_options::precision 53 | -------------------------------------------------------------------------------- /docs/source/api/xiterable.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xiterable 8 | ========= 9 | 10 | Defined in ``xtensor/core/xiterable.hpp`` 11 | 12 | .. doxygenclass:: xt::xconst_iterable 13 | :members: 14 | 15 | .. doxygenclass:: xt::xiterable 16 | :members: 17 | 18 | .. doxygenclass:: xt::xcontiguous_iterable 19 | :members: 20 | -------------------------------------------------------------------------------- /docs/source/api/xjson.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xjson: serialize to/from JSON 8 | ============================= 9 | 10 | Defined in ``xtensor/io/xjson.hpp`` 11 | 12 | .. doxygenfunction:: xt::to_json(nlohmann::json&, const E&); 13 | 14 | .. doxygenfunction:: xt::from_json(const nlohmann::json&, E&); 15 | -------------------------------------------------------------------------------- /docs/source/api/xmanipulation.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xmanipulation 8 | ============= 9 | 10 | Defined in ``xtensor/misc/xmanipulation.hpp`` 11 | 12 | .. cpp:namespace-push:: xt 13 | 14 | .. doxygengroup:: xt_xmanipulation 15 | 16 | .. cpp:namespace-pop:: 17 | -------------------------------------------------------------------------------- /docs/source/api/xmasked_view.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xmasked_view 8 | ============ 9 | 10 | Defined in ``xtensor/views/xmasked_view.hpp`` 11 | 12 | .. doxygenclass:: xt::xmasked_view 13 | :members: 14 | -------------------------------------------------------------------------------- /docs/source/api/xnpy.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xnpy: read/write NPY files 8 | ========================== 9 | 10 | Defined in ``xtensor/io/xnpy.hpp`` 11 | 12 | .. doxygenfunction:: xt::load_npy(std::istream&) 13 | 14 | .. doxygenfunction:: xt::load_npy(const std::string&) 15 | 16 | .. doxygenfunction:: xt::dump_npy(const std::string&, const xexpression&) 17 | 18 | .. doxygenfunction:: xt::dump_npy(const xexpression&) 19 | -------------------------------------------------------------------------------- /docs/source/api/xoptional_assembly.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xoptional_assembly 8 | ================== 9 | 10 | Defined in ``xtensor/optional/xoptional_assembly.hpp`` 11 | 12 | .. doxygenclass:: xt::xoptional_assembly 13 | :members: 14 | -------------------------------------------------------------------------------- /docs/source/api/xoptional_assembly_adaptor.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xoptional_assembly_adaptor 8 | ========================== 9 | 10 | Defined in ``xtensor/optional/xoptional_assembly.hpp`` 11 | 12 | .. doxygenclass:: xt::xoptional_assembly_adaptor 13 | :members: 14 | -------------------------------------------------------------------------------- /docs/source/api/xoptional_assembly_base.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xoptional_assembly_base 8 | ======================= 9 | 10 | Defined in ``xtensor/optional/xoptional_assembly_base.hpp`` 11 | 12 | .. doxygenclass:: xt::xoptional_assembly_base 13 | :members: 14 | -------------------------------------------------------------------------------- /docs/source/api/xpad.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xpad 8 | ==== 9 | 10 | Defined in ``xtensor/misc/xpad.hpp`` 11 | 12 | .. doxygenenum:: xt::pad_mode 13 | 14 | .. doxygenfunction:: xt::pad(E&& , const std::vector>&, pad_mode, V) 15 | 16 | .. doxygenfunction:: xt::pad(E&& , const std::vector&, pad_mode, V) 17 | 18 | .. doxygenfunction:: xt::pad(E&& , S, pad_mode, V) 19 | 20 | .. doxygenfunction:: xt::tile(E&& , std::initializer_list) 21 | 22 | .. doxygenfunction:: xt::tile(E&& , S) 23 | -------------------------------------------------------------------------------- /docs/source/api/xrandom.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xrandom 8 | ======= 9 | 10 | Defined in ``xtensor/generators/xrandom.hpp`` 11 | 12 | .. warning:: xtensor uses a lazy generator for random numbers. You need to assign them or use ``eval`` to keep the generated values consistent. 13 | 14 | .. doxygenfunction:: xt::random::get_default_random_engine 15 | 16 | .. doxygenfunction:: xt::random::seed 17 | 18 | .. doxygenfunction:: xt::random::rand(const S&, T, T, E&) 19 | 20 | .. doxygenfunction:: xt::random::randint(const S&, T, T, E&) 21 | 22 | .. doxygenfunction:: xt::random::randn(const S&, T, T, E&) 23 | 24 | .. doxygenfunction:: xt::random::binomial(const S&, T, D, E&) 25 | 26 | .. doxygenfunction:: xt::random::geometric(const S&, D, E&) 27 | 28 | .. doxygenfunction:: xt::random::negative_binomial(const S&, T, D, E&) 29 | 30 | .. doxygenfunction:: xt::random::poisson(const S&, D, E&) 31 | 32 | .. doxygenfunction:: xt::random::exponential(const S&, T, E&) 33 | 34 | .. doxygenfunction:: xt::random::gamma(const S&, T, T, E&) 35 | 36 | .. doxygenfunction:: xt::random::weibull(const S&, T, T, E&) 37 | 38 | .. doxygenfunction:: xt::random::extreme_value(const S&, T, T, E&) 39 | 40 | .. doxygenfunction:: xt::random::lognormal(const S&, T, T, E&) 41 | 42 | .. doxygenfunction:: xt::random::chi_squared(const S&, T, E&) 43 | 44 | .. doxygenfunction:: xt::random::cauchy(const S&, T, T, E&) 45 | 46 | .. doxygenfunction:: xt::random::fisher_f(const S&, T, T, E&) 47 | 48 | .. doxygenfunction:: xt::random::student_t(const S&, T, E&) 49 | 50 | .. doxygenfunction:: xt::random::choice(const xexpression&, std::size_t, bool, E&) 51 | .. doxygenfunction:: xt::random::choice(const xexpression&, std::size_t, const xexpression&, bool, E&) 52 | 53 | .. doxygenfunction:: xt::random::shuffle 54 | 55 | .. doxygenfunction:: xt::random::permutation(T, E&) 56 | -------------------------------------------------------------------------------- /docs/source/api/xreducer.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xreducer 8 | ======== 9 | 10 | Defined in ``xtensor/reducers/xreducer.hpp`` 11 | 12 | .. doxygenclass:: xt::xreducer 13 | :members: 14 | 15 | .. doxygenfunction:: xt::reduce(F&&, E&&, X&&, EVS&&) 16 | -------------------------------------------------------------------------------- /docs/source/api/xrepeat.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xrepeat 8 | ======= 9 | 10 | Defined in ``xtensor/views/xrepeat.hpp`` 11 | 12 | .. doxygenclass:: xt::xrepeat 13 | :members: 14 | -------------------------------------------------------------------------------- /docs/source/api/xsemantic_base.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xsemantic_base 8 | ============== 9 | 10 | Defined in ``xtensor/core/xsemantic.hpp`` 11 | 12 | .. doxygenclass:: xt::xsemantic_base 13 | :members: 14 | -------------------------------------------------------------------------------- /docs/source/api/xset_operation.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xset_operation 8 | ============== 9 | 10 | Defined in ``xtensor/misc/xset_operation.hpp`` 11 | 12 | .. doxygenenum:: xt::isin(E&&, F&&) 13 | 14 | .. doxygenenum:: xt::in1d(E&&, F&&) 15 | 16 | .. doxygenenum:: xt::searchsorted(E1&&, E2&&, bool) 17 | 18 | Further overloads 19 | ----------------- 20 | 21 | .. doxygenenum:: xt::isin(E&&, std::initializer_list) 22 | 23 | .. doxygenenum:: xt::isin(E&&, I&&, I&&) 24 | 25 | .. doxygenenum:: xt::in1d(E&&, std::initializer_list) 26 | 27 | .. doxygenenum:: xt::in1d(E&&, I&&, I&&) 28 | -------------------------------------------------------------------------------- /docs/source/api/xshape.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xshape 8 | ====== 9 | 10 | Defined in ``xtensor/core/xshape.hpp`` 11 | 12 | .. cpp:namespace-push:: xt 13 | 14 | .. doxygengroup:: xt_xshape 15 | 16 | .. cpp:namespace-pop:: 17 | -------------------------------------------------------------------------------- /docs/source/api/xsort.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xsort 8 | ===== 9 | 10 | Defined in ``xtensor/misc/xsort.hpp`` 11 | 12 | .. cpp:namespace-push:: xt 13 | 14 | .. doxygengroup:: xt_xsort 15 | 16 | .. cpp:namespace-pop:: 17 | -------------------------------------------------------------------------------- /docs/source/api/xstrided_view.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xstrided_view 8 | ============= 9 | 10 | Defined in ``xtensor/views/xstrided_view.hpp`` 11 | 12 | .. doxygenclass:: xt::xstrided_view 13 | :members: 14 | 15 | .. doxygentypedef:: xt::xstrided_slice_vector 16 | 17 | .. doxygenfunction:: xt::strided_view(E&&, S&&, X&&, std::size_t, layout_type) 18 | 19 | .. doxygenfunction:: xt::strided_view(E&&, const xstrided_slice_vector&) 20 | 21 | .. doxygenfunction:: xt::reshape_view(E&&, S&&, layout_type) 22 | -------------------------------------------------------------------------------- /docs/source/api/xstrides.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xstrides 8 | ======== 9 | 10 | Defined in ``xtensor/core/xstrides.hpp`` 11 | 12 | .. cpp:namespace-push:: xt 13 | 14 | .. doxygengroup:: xt_xstrides 15 | 16 | .. cpp:namespace-pop:: 17 | -------------------------------------------------------------------------------- /docs/source/api/xtensor.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xtensor 8 | ======= 9 | 10 | Defined in ``xtensor/containers/xtensor.hpp`` 11 | 12 | .. doxygenclass:: xt::xtensor_container 13 | :members: 14 | 15 | .. doxygentypedef:: xt::xtensor 16 | 17 | .. doxygentypedef:: xt::xtensor_optional 18 | 19 | .. doxygenfunction:: xt::from_indices 20 | 21 | .. doxygenfunction:: xt::flatten_indices 22 | 23 | .. doxygenfunction:: xt::ravel_indices 24 | -------------------------------------------------------------------------------- /docs/source/api/xtensor_adaptor.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xtensor_adaptor 8 | =============== 9 | 10 | Defined in ``xtensor/containers/xtensor.hpp`` 11 | 12 | .. doxygenclass:: xt::xtensor_adaptor 13 | :members: 14 | -------------------------------------------------------------------------------- /docs/source/api/xview.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xview 8 | ===== 9 | 10 | Defined in ``xtensor/views/xview.hpp`` 11 | 12 | .. doxygenclass:: xt::xview 13 | :members: 14 | 15 | .. doxygenfunction:: xt::view 16 | 17 | .. doxygenfunction:: xt::row 18 | 19 | .. doxygenfunction:: xt::col 20 | 21 | Defined in ``xtensor/views/xslice.hpp`` 22 | 23 | .. doxygenfunction:: xt::range(A, B) 24 | 25 | .. doxygenfunction:: xt::range(A, B, C) 26 | 27 | .. doxygenfunction:: xt::all 28 | 29 | .. doxygenfunction:: xt::newaxis 30 | 31 | .. doxygenfunction:: xt::ellipsis 32 | 33 | .. doxygenfunction:: xt::keep(T&&) 34 | 35 | .. doxygenfunction:: xt::drop(T&&) 36 | -------------------------------------------------------------------------------- /docs/source/api/xview_semantic.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | xview_semantic 8 | ============== 9 | 10 | Defined in ``xtensor/core/xsemantic.hpp`` 11 | 12 | .. doxygenclass:: xt::xview_semantic 13 | :members: 14 | -------------------------------------------------------------------------------- /docs/source/binder-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 12 | 14 | 16 | 19 | 23 | 26 | 27 | 28 | 29 | 30 | 32 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /docs/source/conda.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | import subprocess 6 | 7 | on_rtd = os.environ.get('READTHEDOCS', None) == 'True' 8 | 9 | if on_rtd: 10 | subprocess.call('cd ..; doxygen', shell=True) 11 | 12 | import sphinx_rtd_theme 13 | 14 | html_theme = "sphinx_rtd_theme" 15 | 16 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] 17 | 18 | def setup(app): 19 | app.add_css_file("main_stylesheet.css") 20 | 21 | extensions = ['breathe', 'sphinx_rtd_theme'] 22 | breathe_projects = { 'xtensor': '../xml' } 23 | breathe_default_project = "xtensor" 24 | templates_path = ['_templates'] 25 | html_static_path = ['_static'] 26 | source_suffix = '.rst' 27 | master_doc = 'index' 28 | project = 'xtensor' 29 | copyright = '2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht' 30 | author = 'Johan Mabille, Sylvain Corlay and Wolf Vollprecht' 31 | 32 | html_logo = 'quantstack-white.svg' 33 | 34 | exclude_patterns = [] 35 | highlight_language = 'c++' 36 | pygments_style = 'sphinx' 37 | todo_include_todos = False 38 | htmlhelp_basename = 'xtensordoc' 39 | 40 | html_js_files = [ 41 | 'goatcounter.js' 42 | ] 43 | 44 | # Automatically link to NumPy doc 45 | extensions += ['sphinx.ext.intersphinx'] 46 | intersphinx_mapping = { 47 | "numpy": ("https://numpy.org/doc/stable/", None), 48 | "scipy": ("https://docs.scipy.org/doc/scipy/reference", None), 49 | "xtensor-blas": ("https://xtensor-blas.readthedocs.io/en/stable", None), 50 | "xtl": ("https://xtl.readthedocs.io/en/stable", None), 51 | } 52 | -------------------------------------------------------------------------------- /docs/source/developer/xtensor_internals.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Internals of xtensor 8 | ==================== 9 | 10 | This section provides information about *xtensor*'s internals and its architecture. It is intended for developers 11 | who want to contribute to *xtensor* or simply understand how it works under the hood. *xtensor* makes heavy use 12 | of the CRTP pattern, template meta-programming, universal references and perfect forwarding. One should be familiar 13 | with these notions before going any further. 14 | 15 | .. toctree:: 16 | 17 | concepts 18 | implementation_classes 19 | expression_tree.rst 20 | iterating_expression.rst 21 | assignment.rst 22 | -------------------------------------------------------------------------------- /docs/source/file_loading.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | File input and output 8 | ===================== 9 | 10 | *xtensor* has some built-in mechanisms to make loading and saving data easy. 11 | The base *xtensor* package allows to save and load data in the ``.csv``, ``.json`` and ``.npy`` 12 | format. 13 | Please note that many more input and output formats are available in the `xtensor-io 14 | `_ package. 15 | `xtensor-io` offers functions to load and store from image files (``jpg``, ``gif``, ``png``...), 16 | sound files (``wav``, ``ogg``...), HDF5 files (``h5``, ``hdf5``, ...), and compressed NumPy format (``npz``). 17 | 18 | 19 | Loading CSV data into xtensor 20 | ----------------------------- 21 | 22 | The following example code demonstrates how to use :cpp:func:`xt::load_csv` and :cpp:func:`xt::dump_csv` to load and 23 | save data in the Comma-separated value format. The reference documentation is :doc:`api/xcsv`. 24 | 25 | .. code:: 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | int main() 35 | { 36 | std::ifstream in_file; 37 | in_file.open("in.csv"); 38 | auto data = xt::load_csv(in_file); 39 | 40 | std::ofstream out_file; 41 | out_file("out.csv"); 42 | 43 | xt::xarray a = {{1,2,3,4}, {5,6,7,8}}; 44 | xt::dump_csv(out_file, a); 45 | 46 | return 0; 47 | } 48 | 49 | Loading NPY data into xtensor 50 | ----------------------------- 51 | 52 | The following example demonstrates how to load and store xtensor data in the ``npy`` "NumPy" format, 53 | using the :cpp:func:`xt::load_npy` and :cpp:func:`xt::dump_npy` functions. 54 | Reference documentation for the functions used is found here :doc:`api/xnpy`. 55 | 56 | .. code:: 57 | 58 | #include 59 | #include 60 | #include 61 | 62 | #include 63 | #include 64 | 65 | int main() 66 | { 67 | // Note: you need to supply the data type you are loading 68 | // in this case "double". 69 | auto data = xt::load_npy("in.npy"); 70 | 71 | xt::xarray a = {{1,2,3,4}, {5,6,7,8}}; 72 | xt::dump_npy("out.npy", a); 73 | 74 | return 0; 75 | } 76 | 77 | Loading JSON data into xtensor 78 | ------------------------------ 79 | 80 | It's possible to load and dump data to json, using the json library written by 81 | `nlohmann` (https://nlohmann.github.io/json/) which offers a convenient way 82 | to handle json data in C++. Note that the library needs to be separately installed. 83 | The reference documentation is found :doc:`api/xjson`. 84 | 85 | 86 | .. code:: 87 | 88 | #include 89 | #include 90 | 91 | int main() 92 | { 93 | 94 | xt::xarray t = {{{1, 2}, 95 | {3, 4}}, 96 | {{1, 2}, 97 | {3, 4}}}; 98 | 99 | nlohmann::json jl = t; 100 | // To obtain the json serialized string 101 | std::string s = jl.dump(); 102 | 103 | xt::xarray res; 104 | auto j = "[[10.0,10.0],[10.0,10.0]]"_json; 105 | xt::from_json(j, res); 106 | } 107 | -------------------------------------------------------------------------------- /docs/source/histogram.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. _histogram: 8 | 9 | Histogram 10 | ========= 11 | 12 | Basic usage 13 | ----------- 14 | 15 | * :cpp:func:`xt::histogram(a, bins[, weights][, density]) ` 16 | * :cpp:func:`xt::histogram_bin_edges(a[, weights][, left, right][, bins][, mode]) ` 17 | 18 | .. note:: 19 | Any of the options ``[...]`` can be omitted (though the order must be preserved). The defaults are: 20 | 21 | * ``weights`` = :cpp:func:`xt::ones(data.shape()) ` 22 | * ``density`` = ``false`` 23 | * ``left`` = :cpp:func:`xt::amin(data)(0) ` 24 | * ``right`` = :cpp:func:`Xt::amax(data)(0) ` 25 | * ``bins`` = ``10`` 26 | * ``mode`` = :cpp:enumerator:`xt::histogram::automatic` 27 | 28 | The behavior, in-, and output of :cpp:func:`xt::histogram` is similar to that of :any:`numpy.histogram` 29 | with that difference that the bin-edges are obtained by a separate function call: 30 | 31 | .. code-block:: cpp 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | int main() 38 | { 39 | xt::xtensor data = {1., 1., 2., 2., 3.}; 40 | 41 | xt::xtensor count = xt::histogram(data, std::size_t(2)); 42 | 43 | xt::xtensor bin_edges = xt::histogram_bin_edges(data, std::size_t(2)); 44 | 45 | return 0; 46 | } 47 | 48 | Bin-edges algorithm 49 | ------------------- 50 | 51 | To customize the algorithm to be used to construct the histogram, one needs to make use of the latter 52 | :cpp:func:`xt::histogram_bin_edges`. For example: 53 | 54 | .. code-block:: cpp 55 | 56 | #include 57 | #include 58 | #include 59 | 60 | int main() 61 | { 62 | xt::xtensor data = {1., 1., 2., 2., 3.}; 63 | 64 | xt::xtensor bin_edges = xt::histogram_bin_edges(data, std::size_t(2), xt::histogram_algorithm::uniform); 65 | 66 | xt::xtensor prob = xt::histogram(data, bin_edges, true); 67 | 68 | std::cout << bin_edges << std::endl; 69 | std::cout << prob << std::endl; 70 | 71 | return 0; 72 | } 73 | 74 | The following :cpp:enum:`xt::histogram_algorithm` are available: 75 | 76 | * :cpp:enumerator:`~xt::histogram_algorithm::automatic`: equivalent to :cpp:enumerator:`~xt::histogram_algorithm::linspace`. 77 | * :cpp:enumerator:`~xt::histogram_algorithm::linspace`: linearly spaced bin-edges. 78 | * :cpp:enumerator:`~xt::histogram_algorithm::logspace`: bins that logarithmically increase in size. 79 | * :cpp:enumerator:`~xt::histogram_algorithm::uniform`: bin-edges such that the number of data points is 80 | the same in all bins (as much as possible). 81 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. image:: xtensor.svg 8 | :alt: xtensor 9 | 10 | Multi-dimensional arrays with broadcasting and lazy computing. 11 | 12 | Introduction 13 | ------------ 14 | 15 | *xtensor* is a C++ library meant for numerical analysis with multi-dimensional 16 | array expressions. 17 | 18 | *xtensor* provides 19 | 20 | - an extensible expression system enabling **lazy broadcasting**. 21 | - an API following the idioms of the **C++ standard library**. 22 | - tools to manipulate array expressions and build upon *xtensor*. 23 | 24 | Containers of *xtensor* are inspired by `NumPy`_, the Python array programming 25 | library. **Adaptors** for existing data structures to be plugged into the 26 | expression system can easily be written. 27 | 28 | In fact, *xtensor* can be used to **process NumPy data structures in-place** 29 | using Python's `buffer protocol`_. For more details on the NumPy bindings, 30 | check out the xtensor-python_ project. Language bindings for R and Julia are 31 | also available. 32 | 33 | *xtensor* requires a modern C++ compiler supporting C++14. The following C++ 34 | compilers are supported: 35 | 36 | - On Windows platforms, Visual C++ 2015 Update 2, or more recent 37 | - On Unix platforms, gcc 4.9 or a recent version of Clang 38 | 39 | Licensing 40 | --------- 41 | 42 | We use a shared copyright model that enables all contributors to maintain the 43 | copyright on their contributions. 44 | 45 | This software is licensed under the BSD-3-Clause license. See the LICENSE file 46 | for details. 47 | 48 | 49 | .. toctree:: 50 | :caption: INSTALLATION 51 | :maxdepth: 1 52 | 53 | installation 54 | changelog 55 | 56 | .. toctree:: 57 | :caption: USAGE 58 | :maxdepth: 2 59 | 60 | getting_started 61 | expression 62 | container 63 | scalar 64 | adaptor 65 | operator 66 | view 67 | indices 68 | builder 69 | missing 70 | histogram 71 | random 72 | rank 73 | file_loading 74 | build-options 75 | pitfall 76 | 77 | .. toctree:: 78 | :caption: QUICK REFERENCE 79 | :maxdepth: 2 80 | 81 | quickref/basic 82 | quickref/builder 83 | quickref/operator 84 | quickref/math 85 | quickref/reducer 86 | view 87 | quickref/iterator 88 | quickref/manipulation 89 | quickref/chunked_arrays 90 | 91 | .. toctree:: 92 | :caption: API REFERENCE 93 | :maxdepth: 2 94 | 95 | api/expression_index 96 | api/container_index 97 | api/iterator_index 98 | api/function_index 99 | api/io_index 100 | api/xmath 101 | api/shape 102 | 103 | .. toctree:: 104 | :caption: DEVELOPER ZONE 105 | :maxdepth: 2 106 | 107 | compilers 108 | dev-build-options 109 | developer/xtensor_internals 110 | external-structures 111 | releasing 112 | 113 | .. toctree:: 114 | :caption: MISCELLANEOUS 115 | 116 | numpy 117 | numpy-differences 118 | closure-semantics 119 | related 120 | bindings 121 | 122 | .. _NumPy: http://www.numpy.org 123 | .. _Buffer Protocol: https://docs.python.org/3/c-api/buffer.html 124 | .. _libdynd: http://libdynd.org 125 | .. _xtensor-python: https://github.com/xtensor-stack/xtensor-python 126 | -------------------------------------------------------------------------------- /docs/source/installation.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | 8 | .. raw:: html 9 | 10 | 20 | 21 | Installation 22 | ============ 23 | 24 | Although *xtensor* is a header-only library, we provide standardized means to 25 | install it, with package managers or with cmake. 26 | 27 | Besides the xtensor headers, all these methods place the ``cmake`` project 28 | configuration file in the right location so that third-party projects can use 29 | cmake's ``find_package`` to locate xtensor headers. 30 | 31 | .. image:: conda.svg 32 | 33 | Using the conda-forge package 34 | ----------------------------- 35 | 36 | A package for xtensor is available on the mamba (or conda) package manager. 37 | 38 | .. code:: 39 | 40 | mamba install -c conda-forge xtensor 41 | 42 | .. image:: debian.svg 43 | 44 | Using the Debian package 45 | ------------------------ 46 | 47 | A package for xtensor is available on Debian. 48 | 49 | .. code:: 50 | 51 | sudo apt-get install xtensor-dev 52 | 53 | .. image:: spack.svg 54 | 55 | Using the Spack package 56 | ----------------------- 57 | 58 | A package for xtensor is available on the Spack package manager. 59 | 60 | .. code:: 61 | 62 | spack install xtensor 63 | spack load --dependencies xtensor 64 | 65 | .. image:: cmake.svg 66 | 67 | From source with cmake 68 | ---------------------- 69 | 70 | You can also install *xtensor* from source with cmake. This requires that you 71 | have the xtl_ library installed on your system. On Unix platforms, from the 72 | source directory: 73 | 74 | .. code:: 75 | 76 | mkdir build 77 | cd build 78 | cmake -DCMAKE_INSTALL_PREFIX=path_to_prefix .. 79 | make install 80 | 81 | On Windows platforms, from the source directory: 82 | 83 | .. code:: 84 | 85 | mkdir build 86 | cd build 87 | cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=path_to_prefix .. 88 | nmake 89 | nmake install 90 | 91 | ``path_to_prefix`` is the absolute path to the folder where cmake searches for 92 | dependencies and installs libraries. *xtensor* installation from cmake assumes 93 | this folder contains ``include`` and ``lib`` subfolders. 94 | 95 | See the :doc:`build-options` section for more details about cmake options. 96 | 97 | Although not officially supported, *xtensor* can be installed with MinGW: 98 | 99 | .. code:: 100 | 101 | mkdir build 102 | cd build 103 | cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=path_to_prefix .. 104 | mingw32-make 105 | mingw32-make install 106 | 107 | Including xtensor in your project 108 | --------------------------------- 109 | 110 | The different packages of *xtensor* are built with cmake, so whatever the 111 | installation mode you choose, you can add *xtensor* to your project using cmake: 112 | 113 | .. code:: 114 | 115 | find_package(xtensor REQUIRED) 116 | target_include_directories(your_target PUBLIC ${xtensor_INCLUDE_DIRS}) 117 | target_link_libraries(your_target PUBLIC xtensor) 118 | 119 | .. _xtl: https://github.com/xtensor-stack/xtl 120 | -------------------------------------------------------------------------------- /docs/source/quickref/chunked_arrays.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Chunked arrays 8 | ============== 9 | 10 | Motivation 11 | ---------- 12 | 13 | Arrays can be very large and may not fit in memory. In this case, you may not be 14 | able to use an in-memory array such as an :cpp:type:`xt::xarray`. A solution to this problem 15 | is to cut up the large array into many small arrays, called chunks. Not only do 16 | the chunks fit comfortably in memory, but this also allows to process them in 17 | parallel, including in a distributed environment (although this is not supported 18 | yet). 19 | 20 | Formats for the storage of arrays such as `Zarr `_ 21 | specifically target chunked arrays. Such formats are becoming increasingly 22 | popular in the field of big data, since the chunks can be stored in the cloud. 23 | 24 | In-memory chunked arrays 25 | ------------------------ 26 | 27 | This may not look very useful at first sight, since each chunk (and thus the 28 | whole array) is held in memory. It means that it cannot work with very large 29 | arrays, but it may be used to parallelize an algorithm, by processing several 30 | chunks at the same time. 31 | 32 | An in-memory chunked array has the following type: 33 | 34 | .. code:: 35 | 36 | #include 37 | 38 | using data_type = double; 39 | // don't use this code: 40 | using inmemory_chunked_array = xt::xchunked_array>>; 41 | 42 | But you should not directly use this type to create a chunked array. Instead, 43 | use the ``chunked_array`` factory function: 44 | 45 | .. code:: 46 | 47 | #include 48 | 49 | std::vector shape = {10, 10, 10}; 50 | std::vector chunk_shape = {2, 3, 4}; 51 | auto a = xt::chunked_array(shape, chunk_shape); 52 | // a is an in-memory chunked array 53 | // each chunk is an xarray, and chunks are hold in an xarray 54 | // thus a is an xarray of xarray elements 55 | a(3, 9, 2) = 1.; // this will address the chunk of index (1, 3, 0) 56 | // and in this chunk, the element of index (1, 0, 2) 57 | 58 | Chunked arrays implement the full semantic of :cpp:type:`xt::xarray`, including lazy 59 | evaluation. 60 | 61 | Stored chunked arrays 62 | --------------------- 63 | 64 | These are arrays whose chunks are stored on a file system, allowing for 65 | persistence of data. In particular, they are used as a building block for the 66 | `xtensor-zarr `_ library. 67 | 68 | For further details, please refer to the documentation 69 | of `xtensor-io `_. 70 | -------------------------------------------------------------------------------- /docs/source/quickref/manipulation.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Manipulation 8 | ============ 9 | 10 | atleast_Nd 11 | ---------- 12 | 13 | .. code:: 14 | 15 | #include 16 | 17 | xt::xarray a0 = 123; 18 | auto r1 = xt::atleast_1d(a0); 19 | 20 | xt::xarray a1 = { 1, 2, 3 }; 21 | auto r2 = xt::atleast_2d(a1); 22 | auto r3 = xt::atleast_3d(a1); 23 | auto r4 = xt::atleast_Nd<4>(a1); 24 | 25 | expand_dims 26 | ----------- 27 | 28 | .. code:: 29 | 30 | #include 31 | 32 | xt::xarray a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 33 | auto r0 = xt::expand_dims(a, 0); 34 | auto r1 = xt::expand_dims(a, 1); 35 | auto r2 = xt::expand_dims(a, 2); 36 | 37 | flip 38 | ---- 39 | 40 | .. code:: 41 | 42 | #include 43 | 44 | xt::xarray a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 45 | auto f0 = xt::flip(a, 0); 46 | auto f1 = xt::flip(a, 1); 47 | 48 | repeat 49 | ------ 50 | 51 | .. code:: 52 | 53 | #include 54 | 55 | xt::xarray a = {{1, 2}, {3, 4}}; 56 | auto r0 = xt::repeat(a, 3, 1); 57 | auto r1 = xt::repeat(a, {1, 2}, 0); 58 | 59 | roll 60 | ---- 61 | 62 | .. code:: 63 | 64 | #include 65 | 66 | xt::xarray a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 67 | auto t0 = xt::roll(a, 2); 68 | auto t1 = xt::roll(a, 2, 1); 69 | 70 | rot90 71 | ----- 72 | 73 | .. code:: 74 | 75 | #include 76 | 77 | xt::xarray a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 78 | auto r0 = xt::rot90<1>(a); 79 | auto r1 = xt::rot90<-2>(a); 80 | auto r2 = xt::rot90(a); 81 | auto r4 = xt::rot90(a, {-2, -1}); 82 | 83 | split 84 | ----- 85 | 86 | .. code:: 87 | 88 | #include 89 | 90 | xt::xarray a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 91 | auto s0 = xt::split(a, 3); 92 | auto s1 = xt::split(a, 3, 1); 93 | 94 | hsplit 95 | ------ 96 | 97 | .. code:: 98 | 99 | #include 100 | 101 | xt::xarray a = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; 102 | auto res = xt::hsplit(a, 2); 103 | 104 | vsplit 105 | ------ 106 | 107 | .. code:: 108 | 109 | #include 110 | 111 | xt::xarray a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}; 112 | auto res = xt::vsplit(a, 2); 113 | 114 | squeeze 115 | ------- 116 | 117 | .. code:: 118 | 119 | #include 120 | 121 | auto b = xt::xarray::from_shape({3, 3, 1, 1, 2, 1, 3}); 122 | auto sq0 = xt::xqueeze(b); 123 | auto sq1 = squeeze(b, {2, 3}, check_policy::full()); 124 | auto sq2 = squeeze(b, 2); 125 | 126 | trim_zeros 127 | ---------- 128 | 129 | .. code:: 130 | 131 | #include 132 | 133 | xt::xarray a = {0, 0, 0, 1, 3, 0}; 134 | auto t0 = xt::trim_zeros(a); 135 | auto t1 = xt::trim_zeros(a, "b"); 136 | auto t2 = xt::trim_zeros(a, "f"); 137 | -------------------------------------------------------------------------------- /docs/source/quickref/operator.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Operators 8 | ========= 9 | 10 | Operations and functions of *xtensor* are not evaluated until they are assigned. 11 | In the following, ``e1``, ``e2`` and ``e3`` can be arbitrary tensor expressions. 12 | The results of operations and functions are assigned to :cpp:type:`xt::xarray` in the examples, 13 | but that could be any other container (or even views). To keep an unevaluated 14 | operator / function, assign to an ``auto`` variable: 15 | 16 | .. code:: 17 | 18 | auto res = e1 + e2; 19 | 20 | See :ref:`lazy-evaluation` for more details on unevaluated expressions. 21 | 22 | Arithmetic operators 23 | -------------------- 24 | 25 | .. code:: 26 | 27 | xt::xarray res0 = -e1; 28 | xt::xarray res1 = e1 + e2; 29 | xt::xarray res2 = e1 - e2; 30 | xt::xarray res3 = e1 * e2; 31 | xt::xarray res4 = e1 / e2; 32 | xt::xarray res5 = e1 % e2; 33 | 34 | res1 += e2; 35 | res2 -= e2; 36 | res3 *= e2; 37 | res4 /= e2; 38 | res5 %= e2; 39 | 40 | Bitwise operators 41 | ----------------- 42 | 43 | .. code:: 44 | 45 | xt::xarray res0 = e1 & e2; 46 | xt::xarray res1 = e1 | e2; 47 | xt::xarray res2 = e1 ^ e2; 48 | xt::xarray res3 = ~e1; 49 | 50 | res0 &= e2; 51 | res1 |= e2; 52 | 53 | Logical operators 54 | ----------------- 55 | 56 | .. code:: 57 | 58 | xt::xarray res0 = e1 && e2; 59 | xt::xarray res1 = e1 || e2; 60 | xt::xarray res2 = !e1; 61 | bool res3 = any(e1); 62 | bool res4 = all(e1); 63 | xt::xarray res5 = where(e1, e2, e3); 64 | 65 | Comparison operators 66 | -------------------- 67 | 68 | Comparison operators return expressions performing element-wise 69 | comparison: 70 | 71 | .. code:: 72 | 73 | xt::xarray res0 = e1 < e2; 74 | xt::xarray res1 = e1 > e2; 75 | xt::xarray res2 = e1 <= e2; 76 | xt::xarray res3 = e1 >= e2; 77 | xt::xarray res4 = xt::equal(e1, e2); 78 | xt::xarray res5 = xt::not_equal(e1, e2); 79 | 80 | Except for equality and inequality operators which performs traditional 81 | comparison and return a boolean: 82 | 83 | .. code:: 84 | 85 | bool res0 = e1 == e2; // true if all elements in e1 equal those in e2 86 | bool res1 = e1 != e2; 87 | -------------------------------------------------------------------------------- /docs/source/rank.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. _rank: 8 | 9 | Tensor Rank 10 | =========== 11 | 12 | Rank overload 13 | ------------- 14 | 15 | All *xtensor*'s classes have a member ``rank`` that can be used 16 | to overload based on rank using *SFINAE*. 17 | Consider the following example: 18 | 19 | .. code-block:: cpp 20 | 21 | template ::value, int> = 0> 22 | inline E foo(E&& a) 23 | { 24 | ... // act on object of flexible rank, or fixed rank != 2 25 | } 26 | 27 | template ::value, int> = 0> 28 | inline E foo(E&& a) 29 | { 30 | ... // act on object of fixed rank == 2 31 | } 32 | 33 | int main() 34 | { 35 | xt::xarray a = {{9, 9}, {9, 9}}; 36 | xt::xtensor b = {9, 9}; 37 | xt::xtensor c = {{9, 9}, {9, 9}}; 38 | 39 | foo(a); // flexible rank -> first overload 40 | foo(b); // fixed rank == 2 -> first overload 41 | foo(c); // fixed rank == 2 -> second overload 42 | 43 | return 0; 44 | } 45 | 46 | .. note:: 47 | 48 | If one wants to test for more than a single value for ``rank``, 49 | one can use the default value ``SIZE_MAX`` used for flexible rank objects. 50 | For example, one could have the following overloads: 51 | 52 | .. code-block:: cpp 53 | 54 | // flexible rank 55 | template ::value, int> = 0> 56 | inline E foo(E&& a); 57 | 58 | // fixed rank == 1 59 | template ::value, int> = 0> 60 | inline E foo(E&& a); 61 | 62 | // fixed rank == 2 63 | template ::value, int> = 0> 64 | inline E foo(E&& a); 65 | 66 | Note that fixed ranks other than 1 and 2 will raise a compiler error. 67 | 68 | Of course, if one wants a more limited scope, one could also do the following: 69 | 70 | .. code-block:: cpp 71 | 72 | // flexible rank 73 | inline void foo(xt::xarray& a); 74 | 75 | // fixed rank == 1 76 | inline void foo(xt::xtensor& a); 77 | 78 | // fixed rank == 2 79 | inline void foo(xt::xtensor& a); 80 | 81 | Rank as member 82 | -------------- 83 | 84 | If you want to use the rank as a member of your own class you can use 85 | :cpp:type:`xt::get_rank\ `. 86 | Consider the following example: 87 | 88 | .. code-block:: cpp 89 | 90 | template 91 | struct Foo 92 | { 93 | static const size_t rank = xt::get_rank::value; 94 | 95 | static size_t value() 96 | { 97 | return rank; 98 | } 99 | }; 100 | 101 | int main() 102 | { 103 | xt::xtensor A = xt::zeros({2}); 104 | xt::xtensor B = xt::zeros({2, 2}); 105 | xt::xarray C = xt::zeros({2, 2}); 106 | 107 | assert(Foo::value() == 1); 108 | assert(Foo::value() == 2); 109 | assert(Foo::value() == SIZE_MAX); 110 | 111 | return 0; 112 | } 113 | 114 | ``xt::get_rank`` 'returns' the rank of the *xtensor* object if its rank is fixed. 115 | In all other cases it 'returns' ``SIZE_MAX``. 116 | Indeed ``xt::get_rank>::value`` is equal to ``SIZE_MAX``, but equally so is ``xt::get_rank::value``. 117 | -------------------------------------------------------------------------------- /docs/source/releasing.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Releasing xtensor 8 | ================= 9 | 10 | Releasing a new version 11 | ----------------------- 12 | 13 | From the master branch of xtensor 14 | 15 | - Make sure that you are in sync with the master branch of the upstream remote. 16 | - Update the `changelog `_. 17 | - In file ``xtensor_config.hpp``, set the macros for ``XTENSOR_VERSION_MAJOR``, ``XTENSOR_VERSION_MINOR`` and ``XTENSOR_VERSION_PATCH`` to the desired values. 18 | - In file ``CMakeLists.txt``, update the version of the dependencies and the corresponding variables, e.g. ``xtl_REQUIRED_VERSION``. 19 | - In file ``environment.yml``, update the version of the dependencies including ``xtensor``. 20 | - In file ``README.md``, update the dependencies table. 21 | - Stage the changes (``git add``), commit the changes (``git commit``) and add a tag of the form ``Major.minor.patch``. It is important to not add any other content to the tag name. 22 | - Push the new commit and tag to the main repository. (``git push``, and ``git push --tags``) 23 | 24 | Updating the conda-forge recipe 25 | ------------------------------- 26 | 27 | xtensor has been packaged for the conda package manager. Once the new tag has been pushed on GitHub, edit the conda-forge recipe for xtensor in the following fashion: 28 | 29 | - Update the version number to the new ``Major.minor.patch``. 30 | - Set the build number to ``0``. 31 | - Update the hash of the source tarball. 32 | - Check for the versions of the dependencies. 33 | - Optionally, rerender the conda-forge feedstock. 34 | 35 | Updating the stable branch 36 | -------------------------- 37 | 38 | Once the conda-forge package has been updated, update the ``stable`` branch to 39 | the newly added tag. 40 | -------------------------------------------------------------------------------- /docs/source/spack.svg: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 19 | 20 | 22 | 23 | 24 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 37 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 51 | 52 | 54 | 56 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /docs/source/xeus-cling-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/docs/source/xeus-cling-screenshot.png -------------------------------------------------------------------------------- /docs/source/xfft.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | Distributed under the terms of the BSD 3-Clause License. 3 | The full license is in the file LICENSE, distributed with this software. 4 | xfft 5 | ==== 6 | 7 | Defined in ``xtensor/misc/xfft.hpp`` 8 | 9 | .. doxygenclass:: xt::fft::convolve 10 | :project: xtensor 11 | :members: 12 | 13 | .. doxygentypedef:: xt::fft::fft 14 | :project: xtensor 15 | 16 | .. doxygentypedef:: xt::fft::ifft 17 | :project: xtensor 18 | -------------------------------------------------------------------------------- /docs/source/xsimd.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 25 | 30 | 31 | -------------------------------------------------------------------------------- /docs/source/xtensor.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 30 | 35 | 36 | -------------------------------------------------------------------------------- /environment-dev.yml: -------------------------------------------------------------------------------- 1 | name: xtensor 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - cmake 6 | - xtl=0.8.0 7 | - xsimd=13.2.0 8 | - nlohmann_json 9 | - doctest 10 | - pre-commit 11 | - ninja 12 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: xtensor 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - xtensor=0.24.6 6 | - xtensor-blas=0.20.0 7 | - xeus-cling=0.15.0 8 | -------------------------------------------------------------------------------- /include/xtensor/core/xvectorize.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #ifndef XTENSOR_VECTORIZE_HPP 11 | #define XTENSOR_VECTORIZE_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "../core/xfunction.hpp" 17 | #include "../utils/xutils.hpp" 18 | 19 | namespace xt 20 | { 21 | 22 | /*************** 23 | * xvectorizer * 24 | ***************/ 25 | 26 | template 27 | class xvectorizer 28 | { 29 | public: 30 | 31 | template 32 | using xfunction_type = xfunction...>; 33 | 34 | template , xvectorizer>::value>> 35 | xvectorizer(Func&& f); 36 | 37 | template 38 | xfunction_type operator()(E&&... e) const; 39 | 40 | private: 41 | 42 | typename std::remove_reference::type m_f; 43 | }; 44 | 45 | namespace detail 46 | { 47 | template 48 | using get_function_type = remove_class_t::operator())>; 49 | } 50 | 51 | template 52 | xvectorizer vectorize(R (*f)(Args...)); 53 | 54 | template 55 | xvectorizer vectorize(F&& f, R (*)(Args...)); 56 | 57 | // Workaround for Visual Studio 15.7.1. 58 | // Error C2668 (ambiguous call to overloaded function) mistaking a declarations 59 | // for the definition of another overload. 60 | #ifndef _MSC_VER 61 | template 62 | auto vectorize(F&& f) 63 | -> decltype(vectorize(std::forward(f), std::declval*>())); 64 | #endif 65 | 66 | /****************************** 67 | * xvectorizer implementation * 68 | ******************************/ 69 | 70 | template 71 | template 72 | inline xvectorizer::xvectorizer(Func&& f) 73 | : m_f(std::forward(f)) 74 | { 75 | } 76 | 77 | template 78 | template 79 | inline auto xvectorizer::operator()(E&&... e) const -> xfunction_type 80 | { 81 | return xfunction_type(m_f, std::forward(e)...); 82 | } 83 | 84 | template 85 | inline xvectorizer vectorize(R (*f)(Args...)) 86 | { 87 | return xvectorizer(f); 88 | } 89 | 90 | template 91 | inline xvectorizer vectorize(F&& f, R (*)(Args...)) 92 | { 93 | return xvectorizer(std::forward(f)); 94 | } 95 | 96 | template 97 | inline auto vectorize(F&& f) 98 | -> decltype(vectorize(std::forward(f), std::declval*>())) 99 | { 100 | return vectorize(std::forward(f), static_cast*>(nullptr)); 101 | } 102 | } 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /include/xtensor/misc/xtl_concepts.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #ifndef XTENSOR_CONCEPTS_HPP 11 | #define XTENSOR_CONCEPTS_HPP 12 | 13 | #include 14 | #include 15 | 16 | namespace xtl 17 | { 18 | template 19 | concept integral_concept = xtl::is_integral::value; 20 | template 21 | concept non_integral_concept = !xtl::is_integral::value; 22 | template 23 | concept complex_concept = xtl::is_complex::type::value_type>::value; 24 | } 25 | 26 | #endif // XTENSOR_CONCEPTS_HPP 27 | -------------------------------------------------------------------------------- /include/xtensor/views/xoffset_view.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #ifndef XTENSOR_OFFSET_VIEW_HPP 11 | #define XTENSOR_OFFSET_VIEW_HPP 12 | 13 | #include 14 | 15 | #include "../views/xfunctor_view.hpp" 16 | 17 | namespace xt 18 | { 19 | namespace detail 20 | { 21 | template 22 | struct offset_forwarder 23 | { 24 | using value_type = M; 25 | using reference = M&; 26 | using const_reference = const M&; 27 | using pointer = M*; 28 | using const_pointer = const M*; 29 | 30 | using proxy = xtl::xproxy_wrapper; 31 | 32 | template 33 | using simd_return_type = xt_simd::simd_return_type; 34 | 35 | template 36 | decltype(auto) operator()(T&& t) const 37 | { 38 | return xtl::forward_offset(std::forward(t)); 39 | } 40 | 41 | template < 42 | class align, 43 | class requested_type, 44 | std::size_t N, 45 | class E, 46 | class MF = M, 47 | class = std::enable_if_t< 48 | (std::is_same::value || std::is_same::value) && I <= sizeof(MF), 49 | int>> 50 | auto proxy_simd_load(const E& expr, std::size_t n) const 51 | { 52 | // TODO refactor using shuffle only 53 | auto batch = expr.template load_simd(n); 54 | if (I == 0) 55 | { 56 | return batch.real(); 57 | } 58 | else 59 | { 60 | return batch.imag(); 61 | } 62 | } 63 | 64 | template < 65 | class align, 66 | class simd, 67 | class E, 68 | class MF = M, 69 | class = std::enable_if_t< 70 | (std::is_same::value || std::is_same::value) && I <= sizeof(MF), 71 | int>> 72 | auto proxy_simd_store(E& expr, std::size_t n, const simd& batch) const 73 | { 74 | auto x = expr.template load_simd(n); 75 | if (I == 0) 76 | { 77 | x.real() = batch; 78 | } 79 | else 80 | { 81 | x.imag() = batch; 82 | } 83 | expr.template store_simd(n, x); 84 | } 85 | }; 86 | } 87 | 88 | template 89 | using xoffset_view = xfunctor_view, CT>; 90 | 91 | template 92 | using xoffset_adaptor = xfunctor_adaptor, CT>; 93 | } 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /notebooks/images/xtensor-blas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/notebooks/images/xtensor-blas.png -------------------------------------------------------------------------------- /notebooks/images/xtensor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/notebooks/images/xtensor.png -------------------------------------------------------------------------------- /readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | build: 4 | os: ubuntu-22.04 5 | tools: 6 | python: mambaforge-22.9 7 | 8 | sphinx: 9 | # Path to Sphinx configuration file 10 | configuration: docs/source/conf.py 11 | 12 | conda: 13 | environment: docs/rtd_environment.yml 14 | -------------------------------------------------------------------------------- /test/files/cppy_source/test_extended_xhistogram.cppy: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include 11 | 12 | #include "xtensor/xarray.hpp" 13 | #include "xtensor/xtensor.hpp" 14 | #include "xtensor/xhistogram.hpp" 15 | 16 | #include "test_common_macros.hpp" 17 | 18 | namespace xt 19 | { 20 | using namespace xt::placeholders; 21 | 22 | /*py 23 | 24 | a = (np.random.random(1000) * 51).astype(np.int) 25 | 26 | count, bin_edges = np.histogram(a, 50) 27 | 28 | prob, _ = np.histogram(a, 50, density=True) 29 | 30 | */ 31 | TEST(xtest_extended_histogram, histogram_auto) 32 | { 33 | // py_a 34 | // py_bin_edges 35 | // py_count 36 | // py_prob 37 | 38 | auto bin_edges = xt::histogram_bin_edges(py_a, std::size_t(50)); 39 | 40 | auto count = xt::histogram(py_a, bin_edges); 41 | 42 | auto prob = xt::histogram(py_a, bin_edges, true); 43 | 44 | EXPECT_EQ(xt::cast(bin_edges), py_bin_edges); 45 | 46 | EXPECT_EQ(count, xt::cast(py_count)); 47 | 48 | EXPECT_EQ(prob, py_prob); 49 | } 50 | 51 | /*py 52 | 53 | a = (np.random.random(1000) * 51).astype(np.int) 54 | 55 | count, bin_edges = np.histogram(a, 30, (10, 40)) 56 | 57 | */ 58 | TEST(xtest_extended_histogram, histogram_with_range) 59 | { 60 | // py_a 61 | // py_bin_edges 62 | // py_count 63 | 64 | auto bin_edges = xt::histogram_bin_edges(py_a, 10, 40, std::size_t(30)); 65 | 66 | auto count = xt::histogram(py_a, bin_edges); 67 | 68 | EXPECT_EQ(xt::cast(bin_edges), py_bin_edges); 69 | 70 | EXPECT_EQ(count, xt::cast(py_count)); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /test/files/cppy_source/test_extended_xmath_interp.cppy: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include 11 | 12 | #include "xtensor/xarray.hpp" 13 | #include "xtensor/xtensor.hpp" 14 | #include "xtensor/xmath.hpp" 15 | 16 | #include "test_common_macros.hpp" 17 | 18 | namespace xt 19 | { 20 | using namespace xt::placeholders; 21 | 22 | /*py 23 | xp = np.sort(np.random.random(20) - 0.5) 24 | fp = np.random.random(20) - 0.5 25 | x = np.linspace(-1,1,50) 26 | f = np.interp(x, xp, fp) 27 | */ 28 | TEST(xtest_extended_xmath, interp) 29 | { 30 | // py_xp 31 | // py_fp 32 | // py_x 33 | // py_f 34 | 35 | auto f = xt::interp(py_x, py_xp, py_fp); 36 | 37 | EXPECT_TRUE(xt::allclose(f, py_f)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/files/cppy_source/test_extended_xmath_reducers.cppy: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include 11 | 12 | #include "xtensor/xarray.hpp" 13 | #include "xtensor/xtensor.hpp" 14 | #include "xtensor/xmath.hpp" 15 | 16 | #include "test_common_macros.hpp" 17 | 18 | namespace xt 19 | { 20 | using namespace xt::placeholders; 21 | 22 | // Temporary disabling for TBB and OPENMP due to a potential 23 | // race condition that must be identified 24 | 25 | /*py 26 | a = np.random.random(4*5*6*7).reshape(4,5,6,7) 27 | w = np.random.random(4*5*6*7).reshape(4,5,6,7) 28 | av = np.average(a, weights=w, axis=(0,1)) 29 | */ 30 | TEST(xtest_extended_xmath, average) 31 | { 32 | // py_a 33 | // py_w 34 | // py_av 35 | 36 | auto av = xt::average(py_a, py_w, {0,1}); 37 | EXPECT_TRUE(xt::allclose(av, py_av)); 38 | } 39 | 40 | /*py 41 | a = np.random.random(4*5*6*7).reshape(4,5,6,7) 42 | vr_all = np.var(a) 43 | st_all = np.std(a) 44 | vr_all_ddof = np.var(a, ddof=1) 45 | vr = np.var(a, axis=(0,2)) 46 | st = np.std(a, axis=(0,2)) 47 | vr_ddof = np.var(a, axis=(0,2), ddof=1) 48 | */ 49 | TEST(xtest_extended_xmath, var_std) 50 | { 51 | // py_a 52 | 53 | // py_vr_all 54 | // py_vr_all_ddof 55 | // py_st_all 56 | // py_vr 57 | // py_vr_ddof 58 | // py_st 59 | 60 | auto st_all = xt::stddev(py_a); 61 | auto vr_all = xt::variance(py_a); 62 | auto vr_all_ddof = xt::variance(py_a, {0, 1, 2, 3}, 1); 63 | std::vector axes_all = {0, 1, 2, 3}; 64 | auto vr_all_ddof_with_axes_arr = xt::variance(py_a, axes_all, 1); 65 | 66 | auto st = xt::stddev(py_a, {0, 2}); 67 | auto vr = xt::variance(py_a, {0, 2}); 68 | auto vr_ddof = xt::variance(py_a, {0, 2}, 1); 69 | std::vector axes02 = {0, 2}; 70 | auto vr_ddof_with_axes_arr = xt::variance(py_a, axes02, 1); 71 | 72 | EXPECT_TRUE(xt::allclose(st_all, py_st_all)); 73 | EXPECT_TRUE(xt::allclose(vr_all, py_vr_all)); 74 | EXPECT_TRUE(xt::allclose(vr_all_ddof, py_vr_all_ddof)); 75 | EXPECT_TRUE(xt::allclose(vr_all_ddof_with_axes_arr, py_vr_all_ddof)); 76 | EXPECT_TRUE(xt::allclose(st, py_st)); 77 | EXPECT_TRUE(xt::allclose(vr, py_vr)); 78 | EXPECT_TRUE(xt::allclose(vr_ddof, py_vr_ddof)); 79 | EXPECT_TRUE(xt::allclose(vr_ddof_with_axes_arr, py_vr_ddof)); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /test/files/generate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import glob 4 | 5 | fs = glob.glob("xio_expected_results/*.txt") 6 | 7 | include_file = "#include \n\n" 8 | 9 | for f in fs: 10 | with open(f) as ff: 11 | ctn = ff.read() 12 | n = f.split("/")[1] 13 | include_file += "static std::string {} = R\"xio({})xio\";\n\n\n".format(n[:-4], ctn) 14 | 15 | with open("xio_expected_results.hpp", "w+") as fo: 16 | fo.write(include_file) 17 | -------------------------------------------------------------------------------- /test/files/preprocess.py: -------------------------------------------------------------------------------- 1 | import glob 2 | import os 3 | import re 4 | import sys 5 | import numpy as np 6 | 7 | my_path = os.path.dirname(os.path.realpath(__file__)) 8 | cppy_files = glob.glob(my_path + '/cppy_source/*.cppy') 9 | 10 | dtype_map = { 11 | 'bool': 'bool', 12 | 'float32': 'float', 13 | 'float64': 'double', 14 | 'int32': 'int', 15 | 'int64': 'long', 16 | 'uint32': 'unsigned int', 17 | 'uint64': 'unsigned long', 18 | 'complex64': 'std::complex', 19 | 'complex128': 'std::complex', 20 | } 21 | 22 | def get_xtype(arr, xtensor=False): 23 | if isinstance(arr, (int)): 24 | return "int" 25 | elif isinstance(arr, float): 26 | return "double" 27 | 28 | if xtensor: 29 | s = "xtensor<" + dtype_map[str(arr.dtype)] + ", " + str(arr.ndim) + ">" 30 | else: 31 | s = "xarray<" + dtype_map[str(arr.dtype)] + ">" 32 | return s 33 | 34 | def get_cpp_initlist(arr, name): 35 | if isinstance(arr, (int, str, float)): 36 | return get_xtype(arr) + " " + name + " = " + str(arr) + ';' 37 | name = get_xtype(arr) + " " + name 38 | s = np.array2string(arr, separator=',', precision=16) 39 | s = s.replace('[', '{') 40 | s = s.replace(']', '}') 41 | s = s.replace('j', 'i') 42 | s += ';' 43 | s = s.replace("\n", "\n" + " " * (len(name) + 3)) 44 | s = name + " = " + s 45 | return s 46 | 47 | 48 | 49 | def translate_file(contents, f): 50 | current_vars = {} 51 | 52 | matches = re.findall(r"\/\*py.*?\*\/", contents, re.MULTILINE | re.DOTALL) 53 | 54 | def exec_comment(txt, upper_level=False): 55 | lines = txt.split('\n') 56 | if upper_level: 57 | txt = '\n'.join(["import numpy as np"] + [x.strip() for x in lines[1:-1]]) 58 | locals_before = list(locals().keys()) 59 | exec(txt, globals(), current_vars) 60 | current_vars.update( 61 | {x: val for x, val in locals().items() if x not in locals_before} 62 | ) 63 | 64 | result_file = "" 65 | 66 | idx = 0 67 | lidx = 0 68 | for line in contents.split('\n'): 69 | if lidx == 8: 70 | f = os.path.split(f)[1] 71 | result_file += "// This file is generated from test/files/cppy_source/{} by preprocess.py!\n".format(f) 72 | result_file += "// Warning: This file should not be modified directly! " \ 73 | "Instead, modify the `*.cppy` file.\n\n" 74 | 75 | lstrip = line.lstrip() 76 | if lstrip.startswith("/*py"): 77 | exec_comment(matches[idx], True) 78 | idx += 1 79 | if lstrip.startswith("// py_"): 80 | indent_n = len(line) - len(lstrip) 81 | if '=' in lstrip: 82 | exec_comment(lstrip[6:]) 83 | var = line.strip()[6:lstrip.index('=')].strip() 84 | else: 85 | var = line.strip()[6:] 86 | indent = line[:indent_n] 87 | init_list = get_cpp_initlist(current_vars[var], 'py_' + var) 88 | init_list = '\n'.join([indent + x for x in init_list.split('\n')]) 89 | result_file += line + '\n' 90 | result_file += init_list + '\n' 91 | else: 92 | result_file += line + '\n' 93 | lidx += 1 94 | return result_file 95 | 96 | print("::: PREPROCESSING :::\n") 97 | 98 | for f in cppy_files: 99 | print(" - PROCESSING {}".format(f)) 100 | 101 | global current_vars 102 | current_vars = {} # reset 103 | 104 | with open(f) as fi: 105 | contents = fi.read() 106 | 107 | # reset global seed 108 | np.random.seed(42) 109 | result = translate_file(contents, f) 110 | f_result = os.path.split(f)[1] 111 | with open(my_path + "/../" + f_result[:-1], 'w+') as fo: 112 | fo.write(result) 113 | print("::: DONE :::") 114 | # print(result) 115 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/big_exp.txt: -------------------------------------------------------------------------------- 1 | {{ 4.259106e+000, -1.430581e+000, 3.817697e+000, 4.383006e+000}, 2 | {-1.776213e-001, 1.000000e+220, 1.000000e-124, 1.593886e+000}, 3 | {-7.200985e+000, -1.979649e+000, 2.546340e+000, -3.516982e+000}, 4 | {-5.104814e+000, 3.895104e+000, 1.878048e+000, 2.635840e+000}, 5 | {-1.194856e+000, -8.325470e+000, 4.246604e+000, -1.442730e+000}} 6 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/bool_fn.txt: -------------------------------------------------------------------------------- 1 | {{ true, false, true, true, false}, 2 | { true, false, true, false, false}, 3 | { true, false, false, true, true}, 4 | { true, false, false, true, false}, 5 | {false, false, true, false, false}} 6 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/complex_numbers.txt: -------------------------------------------------------------------------------- 1 | {{ 4.259106-4.705763i, -1.430581+0.520437i, 3.817697-2.597525i, 2 | 4.383006+3.84805i , -0.177621-0.397616i, 5.600555-3.068297i, 3 | -1.781513-2.063075i, 1.593886+3.179275i, -7.200985+0.594874i, 4 | -1.979649+1.779254i}, 5 | { 2.54634 +3.091267i, -3.516982+3.685722i, -5.104814-0.820075i, 6 | 3.895104-4.410618i, 1.878048-0.21541i , 2.63584 +0.211594i, 7 | -1.194856+0.80632i , -8.32547 -1.90801i , 4.246604+4.198826i, 8 | -1.44273 +1.553475i}, 9 | {-4.04439 -1.507586i, -0.158305+0.41094i , 4.805928-0.509466i, 10 | -2.845422-2.17679i , -1.655801-2.041235i, 3.094426+0.63481i , 11 | -2.523971+2.151913i, -5.309743+0.176187i, 9.759906-1.479582i, 12 | 5.319919+1.327789i}, 13 | { 5.540089+3.73119i , -9.440361-3.321116i, -6.52187 +4.874783i, 14 | -6.918355-1.505851i, -8.45827 +3.262051i, 7.797314-4.345385i, 15 | 5.007574-4.946467i, 3.868065+3.869446i, 0.235268+4.113181i, 16 | -0.714639-3.005922i}, 17 | { 1.368614-4.724486i, -3.949011+3.173349i, -0.053824-2.581724i, 18 | 3.665258-4.43917i , 8.333974-4.324392i, -7.821421-0.261281i, 19 | -0.090164+0.094293i, -5.343281-0.832049i, -1.262787-2.441571i, 20 | 5.03086 -1.184879i}, 21 | {-0.382158+3.073844i, 5.954568+3.110391i, -4.345941+1.861869i, 22 | -1.331635+4.926136i, -9.804853-0.948148i, -3.18408 -3.098263i, 23 | 3.78544 -0.118255i, 7.387386+0.023696i, -4.643924-0.966452i, 24 | -0.865042-3.189046i}, 25 | {-4.634374-4.519702i, 6.741056+1.046913i, -4.589707-2.340888i, 26 | 0.60124 +3.81347i , -6.492547+0.840461i, -3.700671-0.225395i, 27 | 7.822182-3.28485i , -6.393274-4.4338i , -0.113676-3.429648i, 28 | -5.754038-1.613825i}, 29 | { 0.417537-0.59357i , -6.798001+1.838431i, 8.381136-2.941283i, 30 | 9.885798+1.164337i, -0.459049+4.244716i, -3.80233 -4.203717i, 31 | 0.144086-0.146032i, -4.384136+1.985636i, 5.276734-4.184315i, 32 | -7.829154+3.691024i}, 33 | { 0.233094-0.668943i, 8.195388-0.056699i, -5.63248 -0.042595i, 34 | -2.737919-1.292779i, 7.099456+4.221287i, 4.227836+3.412782i, 35 | -2.141112+1.555259i, -5.37397 -0.37315i , -2.396506+0.650113i, 36 | 0.983242-0.760845i}, 37 | { 1.134381-2.117881i, -9.917307-2.360193i, 2.76045 +1.907382i, 38 | -8.84704 +3.328365i, -9.139462+0.923916i, 7.501023-0.334774i, 39 | -4.148248+1.7366i , 5.255353-1.085206i, -2.642695+2.021044i, 40 | 7.470045+4.656976i}} 41 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/complex_zero_erasing.txt: -------------------------------------------------------------------------------- 1 | {{ 0.212955-0.470576i, -0.071529+0.052044i, 0.190885-0.259752i, 2 | 0.21915 +0.384805i, -0.008881-0.039762i, 0.280028-0.30683i , 3 | -0.089076-0.206307i, 0.079694+0.317928i, -0.360049+0.059487i, 4 | -0.098982+0.177925i}, 5 | { 0.127317+0.309127i, -0.175849+0.368572i, -0.255241-0.082008i, 6 | 0.194755-0.441062i, 0.093902-0.021541i, 0.131792+0.021159i, 7 | -0.059743+0.080632i, -0.416274-0.190801i, 0.21233 +0.419883i, 8 | -0.072137+0.155348i}, 9 | {-0.20222 -0.150759i, -0.007915+0.041094i, 0.240296-0.050947i, 10 | -0.142271-0.217679i, -0.08279 -0.204123i, 0.154721+0.063481i, 11 | -0.126199+0.215191i, -0.265487+0.017619i, 0.487995-0.147958i, 12 | 0.265996+0.132779i}, 13 | { 0.277004+0.373119i, -0.472018-0.332112i, -0.326093+0.487478i, 14 | -0.345918-0.150585i, -0.422914+0.326205i, 0.389866-0.434538i, 15 | 0.250379-0.494647i, 0.193403+0.386945i, 0.011763+0.411318i, 16 | -0.035732-0.300592i}, 17 | { 0.068431-0.472449i, -0.197451+0.317335i, -0.002691-0.258172i, 18 | 0.183263-0.443917i, 0.416699-0.432439i, -0.391071-0.026128i, 19 | -0.004508+0.009429i, -0.267164-0.083205i, -0.063139-0.244157i, 20 | 0.251543-0.118488i}, 21 | {-0.019108+0.307384i, 0.297728+0.311039i, -0.217297+0.186187i, 22 | -0.066582+0.492614i, -0.490243-0.094815i, -0.159204-0.309826i, 23 | 0.189272-0.011826i, 0.369369+0.00237i , -0.232196-0.096645i, 24 | -0.043252-0.318905i}, 25 | {-0.231719-0.45197i , 0.337053+0.104691i, -0.229485-0.234089i, 26 | 0.030062+0.381347i, -0.324627+0.084046i, -0.185034-0.02254i , 27 | 0.391109-0.328485i, -0.319664-0.44338i , -0.005684-0.342965i, 28 | -0.287702-0.161383i}, 29 | { 0.020877-0.059357i, -0.3399 +0.183843i, 0.419057-0.294128i, 30 | 0.49429 +0.116434i, -0.022952+0.424472i, -0.190116-0.420372i, 31 | 0.007204-0.014603i, -0.219207+0.198564i, 0.263837-0.418432i, 32 | -0.391458+0.369102i}, 33 | { 0.011655-0.066894i, 0.409769-0.00567i , -0.281624-0.00426i , 34 | -0.136896-0.129278i, 0.354973+0.422129i, 0.211392+0.341278i, 35 | -0.107056+0.155526i, -0.268699-0.037315i, -0.119825+0.065011i, 36 | 0.049162-0.076084i}, 37 | { 0.056719-0.211788i, -0.495865-0.236019i, 0.138023+0.190738i, 38 | -0.442352+0.332837i, -0.456973+0.092392i, 0.375051-0.033477i, 39 | -0.207412+0.17366i , 0.262768-0.108521i, -0.132135+0.202104i, 40 | 0.373502+0.465698i}} 41 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/custom_formatter_result.txt: -------------------------------------------------------------------------------- 1 | {{ 0x1, 0x2, 0x3, 0x4}, 2 | { 0x64, 0xc8, 0x3e8, 0x989680}} 3 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/cut_both.txt: -------------------------------------------------------------------------------- 1 | {{1, 1, 1, ..., 1, 1, 1}, 2 | {1, 1, 1, ..., 1, 1, 1}, 3 | {1, 1, 1, ..., 1, 1, 1}, 4 | ..., 5 | {1, 1, 1, ..., 1, 1, 1}, 6 | {1, 1, 1, ..., 1, 1, 1}, 7 | {1, 1, 1, ..., 1, 1, 1}} 8 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/cut_high.txt: -------------------------------------------------------------------------------- 1 | {{1}, 2 | {1}, 3 | {1}, 4 | ..., 5 | {1}, 6 | {1}, 7 | {1}} 8 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/cut_long.txt: -------------------------------------------------------------------------------- 1 | {{1, 1, 1, ..., 1, 1, 1}, 2 | {1, 1, 1, ..., 1, 1, 1}, 3 | {1, 1, 1, ..., 1, 1, 1}, 4 | {1, 1, 1, ..., 1, 1, 1}, 5 | {1, 1, 1, ..., 1, 1, 1}} 6 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/float_leading_zero.txt: -------------------------------------------------------------------------------- 1 | {{ 0.212955, -0.071529, 0.190885, 0.21915 , -0.008881, 0.280028, 2 | -0.089076, 0.079694, -0.360049, -0.098982}, 3 | { 0.127317, -0.175849, -0.255241, 0.194755, 0.093902, 0.131792, 4 | -0.059743, -0.416274, 0.21233 , -0.072137}, 5 | {-0.20222 , -0.007915, 0.240296, -0.142271, -0.08279 , 0.154721, 6 | -0.126199, -0.265487, 0.487995, 0.265996}, 7 | { 0.277004, -0.472018, -0.326093, -0.345918, -0.422914, 0.389866, 8 | 0.250379, 0.193403, 0.011763, -0.035732}, 9 | { 0.068431, -0.197451, -0.002691, 0.183263, 0.416699, -0.391071, 10 | -0.004508, -0.267164, -0.063139, 0.251543}, 11 | {-0.019108, 0.297728, -0.217297, -0.066582, -0.490243, -0.159204, 12 | 0.189272, 0.369369, -0.232196, -0.043252}, 13 | {-0.231719, 0.337053, -0.229485, 0.030062, -0.324627, -0.185034, 14 | 0.391109, -0.319664, -0.005684, -0.287702}, 15 | { 0.020877, -0.3399 , 0.419057, 0.49429 , -0.022952, -0.190116, 16 | 0.007204, -0.219207, 0.263837, -0.391458}, 17 | { 0.011655, 0.409769, -0.281624, -0.136896, 0.354973, 0.211392, 18 | -0.107056, -0.268699, -0.119825, 0.049162}, 19 | { 0.056719, -0.495865, 0.138023, -0.442352, -0.456973, 0.375051, 20 | -0.207412, 0.262768, -0.132135, 0.373502}} 21 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/long_strings.txt: -------------------------------------------------------------------------------- 1 | {{some, random very long and very very, boring}, 2 | {strings, in, xtensor xarray}} 3 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/precision.txt: -------------------------------------------------------------------------------- 1 | {{ 4.259106431606, -1.430581499421, 3.817697028755, 4.383006177616}, 2 | {-0.177621344479, 5.600555210482, -1.781512638644, 1.593885951139}, 3 | {-7.200984733734, -1.979648916087, 2.546340079714, -3.516982077951}, 4 | {-5.104814402579, 3.895103503297, 1.87804795987 , 2.635840409147}, 5 | {-1.194856450043, -8.325470293986, 4.246603560315, -1.442730205451}} 6 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/random_strings.txt: -------------------------------------------------------------------------------- 1 | {{ some, random, boring}, 2 | { strings, in, xtensor xarray}} 3 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/threed_double.txt: -------------------------------------------------------------------------------- 1 | {{{ 1., 2.}, 2 | { 3., 4.}, 3 | { 5., 6.}, 4 | { 7., 8.}}, 5 | {{ 9., 10.}, 6 | { 11., 12.}, 7 | { 7., 9.}, 8 | { 11., 14.}}, 9 | {{ 5., 26.}, 10 | { 7., 8.}, 11 | { 10., 8.}, 12 | { 4., 3.}}} 13 | -------------------------------------------------------------------------------- /test/files/xio_expected_results/twod_double.txt: -------------------------------------------------------------------------------- 1 | {{ 1., 2., 3., 4.}, 2 | { 5., 6., 7., 8.}, 3 | { 9., 10., 11., 12.}} 4 | -------------------------------------------------------------------------------- /test/files/xnpy_files/bool.be.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/bool.be.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/bool.le.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/bool.le.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/bool_fortran.be.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/bool_fortran.be.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/bool_fortran.le.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/bool_fortran.le.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/double.be.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/double.be.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/double.le.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/double.le.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/double_fortran.be.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/double_fortran.be.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/double_fortran.le.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/double_fortran.le.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/int.be.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/int.be.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/int.le.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/int.le.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/unsignedlong.be.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/unsignedlong.be.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/unsignedlong.le.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/unsignedlong.le.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/unsignedlong_fortran.be.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/unsignedlong_fortran.be.npy -------------------------------------------------------------------------------- /test/files/xnpy_files/unsignedlong_fortran.le.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtensor-stack/xtensor/2be98b4b32caca43e7f376bac6dab3d6e538f26d/test/files/xnpy_files/unsignedlong_fortran.le.npy -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 2 | #if defined(XTENSOR_DISABLE_EXCEPTIONS) 3 | #define DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS 4 | #endif 5 | #include "doctest/doctest.h" 6 | -------------------------------------------------------------------------------- /test/set_compiler_flag.cmake: -------------------------------------------------------------------------------- 1 | # Copied from 2 | # https://github.com/dev-cafe/cmake-cookbook/blob/master/chapter-07/recipe-03/c-cxx-example/set_compiler_flag.cmake 3 | # Adapted from 4 | # https://github.com/robertodr/ddPCM/blob/expose-C-api/cmake/custom/compilers/SetCompilerFlag.cmake 5 | # which was adapted by Roberto Di Remigio from 6 | # https://github.com/SethMMorton/cmake_fortran_template/blob/master/cmake/Modules/SetCompileFlag.cmake 7 | 8 | # Given a list of flags, this stateless function will try each, one at a time, 9 | # and set result to the first flag that works. 10 | # If none of the flags works, result is "". 11 | # If the REQUIRED key is given and no flag is found, a FATAL_ERROR is raised. 12 | # 13 | # Call is: 14 | # set_compile_flag(result (Fortran|C|CXX) flag1 flag2 ...) 15 | # 16 | # Example: 17 | # set_compiler_flag(working_compile_flag C REQUIRED "-Wall" "-warn all") 18 | 19 | include(CheckCCompilerFlag) 20 | include(CheckCXXCompilerFlag) 21 | include(CheckFortranCompilerFlag) 22 | 23 | function(set_compiler_flag _result _lang) 24 | # build a list of flags from the arguments 25 | set(_list_of_flags) 26 | # also figure out whether the function 27 | # is required to find a flag 28 | set(_flag_is_required FALSE) 29 | foreach(_arg IN ITEMS ${ARGN}) 30 | string(TOUPPER "${_arg}" _arg_uppercase) 31 | if(_arg_uppercase STREQUAL "REQUIRED") 32 | set(_flag_is_required TRUE) 33 | else() 34 | list(APPEND _list_of_flags "${_arg}") 35 | endif() 36 | endforeach() 37 | 38 | set(_flag_found FALSE) 39 | # loop over all flags, try to find the first which works 40 | foreach(flag IN ITEMS ${_list_of_flags}) 41 | 42 | unset(_${flag}_works CACHE) 43 | if(_lang STREQUAL "C") 44 | check_c_compiler_flag("${flag}" _${flag}_works) 45 | elseif(_lang STREQUAL "CXX") 46 | check_cxx_compiler_flag("${flag}" _${flag}_works) 47 | elseif(_lang STREQUAL "Fortran") 48 | check_Fortran_compiler_flag("${flag}" _${flag}_works) 49 | else() 50 | message(FATAL_ERROR "Unknown language in set_compiler_flag: ${_lang}") 51 | endif() 52 | 53 | # if the flag works, use it, and exit 54 | # otherwise try next flag 55 | if(_${flag}_works) 56 | set(${_result} "${flag}" PARENT_SCOPE) 57 | set(_flag_found TRUE) 58 | break() 59 | endif() 60 | endforeach() 61 | 62 | # raise an error if no flag was found 63 | if(_flag_is_required AND NOT _flag_found) 64 | message(FATAL_ERROR "None of the required flags were supported") 65 | endif() 66 | endfunction() 67 | -------------------------------------------------------------------------------- /test/test_common_macros.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEST_COMMON_MACROS_HPP 2 | #define TEST_COMMON_MACROS_HPP 3 | 4 | #if defined(XTENSOR_DISABLE_EXCEPTIONS) 5 | #define DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS 6 | #endif 7 | 8 | #include "xtensor/core/xtensor_config.hpp" 9 | 10 | #include "doctest/doctest.h" 11 | #include "test_utils.hpp" 12 | 13 | #if defined(XTENSOR_DISABLE_EXCEPTIONS) 14 | #warning "XT_EXPECT_THROW, XT_ASSERT_THROW, XT_EXPECT_ANY_THROW and XT_ASSERT_ANY_THROW are disabled" 15 | #define XT_EXPECT_THROW(x, y) 16 | #define XT_ASSERT_THROW(x, y) 17 | #define XT_EXPECT_ANY_THROW(x) 18 | #define XT_ASSERT_ANY_THROW(x) 19 | #define XT_EXPECT_NO_THROW(x) x; 20 | #define XT_ASSERT_NO_THROW(x) x; 21 | 22 | #else 23 | 24 | #define XT_EXPECT_THROW(x, y) CHECK_THROWS_AS(x, y); 25 | #define XT_ASSERT_THROW(x, y) REQUIRE_THROWS_AS(x, y); 26 | #define XT_EXPECT_ANY_THROW(x) CHECK_THROWS_AS(x, std::exception); 27 | #define XT_ASSERT_ANY_THROW(x) REQUIRE_THROWS_AS(x, std::exception); 28 | #define XT_EXPECT_NO_THROW(x) x; 29 | #define XT_ASSERT_NO_THROW(x) x; 30 | #endif 31 | 32 | 33 | #define EXPECT_NO_THROW(x) XT_EXPECT_NO_THROW(x) 34 | #define EXPECT_THROW(x, y) XT_EXPECT_THROW(x, y) 35 | 36 | #define TEST(A, B) TEST_CASE(#A "." #B) 37 | #define EXPECT_EQ(A, B) CHECK_EQ(A, B) 38 | #define EXPECT_NE(A, B) CHECK_NE(A, B) 39 | #define EXPECT_LE(A, B) CHECK_LE(A, B) 40 | #define EXPECT_GE(A, B) CHECK_GE(A, B) 41 | #define EXPECT_LT(A, B) CHECK_LT(A, B) 42 | #define EXPECT_GT(A, B) CHECK_GT(A, B) 43 | #define EXPECT_TRUE(A) CHECK_EQ(A, true) 44 | #define EXPECT_FALSE(A) CHECK_FALSE(A) 45 | 46 | #define ASSERT_EQ(A, B) REQUIRE_EQ(A, B) 47 | #define ASSERT_NE(A, B) REQUIRE_NE(A, B) 48 | #define ASSERT_LE(A, B) REQUIRE_LE(A, B) 49 | #define ASSERT_GE(A, B) REQUIRE_GE(A, B) 50 | #define ASSERT_LT(A, B) REQUIRE_LT(A, B) 51 | #define ASSERT_GT(A, B) REQUIRE_GT(A, B) 52 | #define ASSERT_TRUE(A) REQUIRE_EQ(A, true) 53 | #define ASSERT_FALSE(A) REQUIRE_FALSE(A) 54 | 55 | #define EXPECT_DOUBLE_EQ(x, y) CHECK(xt::scalar_near(x, y)); 56 | #define EXPECT_TENSOR_EQ(x, y) CHECK(xt::tensor_near(x, y)); 57 | 58 | #define TEST_F(FIXTURE_CLASS, NAME) TEST_CASE_FIXTURE(FIXTURE_CLASS, #NAME) 59 | 60 | #define HETEROGEN_PARAMETRIZED_DEFINE(ID) TEST_CASE_TEMPLATE_DEFINE(#ID, TypeParam, ID) 61 | 62 | #define HETEROGEN_PARAMETRIZED_TEST_APPLY(ID, TEST_FUNC) \ 63 | TEST_CASE_TEMPLATE_APPLY(ID, augment_t>) 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /test/test_utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEST_UTILS_HPP 2 | #define TEST_UTILS_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "xtensor/core/xexpression.hpp" 9 | 10 | namespace xt 11 | { 12 | namespace detail 13 | { 14 | template 15 | bool check_is_small(const T& value, const T& tolerance) 16 | { 17 | using std::abs; 18 | return abs(value) < abs(tolerance); 19 | } 20 | 21 | template 22 | T safe_division(const T& lhs, const T& rhs) 23 | { 24 | if (rhs < static_cast(1) && lhs > rhs * (std::numeric_limits::max)()) 25 | { 26 | return (std::numeric_limits::max)(); 27 | } 28 | if ((lhs == static_cast(0)) 29 | || (rhs > static_cast(1) && lhs < rhs * (std::numeric_limits::min)())) 30 | { 31 | return static_cast(0); 32 | } 33 | return lhs / rhs; 34 | } 35 | 36 | template 37 | bool check_is_close(const T& lhs, const T& rhs, const T& relative_precision) 38 | { 39 | using std::abs; 40 | T diff = abs(lhs - rhs); 41 | T d1 = safe_division(diff, T(abs(rhs))); 42 | T d2 = safe_division(diff, T(abs(lhs))); 43 | 44 | return d1 <= relative_precision && d2 <= relative_precision; 45 | } 46 | } 47 | 48 | template 49 | bool scalar_near(const T& lhs, const T& rhs) 50 | { 51 | using std::abs; 52 | using std::max; 53 | 54 | if (std::isnan(lhs)) 55 | { 56 | return std::isnan(rhs); 57 | } 58 | 59 | if (std::isinf(lhs)) 60 | { 61 | return std::isinf(rhs) && (lhs * rhs > 0) /* same sign */; 62 | } 63 | 64 | T relative_precision = 2048 * std::numeric_limits::epsilon(); 65 | T absolute_zero_prox = 2048 * std::numeric_limits::epsilon(); 66 | 67 | if (max(abs(lhs), abs(rhs)) < T(1e-3)) 68 | { 69 | using res_type = decltype(lhs - rhs); 70 | return detail::check_is_small(lhs - rhs, res_type(absolute_zero_prox)); 71 | } 72 | else 73 | { 74 | return detail::check_is_close(lhs, rhs, relative_precision); 75 | } 76 | } 77 | 78 | template 79 | bool scalar_near(const std::complex& lhs, const std::complex& rhs) 80 | { 81 | return scalar_near(lhs.real(), rhs.real()) && scalar_near(lhs.imag(), rhs.imag()); 82 | } 83 | 84 | template 85 | bool tensor_near(const E1& e1, const E2& e2) 86 | { 87 | bool res = e1.dimension() == e2.dimension() 88 | && std::equal(e1.shape().begin(), e1.shape().end(), e2.shape().begin()); 89 | auto iter1 = e1.begin(); 90 | auto iter2 = e2.begin(); 91 | auto iter_end = e1.end(); 92 | while (res && iter1 != iter_end) 93 | { 94 | res = scalar_near(*iter1++, *iter2++); 95 | } 96 | return res; 97 | } 98 | } 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /test/test_xchunked_view.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include "xtensor/chunk/xchunked_array.hpp" 11 | #include "xtensor/chunk/xchunked_view.hpp" 12 | #include "xtensor/containers/xarray.hpp" 13 | 14 | #include "test_common_macros.hpp" 15 | 16 | namespace xt 17 | { 18 | TEST(xchunked_view, iterate) 19 | { 20 | std::vector shape = {3, 4}; 21 | std::vector chunk_shape = {1, 2}; 22 | xarray a(shape); 23 | std::size_t chunk_nb = 0; 24 | auto chunked_view = xchunked_view>(a, chunk_shape); 25 | for (auto it = chunked_view.chunk_begin(); it != chunked_view.chunk_end(); it++) 26 | { 27 | chunk_nb++; 28 | } 29 | 30 | std::size_t expected_chunk_nb = (shape[0] / chunk_shape[0]) * (shape[1] / chunk_shape[1]); 31 | 32 | EXPECT_EQ(chunk_nb, expected_chunk_nb); 33 | } 34 | 35 | TEST(xchunked_view, assign) 36 | { 37 | std::vector shape = {3, 4}; 38 | std::vector chunk_shape = {1, 2}; 39 | xarray a(shape); 40 | std::vector data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; 41 | std::copy(data.cbegin(), data.cend(), a.begin()); 42 | xarray b(shape); 43 | 44 | as_chunked(b, chunk_shape) = a; 45 | 46 | EXPECT_EQ(a, b); 47 | } 48 | 49 | TEST(xchunked_view, assign_chunked_array) 50 | { 51 | std::vector shape = {10, 10, 10}; 52 | std::vector chunk_shape = {2, 3, 4}; 53 | auto a = chunked_array(shape, chunk_shape); 54 | xarray b(shape); 55 | auto ref = arange(0, 1000).reshape(shape); 56 | 57 | as_chunked(a, chunk_shape) = ref; 58 | as_chunked(b, chunk_shape) = a; 59 | 60 | EXPECT_EQ(ref, a); 61 | EXPECT_EQ(ref, b); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /test/test_xcsv.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include 11 | #include 12 | 13 | #include "xtensor/core/xmath.hpp" 14 | #include "xtensor/io/xcsv.hpp" 15 | #include "xtensor/io/xio.hpp" 16 | 17 | #include "test_common_macros.hpp" 18 | 19 | namespace xt 20 | { 21 | TEST(xcsv, load_double) 22 | { 23 | std::string source = "1.0, 2.0, 3.0, 4.0\n" 24 | "10.0, 12.0, 15.0, 18.0"; 25 | 26 | std::stringstream source_stream(source); 27 | 28 | xtensor res = load_csv(source_stream); 29 | 30 | xtensor exp{{1.0, 2.0, 3.0, 4.0}, {10.0, 12.0, 15.0, 18.0}}; 31 | 32 | ASSERT_TRUE(all(equal(res, exp))); 33 | } 34 | 35 | TEST(xcsv, load_double_with_options) 36 | { 37 | std::string source = "A B C D\n" 38 | "#0.0 1.0 1.1 1.2\n" 39 | "1.0 2.0 3.0 4.0\n" 40 | "10.0 12.0 15.0 18.0\n" 41 | "9.0, 8.0, 7.0, 6."; 42 | 43 | std::stringstream source_stream(source); 44 | 45 | auto res = load_csv(source_stream, ' ', 1, 2, "#"); 46 | 47 | xtensor exp{{1.0, 2.0, 3.0, 4.0}, {10.0, 12.0, 15.0, 18.0}}; 48 | 49 | ASSERT_TRUE(all(equal(res, exp))); 50 | } 51 | 52 | TEST(xcsv, dump_double) 53 | { 54 | xtensor data{{1.0, 2.0, 3.0, 4.0}, {10.0, 12.0, 15.0, 18.0}}; 55 | 56 | std::stringstream res; 57 | 58 | dump_csv(res, data); 59 | ASSERT_EQ("1,2,3,4\n10,12,15,18\n", res.str()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /test/test_xdatesupport.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #if defined(__GNUC__) && (__GNUC__ == 7) && (__cplusplus == 201703L) 11 | #warning "test_xdatesupport.cpp has been deactivated because it leads to internal compiler error" 12 | #else 13 | 14 | #include 15 | 16 | #include "xtensor/containers/xarray.hpp" 17 | #include "xtensor/containers/xfixed.hpp" 18 | #include "xtensor/containers/xtensor.hpp" 19 | #include "xtensor/core/xmath.hpp" 20 | #include "xtensor/io/xio.hpp" 21 | 22 | #include "test_common_macros.hpp" 23 | 24 | namespace xt 25 | { 26 | using days = std::chrono::duration>; 27 | using days_time_point = std::chrono::time_point; 28 | using tp = std::chrono::system_clock::time_point; 29 | 30 | std::ostream& operator<<(std::ostream& os, const days_time_point& /*rhs*/) 31 | { 32 | // Too many problems with puttime on old compilers, so removing it. 33 | // std::time_t x = std::chrono::system_clock::to_time_t(rhs); 34 | // os << std::put_time(std::gmtime(&x), "%F %T"); 35 | os << "puttime here"; 36 | return os; 37 | } 38 | 39 | TEST(xdate, xarray_of_dates) 40 | { 41 | xt::xarray dates( 42 | {days_time_point{days{300}}, 43 | days_time_point{days{400}}, 44 | days_time_point{days{600}}, 45 | days_time_point{days{10000}}} 46 | ); 47 | 48 | xt::xarray durations({days{300}, days{400}, days{600}, days{10000}}); 49 | 50 | xt::xarray result = dates + durations; 51 | xt::xarray result2 = dates + days{500}; 52 | 53 | xt::xarray expected = {true, true, false, false}; 54 | 55 | EXPECT_EQ((result < result2), expected); 56 | } 57 | 58 | // need to wait until the system clock on Windows catches up with Linux 59 | #ifndef _MSC_VER 60 | TEST(xdate, date_arange) 61 | { 62 | xarray tarr = xt::arange( 63 | std::chrono::system_clock::now(), 64 | std::chrono::system_clock::now() + std::chrono::hours(15), 65 | std::chrono::hours(1) 66 | ); 67 | EXPECT_TRUE(tarr.storage().back() > tarr.storage().front()); 68 | } 69 | #endif 70 | 71 | TEST(xdate, xfunction) 72 | { 73 | xarray tarr = { 74 | std::chrono::system_clock::now(), 75 | std::chrono::system_clock::now(), 76 | std::chrono::system_clock::now() 77 | }; 78 | 79 | auto hours = std::chrono::hours(15); 80 | 81 | auto func = tarr + hours; 82 | xarray arrpf = func; 83 | 84 | arrpf(0) -= std::chrono::hours(200); 85 | 86 | EXPECT_TRUE(all(equal(tarr, tarr))); 87 | xarray cmp_res = {true, false, false}; 88 | EXPECT_EQ(cmp_res, (arrpf < tarr)); 89 | EXPECT_EQ(!cmp_res, (arrpf > tarr)); 90 | cmp_res = {false, false, false}; 91 | EXPECT_EQ(cmp_res, equal(tarr, arrpf)); 92 | } 93 | } 94 | 95 | #endif // defined(__GNUC__) && (__GNUC__ == 7) && (__cplusplus == 201703L) 96 | -------------------------------------------------------------------------------- /test/test_xexception.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #ifndef XTENSOR_ENABLE_ASSERT 11 | #define XTENSOR_ENABLE_ASSERT 12 | #endif 13 | 14 | #include 15 | 16 | #include "xtensor/utils/xexception.hpp" 17 | 18 | #include "test_common_macros.hpp" 19 | 20 | namespace xt 21 | { 22 | 23 | TEST(xexception, macros) 24 | { 25 | XT_EXPECT_THROW(XTENSOR_ASSERT_MSG(false, "Intentional error"), std::runtime_error); 26 | XT_EXPECT_THROW(XTENSOR_PRECONDITION(false, "Intentional error"), std::runtime_error); 27 | } 28 | 29 | 30 | #if !defined(XTENSOR_DISABLE_EXCEPTIONS) 31 | TEST(xexception, assert) 32 | { 33 | try 34 | { 35 | XTENSOR_ASSERT_MSG(false, "Intentional error"); 36 | CHECK_MESSAGE(false, "no exception thrown"); 37 | } 38 | catch (std::runtime_error& e) 39 | { 40 | std::string expected("Assertion error!\nIntentional error"); 41 | std::string message(e.what()); 42 | EXPECT_TRUE(0 == expected.compare(message.substr(0, expected.size()))); 43 | } 44 | try 45 | { 46 | XTENSOR_PRECONDITION(false, "Intentional error"); 47 | CHECK_MESSAGE(false, "no exception thrown"); 48 | } 49 | catch (std::runtime_error& e) 50 | { 51 | std::string expected("Precondition violation!\nIntentional error"); 52 | std::string message(e.what()); 53 | EXPECT_TRUE(0 == expected.compare(message.substr(0, expected.size()))); 54 | } 55 | } 56 | #endif 57 | 58 | } // namespace xt 59 | -------------------------------------------------------------------------------- /test/test_xexpression_holder.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include "xtensor/containers/xarray.hpp" 11 | #include "xtensor/io/xio.hpp" 12 | #include "xtensor/misc/xexpression_holder.hpp" 13 | #include "xtensor/views/xview.hpp" 14 | 15 | #include "test_common_macros.hpp" 16 | 17 | namespace xt 18 | { 19 | TEST(xexpression_holder, ctor) 20 | { 21 | xarray a = {{1, 2, 3, 4}, {5, 6, 7, 8}}; 22 | xarray b = {{3, 2, 1}, {5, 6, 7}}; 23 | xarray c = {{56, 5, 2}, {4, 2, 6}}; 24 | 25 | xexpression_holder holder_a = xexpression_holder(a); 26 | xexpression_holder holder_b(b); 27 | xexpression_holder holder_c(std::move(xexpression_holder(c))); 28 | } 29 | 30 | TEST(xexpression_holder, assign) 31 | { 32 | xarray a = {{1, 2, 3, 4}, {5, 6, 7, 8}}; 33 | xarray b = {{3, 2, 1}, {5, 6, 7}}; 34 | xarray c = {{56, 5, 2}, {4, 2, 6}}; 35 | 36 | xexpression_holder holder_a = xexpression_holder(a); 37 | xexpression_holder holder_b(b); 38 | 39 | holder_a = holder_b; 40 | holder_b = xexpression_holder(c); 41 | } 42 | 43 | TEST(xexpression_holder, to_json) 44 | { 45 | xarray a = {{1, 2, 3, 4}, {5, 6, 7, 8}}; 46 | xexpression_holder holder_a = xexpression_holder(a); 47 | 48 | nlohmann::json json_out; 49 | to_json(json_out, holder_a); 50 | 51 | ASSERT_EQ(json_out[0][0], 1); 52 | ASSERT_EQ(json_out[0][1], 2); 53 | ASSERT_EQ(json_out[0][2], 3); 54 | ASSERT_EQ(json_out[1][1], 6); 55 | } 56 | 57 | TEST(xexpression_holder, from_json) 58 | { 59 | xarray a = {{1, 2, 3, 4}, {5, 6, 7, 8}}; 60 | xarray b = {{5, 6, 7, 8}, {1, 2, 3, 4}}; 61 | 62 | xexpression_holder holder_a = xexpression_holder(a); 63 | 64 | nlohmann::json json_b; 65 | to_json(json_b, b); 66 | from_json(json_b, holder_a); 67 | 68 | ASSERT_EQ(a, b); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /test/test_xexpression_traits.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include "xtensor/containers/xarray.hpp" 11 | #include "xtensor/containers/xfixed.hpp" 12 | #include "xtensor/containers/xtensor.hpp" 13 | 14 | #include "test_common_macros.hpp" 15 | 16 | namespace xt 17 | { 18 | TEST(xexpression_traits, common_tensor_deduction) 19 | { 20 | xt::xarray a1{0.0, 0.0, 0.0}; 21 | xt::xtensor a2{0.0, 0.0, 0.0}; 22 | xt::xtensor_fixed> a3({0.0, 0.0, 0.0}); 23 | 24 | EXPECT_TRUE((std::is_same, decltype(a1)>::value)); 25 | EXPECT_TRUE((std::is_same, decltype(a2)>::value)); 26 | EXPECT_TRUE((std::is_same, decltype(a3)>::value)); 27 | 28 | EXPECT_TRUE((std::is_same, decltype(a1)>::value)); 29 | EXPECT_TRUE((std::is_same, decltype(a1)>::value)); 30 | EXPECT_TRUE((std::is_same, decltype(a2)>::value)); 31 | 32 | auto sum1 = a1 + a2; 33 | EXPECT_TRUE((std::is_same, decltype(a1)>::value)); 34 | auto sum2 = a1 + a3; 35 | EXPECT_TRUE((std::is_same, decltype(a1)>::value)); 36 | auto sum3 = a2 + a3; 37 | EXPECT_TRUE((std::is_same, decltype(a2)>::value)); 38 | 39 | xt::xarray b1{{0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}}; 40 | xt::xtensor b2{{0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}}; 41 | xt::xtensor_fixed> b3({{0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}}); 42 | 43 | EXPECT_TRUE((std::is_same, decltype(b1)>::value)); 44 | EXPECT_TRUE((std::is_same, decltype(b2)>::value)); 45 | EXPECT_TRUE((std::is_same, decltype(b3)>::value)); 46 | 47 | EXPECT_TRUE((std::is_same, decltype(b1)>::value)); 48 | EXPECT_TRUE((std::is_same, decltype(b1)>::value)); 49 | EXPECT_TRUE((std::is_same, decltype(b2)>::value)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/test_xfft.cpp: -------------------------------------------------------------------------------- 1 | #include "xtensor/containers/xarray.hpp" 2 | #include "xtensor/misc/xfft.hpp" 3 | 4 | #include "test_common_macros.hpp" 5 | 6 | namespace xt 7 | { 8 | TEST(xfft, fft_power_2) 9 | { 10 | size_t k = 2; 11 | size_t n = 8192; 12 | size_t A = 10; 13 | auto x = xt::linspace(0, static_cast(n - 1), n); 14 | xt::xarray y = A * xt::sin(2 * xt::numeric_constants::PI * x * k / n); 15 | auto res = xt::fft::fft(y) / (n / 2); 16 | REQUIRE(A == doctest::Approx(std::abs(res(k))).epsilon(.0001)); 17 | } 18 | 19 | TEST(xfft, ifft_power_2) 20 | { 21 | size_t k = 2; 22 | size_t n = 8; 23 | size_t A = 10; 24 | auto x = xt::linspace(0, static_cast(n - 1), n); 25 | xt::xarray y = A * xt::sin(2 * xt::numeric_constants::PI * x * k / n); 26 | auto res = xt::fft::ifft(y) / (n / 2); 27 | REQUIRE(A == doctest::Approx(std::abs(res(k))).epsilon(.0001)); 28 | } 29 | 30 | TEST(xfft, convolve_power_2) 31 | { 32 | xt::xarray x = {1.0, 1.0, 1.0, 5.0}; 33 | xt::xarray y = {5.0, 1.0, 1.0, 1.0}; 34 | xt::xarray expected = {12, 12, 12, 28}; 35 | 36 | auto result = xt::fft::convolve(x, y); 37 | 38 | for (size_t i = 0; i < x.size(); i++) 39 | { 40 | REQUIRE(expected(i) == doctest::Approx(std::abs(result(i))).epsilon(.0001)); 41 | } 42 | } 43 | 44 | TEST(xfft, fft_n_0_axis) 45 | { 46 | size_t k = 2; 47 | size_t n = 10; 48 | size_t A = 1; 49 | size_t dim = 10; 50 | auto x = xt::linspace(0, n - 1, n) * xt::ones({dim, n}); 51 | xt::xarray y = A * xt::sin(2 * xt::numeric_constants::PI * x * k / n); 52 | y = xt::transpose(y); 53 | auto res = xt::fft::fft(y, 0) / (n / 2.0); 54 | REQUIRE(A == doctest::Approx(std::abs(res(k, 0))).epsilon(.0001)); 55 | REQUIRE(A == doctest::Approx(std::abs(res(k, 1))).epsilon(.0001)); 56 | } 57 | 58 | TEST(xfft, fft_n_1_axis) 59 | { 60 | size_t k = 2; 61 | size_t n = 15; 62 | size_t A = 1; 63 | size_t dim = 2; 64 | auto x = xt::linspace(0, n - 1, n) * xt::ones({dim, n}); 65 | xt::xarray y = A * xt::sin(2 * xt::numeric_constants::PI * x * k / n); 66 | auto res = xt::fft::fft(y) / (n / 2.0); 67 | REQUIRE(A == doctest::Approx(std::abs(res(0, k))).epsilon(.0001)); 68 | REQUIRE(A == doctest::Approx(std::abs(res(1, k))).epsilon(.0001)); 69 | } 70 | 71 | TEST(xfft, convolve_n) 72 | { 73 | xt::xarray x = {1.0, 1.0, 1.0, 5.0, 1.0}; 74 | xt::xarray y = {5.0, 1.0, 1.0, 1.0, 1.0}; 75 | xt::xarray expected = {13, 13, 13, 29, 13}; 76 | 77 | auto result = xt::fft::convolve(x, y); 78 | 79 | xt::xarray abs = xt::abs(result); 80 | 81 | for (size_t i = 0; i < abs.size(); i++) 82 | { 83 | REQUIRE(expected(i) == doctest::Approx(abs(i)).epsilon(.0001)); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /test/test_xinfo.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include 11 | #include 12 | 13 | #include "xtensor/containers/xarray.hpp" 14 | #include "xtensor/io/xinfo.hpp" 15 | 16 | #include "test_common_macros.hpp" 17 | 18 | namespace xt 19 | { 20 | TEST(xinfo, compiles) 21 | { 22 | xarray test = {{1, 2, 3}, {4, 5, 6}}; 23 | std::stringstream ss; 24 | 25 | ss << info(test) << std::endl; 26 | } 27 | 28 | // See https://github.com/xtensor-stack/xtensor/issues/2694 29 | TEST(xinfo, typename) 30 | { 31 | xarray test = {{1, 2, 3}, {4, 5, 6}}; 32 | auto t_s = type_to_string(); 33 | std::string expected = "double"; 34 | #if defined(__clang__) 35 | WARN_EQ(expected, t_s); 36 | #else 37 | EXPECT_EQ(expected, t_s); 38 | #endif 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/test_xjson.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include 11 | 12 | #include "xtensor/containers/xarray.hpp" 13 | #include "xtensor/containers/xtensor.hpp" 14 | #include "xtensor/io/xjson.hpp" 15 | #include "xtensor/views/xview.hpp" 16 | 17 | #include "test_common_macros.hpp" 18 | 19 | namespace xt 20 | { 21 | TEST(xjson, xarray_to_json) 22 | { 23 | xt::xarray t = {{{1, 2}, {3, 4}}, {{1, 2}, {3, 4}}}; 24 | 25 | nlohmann::json jl = t; 26 | std::string s = jl.dump(); 27 | EXPECT_EQ(s, "[[[1.0,2.0],[3.0,4.0]],[[1.0,2.0],[3.0,4.0]]]"); 28 | } 29 | 30 | TEST(xjson, xarray_from_json) 31 | { 32 | nlohmann::json j = "[[[1.0,2.0],[3.0,4.0]],[[1.0,2.0],[3.0,4.0]]]"_json; 33 | auto arr = j.get>(); 34 | auto ref = xt::xarray({{{1, 2}, {3, 4}}, {{1, 2}, {3, 4}}}); 35 | EXPECT_TRUE(all(equal(arr, ref))); 36 | } 37 | 38 | TEST(xjson, xview_from_json) 39 | { 40 | xt::xarray arr = {{{1, 2}, {3, 4}}, {{1, 2}, {3, 4}}}; 41 | 42 | auto v = xt::view(arr, 0); 43 | auto j = "[[10.0,10.0],[10.0,10.0]]"_json; 44 | from_json(j, v); 45 | 46 | auto ref = xt::xarray({{{10, 10}, {10, 10}}, {{1, 2}, {3, 4}}}); 47 | EXPECT_TRUE(all(equal(arr, ref))); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /test/test_xmime.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include "xtensor/containers/xarray.hpp" 15 | #include "xtensor/io/xmime.hpp" 16 | 17 | #include "test_common_macros.hpp" 18 | 19 | namespace xt 20 | { 21 | TEST(xmime, xarray_two_d) 22 | { 23 | xarray e{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; 24 | 25 | nlohmann::json ser = mime_bundle_repr_impl(e); 26 | 27 | nlohmann::json ref = { 28 | {"text/html", 29 | "
  1.
  2.
  3.
  4.
  5.
  6.
  7.
  8.
  9.
 10.
 11.
 12.
" 30 | } 31 | }; 32 | 33 | EXPECT_EQ(ser, ref); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/test_xmultiindex_iterator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "xtensor/core/xmultiindex_iterator.hpp" 4 | 5 | #include "test_common.hpp" 6 | 7 | namespace xt 8 | { 9 | 10 | TEST_SUITE("xmultiindex_iterator") 11 | { 12 | TEST_CASE("sum") 13 | { 14 | using shape_type = std::vector; 15 | using iter_type = xmultiindex_iterator; 16 | 17 | shape_type roi_begin{2, 3, 4}; 18 | shape_type roi_end{3, 5, 6}; 19 | shape_type current{2, 3, 4}; 20 | iter_type iter(roi_begin, roi_end, current, 0); 21 | 22 | 23 | iter_type end(roi_begin, roi_end, roi_end, 4); 24 | 25 | shape_type should(3); 26 | for (should[0] = roi_begin[0]; should[0] < roi_end[0]; ++should[0]) 27 | { 28 | for (should[1] = roi_begin[1]; should[1] < roi_end[1]; ++should[1]) 29 | { 30 | for (should[2] = roi_begin[2]; should[2] < roi_end[2]; ++should[2]) 31 | { 32 | EXPECT_EQ(*iter, should); 33 | ++iter; 34 | } 35 | } 36 | } 37 | EXPECT_TRUE(iter == end); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /test/test_xset_operation.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include 11 | 12 | #include "xtensor/containers/xarray.hpp" 13 | #include "xtensor/containers/xtensor.hpp" 14 | #include "xtensor/misc/xset_operation.hpp" 15 | 16 | #include "test_common_macros.hpp" 17 | 18 | namespace xt 19 | { 20 | TEST(xset_operation, isin) 21 | { 22 | xt::xtensor a = {{1, 2, 1}, {0, 3, 1}}; 23 | xt::xtensor b = {1, 2}; 24 | xt::xtensor res = {{true, true, true}, {false, false, true}}; 25 | EXPECT_EQ(xt::isin(a, b), res); 26 | EXPECT_EQ(xt::isin(a, b.begin(), b.end()), res); 27 | EXPECT_EQ(xt::isin(a, {1, 2}), res); 28 | } 29 | 30 | TEST(xset_operation, in1d) 31 | { 32 | xt::xtensor a = {1, 2, 1, 0, 3, 5, 1}; 33 | xt::xtensor b = {1, 2}; 34 | xt::xtensor res = {true, true, true, false, false, false, true}; 35 | EXPECT_EQ(xt::in1d(a, b), res); 36 | EXPECT_EQ(xt::in1d(a, b.begin(), b.end()), res); 37 | EXPECT_EQ(xt::in1d(a, {1, 2}), res); 38 | } 39 | 40 | TEST(xset_operation, searchsorted) 41 | { 42 | xt::xtensor a = {1, 2, 7, 8, 20}; 43 | xt::xtensor v = {9, 2, 2, 3, 22, 0}; 44 | xt::xtensor res_right = {4, 1, 1, 2, 5, 0}; 45 | xt::xtensor res_left = {4, 2, 2, 2, 5, 0}; 46 | EXPECT_EQ(xt::searchsorted(a, v), res_right); 47 | EXPECT_EQ(xt::searchsorted(a, v, true), res_right); 48 | EXPECT_EQ(xt::searchsorted(a, v, false), res_left); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/test_xshape.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include "xtensor/containers/xarray.hpp" 11 | #include "xtensor/containers/xfixed.hpp" 12 | #include "xtensor/containers/xtensor.hpp" 13 | #include "xtensor/core/xshape.hpp" 14 | #include "xtensor/core/xstrides.hpp" 15 | #include "xtensor/views/xbroadcast.hpp" 16 | 17 | #include "test_common_macros.hpp" 18 | 19 | namespace xt 20 | { 21 | TEST(xshape, initializer_dimension) 22 | { 23 | size_t d0 = initializer_dimension::value; 24 | size_t d1 = initializer_dimension>::value; 25 | size_t d2 = initializer_dimension>>::value; 26 | EXPECT_EQ(size_t(0), d0); 27 | EXPECT_EQ(size_t(1), d1); 28 | EXPECT_EQ(size_t(2), d2); 29 | } 30 | 31 | TEST(xshape, shape) 32 | { 33 | auto s0 = shape>(3); 34 | auto s1 = shape>(std::initializer_list{1, 2}); 35 | auto s2 = shape>( 36 | std::initializer_list>{{1, 2, 4}, {1, 3, 5}} 37 | ); 38 | 39 | std::vector e0 = {}; 40 | std::vector e1 = {2}; 41 | std::vector e2 = {2, 3}; 42 | 43 | EXPECT_EQ(e0, s0); 44 | EXPECT_EQ(e1, s1); 45 | EXPECT_EQ(e2, s2); 46 | } 47 | 48 | TEST(xshape, promote_shape) 49 | { 50 | bool expect_v = std::is_same< 51 | dynamic_shape, 52 | promote_shape_t, std::array, std::array>>::value; 53 | 54 | bool expect_a = std::is_same< 55 | std::array, 56 | promote_shape_t, std::array, std::array>>::value; 57 | 58 | ASSERT_TRUE(expect_v); 59 | ASSERT_TRUE(expect_a); 60 | } 61 | 62 | TEST(xshape, has_shape) 63 | { 64 | std::array shape = {2, 3}; 65 | xt::xtensor A = xt::zeros(shape); 66 | ASSERT_TRUE(xt::has_shape(A, shape)); 67 | ASSERT_TRUE(xt::has_shape(A, {2, 3})); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /test/test_xsimd.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | #if defined(_MSC_VER) && !defined(__clang__) 10 | #define VS_SKIP_XFIXED 1 11 | #endif 12 | 13 | // xfixed leads to ICE in debug mode, this provides 14 | // an easy way to prevent compilation 15 | #ifndef VS_SKIP_XFIXED 16 | 17 | 18 | #if (_MSC_VER < 1910 && _WIN64) || (_MSC_VER >= 1910) || !defined(_MSC_VER) 19 | 20 | #include 21 | #include 22 | 23 | #include "xtensor/containers/xfixed.hpp" 24 | #include "xtensor/core/xtensor_config.hpp" 25 | 26 | #include "test_common_macros.hpp" 27 | 28 | // On VS2015, when compiling in x86 mode, alignas(T) leads to C2718 29 | // when used for a function parameter, even indirectly. This means that 30 | // we cannot pass parameters whose class is declared with alignas specifier 31 | // or any type wrapping or inheriting from such a type. 32 | // The xtensor_fixed class internally uses aligned_array which is declared as 33 | // alignas(something_different_from_0), hence the workaround. 34 | #if _MSC_VER < 1910 && !_WIN64 35 | #define VS_X86_WORKAROUND 1 36 | #endif 37 | 38 | 39 | template 40 | class alignas(XTENSOR_FIXED_ALIGN) Foo 41 | { 42 | public: 43 | 44 | using allocator_type = std::conditional_t< 45 | XTENSOR_FIXED_ALIGN != 0, 46 | xt_simd::aligned_allocator, 47 | std::allocator>; 48 | 49 | Foo(T fac) 50 | : m_fac(fac) 51 | { 52 | m_bar.fill(fac); 53 | } 54 | 55 | auto get() const 56 | { 57 | return m_bar; 58 | } 59 | 60 | private: 61 | 62 | xt::xtensor_fixed> m_bar; 63 | T m_fac; 64 | }; 65 | 66 | namespace xt 67 | { 68 | 69 | TEST(xsimd, alignas) 70 | { 71 | int fac = 10; 72 | Foo foo(10); 73 | EXPECT_TRUE(xt::sum(foo.get())() == fac * 10 * 10); 74 | } 75 | } 76 | 77 | #endif 78 | #endif // VS_SKIP_XFIXED 79 | -------------------------------------------------------------------------------- /test/test_xsimd8.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include 11 | 12 | #include "xtensor/containers/xarray.hpp" 13 | #include "xtensor/misc/xcomplex.hpp" 14 | 15 | #include "test_common_macros.hpp" 16 | 17 | namespace xt 18 | { 19 | using namespace std::complex_literals; 20 | 21 | TEST(xcomplex, arg) 22 | { 23 | xarray> cmplarg_0 = { 24 | {0.40101756 + 0.71233018i, 0.62731701 + 0.42786349i, 0.32415089 + 0.2977805i}, 25 | {0.24475928 + 0.49208478i, 0.69475518 + 0.74029639i, 0.59390240 + 0.35772892i}, 26 | {0.63179202 + 0.41720995i, 0.44025718 + 0.65472131i, 0.08372648 + 0.37380143i} 27 | }; 28 | xarray> res = xt::conj(cmplarg_0); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/test_xtensor_semantic.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include "xtensor/containers/xarray.hpp" 11 | #include "xtensor/containers/xtensor.hpp" 12 | 13 | #include "test_common.hpp" 14 | #include "test_common_macros.hpp" 15 | 16 | namespace xt 17 | { 18 | using array_type = xarray; 19 | using tensor_type = xtensor; 20 | using array_shape = array_type::shape_type; 21 | using tensor_shape = tensor_type::shape_type; 22 | 23 | TEST(xtensor_semantic, tensor_plus_tensor) 24 | { 25 | tensor_shape s = {3, 2}; 26 | tensor_type t1(s, 3.2); 27 | tensor_type t2(s, 2.5); 28 | tensor_type res = t1 + t2; 29 | EXPECT_EQ(res(0, 0), t1(0, 0) + t2(0, 0)); 30 | } 31 | 32 | TEST(xtensor_semantic, tensor_plus_array) 33 | { 34 | tensor_shape s1 = {3, 2}; 35 | tensor_type t1(s1, 3.2); 36 | array_shape s2 = {3, 2}; 37 | array_type t2(s2, 2.5); 38 | tensor_type res = t1 + t2; 39 | EXPECT_EQ(res(0, 0), t1(0, 0) + t2(0, 0)); 40 | } 41 | 42 | TEST(xtensor_semantic, array_plus_tensor) 43 | { 44 | tensor_shape s1 = {3, 2}; 45 | tensor_type t1(s1, 3.2); 46 | array_shape s2 = {3, 2}; 47 | array_type t2(s2, 2.5); 48 | array_type res = t1 + t2; 49 | EXPECT_EQ(res(0, 0), t1(0, 0) + t2(0, 0)); 50 | } 51 | 52 | TEST(xtensor_semantic, tensor_cast) 53 | { 54 | using int8_tensor = xtensor; 55 | using int32_tensor = xtensor; 56 | using double_tensor = xtensor; 57 | 58 | int8_tensor i8t = {{int8_t(0), int8_t(1)}, {int8_t(2), int8_t(3)}, {int8_t(4), int8_t(5)}}; 59 | 60 | int32_tensor i32t = {{int32_t(0), int32_t(1)}, {int8_t(2), int8_t(3)}, {int8_t(4), int8_t(5)}}; 61 | 62 | double_tensor dt = {{0., 1.}, {2., 3.}, {4., 5.}}; 63 | 64 | int32_tensor i32res = i8t; 65 | EXPECT_EQ(i32res, i32t); 66 | 67 | double_tensor dres = i32t; 68 | EXPECT_EQ(dres, dt); 69 | } 70 | 71 | TEST(xtensor_semantic, broadcasting_single_element) 72 | { 73 | xtensor t = xt::zeros({1, 1}); 74 | EXPECT_EQ(t.backstrides().size(), 2u); 75 | EXPECT_EQ(t.backstrides()[0], 0u); 76 | EXPECT_EQ(t.backstrides()[1], 0u); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /test/test_xvectorize.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * 3 | * Copyright (c) QuantStack * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | ****************************************************************************/ 9 | 10 | #include "xtensor/containers/xarray.hpp" 11 | #include "xtensor/core/xvectorize.hpp" 12 | 13 | #include "test_common_macros.hpp" 14 | 15 | namespace xt 16 | { 17 | double f1(double d1, double d2) 18 | { 19 | return d1 + d2; 20 | } 21 | 22 | using shape_type = dynamic_shape; 23 | 24 | TEST(xvectorize, function) 25 | { 26 | auto vecf1 = vectorize(f1); 27 | shape_type shape = {3, 2}; 28 | xarray a(shape, 1.5); 29 | xarray b(shape, 2.3); 30 | xarray c = vecf1(a, b); 31 | EXPECT_EQ(a(0, 0) + b(0, 0), c(0, 0)); 32 | } 33 | 34 | TEST(xvectorize, lambda) 35 | { 36 | auto lambda = [](double d1, double d2) 37 | { 38 | return d1 + d2; 39 | }; 40 | auto vec_lambda = vectorize(lambda); 41 | shape_type shape = {3, 2}; 42 | xarray a(shape, 1.5); 43 | xarray b(shape, 2.3); 44 | xarray c = vec_lambda(a, b); 45 | EXPECT_EQ(a(0, 0) + b(0, 0), c(0, 0)); 46 | } 47 | 48 | struct func 49 | { 50 | inline double operator()(double d1, double d2) const 51 | { 52 | return d1 + d2; 53 | } 54 | }; 55 | 56 | TEST(xvectorize, functor) 57 | { 58 | func f; 59 | auto vecfunc = vectorize(f); 60 | shape_type shape = {3, 2}; 61 | xarray a(shape, 1.5); 62 | xarray b(shape, 2.3); 63 | xarray c = vecfunc(a, b); 64 | EXPECT_EQ(a(0, 0) + b(0, 0), c(0, 0)); 65 | } 66 | 67 | TEST(xvectorize, noargument) 68 | { 69 | auto vecfunc = vectorize( 70 | [] 71 | { 72 | return double(1.); 73 | } 74 | ); 75 | shape_type shape = {3, 2}; 76 | xarray a(shape, 1.5); 77 | a = vecfunc(); 78 | EXPECT_EQ(size_t(0), a.dimension()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /tools/check_circular.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import sys 5 | import networkx as nx 6 | 7 | def build_graph(path): 8 | graph = nx.DiGraph() 9 | for f in os.listdir(path): 10 | graph.add_node(f) 11 | cnt = 0 12 | with open(path+"/"+f) as fp: 13 | line = fp.readline() 14 | enter_include = False 15 | exit_include = False 16 | while line and not exit_include: 17 | if line.startswith('#include "'): 18 | enter_include = True 19 | node = line.split()[1].replace('"', '') 20 | graph.add_node(node) 21 | graph.add_edge(f, node) 22 | elif enter_include: 23 | exit_include = True 24 | line = fp.readline() 25 | return graph 26 | 27 | def main(): 28 | graph = build_graph("../include/xtensor") 29 | cycle = list(nx.simple_cycles(graph)) 30 | for x in cycle: 31 | print(x) 32 | exception_message = ' - '.join([str(y) for y in cycle]) 33 | if len(cycle) != 0: 34 | raise Exception('CircularInclude', exception_message) 35 | 36 | main() 37 | -------------------------------------------------------------------------------- /xtensor.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | includedir=${prefix}/include 3 | 4 | Name: xtensor 5 | Description: xtensor is a C++ library meant for numerical analysis with multi-dimensional array expressions. 6 | Version: @xtensor_VERSION@ 7 | Cflags: -I${includedir} 8 | -------------------------------------------------------------------------------- /xtensorConfig.cmake.in: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht # 3 | # Copyright (c) QuantStack 4 | # # 5 | # Distributed under the terms of the BSD 3-Clause License. # 6 | # # 7 | # The full license is in the file LICENSE, distributed with this software. # 8 | ############################################################################ 9 | 10 | # xtensor cmake module 11 | # This module sets the following variables in your project:: 12 | # 13 | # xtensor_FOUND - true if xtensor found on the system 14 | # xtensor_INCLUDE_DIRS - the directory containing xtensor headers 15 | # xtensor_LIBRARY - empty 16 | 17 | @PACKAGE_INIT@ 18 | 19 | include(CMakeFindDependencyMacro) 20 | find_dependency(xtl @xtl_REQUIRED_VERSION@) 21 | 22 | if(NOT TARGET @PROJECT_NAME@) 23 | include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") 24 | get_target_property(@PROJECT_NAME@_INCLUDE_DIRS @PROJECT_NAME@ INTERFACE_INCLUDE_DIRECTORIES) 25 | endif() 26 | 27 | if(XTENSOR_USE_XSIMD) 28 | find_dependency(xsimd @xsimd_REQUIRED_VERSION@) 29 | target_link_libraries(@PROJECT_NAME@ INTERFACE xsimd) 30 | target_compile_definitions(@PROJECT_NAME@ INTERFACE XTENSOR_USE_XSIMD) 31 | endif() 32 | 33 | if(XTENSOR_USE_TBB) 34 | find_dependency(TBB) 35 | target_link_libraries(@PROJECT_NAME@ INTERFACE TBB::tbb) 36 | target_compile_definitions(@PROJECT_NAME@ INTERFACE XTENSOR_USE_TBB) 37 | endif() 38 | 39 | if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER_EQUAL 3.11) 40 | if(NOT TARGET xtensor::optimize) 41 | add_library(xtensor::optimize INTERFACE IMPORTED) 42 | # Microsoft compiler 43 | if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_MSVC) 44 | target_compile_options(xtensor::optimize INTERFACE /EHsc /MP /bigobj) 45 | # gcc, clang, ... 46 | else() 47 | include(CheckCXXCompilerFlag) 48 | CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported) 49 | if(arch_native_supported) 50 | target_compile_options(xtensor::optimize INTERFACE -march=native) 51 | endif() 52 | endif() 53 | endif() 54 | 55 | if(NOT TARGET xtensor::use_xsimd) 56 | find_package(xsimd QUIET) 57 | if (xsimd_FOUND) 58 | add_library(xtensor::use_xsimd INTERFACE IMPORTED) 59 | target_link_libraries(xtensor::use_xsimd INTERFACE xsimd) 60 | target_compile_definitions(xtensor::use_xsimd INTERFACE XTENSOR_USE_XSIMD) 61 | endif() 62 | endif() 63 | 64 | if(NOT TARGET xtensor::use_TBB) 65 | find_package(TBB QUIET) 66 | if (TBB_FOUND) 67 | add_library(xtensor::use_TBB INTERFACE IMPORTED) 68 | target_compile_definitions(xtensor::use_TBB INTERFACE XTENSOR_USE_TBB) 69 | endif() 70 | endif() 71 | endif() 72 | --------------------------------------------------------------------------------