├── .ci ├── install-clblas.sh ├── install-ocl-ubuntu.sh ├── post_review.py └── report_coverage.sh ├── .clang-format ├── .clang-tidy ├── .gitattributes ├── .github └── workflows │ ├── apple.yml │ ├── clangtidy.yml │ ├── code_format.yml │ ├── documentation.yml │ ├── linux.yml │ ├── sanitizer.yml │ └── windows.yml ├── .gitignore ├── CMakeLists.txt ├── Changelog ├── IDEs └── qtcreator │ ├── examples │ ├── configuration.pri │ ├── examples.pro │ └── tensor │ │ └── tensor.pro │ ├── include │ ├── detail │ │ └── detail.pri │ ├── experimental │ │ └── experimental.pri │ ├── include.pro │ ├── operation │ │ └── operation.pri │ ├── tensor │ │ └── tensor.pri │ └── traits │ │ └── traits.pri │ ├── test │ ├── begin_end.pro │ ├── comp_mat_erase.pro │ ├── concepts.pro │ ├── configuration.pri │ ├── num_columns.pro │ ├── num_rows.pro │ ├── placement_new.pro │ ├── size.pro │ ├── sparse_view_test.pro │ ├── test1.pro │ ├── test2.pro │ ├── test3.pro │ ├── test3_coo.pro │ ├── test3_mvov.pro │ ├── test4.pro │ ├── test5.pro │ ├── test6.pro │ ├── test7.pro │ ├── test_assignment.pro │ ├── test_banded_storage_layout.pro │ ├── test_complex_norms.pro │ ├── test_coordinate_matrix_always_do_full_sort.pro │ ├── test_coordinate_matrix_inplace_merge.pro │ ├── test_coordinate_matrix_sort.pro │ ├── test_coordinate_vector_inplace_merge.pro │ ├── test_fixed_containers.pro │ ├── test_inplace_solve_basic.pro │ ├── test_inplace_solve_mvov.pro │ ├── test_inplace_solve_sparse.pro │ ├── test_lu.pro │ ├── test_matrix_vector.pro │ ├── test_tensor.pro │ ├── test_ticket7296.pro │ ├── test_triangular.pro │ ├── triangular_access.pro │ └── triangular_layout.pro │ ├── tests.pri │ └── ublas_develop.pro ├── README.md ├── benchmarks ├── Jamfile ├── add.cpp ├── add.hpp ├── benchmark.hpp ├── init.hpp ├── inner_prod.cpp ├── mm_prod.cpp ├── mv_prod.cpp ├── opencl │ ├── Jamfile │ ├── add.cpp │ ├── benchmark.hpp │ ├── init.hpp │ ├── inner_prod.cpp │ ├── mm_prod.cpp │ ├── mv_prod.cpp │ └── outer_prod.cpp ├── outer_prod.cpp ├── plot.py ├── prod.hpp └── reference │ ├── add.cpp │ ├── inner_prod.cpp │ ├── mm_prod.cpp │ ├── mv_prod.cpp │ └── outer_prod.cpp ├── clblas.jam ├── codecov.yml ├── doc ├── .gitignore ├── Jamfile ├── ublas-docinfo-footer.html ├── ublas.adoc └── ublas │ ├── banded.adoc │ ├── blas.adoc │ ├── bounded_array.adoc │ ├── container_concept.adoc │ ├── expression_concept.adoc │ ├── hermitian.adoc │ ├── index.adoc │ ├── iterator_concept.adoc │ ├── matrix.adoc │ ├── matrix_expression.adoc │ ├── matrix_proxy.adoc │ ├── matrix_sparse.adoc │ ├── operations_overview.adoc │ ├── options.adoc │ ├── overview.adoc │ ├── products.adoc │ ├── range.adoc │ ├── release_notes.adoc │ ├── samples │ ├── Jamfile.v2 │ ├── assignment_examples.cpp │ ├── banded_adaptor.cpp │ ├── banded_matrix.cpp │ ├── bounded_array.cpp │ ├── compressed_matrix.cpp │ ├── compressed_vector.cpp │ ├── coordinate_matrix.cpp │ ├── coordinate_vector.cpp │ ├── ex_triangular.cpp │ ├── hermitian_adaptor.cpp │ ├── hermitian_matrix.cpp │ ├── identity_matrix.cpp │ ├── map_array.cpp │ ├── mapped_matrix.cpp │ ├── mapped_vector.cpp │ ├── matrix.cpp │ ├── matrix_binary.cpp │ ├── matrix_binary_scalar.cpp │ ├── matrix_column.cpp │ ├── matrix_column_project.cpp │ ├── matrix_matrix_binary.cpp │ ├── matrix_matrix_solve.cpp │ ├── matrix_range.cpp │ ├── matrix_range_project.cpp │ ├── matrix_row.cpp │ ├── matrix_row_project.cpp │ ├── matrix_slice.cpp │ ├── matrix_slice_project.cpp │ ├── matrix_unary.cpp │ ├── matrix_vector_binary.cpp │ ├── matrix_vector_range.cpp │ ├── matrix_vector_slice.cpp │ ├── matrix_vector_solve.cpp │ ├── range.cpp │ ├── slice.cpp │ ├── symmetric_adaptor.cpp │ ├── symmetric_matrix.cpp │ ├── triangular_adaptor.cpp │ ├── triangular_matrix.cpp │ ├── unbounded_array.cpp │ ├── unit_vector.cpp │ ├── vector.cpp │ ├── vector_binary.cpp │ ├── vector_binary_outer.cpp │ ├── vector_binary_redux.cpp │ ├── vector_binary_scalar.cpp │ ├── vector_range.cpp │ ├── vector_range_project.cpp │ ├── vector_slice.cpp │ ├── vector_slice_project.cpp │ ├── vector_unary.cpp │ ├── vector_unary_redux.cpp │ ├── zero_matrix.cpp │ └── zero_vector.cpp │ ├── storage_concept.adoc │ ├── storage_sparse.adoc │ ├── symmetric.adoc │ ├── tensor.adoc │ ├── tensor │ ├── extents.adoc │ ├── strides.adoc │ ├── tensor_expression.adoc │ └── tensor_index.adoc │ ├── triangular.adoc │ ├── types_overview.adoc │ ├── unbounded_array.adoc │ ├── vector.adoc │ ├── vector_expression.adoc │ ├── vector_proxy.adoc │ └── vector_sparse.adoc ├── examples └── tensor │ ├── Jamfile │ ├── access_tensor.cpp │ ├── instantiate_tensor.cpp │ ├── multiply_tensors_einstein_notation.cpp │ ├── multiply_tensors_product_function.cpp │ └── simple_expressions.cpp ├── include └── boost │ └── numeric │ └── ublas │ ├── assignment.hpp │ ├── banded.hpp │ ├── blas.hpp │ ├── detail │ ├── concepts.hpp │ ├── config.hpp │ ├── definitions.hpp │ ├── documentation.hpp │ ├── duff.hpp │ ├── iterator.hpp │ ├── matrix_assign.hpp │ ├── raw.hpp │ ├── returntype_deduction.hpp │ ├── temporary.hpp │ └── vector_assign.hpp │ ├── doxydoc.hpp │ ├── exception.hpp │ ├── experimental │ └── sparse_view.hpp │ ├── expression_types.hpp │ ├── functional.hpp │ ├── fwd.hpp │ ├── hermitian.hpp │ ├── io.hpp │ ├── lu.hpp │ ├── matrix.hpp │ ├── matrix_expression.hpp │ ├── matrix_proxy.hpp │ ├── matrix_sparse.hpp │ ├── matrix_vector.hpp │ ├── opencl.hpp │ ├── opencl │ ├── elementwise.hpp │ ├── library.hpp │ ├── matrix.hpp │ ├── misc.hpp │ ├── operations.hpp │ ├── prod.hpp │ ├── transpose.hpp │ └── vector.hpp │ ├── operation.hpp │ ├── operation │ ├── begin.hpp │ ├── c_array.hpp │ ├── end.hpp │ ├── num_columns.hpp │ ├── num_rows.hpp │ └── size.hpp │ ├── operation_blocked.hpp │ ├── operation_sparse.hpp │ ├── operations.hpp │ ├── storage.hpp │ ├── storage_sparse.hpp │ ├── symmetric.hpp │ ├── tags.hpp │ ├── tensor.hpp │ ├── tensor │ ├── algorithms.hpp │ ├── concepts.hpp │ ├── expression.hpp │ ├── expression_evaluation.hpp │ ├── extents.hpp │ ├── extents │ │ ├── extents_base.hpp │ │ ├── extents_dynamic_size.hpp │ │ ├── extents_functions.hpp │ │ ├── extents_static.hpp │ │ ├── extents_static_functions.hpp │ │ └── extents_static_size.hpp │ ├── fixed_rank_strides.hpp │ ├── function │ │ ├── conj.hpp │ │ ├── imag.hpp │ │ ├── init.hpp │ │ ├── inner_prod.hpp │ │ ├── norm.hpp │ │ ├── outer_prod.hpp │ │ ├── real.hpp │ │ ├── reshape.hpp │ │ ├── tensor_times_matrix.hpp │ │ ├── tensor_times_tensor.hpp │ │ ├── tensor_times_vector.hpp │ │ └── trans.hpp │ ├── functions.hpp │ ├── index.hpp │ ├── index_functions.hpp │ ├── layout.hpp │ ├── multi_index.hpp │ ├── multi_index_utility.hpp │ ├── multiplication.hpp │ ├── operators_arithmetic.hpp │ ├── operators_comparison.hpp │ ├── ostream.hpp │ ├── tags.hpp │ ├── tensor.hpp │ ├── tensor │ │ ├── tensor_core.hpp │ │ ├── tensor_dynamic.hpp │ │ ├── tensor_engine.hpp │ │ ├── tensor_static.hpp │ │ └── tensor_static_rank.hpp │ ├── traits │ │ ├── basic_type_traits.hpp │ │ └── storage_traits.hpp │ └── type_traits.hpp │ ├── traits.hpp │ ├── traits │ ├── c_array.hpp │ ├── const_iterator_type.hpp │ └── iterator_type.hpp │ ├── triangular.hpp │ ├── vector.hpp │ ├── vector_expression.hpp │ ├── vector_of_vector.hpp │ ├── vector_proxy.hpp │ └── vector_sparse.hpp ├── index.html ├── meta └── libraries.json ├── opencl.jam └── test ├── Jamfile ├── README ├── begin_end.cpp ├── common ├── init.hpp └── testhelper.hpp ├── comp_mat_erase.cpp ├── concepts.cpp ├── manual ├── Jamfile.v2 ├── sp_resize.cpp └── test_move_semantics.cpp ├── minimal_allocator_test.cpp ├── num_columns.cpp ├── num_rows.cpp ├── opencl ├── Jamfile ├── elementwise_operations_test.cpp ├── elementwise_operations_test.hpp ├── elementwise_operations_with_constants_test.cpp ├── elementwise_operations_with_constants_test.hpp ├── inner_prod_test.cpp ├── inner_prod_test.hpp ├── norm2_test.cpp ├── norm2_test.hpp ├── norm_test.cpp ├── norm_test.hpp ├── outer_prod_test.cpp ├── outer_prod_test.hpp ├── prod_test.cpp ├── prod_test.hpp ├── test_opencl.hpp ├── transposition_test.cpp └── transposition_test.hpp ├── placement_new.cpp ├── size.cpp ├── sparse_view_test.cpp ├── tensor ├── Jamfile ├── algorithm │ ├── test_algorithm_accumulate.cpp │ ├── test_algorithm_copy.cpp │ ├── test_algorithm_trans.cpp │ └── test_algorithm_transform.cpp ├── extents │ ├── test_extents_access_operator.cpp │ ├── test_extents_assignment_operator.cpp │ ├── test_extents_at.cpp │ ├── test_extents_comparision.cpp │ ├── test_extents_construction.cpp │ ├── test_extents_empty.cpp │ ├── test_extents_is_matrix.cpp │ ├── test_extents_is_scalar.cpp │ ├── test_extents_is_tensor.cpp │ ├── test_extents_is_valid.cpp │ ├── test_extents_is_vector.cpp │ ├── test_extents_product.cpp │ └── test_extents_size.cpp ├── fixture_utility.hpp ├── functions │ ├── test_functions_inner.cpp │ ├── test_functions_matrix.cpp │ ├── test_functions_norm.cpp │ ├── test_functions_outer.cpp │ ├── test_functions_real_imag_conj.cpp │ ├── test_functions_tensor.cpp │ ├── test_functions_tensor_permutation.cpp │ ├── test_functions_trans.cpp │ └── test_functions_vector.cpp ├── multiplication │ ├── test_multiplication_inner.cpp │ ├── test_multiplication_mtm.cpp │ ├── test_multiplication_mtv.cpp │ ├── test_multiplication_outer.cpp │ ├── test_multiplication_ttm.cpp │ ├── test_multiplication_ttt.cpp │ ├── test_multiplication_ttt_permutation.cpp │ └── test_multiplication_ttv.cpp ├── tensor │ ├── test_tensor_access_operator.cpp │ ├── test_tensor_assignment_operator.cpp │ ├── test_tensor_at.cpp │ ├── test_tensor_binary_expression.cpp │ ├── test_tensor_comparision.cpp │ ├── test_tensor_comparision_with_scalar.cpp │ ├── test_tensor_comparision_with_tensor_expression.cpp │ ├── test_tensor_construction.cpp │ ├── test_tensor_empty.cpp │ ├── test_tensor_expression_access.cpp │ ├── test_tensor_expression_evaluation_all_extents_equal.cpp │ ├── test_tensor_expression_evaluation_retrieve_extents.cpp │ ├── test_tensor_operator_arithmetic_assignment.cpp │ ├── test_tensor_operator_arithmetic_binary.cpp │ ├── test_tensor_operator_arithmetic_unary.cpp │ ├── test_tensor_size.cpp │ └── test_tensor_unary_expression.cpp ├── test_einstein_notation.cpp ├── test_main.cpp ├── test_multi_index.cpp ├── test_multi_index_utility.cpp ├── test_strides.cpp ├── test_tensor.cpp └── utility.hpp ├── test1.cpp ├── test1.hpp ├── test11.cpp ├── test12.cpp ├── test13.cpp ├── test2.cpp ├── test2.hpp ├── test21.cpp ├── test22.cpp ├── test23.cpp ├── test3.cpp ├── test3.hpp ├── test31.cpp ├── test32.cpp ├── test33.cpp ├── test4.cpp ├── test4.hpp ├── test42.cpp ├── test43.cpp ├── test5.cpp ├── test5.hpp ├── test52.cpp ├── test53.cpp ├── test6.cpp ├── test6.hpp ├── test62.cpp ├── test63.cpp ├── test7.cpp ├── test7.hpp ├── test71.cpp ├── test72.cpp ├── test73.cpp ├── test_assignment.cpp ├── test_banded_storage_layout.cpp ├── test_complex_norms.cpp ├── test_coordinate_matrix_inplace_merge.cpp ├── test_coordinate_matrix_sort.cpp ├── test_coordinate_vector_inplace_merge.cpp ├── test_fixed_containers.cpp ├── test_inplace_solve.cpp ├── test_lu.cpp ├── test_matrix_vector.cpp ├── test_scaled_norm.cpp ├── test_ticket7296.cpp ├── test_triangular.cpp ├── triangular_access.cpp ├── triangular_layout.cpp └── utils.hpp /.ci/install-clblas.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash -e 2 | 3 | wget https://github.com/clMathLibraries/clBLAS/releases/download/v2.12/clBLAS-2.12.0-Linux-x64.tar.gz 4 | tar xvf clBLAS-2.12.0-Linux-x64.tar.gz 5 | if [ ${CLBLAS_PREFIX} ]; then 6 | echo "Installing clBLAS-2.12.0" 7 | mkdir -p ${CLBLAS_PREFIX}/lib/ 8 | cp -r clBLAS-2.12.0-Linux-x64/include ${CLBLAS_PREFIX}/include 9 | cp -r clBLAS-2.12.0-Linux-x64/lib64/* ${CLBLAS_PREFIX}/lib/ 10 | cp -r clBLAS-2.12.0-Linux-x64/bin ${CLBLAS_PREFIX}/bin 11 | else 12 | echo "CLBLAS_PREFIX is not set. Skipping CLBLAS Installation" 13 | fi 14 | -------------------------------------------------------------------------------- /.ci/report_coverage.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash -e 2 | 3 | sudo apt-get install lcov 4 | lcov --directory $BOOST_ROOT --capture --output-file coverage.info 5 | 6 | # Remove all unwanted coverages libs. 7 | # Boost.uBLAS depends uses many internal boost libs, we don't want them to be in coverage. 8 | 9 | lcov --extract coverage.info "*/boost/numeric/ublas/tensor/*" "*/libs/numeric/ublas/tensor/*" --output-file coverage.info 10 | lcov --list coverage.info 11 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | --- 2 | Checks: '-*,clang-*,bugprone-*,cppcoreguidelines-*,google-*,hicpp-*,modernize-*,performance-*,readability-*,portability-*, 3 | -modernize-use-trailing-return-type, -readability-uppercase-literal-suffix, -readability-braces-around-statements, -hicpp-uppercase-literal-suffix, -hicpp-braces-around-statements, -hicpp-no-array-decay, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -readability-avoid-const-params-in-decls, -google-readability-braces-around-statements,-google-explicit-constructor,-hicpp-vararg,-cppcoreguidelines-pro-type-vararg, -cppcoreguidelines-avoid-non-const-global-variables, -google-readability-todo, -cppcoreguidelines-pro-type-member-init, -hicpp-member-init, -cppcoreguidelines-special-member-functions, -hicpp-special-member-functions' 4 | HeaderFilterRegex: 'boost\/numeric\/ublas\/tensor\/.*' 5 | AnalyzeTemporaryDtors: false 6 | FormatStyle: file 7 | User: ublas-developers 8 | CheckOptions: 9 | - key: modernize-use-nullptr.NullMacros 10 | value: 'NULL' 11 | - key: readability-magic-numbers.IgnoredIntegerValues 12 | value: '1;2;3;4;5;6;7;8;9;' 13 | - key: cppcoreguidelines-avoid-magic-numbers.IgnoredIntegerValues 14 | value: '1;2;3;4;5;6;7;8;9;' 15 | ... 16 | -------------------------------------------------------------------------------- /.github/workflows/apple.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Mohammad Ashar Khan 2 | # Copyright (c) 2021 Cem Bassoy 3 | # Distributed under Boost Software License, Version 1.0 4 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 5 | 6 | name: "Apple MacOS" 7 | 8 | on: 9 | push: 10 | paths-ignore: 11 | - '**.md' 12 | - 'doc/**' 13 | pull_request: 14 | paths-ignore: 15 | - '**.md' 16 | - 'doc/**' 17 | jobs: 18 | build: 19 | name: "MacOS 11 clang -std=c++${{matrix.cxxstd}}" 20 | runs-on: macos-11 21 | strategy: 22 | fail-fast: true 23 | matrix: 24 | cxxstd: [2a] 25 | 26 | steps: 27 | - uses: actions/checkout@v2 28 | 29 | - name: Git Clone Boost.uBlas 30 | run: | 31 | cd ${GITHUB_WORKSPACE} 32 | cd .. 33 | 34 | git clone -b master --depth 1 https://github.com/boostorg/boost.git boost-root 35 | cd boost-root 36 | echo "BOOST_ROOT=${PWD}" >> ${GITHUB_ENV} 37 | echo $BOOST_ROOT 38 | 39 | git submodule update --init --depth=1 --jobs 8 tools/build 40 | git submodule update --init --depth=1 --jobs 8 libs/config 41 | git submodule update --init --depth=1 --jobs 8 tools/boostdep 42 | 43 | mkdir -p libs/numeric/ 44 | cp -rp ${GITHUB_WORKSPACE}/. libs/numeric/ublas 45 | python tools/boostdep/depinst/depinst.py -g " --depth=1" -I benchmarks numeric/ublas 46 | 47 | - name: Bootstrap and Compile Boost.uBlas 48 | run: | 49 | cd $BOOST_ROOT 50 | ./bootstrap.sh 51 | ./b2 -j8 headers 52 | echo "using clang : : $(brew --prefix llvm)/bin/clang++ ;" >> ~/user-config.jam; 53 | 54 | 55 | - name: Test Benchmarks 56 | run: | 57 | cd $BOOST_ROOT 58 | cd libs/numeric/ublas 59 | $BOOST_ROOT/b2 -j8 benchmarks cxxstd=${{matrix.cxxstd}} 60 | 61 | - name: Test Tensor Examples 62 | run: | 63 | cd $BOOST_ROOT 64 | cd libs/numeric/ublas 65 | $BOOST_ROOT/b2 -j8 examples/tensor cxxstd=${{matrix.cxxstd}} 66 | 67 | - name: Test Tensor 68 | run: | 69 | cd $BOOST_ROOT 70 | cd libs/numeric/ublas 71 | $BOOST_ROOT/b2 -j8 test/tensor cxxstd=${{matrix.cxxstd}} 72 | 73 | -------------------------------------------------------------------------------- /.github/workflows/clangtidy.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Mohammad Ashar Khan 2 | # Copyright (c) 2021 Cem Bassoy 3 | # Distributed under Boost Software License, Version 1.0 4 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 5 | 6 | name: "Static Analysis" 7 | 8 | on: 9 | push: 10 | paths-ignore: 11 | - '**.md' 12 | - 'doc/**' 13 | pull_request: 14 | paths-ignore: 15 | - '**.md' 16 | - 'doc/**' 17 | jobs: 18 | check: 19 | name: Linux Clang-Tidy 20 | runs-on: ubuntu-20.04 21 | steps: 22 | - uses: actions/checkout@v2 23 | 24 | - name: Install Clang 11 25 | run: sudo apt-get update && sudo apt-get install -y clang-11 clang-tidy-11 26 | 27 | - name: "Install Boost from Source" 28 | run: | 29 | cd .. 30 | git clone --depth 1 https://github.com/boostorg/boost.git --recursive --shallow-submodules 31 | cd boost 32 | ./bootstrap.sh 33 | ./b2 headers 34 | sudo cp -r -L boost /usr/include 35 | rm -rf boost 36 | 37 | - name: "Run Clang-Tidy" 38 | run: clang-tidy-11 examples/tensor/*.cpp test/tensor/*.cpp -- -Iinclude -std=c++20 > reports.txt 39 | 40 | - name: "Print Clang-Tidy Report" 41 | run: cat reports.txt 42 | 43 | - uses: actions/setup-python@v2 44 | 45 | - name: "Post review comments" 46 | if: github.event.pull_request.head.repo.full_name == github.repository 47 | run: | 48 | pip3 install 'unidiff~=0.6.0' --force-reinstall 49 | pip3 install 'PyGithub~=1.51' --force-reinstall 50 | pip3 install 'requests~=2.23' --force-reinstall 51 | python ./.ci/post_review.py --repository ${{ github.repository }} --token ${{ github.token}} --pr ${{ github.event.pull_request.number }} --path reports.txt 52 | 53 | -------------------------------------------------------------------------------- /.github/workflows/code_format.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Mohammad Ashar Khan 2 | # Distributed under Boost Software License, Version 1.0 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 4 | 5 | name: "Clang Code Format" 6 | 7 | on: 8 | push: 9 | paths-ignore: 10 | - '**.md' 11 | - 'doc/**' 12 | pull_request: 13 | paths-ignore: 14 | - '**.md' 15 | - 'doc/**' 16 | jobs: 17 | format: 18 | name: "Clang Code Formatting Check" 19 | runs-on: ubuntu-20.04 20 | steps: 21 | - uses: actions/checkout@v2 22 | 23 | - name: Install Clang Format 10 24 | run: | 25 | sudo apt-get install -y clang-format-10 26 | 27 | # - name: "Format Codes" 28 | # run: clang-format-10 -i examples/tensor/*.cpp test/tensor/*.cpp include/boost/numeric/ublas/tensor/*.hpp include/boost/numeric/ublas/tensor/*/*.hpp 29 | 30 | # - name: Check diff 31 | # run: git diff --exit-code HEAD 32 | -------------------------------------------------------------------------------- /.github/workflows/documentation.yml: -------------------------------------------------------------------------------- 1 | name: documentation 2 | 'on': 3 | push: 4 | paths: 5 | - doc/** 6 | pull_request: 7 | paths: 8 | - doc/** 9 | jobs: 10 | asciidoc: 11 | runs-on: ubuntu-latest 12 | name: asciidoc-documentation 13 | steps: 14 | - uses: actions/checkout@v2 15 | - uses: ruby/setup-ruby@v1 16 | with: 17 | ruby-version: 2.7 18 | - uses: reitzig/actions-asciidoctor@v2.0.0 19 | with: 20 | version: 2.0.10 21 | - run: asciidoctor doc/ublas.adoc 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | .DS_Store -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated by `boostdep --cmake numeric/ublas` 2 | # Copyright 2020, 2021 Peter Dimov 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # https://www.boost.org/LICENSE_1_0.txt 5 | 6 | cmake_minimum_required(VERSION 3.8...3.20) 7 | 8 | project(boost_numeric_ublas VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) 9 | 10 | add_library(boost_numeric_ublas INTERFACE) 11 | add_library(Boost::numeric_ublas ALIAS boost_numeric_ublas) 12 | 13 | target_include_directories(boost_numeric_ublas INTERFACE include) 14 | 15 | target_link_libraries(boost_numeric_ublas 16 | INTERFACE 17 | Boost::compute 18 | Boost::concept_check 19 | Boost::config 20 | Boost::core 21 | Boost::iterator 22 | Boost::mpl 23 | Boost::numeric_interval 24 | Boost::range 25 | Boost::serialization 26 | Boost::smart_ptr 27 | Boost::static_assert 28 | Boost::type_traits 29 | Boost::typeof 30 | ) 31 | 32 | target_compile_features(boost_numeric_ublas INTERFACE cxx_std_11) 33 | 34 | if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") 35 | 36 | add_subdirectory(test) 37 | 38 | endif() 39 | -------------------------------------------------------------------------------- /Changelog: -------------------------------------------------------------------------------- 1 | Version 1.1.0 2 | ------------- 3 | 4 | 2014-09-16: Nasos Iliopoulos <> 5 | * feature: Merged matrix row and column facades ( matrix as a vector of rows/columns ) 6 | 7 | 2014-05-03: David Bellot 8 | * removed doxygen documentation from main source 9 | * changed the changelog file for GNU format 10 | * changed doc extension to a more "standard" .html 11 | 12 | 2014-04-08 Nasos Iliopoulos <> 13 | 14 | * bugfix: introduced an additional swap implementation for index_pair_array and 15 | index_triple_array to allow proper compilation of sparse containers 16 | with g++>4.8 (4.7 also?) in C++11 mode. 17 | 18 | 2014-04-02 Nasos Iliopoulos <> 19 | 20 | * Added changelog 21 | * bugfix: corrected a big number of warnings coming from stray typedefs. Other 22 | similar issues may be present that are not triggered by the unit tests 23 | * bugfix: Corrected the banded matrix bug (https://svn.boost.org/trac/boost/ticket/7549) 24 | and updated appropriate unit tests. To enable the old (incorrect though) 25 | behaviour one should define BOOST_UBLAS_LEGACY_BANDED. 26 | -------------------------------------------------------------------------------- /IDEs/qtcreator/examples/configuration.pri: -------------------------------------------------------------------------------- 1 | CONFIG -= qt 2 | CONFIG += depend_includepath 3 | win*: CONFIG += console 4 | CONFIG += object_parallel_to_source 5 | 6 | QMAKE_CXXFLAGS =-std=c++20 7 | QMAKE_CXXFLAGS +=-Wall -Wpedantic -Wextra 8 | QMAKE_CXXFLAGS +=-Wno-unknown-pragmas 9 | QMAKE_CXXFLAGS +=-Wno-unused-but-set-variable 10 | 11 | gcc:QMAKE_CXXFLAGS_RELEASE =-O3 -march=native -fopenmp 12 | clang: QMAKE_CXXFLAGS_RELEASE =-O3 -march=native -fopenmp=libiomp5 13 | 14 | gcc:QMAKE_CXXFLAGS_DEBUG += -g 15 | clang: QMAKE_CXXFLAGS_DEBUG +=-g 16 | 17 | BOOST_ROOT=../../../../../../../.. 18 | QMAKE_RPATHDIR += $${BOOST_ROOT}/stage/lib 19 | INCLUDEPATH+=$$BOOST_ROOT/libs/numeric/ublas/include 20 | LIBS+=-L$${BOOST_ROOT}/stage/lib 21 | 22 | #message("INCLUDEPATH: $${INCLUDEPATH}") 23 | 24 | INCLUDE_DIR=$${BOOST_ROOT}/libs/numeric/ublas/include 25 | -------------------------------------------------------------------------------- /IDEs/qtcreator/examples/examples.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | SUBDIRS = tensor 3 | -------------------------------------------------------------------------------- /IDEs/qtcreator/examples/tensor/tensor.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | SUBDIRS = \ 3 | simple_expressions \ 4 | multiply_tensors_product_function \ 5 | multiply_tensors_einstein_notation \ 6 | instantiate_tensor \ 7 | access_tensor 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /IDEs/qtcreator/include/detail/detail.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $${INCLUDE_DIR}/boost/numeric/ublas/detail/vector_assign.hpp \ 3 | $${INCLUDE_DIR}/boost/numeric/ublas/detail/temporary.hpp \ 4 | $${INCLUDE_DIR}/boost/numeric/ublas/detail/returntype_deduction.hpp \ 5 | $${INCLUDE_DIR}/boost/numeric/ublas/detail/raw.hpp \ 6 | $${INCLUDE_DIR}/boost/numeric/ublas/detail/matrix_assign.hpp \ 7 | $${INCLUDE_DIR}/boost/numeric/ublas/detail/iterator.hpp \ 8 | $${INCLUDE_DIR}/boost/numeric/ublas/detail/duff.hpp \ 9 | $${INCLUDE_DIR}/boost/numeric/ublas/detail/documentation.hpp \ 10 | $${INCLUDE_DIR}/boost/numeric/ublas/detail/definitions.hpp \ 11 | $${INCLUDE_DIR}/boost/numeric/ublas/detail/config.hpp \ 12 | $${INCLUDE_DIR}/boost/numeric/ublas/detail/concepts.hpp 13 | -------------------------------------------------------------------------------- /IDEs/qtcreator/include/experimental/experimental.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $${INCLUDE_DIR}/boost/numeric/ublas/experimental/sparse_view.hpp 3 | -------------------------------------------------------------------------------- /IDEs/qtcreator/include/include.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | TARGET = ublas 3 | 4 | CONFIG += staticlib depend_includepath 5 | CONFIG -= qt 6 | CONFIG += c++20 7 | INCLUDE_DIR=../../../include 8 | 9 | include(detail/detail.pri) 10 | include(experimental/experimental.pri) 11 | include(operation/operation.pri) 12 | include(traits/traits.pri) 13 | include(tensor/tensor.pri) 14 | 15 | INCLUDEPATH += $${INCLUDE_DIR} 16 | 17 | HEADERS += \ 18 | $${INCLUDE_DIR}/boost/numeric/ublas/vector_sparse.hpp \ 19 | $${INCLUDE_DIR}/boost/numeric/ublas/vector_proxy.hpp \ 20 | $${INCLUDE_DIR}/boost/numeric/ublas/vector_of_vector.hpp \ 21 | $${INCLUDE_DIR}/boost/numeric/ublas/vector_expression.hpp \ 22 | $${INCLUDE_DIR}/boost/numeric/ublas/vector.hpp \ 23 | $${INCLUDE_DIR}/boost/numeric/ublas/triangular.hpp \ 24 | $${INCLUDE_DIR}/boost/numeric/ublas/traits.hpp \ 25 | $${INCLUDE_DIR}/boost/numeric/ublas/tags.hpp \ 26 | $${INCLUDE_DIR}/boost/numeric/ublas/symmetric.hpp \ 27 | $${INCLUDE_DIR}/boost/numeric/ublas/storage_sparse.hpp \ 28 | $${INCLUDE_DIR}/boost/numeric/ublas/storage.hpp \ 29 | $${INCLUDE_DIR}/boost/numeric/ublas/operation_sparse.hpp \ 30 | $${INCLUDE_DIR}/boost/numeric/ublas/operations.hpp \ 31 | $${INCLUDE_DIR}/boost/numeric/ublas/operation_blocked.hpp \ 32 | $${INCLUDE_DIR}/boost/numeric/ublas/operation.hpp \ 33 | $${INCLUDE_DIR}/boost/numeric/ublas/matrix_sparse.hpp \ 34 | $${INCLUDE_DIR}/boost/numeric/ublas/matrix_proxy.hpp \ 35 | $${INCLUDE_DIR}/boost/numeric/ublas/matrix_expression.hpp \ 36 | $${INCLUDE_DIR}/boost/numeric/ublas/matrix.hpp \ 37 | $${INCLUDE_DIR}/boost/numeric/ublas/lu.hpp \ 38 | $${INCLUDE_DIR}/boost/numeric/ublas/io.hpp \ 39 | $${INCLUDE_DIR}/boost/numeric/ublas/hermitian.hpp \ 40 | $${INCLUDE_DIR}/boost/numeric/ublas/fwd.hpp \ 41 | $${INCLUDE_DIR}/boost/numeric/ublas/functional.hpp \ 42 | $${INCLUDE_DIR}/boost/numeric/ublas/expression_types.hpp \ 43 | $${INCLUDE_DIR}/boost/numeric/ublas/exception.hpp \ 44 | $${INCLUDE_DIR}/boost/numeric/ublas/doxydoc.hpp \ 45 | $${INCLUDE_DIR}/boost/numeric/ublas/blas.hpp \ 46 | $${INCLUDE_DIR}/boost/numeric/ublas/banded.hpp \ 47 | $${INCLUDE_DIR}/boost/numeric/ublas/assignment.hpp \ 48 | $${INCLUDE_DIR}/boost/numeric/ublas/matrix_vector.hpp \ 49 | $${INCLUDE_DIR}/boost/numeric/ublas/tensor.hpp 50 | -------------------------------------------------------------------------------- /IDEs/qtcreator/include/operation/operation.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $${INCLUDE_DIR}/boost/numeric/ublas/operation/size.hpp \ 3 | $${INCLUDE_DIR}/boost/numeric/ublas/operation/num_rows.hpp \ 4 | $${INCLUDE_DIR}/boost/numeric/ublas/operation/num_columns.hpp \ 5 | $${INCLUDE_DIR}/boost/numeric/ublas/operation/end.hpp \ 6 | $${INCLUDE_DIR}/boost/numeric/ublas/operation/c_array.hpp \ 7 | $${INCLUDE_DIR}/boost/numeric/ublas/operation/begin.hpp 8 | -------------------------------------------------------------------------------- /IDEs/qtcreator/include/traits/traits.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $${INCLUDE_DIR}/boost/numeric/ublas/traits/iterator_type.hpp \ 3 | $${INCLUDE_DIR}/boost/numeric/ublas/traits/const_iterator_type.hpp \ 4 | $${INCLUDE_DIR}/boost/numeric/ublas/traits/c_array.hpp 5 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/begin_end.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = begin_end 3 | 4 | include (configuration.pri) 5 | 6 | HEADERS += \ 7 | ../../../test/utils.hpp 8 | 9 | SOURCES += \ 10 | ../../../test/begin_end.cpp 11 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/comp_mat_erase.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = comp_mat_erase 3 | 4 | win*: QMAKE_CXXFLAGS += /EHa 5 | 6 | include (configuration.pri) 7 | 8 | SOURCES += \ 9 | ../../../test/comp_mat_erase.cpp 10 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/concepts.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = concepts 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += \ 7 | EXTERNAL 8 | # INTERAL 9 | # SKIP_BAD 10 | 11 | linux: icc: QMAKE_CXXFLAGS += -Xc 12 | macx: QMAKE_CXXFLAGS += -fabi-version=0 13 | 14 | 15 | SOURCES += \ 16 | ../../../test/concepts.cpp 17 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/configuration.pri: -------------------------------------------------------------------------------- 1 | CONFIG -= qt 2 | CONFIG += \ 3 | depend_includepath \ 4 | debug 5 | win*: CONFIG += console 6 | 7 | QMAKE_CXXFLAGS += -fno-inline 8 | 9 | # Create a directory for each test. 10 | DESTDIR = $${TARGET} 11 | OBJECTS_DIR = $${TARGET} 12 | 13 | UBLAS_TESTSET = \ 14 | USE_DOUBLE USE_STD_COMPLEX \ 15 | USE_RANGE USE_SLICE \ 16 | USE_UNBOUNDED_ARRAY USE_STD_VECTOR USE_BOUNDED_VECTOR USE_MATRIX 17 | 18 | UBLAS_TESTSET_SPARSE = \ 19 | USE_DOUBLE USE_STD_COMPLEX \ 20 | USE_UNBOUNDED_ARRAY \ 21 | USE_MAP_ARRAY USE_STD_MAP \ 22 | USE_MAPPED_VECTOR USE_COMPRESSED_VECTOR \ 23 | USE_MAPPED_MATRIX USE_COMPRESSED_MATRIX 24 | # USE_RANGE USE_SLICE # Too complex for regression testing 25 | 26 | UBLAS_TESTSET_SPARSE_COO = \ 27 | USE_DOUBLE USE_STD_COMPLEX \ 28 | USE_UNBOUNDED_ARRAY \ 29 | USE_COORDINATE_VECTOR \ 30 | USE_COORDINATE_MATRIX 31 | 32 | DEFINES += BOOST_UBLAS_NO_EXCEPTIONS 33 | 34 | win*: DEFINES += _SCL_SECURE_NO_WARNINGS 35 | 36 | #Visual age IBM 37 | xlc: DEFINES += BOOST_UBLAS_NO_ELEMENT_PROXIES 38 | 39 | # ublas include and test directory are included 40 | INCLUDEPATH += \ 41 | ../../../include \ 42 | ../../../test 43 | 44 | # If ublas tests are build with boost source code then, 45 | # then boost headers and boost libraries should be used. 46 | exists(../../../../../../boost-build.jam) { 47 | INCLUDEPATH += ../../../../../.. 48 | LIBS += -L../../../../../../stage/lib 49 | QMAKE_RPATHDIR += ../../../../../../stage/lib 50 | } 51 | 52 | # Execute test once compiled. 53 | win*: QMAKE_POST_LINK = .\\$${DESTDIR}\\$${TARGET}.exe 54 | else: QMAKE_POST_LINK = ./$${DESTDIR}/$${TARGET} 55 | 56 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/num_columns.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = num_columns 3 | 4 | include (configuration.pri) 5 | 6 | HEADERS += \ 7 | ../../../test/utils.hpp 8 | 9 | SOURCES += \ 10 | ../../../test/num_columns.cpp 11 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/num_rows.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = num_rows 3 | 4 | include (configuration.pri) 5 | 6 | HEADERS += \ 7 | ../../../test/utils.hpp 8 | 9 | SOURCES += \ 10 | ../../../test/num_rows.cpp 11 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/placement_new.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = placement_new 3 | 4 | include (configuration.pri) 5 | 6 | SOURCES += \ 7 | ../../../test/placement_new.cpp 8 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/size.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = size 3 | 4 | include (configuration.pri) 5 | 6 | HEADERS += \ 7 | ../../../test/utils.hpp 8 | 9 | SOURCES += \ 10 | ../../../test/size.cpp 11 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/sparse_view_test.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = sparse_view_test 3 | 4 | win*:QMAKE_CXXFLAGS += /EHa 5 | # Support asynchronous structured exception handling 6 | # (SEH) with the native C++ catch(...) clause. 7 | 8 | include (configuration.pri) 9 | 10 | SOURCES += \ 11 | ../../../test/sparse_view_test.cpp 12 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test1.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test1 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += $$UBLAS_TESTSET 7 | 8 | HEADERS += ../../../test/test1.hpp 9 | 10 | SOURCES += \ 11 | ../../../test/test13.cpp \ 12 | ../../../test/test12.cpp \ 13 | ../../../test/test11.cpp \ 14 | ../../../test/test1.cpp 15 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test2.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test2 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += $$UBLAS_TESTSET 7 | 8 | HEADERS += ../../../test/test2.hpp 9 | 10 | SOURCES += \ 11 | ../../../test/test23.cpp \ 12 | ../../../test/test22.cpp \ 13 | ../../../test/test21.cpp \ 14 | ../../../test/test2.cpp 15 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test3.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test3 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += $$UBLAS_TESTSET_SPARSE 7 | 8 | HEADERS += ../../../test/test3.hpp 9 | 10 | SOURCES += \ 11 | ../../../test/test33.cpp \ 12 | ../../../test/test32.cpp \ 13 | ../../../test/test31.cpp \ 14 | ../../../test/test3.cpp 15 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test3_coo.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test3_coo 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += $$UBLAS_TESTSET_SPARSE_COO 7 | 8 | HEADERS += ../../../test/test3.hpp 9 | 10 | SOURCES += \ 11 | ../../../test/test33.cpp \ 12 | ../../../test/test32.cpp \ 13 | ../../../test/test31.cpp \ 14 | ../../../test/test3.cpp 15 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test3_mvov.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test3_mvov 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += \ 7 | USE_FLOAT \ 8 | USE_DOUBLE \ 9 | USE_STD_COMPLEX \ 10 | USE_STD_MAP \ 11 | USE_MAPPED_VECTOR_OF_MAPPED_VECTOR 12 | 13 | HEADERS += ../../../test/test3.hpp 14 | 15 | SOURCES += \ 16 | ../../../test/test33.cpp \ 17 | ../../../test/test32.cpp \ 18 | ../../../test/test31.cpp \ 19 | ../../../test/test3.cpp 20 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test4.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test4 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += $$UBLAS_TESTSET 7 | 8 | HEADERS += ../../../test/test4.hpp 9 | 10 | SOURCES += \ 11 | ../../../test/test43.cpp \ 12 | ../../../test/test42.cpp \ 13 | ../../../test/test4.cpp 14 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test5.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test5 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += $$UBLAS_TESTSET 7 | 8 | HEADERS += ../../../test/test5.hpp 9 | 10 | SOURCES += \ 11 | ../../../test/test53.cpp \ 12 | ../../../test/test52.cpp \ 13 | ../../../test/test5.cpp 14 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test6.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test6 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += $$UBLAS_TESTSET 7 | 8 | HEADERS += ../../../test/test6.hpp 9 | 10 | SOURCES += \ 11 | ../../../test/test63.cpp \ 12 | ../../../test/test62.cpp \ 13 | ../../../test/test6.cpp 14 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test7.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test7 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += \ 7 | BOOST_UBLAS_USE_INTERVAL \ 8 | $${UBLAS_TESTSET} 9 | 10 | HEADERS += ../../../test/test7.hpp 11 | 12 | SOURCES += \ 13 | ../../../test/test73.cpp \ 14 | ../../../test/test72.cpp \ 15 | ../../../test/test71.cpp \ 16 | ../../../test/test7.cpp 17 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_assignment.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_assignment 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += \ 7 | BOOST_UBLAS_COO_ALWAYS_DO_FULL_SORT 8 | 9 | HEADERS += \ 10 | ../../../test/utils.hpp 11 | 12 | SOURCES += \ 13 | ../../../test/test_assignment.cpp 14 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_banded_storage_layout.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_banded_storage_layout 3 | 4 | include (configuration.pri) 5 | 6 | HEADERS += \ 7 | ../../../test/utils.hpp 8 | 9 | SOURCES += \ 10 | ../../../test/test_banded_storage_layout.cpp 11 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_complex_norms.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_complex_norms 3 | 4 | include (configuration.pri) 5 | 6 | HEADERS += \ 7 | ../../../test/utils.hpp 8 | 9 | SOURCES += \ 10 | ../../../test/test_complex_norms.cpp 11 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_coordinate_matrix_always_do_full_sort.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_coordinate_matrix_always_do_full_sort 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += \ 7 | BOOST_UBLAS_COO_ALWAYS_DO_FULL_SORT 8 | 9 | HEADERS += \ 10 | ../../../test/utils.hpp 11 | 12 | SOURCES += \ 13 | ../../../test/test_coordinate_matrix_sort.cpp 14 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_coordinate_matrix_inplace_merge.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_coordinate_matrix_inplace_merge 3 | 4 | include (configuration.pri) 5 | 6 | HEADERS += \ 7 | ../../../test/utils.hpp 8 | 9 | SOURCES += \ 10 | ../../../test/test_coordinate_matrix_inplace_merge.cpp 11 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_coordinate_matrix_sort.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_coordinate_matrix_sort 3 | 4 | include (configuration.pri) 5 | 6 | HEADERS += \ 7 | ../../../test/utils.hpp 8 | 9 | SOURCES += \ 10 | ../../../test/test_coordinate_matrix_sort.cpp 11 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_coordinate_vector_inplace_merge.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_coordinate_vector_inplace_merge 3 | 4 | include (configuration.pri) 5 | HEADERS += \ 6 | ../../../test/utils.hpp 7 | 8 | SOURCES += \ 9 | ../../../test/test_coordinate_vector_inplace_merge.cpp 10 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_fixed_containers.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_fixed_containers 3 | 4 | include (configuration.pri) 5 | 6 | HEADERS += \ 7 | ../../../test/utils.hpp 8 | 9 | SOURCES += \ 10 | ../../../test/test_fixed_containers.cpp 11 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_inplace_solve_basic.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_inplace_solve_basic 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += \ 7 | $$UBLAS_TESTSET 8 | 9 | HEADERS += \ 10 | ../../../test/utils.hpp 11 | 12 | SOURCES += \ 13 | ../../../test/test_inplace_solve.cpp 14 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_inplace_solve_mvov.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_inplace_solve_mvov 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += \ 7 | USE_MAPPED_VECTOR_OF_MAPPED_VECTOR 8 | 9 | HEADERS += \ 10 | ../../../test/utils.hpp 11 | 12 | SOURCES += \ 13 | ../../../test/test_inplace_solve.cpp 14 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_inplace_solve_sparse.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_inplace_solve_sparse 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += \ 7 | $$UBLAS_TESTSET_SPARSE \ 8 | $$UBLAS_TESTSET_SPARSE_COO 9 | 10 | HEADERS += \ 11 | ../../../test/utils.hpp 12 | 13 | SOURCES += \ 14 | ../../../test/test_inplace_solve.cpp 15 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_lu.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_lu 3 | 4 | include (configuration.pri) 5 | 6 | HEADERS += \ 7 | ../../../test/common/testhelper.hpp 8 | 9 | SOURCES += \ 10 | ../../../test/test_lu.cpp 11 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_matrix_vector.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_matrix_vector 3 | 4 | include (configuration.pri) 5 | 6 | HEADERS += \ 7 | ../../../test/utils.hpp 8 | 9 | SOURCES += \ 10 | ../../../test/test_matrix_vector.cpp 11 | 12 | INCLUDEPATH += \ 13 | ../../../include 14 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_ticket7296.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_ticket7296 3 | 4 | include (configuration.pri) 5 | 6 | HEADERS += \ 7 | ../../../test/utils.hpp 8 | 9 | SOURCES += \ 10 | ../../../test/test_ticket7296.cpp 11 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/test_triangular.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = test_triangular 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += \ 7 | BOOST_CHRONO_DYN_LINK=1 \ 8 | BOOST_CHRONO_THREAD_DISABLED \ 9 | BOOST_SYSTEM_DYN_LINK=1 \ 10 | BOOST_SYSTEM_NO_DEPRECATED \ 11 | BOOST_TIMER_DYN_LINK=1 12 | 13 | SOURCES += \ 14 | ../../../test/test_triangular.cpp 15 | 16 | LIBS += -lboost_timer -lboost_system -lboost_chrono 17 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/triangular_access.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = triangular_access 3 | 4 | include (configuration.pri) 5 | 6 | DEFINES += NOMESSAGES 7 | 8 | HEADERS += \ 9 | ../../../test/common/testhelper.hpp 10 | 11 | SOURCES += \ 12 | ../../../test/triangular_access.cpp 13 | -------------------------------------------------------------------------------- /IDEs/qtcreator/test/triangular_layout.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = triangular_layout 3 | 4 | include (configuration.pri) 5 | 6 | SOURCES += \ 7 | ../../../test/triangular_layout.cpp 8 | -------------------------------------------------------------------------------- /IDEs/qtcreator/tests.pri: -------------------------------------------------------------------------------- 1 | SUBDIRS += \ 2 | # begin_end \ 3 | # comp_mat_erase \ 4 | # concepts \ 5 | # num_columns \ 6 | # num_rows \ 7 | # placement_new \ 8 | # size \ 9 | # sparse_view_test \ 10 | # test1 \ 11 | # test2 \ 12 | # test3 \ 13 | # test3_coo \ 14 | # test3_mvov \ 15 | # test4 \ 16 | # test5 \ 17 | # test6 \ 18 | # test7 \ 19 | # test_assignment \ 20 | # test_banded_storage_layout \ 21 | # test_complex_norms \ 22 | # test_coordinate_matrix_inplace_merge \ 23 | # test_coordinate_matrix_sort \ 24 | # test_coordinate_matrix_always_do_full_sort \ 25 | # test_coordinate_vector_inplace_merge \ 26 | # test_fixed_containers \ 27 | # test_inplace_solve_basic \ 28 | # test_inplace_solve_sparse \ 29 | # test_inplace_solve_mvov \ 30 | # test_lu \ 31 | # test_matrix_vector \ 32 | # test_ticket7296 \ 33 | # test_triangular \ 34 | # triangular_access \ 35 | # triangular_layout \ 36 | # test_tensor 37 | 38 | #begin_end.file = test/begin_end.pro 39 | #comp_mat_erase.file = test/comp_mat_erase.pro 40 | #concepts.file = test/concepts.pro 41 | #num_columns.file = test/num_columns.pro 42 | #num_rows.file = test/num_rows.pro 43 | #placement_new.file = test/placement_new.pro 44 | #size.file = test/size.pro 45 | #sparse_view_test.file = test/sparse_view_test.pro 46 | #test1.file = test/test1.pro 47 | #test2.file = test/test2.pro 48 | #test3.file = test/test3.pro 49 | #test3_coo.file = test/test3_coo.pro 50 | #test3_mvov.file = test/test3_mvov.pro 51 | #test4.file = test/test4.pro 52 | #test5.file = test/test5.pro 53 | #test6.file = test/test6.pro 54 | #test7.file = test/test7.pro 55 | #test_assignment.file = test/test_assignment.pro 56 | #test_banded_storage_layout.file = test/test_banded_storage_layout.pro 57 | #test_complex_norms.file = test/test_complex_norms.pro 58 | #test_coordinate_matrix_inplace_merge.file = test/test_coordinate_matrix_inplace_merge.pro 59 | #test_coordinate_matrix_sort.file = test/test_coordinate_matrix_sort.pro 60 | #test_coordinate_matrix_always_do_full_sort.file = test/test_coordinate_matrix_always_do_full_sort.pro 61 | #test_coordinate_vector_inplace_merge.file = test/test_coordinate_vector_inplace_merge.pro 62 | #test_fixed_containers.file = test/test_fixed_containers.pro 63 | #test_inplace_solve_basic.file = test/test_inplace_solve_basic.pro 64 | #test_inplace_solve_sparse.file = test/test_inplace_solve_sparse.pro 65 | #test_inplace_solve_mvov.file = test/test_inplace_solve_mvov.pro 66 | #test_lu.file = test/test_lu.pro 67 | #test_matrix_vector.file = test/test_matrix_vector.pro 68 | #test_ticket7296.file = test/test_ticket7296.pro 69 | #test_triangular.file = test/test_triangular.pro 70 | #triangular_access.file = test/triangular_access.pro 71 | #triangular_layout.file = test/triangular_layout.pro 72 | #test_tensor.file = test/test_tensor.pro 73 | -------------------------------------------------------------------------------- /IDEs/qtcreator/ublas_develop.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | CONFIG += ordered 3 | SUBDIRS = include # examples # benchmarks 4 | OTHER_FILES += ../../changelog.txt 5 | 6 | 7 | #include (tests.pri) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /benchmarks/Jamfile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2018 Stefan Seefeld 3 | # Use, modification and distribution are subject to the 4 | # Boost Software License, Version 1.0. (See accompanying file 5 | # LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | project boost/ublas/benchmarks 8 | : requirements /boost/program_options//boost_program_options 9 | ; 10 | 11 | exe add : add.cpp ; 12 | exe mm_prod : mm_prod.cpp ; 13 | exe mv_prod : mv_prod.cpp ; 14 | exe inner_prod : inner_prod.cpp ; 15 | exe outer_prod : outer_prod.cpp ; 16 | 17 | exe reference/add : reference/add.cpp ; 18 | exe reference/mm_prod : reference/mm_prod.cpp ; 19 | exe reference/mv_prod : reference/mv_prod.cpp ; 20 | exe reference/inner_prod : reference/inner_prod.cpp ; 21 | exe reference/outer_prod : reference/outer_prod.cpp ; 22 | 23 | build-project opencl ; 24 | -------------------------------------------------------------------------------- /benchmarks/add.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | #include "add.hpp" 13 | #include 14 | #include 15 | 16 | namespace po = boost::program_options; 17 | namespace ublas = boost::numeric::ublas; 18 | namespace bm = boost::numeric::ublas::benchmark; 19 | 20 | template 21 | void benchmark(std::string const &type) 22 | { 23 | using vector = ublas::vector; 24 | bm::add a("add(vector<" + type + ">, vector<" + type + ">)"); 25 | a.run(std::vector({1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096})); 26 | } 27 | 28 | int main(int argc, char **argv) 29 | { 30 | po::variables_map vm; 31 | try 32 | { 33 | po::options_description desc("Vector-vector addition\n" 34 | "Allowed options"); 35 | desc.add_options()("help,h", "produce help message"); 36 | desc.add_options()("type,t", po::value(), "select value-type (float, double, fcomplex, dcomplex)"); 37 | 38 | po::store(po::parse_command_line(argc, argv, desc), vm); 39 | po::notify(vm); 40 | 41 | if (vm.count("help")) 42 | { 43 | std::cout << desc << std::endl; 44 | return 0; 45 | } 46 | } 47 | catch(std::exception &e) 48 | { 49 | std::cerr << "error: " << e.what() << std::endl; 50 | return 1; 51 | } 52 | std::string type = vm.count("type") ? vm["type"].as() : "float"; 53 | if (type == "float") 54 | benchmark("float"); 55 | else if (type == "double") 56 | benchmark("double"); 57 | else if (type == "fcomplex") 58 | benchmark>("std::complex"); 59 | else if (type == "dcomplex") 60 | benchmark>("std::complex"); 61 | else 62 | std::cerr << "unsupported value-type \"" << vm["type"].as() << '\"' << std::endl; 63 | } 64 | -------------------------------------------------------------------------------- /benchmarks/add.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include "init.hpp" 10 | #include "benchmark.hpp" 11 | 12 | namespace boost { namespace numeric { namespace ublas { namespace benchmark { 13 | 14 | template class add; 15 | 16 | template 17 | class add : public benchmark 18 | { 19 | public: 20 | add(std::string const &name) : benchmark(name) {} 21 | virtual void setup(long l) 22 | { 23 | init(a, l, 200); 24 | init(b, l, 200); 25 | } 26 | virtual void operation(long l) 27 | { 28 | c = a + b; 29 | } 30 | private: 31 | O1 a; 32 | O2 b; 33 | R c; 34 | }; 35 | 36 | }}}} 37 | -------------------------------------------------------------------------------- /benchmarks/benchmark.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { namespace numeric { namespace ublas { namespace benchmark { 19 | 20 | class benchmark 21 | { 22 | using clock = std::chrono::system_clock; 23 | public: 24 | benchmark(std::string const &name) : name_(name) {} 25 | void print_header() 26 | { 27 | std::cout << "# benchmark : " << name_ << '\n' 28 | << "# size \ttime (ms)" << std::endl; 29 | } 30 | virtual void setup(long) {} 31 | virtual void operation(long) {} 32 | virtual void teardown() {} 33 | 34 | void run(std::vector const &sizes, unsigned times = 10) 35 | { 36 | print_header(); 37 | for (auto s : sizes) 38 | { 39 | setup(s); 40 | auto start = clock::now(); 41 | for (unsigned i = 0; i != times; ++i) 42 | operation(s); 43 | auto duration = std::chrono::duration_cast(clock::now() - start); 44 | teardown(); 45 | std::cout << s << '\t' << duration.count()*1./times << std::endl; 46 | } 47 | } 48 | private: 49 | std::string name_; 50 | }; 51 | 52 | }}}} 53 | -------------------------------------------------------------------------------- /benchmarks/init.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | 12 | namespace boost { namespace numeric { namespace ublas { namespace benchmark { 13 | 14 | template 15 | void init(vector &v, unsigned long size, int max_value) 16 | { 17 | v = vector(size); 18 | for (unsigned long i = 0; i < v.size(); ++i) 19 | v(i) = std::rand() % max_value; 20 | } 21 | 22 | template 23 | void init(matrix &m, unsigned long size1, unsigned long size2, int max_value) 24 | { 25 | m = matrix(size1, size2); 26 | for (unsigned long i = 0; i < m.size1(); ++i) 27 | for (unsigned long j = 0; j < m.size2(); ++j) 28 | m(i, j) = std::rand() % max_value; 29 | } 30 | 31 | template 32 | void init(matrix &m, unsigned long size, int max_value) 33 | { 34 | return init(m, size, size, max_value); 35 | } 36 | 37 | }}}} 38 | -------------------------------------------------------------------------------- /benchmarks/inner_prod.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include "init.hpp" 12 | #include "benchmark.hpp" 13 | #include 14 | #include 15 | 16 | namespace boost { namespace numeric { namespace ublas { namespace benchmark { 17 | 18 | template class inner_prod; 19 | 20 | template 21 | class inner_prod : public benchmark 22 | { 23 | public: 24 | inner_prod(std::string const &name) : benchmark(name) {} 25 | virtual void setup(long l) 26 | { 27 | init(a, l, 200); 28 | init(b, l, 200); 29 | } 30 | virtual void operation(long l) 31 | { 32 | c = ublas::inner_prod(a, b); 33 | } 34 | private: 35 | V1 a; 36 | V2 b; 37 | R c; 38 | }; 39 | 40 | }}}} 41 | 42 | namespace po = boost::program_options; 43 | namespace ublas = boost::numeric::ublas; 44 | namespace bm = boost::numeric::ublas::benchmark; 45 | 46 | template 47 | void benchmark(std::string const &type) 48 | { 49 | using vector = ublas::vector; 50 | bm::inner_prod p("inner_prod(vector<" + type + ">)"); 51 | p.run(std::vector({1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536})); 52 | } 53 | 54 | int main(int argc, char **argv) 55 | { 56 | po::variables_map vm; 57 | try 58 | { 59 | po::options_description desc("Inner product\n" 60 | "Allowed options"); 61 | desc.add_options()("help,h", "produce help message"); 62 | desc.add_options()("type,t", po::value(), "select value-type (float, double, fcomplex, dcomplex)"); 63 | 64 | po::store(po::parse_command_line(argc, argv, desc), vm); 65 | po::notify(vm); 66 | 67 | if (vm.count("help")) 68 | { 69 | std::cout << desc << std::endl; 70 | return 0; 71 | } 72 | } 73 | catch(std::exception &e) 74 | { 75 | std::cerr << "error: " << e.what() << std::endl; 76 | return 1; 77 | } 78 | std::string type = vm.count("type") ? vm["type"].as() : "float"; 79 | if (type == "float") 80 | benchmark("float"); 81 | else if (type == "double") 82 | benchmark("double"); 83 | else if (type == "fcomplex") 84 | benchmark>("std::complex"); 85 | else if (type == "dcomplex") 86 | benchmark>("std::complex"); 87 | else 88 | std::cerr << "unsupported value-type \"" << vm["type"].as() << '\"' << std::endl; 89 | } 90 | -------------------------------------------------------------------------------- /benchmarks/mm_prod.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include "prod.hpp" 12 | #include 13 | #include 14 | 15 | namespace po = boost::program_options; 16 | namespace ublas = boost::numeric::ublas; 17 | namespace bm = boost::numeric::ublas::benchmark; 18 | 19 | template 20 | void benchmark(std::string const &type) 21 | { 22 | using matrix = ublas::matrix>; 23 | bm::prod p("prod(matrix<" + type + ">)"); 24 | p.run(std::vector({1, 2, 4, 8, 16, 32, 64, 128, 256, 512}));//, 1024})); 25 | } 26 | 27 | int main(int argc, char **argv) 28 | { 29 | po::variables_map vm; 30 | try 31 | { 32 | po::options_description desc("Matrix product\n" 33 | "Allowed options"); 34 | desc.add_options()("help,h", "produce help message"); 35 | desc.add_options()("type,t", po::value(), "select value-type (float, double, fcomplex, dcomplex)"); 36 | 37 | po::store(po::parse_command_line(argc, argv, desc), vm); 38 | po::notify(vm); 39 | 40 | if (vm.count("help")) 41 | { 42 | std::cout << desc << std::endl; 43 | return 0; 44 | } 45 | } 46 | catch(std::exception &e) 47 | { 48 | std::cerr << "error: " << e.what() << std::endl; 49 | return 1; 50 | } 51 | std::string type = vm.count("type") ? vm["type"].as() : "float"; 52 | if (type == "float") 53 | benchmark("float"); 54 | else if (type == "double") 55 | benchmark("double"); 56 | else if (type == "fcomplex") 57 | benchmark>("std::complex"); 58 | else if (type == "dcomplex") 59 | benchmark>("std::complex"); 60 | else 61 | std::cerr << "unsupported value-type \"" << vm["type"].as() << '\"' << std::endl; 62 | } 63 | -------------------------------------------------------------------------------- /benchmarks/mv_prod.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | #include "prod.hpp" 13 | #include 14 | #include 15 | 16 | namespace po = boost::program_options; 17 | namespace ublas = boost::numeric::ublas; 18 | namespace bm = boost::numeric::ublas::benchmark; 19 | 20 | template 21 | void benchmark(std::string const &type) 22 | { 23 | using matrix = ublas::matrix>; 24 | using vector = ublas::vector; 25 | bm::prod p("prod(matrix<" + type + ">, vector<" + type + ">)"); 26 | p.run(std::vector({1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096})); 27 | } 28 | 29 | int main(int argc, char **argv) 30 | { 31 | po::variables_map vm; 32 | try 33 | { 34 | po::options_description desc("Matrix-vector product\n" 35 | "Allowed options"); 36 | desc.add_options()("help,h", "produce help message"); 37 | desc.add_options()("type,t", po::value(), "select value-type (float, double, fcomplex, dcomplex)"); 38 | 39 | po::store(po::parse_command_line(argc, argv, desc), vm); 40 | po::notify(vm); 41 | 42 | if (vm.count("help")) 43 | { 44 | std::cout << desc << std::endl; 45 | return 0; 46 | } 47 | } 48 | catch(std::exception &e) 49 | { 50 | std::cerr << "error: " << e.what() << std::endl; 51 | return 1; 52 | } 53 | std::string type = vm.count("type") ? vm["type"].as() : "float"; 54 | if (type == "float") 55 | benchmark("float"); 56 | else if (type == "double") 57 | benchmark("double"); 58 | else if (type == "fcomplex") 59 | benchmark>("std::complex"); 60 | else if (type == "dcomplex") 61 | benchmark>("std::complex"); 62 | else 63 | std::cerr << "unsupported value-type \"" << vm["type"].as() << '\"' << std::endl; 64 | } 65 | -------------------------------------------------------------------------------- /benchmarks/opencl/Jamfile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2018 Stefan Seefeld 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (See accompanying file LICENSE_1_0.txt or 6 | # copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | import ac ; 9 | 10 | # work around a bug in Boost.Build 11 | import ../../opencl ; 12 | import ../../clblas ; 13 | using opencl ; 14 | using clblas ; 15 | 16 | project boost/ublas/benchmarks/opencl 17 | : requirements 18 | /boost/program_options//boost_program_options 19 | gcc:-Wno-ignored-attributes 20 | clang:-Wno-ignored-attributes 21 | [ ac.check-library /clblas//clblas : /clblas//clblas /opencl//opencl : no ] 22 | ; 23 | 24 | exe add : add.cpp ; 25 | exe mm_prod : mm_prod.cpp ; 26 | exe mv_prod : mv_prod.cpp ; 27 | exe inner_prod : inner_prod.cpp ; 28 | exe outer_prod : outer_prod.cpp ; 29 | -------------------------------------------------------------------------------- /benchmarks/opencl/init.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #pragma once 10 | 11 | #include 12 | #include "../init.hpp" 13 | 14 | namespace boost { namespace numeric { namespace ublas { namespace benchmark { 15 | 16 | template 17 | void init(T &v, unsigned long size, int max_value) 18 | { 19 | // TBD 20 | } 21 | 22 | template 23 | void init(vector &v, unsigned long size, int max_value) 24 | { 25 | // TBD 26 | } 27 | 28 | template 29 | void init(matrix &m, unsigned long size1, unsigned long size2, int max_value) 30 | { 31 | // TBD 32 | } 33 | 34 | template 35 | void init(matrix &m, unsigned long size, int max_value) 36 | { 37 | init(m, size, size, max_value); 38 | } 39 | 40 | }}}} 41 | -------------------------------------------------------------------------------- /benchmarks/outer_prod.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include "init.hpp" 12 | #include "benchmark.hpp" 13 | #include 14 | #include 15 | 16 | namespace boost { namespace numeric { namespace ublas { namespace benchmark { 17 | 18 | template class outer_prod; 19 | 20 | template 21 | class outer_prod : public benchmark 22 | { 23 | public: 24 | outer_prod(std::string const &name) : benchmark(name) {} 25 | virtual void setup(long l) 26 | { 27 | init(a, l, 200); 28 | init(b, l, 200); 29 | } 30 | virtual void operation(long l) 31 | { 32 | c = ublas::outer_prod(a, b); 33 | } 34 | private: 35 | V1 a; 36 | V2 b; 37 | R c; 38 | }; 39 | 40 | }}}} 41 | 42 | namespace po = boost::program_options; 43 | namespace ublas = boost::numeric::ublas; 44 | namespace bm = boost::numeric::ublas::benchmark; 45 | 46 | template 47 | void benchmark(std::string const &type) 48 | { 49 | using vector = ublas::vector; 50 | using matrix = ublas::matrix; 51 | bm::outer_prod p("outer_prod(vector<" + type + ">)"); 52 | p.run(std::vector({1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096})); 53 | } 54 | 55 | int main(int argc, char **argv) 56 | { 57 | po::variables_map vm; 58 | try 59 | { 60 | po::options_description desc("Outer product\n" 61 | "Allowed options"); 62 | desc.add_options()("help,h", "produce help message"); 63 | desc.add_options()("type,t", po::value(), "select value-type (float, double, fcomplex, dcomplex)"); 64 | 65 | po::store(po::parse_command_line(argc, argv, desc), vm); 66 | po::notify(vm); 67 | 68 | if (vm.count("help")) 69 | { 70 | std::cout << desc << std::endl; 71 | return 0; 72 | } 73 | } 74 | catch(std::exception &e) 75 | { 76 | std::cerr << "error: " << e.what() << std::endl; 77 | return 1; 78 | } 79 | std::string type = vm.count("type") ? vm["type"].as() : "float"; 80 | if (type == "float") 81 | benchmark("float"); 82 | else if (type == "double") 83 | benchmark("double"); 84 | else if (type == "fcomplex") 85 | benchmark>("std::complex"); 86 | else if (type == "dcomplex") 87 | benchmark>("std::complex"); 88 | else 89 | std::cerr << "unsupported value-type \"" << vm["type"].as() << '\"' << std::endl; 90 | } 91 | -------------------------------------------------------------------------------- /benchmarks/plot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright (c) 2018 Stefan Seefeld 4 | # All rights reserved. 5 | # 6 | # This file is part of Boost.uBLAS. It is made available under the 7 | # Boost Software License, Version 1.0. 8 | # (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | import argparse 11 | import matplotlib.pyplot as plt 12 | import numpy as np 13 | 14 | 15 | class plot(object): 16 | 17 | def __init__(self, label, data): 18 | self.label = label 19 | self.data = data 20 | 21 | 22 | def load_file(filename): 23 | 24 | lines = open(filename, 'r').readlines() 25 | label = lines[0][1:-1].strip() 26 | lines = [l.strip() for l in lines] 27 | lines = [l.split('#', 1)[0] for l in lines] 28 | lines = [l for l in lines if l] 29 | data = [l.split() for l in lines] 30 | return plot(label, list(zip(*data))) 31 | 32 | 33 | def main(argv): 34 | 35 | parser = argparse.ArgumentParser(prog=argv[0], description='benchmark plotter') 36 | parser.add_argument('data', nargs='+', help='benchmark data to plot') 37 | parser.add_argument('--log', choices=['no', 'all', 'x', 'y'], help='use a logarithmic scale') 38 | args = parser.parse_args(argv[1:]) 39 | runs = [load_file(d) for d in args.data] 40 | plt.title('Benchmark plot') 41 | plt.xlabel('size') 42 | plt.ylabel('time (s)') 43 | if args.log == 'all': 44 | plot = plt.loglog 45 | elif args.log == 'x': 46 | plot = plt.semilogx 47 | elif args.log == 'y': 48 | plot = plt.semilogy 49 | else: 50 | plot = plt.plot 51 | plots = [plot(r.data[0], r.data[1], label=r.label) for r in runs] 52 | plt.legend() 53 | plt.show() 54 | return True 55 | 56 | 57 | if __name__ == '__main__': 58 | 59 | import sys 60 | sys.exit(0 if main(sys.argv) else 1) 61 | -------------------------------------------------------------------------------- /benchmarks/prod.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include "init.hpp" 10 | #include "benchmark.hpp" 11 | 12 | namespace boost { namespace numeric { namespace ublas { namespace benchmark { 13 | 14 | template class prod; 15 | 16 | template 17 | class prod : public benchmark 18 | { 19 | public: 20 | prod(std::string const &name) : benchmark(name) {} 21 | virtual void setup(long l) 22 | { 23 | init(a, l, 200); 24 | init(b, l, 200); 25 | } 26 | virtual void operation(long l) 27 | { 28 | c = ublas::prod(a, b); 29 | } 30 | private: 31 | O1 a; 32 | O2 b; 33 | R c; 34 | }; 35 | 36 | }}}} 37 | -------------------------------------------------------------------------------- /benchmarks/reference/add.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | #include "../init.hpp" 13 | #include "../benchmark.hpp" 14 | #include 15 | #include 16 | 17 | namespace po = boost::program_options; 18 | namespace ublas = boost::numeric::ublas; 19 | namespace boost { namespace numeric { namespace ublas { namespace benchmark { 20 | 21 | template 22 | class add : public benchmark 23 | { 24 | public: 25 | add(std::string const &name) : benchmark(name) {} 26 | virtual void setup(long l) 27 | { 28 | init(a, l, 200); 29 | init(b, l, 200); 30 | } 31 | virtual void operation(long l) 32 | { 33 | for (int i = 0; i < l; ++i) 34 | c(i) = a(i) + b(i); 35 | } 36 | private: 37 | ublas::vector a; 38 | ublas::vector b; 39 | ublas::vector c; 40 | }; 41 | 42 | }}}} 43 | 44 | namespace bm = boost::numeric::ublas::benchmark; 45 | 46 | template 47 | void benchmark(std::string const &type) 48 | { 49 | bm::add p("ref::add(vector<" + type + ">)"); 50 | p.run(std::vector({1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096})); 51 | } 52 | 53 | int main(int argc, char **argv) 54 | { 55 | po::variables_map vm; 56 | try 57 | { 58 | po::options_description desc("Vector-vector addition (reference implementation)\n" 59 | "Allowed options"); 60 | desc.add_options()("help,h", "produce help message"); 61 | desc.add_options()("type,t", po::value(), "select value-type (float, double, fcomplex, dcomplex)"); 62 | 63 | po::store(po::parse_command_line(argc, argv, desc), vm); 64 | po::notify(vm); 65 | 66 | if (vm.count("help")) 67 | { 68 | std::cout << desc << std::endl; 69 | return 0; 70 | } 71 | } 72 | catch(std::exception &e) 73 | { 74 | std::cerr << "error: " << e.what() << std::endl; 75 | return 1; 76 | } 77 | std::string type = vm.count("type") ? vm["type"].as() : "float"; 78 | if (type == "float") 79 | benchmark("float"); 80 | else if (type == "double") 81 | benchmark("double"); 82 | else if (type == "fcomplex") 83 | benchmark>("std::complex"); 84 | else if (type == "dcomplex") 85 | benchmark>("std::complex"); 86 | else 87 | std::cerr << "unsupported value-type \"" << vm["type"].as() << '\"' << std::endl; 88 | } 89 | -------------------------------------------------------------------------------- /benchmarks/reference/inner_prod.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include "../init.hpp" 12 | #include "../benchmark.hpp" 13 | #include 14 | #include 15 | 16 | namespace boost { namespace numeric { namespace ublas { namespace benchmark { 17 | 18 | template class inner_prod; 19 | 20 | template 21 | class inner_prod : public benchmark 22 | { 23 | public: 24 | inner_prod(std::string const &name) : benchmark(name) {} 25 | virtual void setup(long l) 26 | { 27 | init(a, l, 200); 28 | init(b, l, 200); 29 | } 30 | virtual void operation(long l) 31 | { 32 | c = R(0); 33 | for (int i = 0; i < l; ++i) 34 | c += a(i) * b(i); 35 | } 36 | private: 37 | V1 a; 38 | V2 b; 39 | R c; 40 | }; 41 | 42 | }}}} 43 | 44 | namespace po = boost::program_options; 45 | namespace ublas = boost::numeric::ublas; 46 | namespace bm = boost::numeric::ublas::benchmark; 47 | 48 | template 49 | void benchmark(std::string const &type) 50 | { 51 | using vector = ublas::vector; 52 | bm::inner_prod p("ref::inner_prod(vector<" + type + ">)"); 53 | p.run(std::vector({1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536})); 54 | } 55 | 56 | int main(int argc, char **argv) 57 | { 58 | po::variables_map vm; 59 | try 60 | { 61 | po::options_description desc("Inner product (reference implementation)\n" 62 | "Allowed options"); 63 | desc.add_options()("help,h", "produce help message"); 64 | desc.add_options()("type,t", po::value(), "select value-type (float, double, fcomplex, dcomplex)"); 65 | 66 | po::store(po::parse_command_line(argc, argv, desc), vm); 67 | po::notify(vm); 68 | 69 | if (vm.count("help")) 70 | { 71 | std::cout << desc << std::endl; 72 | return 0; 73 | } 74 | } 75 | catch(std::exception &e) 76 | { 77 | std::cerr << "error: " << e.what() << std::endl; 78 | return 1; 79 | } 80 | std::string type = vm.count("type") ? vm["type"].as() : "float"; 81 | if (type == "float") 82 | benchmark("float"); 83 | else if (type == "double") 84 | benchmark("double"); 85 | else if (type == "fcomplex") 86 | benchmark>("std::complex"); 87 | else if (type == "dcomplex") 88 | benchmark>("std::complex"); 89 | else 90 | std::cerr << "unsupported value-type \"" << vm["type"].as() << '\"' << std::endl; 91 | } 92 | -------------------------------------------------------------------------------- /benchmarks/reference/mv_prod.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // All rights reserved. 4 | // 5 | // This file is part of Boost.uBLAS. It is made available under the 6 | // Boost Software License, Version 1.0. 7 | // (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | #include "../init.hpp" 13 | #include "../benchmark.hpp" 14 | #include 15 | #include 16 | 17 | namespace po = boost::program_options; 18 | namespace ublas = boost::numeric::ublas; 19 | namespace boost { namespace numeric { namespace ublas { namespace benchmark { 20 | 21 | template 22 | class prod : public benchmark 23 | { 24 | public: 25 | prod(std::string const &name) : benchmark(name) {} 26 | virtual void setup(long l) 27 | { 28 | init(a, l, 200); 29 | init(b, l, 200); 30 | } 31 | virtual void operation(long l) 32 | { 33 | for (int i = 0; i < l; ++i) 34 | { 35 | c(i) = 0; 36 | for (int j = 0; j < l; ++j) 37 | c(i) += a(i,j) * b(j); 38 | } 39 | } 40 | private: 41 | ublas::matrix a; 42 | ublas::vector b; 43 | ublas::vector c; 44 | }; 45 | 46 | }}}} 47 | 48 | namespace bm = boost::numeric::ublas::benchmark; 49 | 50 | template 51 | void benchmark(std::string const &type) 52 | { 53 | bm::prod p("ref::prod(vector<" + type + ">)"); 54 | p.run(std::vector({1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096})); 55 | } 56 | 57 | int main(int argc, char **argv) 58 | { 59 | po::variables_map vm; 60 | try 61 | { 62 | po::options_description desc("Matrix-vector product (reference implementation)\n" 63 | "Allowed options"); 64 | desc.add_options()("help,h", "produce help message"); 65 | desc.add_options()("type,t", po::value(), "select value-type (float, double, fcomplex, dcomplex)"); 66 | 67 | po::store(po::parse_command_line(argc, argv, desc), vm); 68 | po::notify(vm); 69 | 70 | if (vm.count("help")) 71 | { 72 | std::cout << desc << std::endl; 73 | return 0; 74 | } 75 | } 76 | catch(std::exception &e) 77 | { 78 | std::cerr << "error: " << e.what() << std::endl; 79 | return 1; 80 | } 81 | std::string type = vm.count("type") ? vm["type"].as() : "float"; 82 | if (type == "float") 83 | benchmark("float"); 84 | else if (type == "double") 85 | benchmark("double"); 86 | else if (type == "fcomplex") 87 | benchmark>("std::complex"); 88 | else if (type == "dcomplex") 89 | benchmark>("std::complex"); 90 | else 91 | std::cerr << "unsupported value-type \"" << vm["type"].as() << '\"' << std::endl; 92 | } 93 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | fixes: 2 | - "home/travis/build/*/boost-root/boost/::include/boost/" 3 | - "home/travis/build/*/boost-root/libs/numeric/ublas/::" 4 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | /html/ 2 | /pdf/ -------------------------------------------------------------------------------- /doc/Jamfile: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Shikhar Vashistha 2 | # 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # (http://www.boost.org/LICENSE_1_0.txt) 5 | # Copyright 2021 Shikhar Vashistha 6 | # 7 | # Distributed under the Boost Software License, Version 1.0. 8 | # (http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | import asciidoctor ; 11 | 12 | html ublas.html : ublas.adoc ; 13 | 14 | install html_ : ublas.html : html ; 15 | 16 | pdf ublas.pdf : ublas.adoc ; 17 | 18 | explicit ublas.pdf ; 19 | 20 | install pdf_ : ublas.pdf : pdf ; 21 | 22 | explicit pdf_ ; 23 | 24 | alias boostdoc ; 25 | 26 | explicit boostdoc ; 27 | 28 | alias boostrelease : html_ ; 29 | 30 | explicit boostrelease ; -------------------------------------------------------------------------------- /doc/ublas-docinfo-footer.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/ublas.adoc: -------------------------------------------------------------------------------- 1 | //// 2 | Copyright 2021 Shikhar Vashistha 3 | 4 | Distributed under the Boost Software License, Version 1.0. 5 | (http://www.boost.org/LICENSE_1_0.txt) 6 | //// 7 | 8 | # Boost.Ublas: The Boost Ublas Library 9 | :toc: left 10 | :toclevels: 2 11 | :idprefix: 12 | :listing-caption: Code Example 13 | :docinfo: private-footer 14 | 15 | :leveloffset: +1 16 | 17 | include::ublas/overview.adoc[] 18 | 19 | include::ublas/index.adoc[] 20 | 21 | include::ublas/vector.adoc[] 22 | 23 | include::ublas/vector_sparse.adoc[] 24 | 25 | include::ublas/vector_proxy.adoc[] 26 | 27 | include::ublas/vector_expression.adoc[] 28 | 29 | include::ublas/matrix.adoc[] 30 | 31 | include::ublas/triangular.adoc[] 32 | 33 | include::ublas/symmetric.adoc[] 34 | 35 | include::ublas/hermitian.adoc[] 36 | 37 | include::ublas/banded.adoc[] 38 | 39 | include::ublas/matrix_sparse.adoc[] 40 | 41 | include::ublas/matrix_proxy.adoc[] 42 | 43 | include::ublas/matrix_expression.adoc[] 44 | 45 | include::ublas/tensor.adoc[] 46 | 47 | include::ublas/tensor/tensor_expression.adoc[] 48 | 49 | include::ublas/unbounded_array.adoc[] 50 | 51 | include::ublas/bounded_array.adoc[] 52 | 53 | include::ublas/range.adoc[] 54 | 55 | include::ublas/tensor/extents.adoc[] 56 | 57 | include::ublas/tensor/strides.adoc[] 58 | 59 | include::ublas/tensor/tensor_expression.adoc[] 60 | 61 | include::ublas/tensor/tensor_index.adoc[] 62 | 63 | include::ublas/storage_sparse.adoc[] 64 | 65 | include::ublas/products.adoc[] 66 | 67 | include::ublas/blas.adoc[] 68 | 69 | include::ublas/container_concept.adoc[] 70 | 71 | include::ublas/expression_concept.adoc[] 72 | 73 | include::ublas/storage_concept.adoc[] 74 | 75 | include::ublas/iterator_concept.adoc[] 76 | 77 | :leveloffset: -1 78 | 79 | [appendix] 80 | ## Copyright and License 81 | 82 | This documentation is 83 | 84 | * Copyright 2021 Shikhar Vashistha 85 | 86 | and is distributed under the http://www.boost.org/LICENSE_1_0.txt[Boost Software License, Version 1.0]. 87 | -------------------------------------------------------------------------------- /doc/ublas/samples/banded_adaptor.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | matrix m (3, 3); 19 | banded_adaptor > ba (m, 1, 1); 20 | for (signed i = 0; i < signed (ba.size1 ()); ++ i) 21 | for (signed j = (std::max) (i - 1, 0); j < (std::min) (i + 2, signed (ba.size2 ())); ++ j) 22 | ba (i, j) = 3 * i + j; 23 | std::cout << ba << std::endl; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /doc/ublas/samples/banded_matrix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | banded_matrix m (3, 3, 1, 1); 19 | for (signed i = 0; i < signed (m.size1 ()); ++ i) 20 | for (signed j = (std::max) (i - 1, 0); j < (std::min) (i + 2, signed (m.size2 ())); ++ j) 21 | m (i, j) = 3 * i + j; 22 | std::cout << m << std::endl; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/ublas/samples/bounded_array.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | 15 | int main () { 16 | using namespace boost::numeric::ublas; 17 | bounded_array a (3); 18 | for (unsigned i = 0; i < a.size (); ++ i) { 19 | a [i] = i; 20 | std::cout << a [i] << std::endl; 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /doc/ublas/samples/compressed_matrix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | compressed_matrix m (3, 3, 3 * 3); 19 | for (unsigned i = 0; i < m.size1 (); ++ i) 20 | for (unsigned j = 0; j < m.size2 (); ++ j) 21 | m (i, j) = 3 * i + j; 22 | std::cout << m << std::endl; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/ublas/samples/compressed_vector.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | compressed_vector v (3, 3); 19 | for (unsigned i = 0; i < v.size (); ++ i) 20 | v (i) = i; 21 | std::cout << v << std::endl; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /doc/ublas/samples/coordinate_matrix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | coordinate_matrix m (3, 3, 3 * 3); 19 | for (unsigned i = 0; i < m.size1 (); ++ i) 20 | for (unsigned j = 0; j < m.size2 (); ++ j) 21 | m (i, j) = 3 * i + j; 22 | std::cout << m << std::endl; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/ublas/samples/coordinate_vector.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | coordinate_vector v (3, 3); 19 | for (unsigned i = 0; i < v.size (); ++ i) 20 | v (i) = i; 21 | std::cout << v << std::endl; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /doc/ublas/samples/ex_triangular.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Gunter Winkler 2004 - 2009. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | using std::cout; 15 | using std::endl; 16 | 17 | 18 | 19 | namespace ublas = boost::numeric::ublas; 20 | 21 | 22 | int main(int argc, char * argv[] ) { 23 | 24 | ublas::matrix M (3, 3); 25 | for (std::size_t i=0; i < M.data().size(); ++i) { M.data()[i] = 1+i ; } 26 | 27 | std::cout << "full M = " << M << "\n" ; 28 | 29 | ublas::triangular_matrix L; 30 | ublas::triangular_matrix UL; 31 | ublas::triangular_matrix SL; 32 | 33 | L = ublas::triangular_adaptor, ublas::lower> (M); 34 | SL = ublas::triangular_adaptor, ublas::strict_lower> (M); 35 | UL = ublas::triangular_adaptor, ublas::unit_lower> (M); 36 | 37 | std::cout << "lower L = " << L << "\n" 38 | << "strict lower SL = " << SL << "\n" 39 | << "unit lower UL = " << UL << "\n" ; 40 | 41 | ublas::triangular_matrix U; 42 | ublas::triangular_matrix UU; 43 | ublas::triangular_matrix SU; 44 | 45 | U = ublas::triangular_adaptor, ublas::upper> (M); 46 | SU = ublas::triangular_adaptor, ublas::strict_upper> (M); 47 | UU = ublas::triangular_adaptor, ublas::unit_upper> (M); 48 | 49 | std::cout << "upper U = " << U << "\n" 50 | << "strict upper SU = " << SU << "\n" 51 | << "unit upper UU = " << UU << "\n" ; 52 | 53 | std::cout << "M = L + SU ? " << ((norm_inf( M - (L + SU) ) == 0.0)?"ok":"failed") << "\n"; 54 | std::cout << "M = U + SL ? " << ((norm_inf( M - (U + SL) ) == 0.0)?"ok":"failed") << "\n"; 55 | 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /doc/ublas/samples/hermitian_adaptor.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | matrix > m (3, 3); 19 | hermitian_adaptor >, lower> hal (m); 20 | for (unsigned i = 0; i < hal.size1 (); ++ i) { 21 | for (unsigned j = 0; j < i; ++ j) 22 | hal (i, j) = std::complex (3 * i + j, 3 * i + j); 23 | hal (i, i) = std::complex (4 * i, 0); 24 | } 25 | std::cout << hal << std::endl; 26 | hermitian_adaptor >, upper> hau (m); 27 | for (unsigned i = 0; i < hau.size1 (); ++ i) { 28 | hau (i, i) = std::complex (4 * i, 0); 29 | for (unsigned j = i + 1; j < hau.size2 (); ++ j) 30 | hau (i, j) = std::complex (3 * i + j, 3 * i + j); 31 | } 32 | std::cout << hau << std::endl; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /doc/ublas/samples/hermitian_matrix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | hermitian_matrix, lower> ml (3, 3); 19 | for (unsigned i = 0; i < ml.size1 (); ++ i) { 20 | for (unsigned j = 0; j < i; ++ j) 21 | ml (i, j) = std::complex (3 * i + j, 3 * i + j); 22 | ml (i, i) = std::complex (4 * i, 0); 23 | } 24 | std::cout << ml << std::endl; 25 | hermitian_matrix, upper> mu (3, 3); 26 | for (unsigned i = 0; i < mu.size1 (); ++ i) { 27 | mu (i, i) = std::complex (4 * i, 0); 28 | for (unsigned j = i + 1; j < mu.size2 (); ++ j) 29 | mu (i, j) = std::complex (3 * i + j, 3 * i + j); 30 | } 31 | std::cout << mu << std::endl; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /doc/ublas/samples/identity_matrix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | identity_matrix m (3); 19 | std::cout << m << std::endl; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /doc/ublas/samples/map_array.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | 15 | int main () { 16 | using namespace boost::numeric::ublas; 17 | map_array a; 18 | a.reserve (3); 19 | for (unsigned i = 0; i < 3; ++ i) { 20 | a [i] = i; 21 | std::cout << a [i] << std::endl; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/ublas/samples/mapped_matrix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | mapped_matrix m (3, 3, 3 * 3); 19 | for (unsigned i = 0; i < m.size1 (); ++ i) 20 | for (unsigned j = 0; j < m.size2 (); ++ j) 21 | m (i, j) = 3 * i + j; 22 | std::cout << m << std::endl; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/ublas/samples/mapped_vector.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | mapped_vector v (3, 3); 19 | for (unsigned i = 0; i < v.size (); ++ i) 20 | v (i) = i; 21 | std::cout << v << std::endl; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | matrix m (3, 3); 19 | for (unsigned i = 0; i < m.size1 (); ++ i) 20 | for (unsigned j = 0; j < m.size2 (); ++ j) 21 | m (i, j) = 3 * i + j; 22 | std::cout << m << std::endl; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_binary.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | matrix m1 (3, 3), m2 (3, 3); 19 | for (unsigned i = 0; i < (std::min) (m1.size1 (), m2.size1 ()); ++ i) 20 | for (unsigned j = 0; j < (std::min) (m1.size2 (), m2.size2 ()); ++ j) 21 | m1 (i, j) = m2 (i, j) = 3 * i + j; 22 | 23 | std::cout << m1 + m2 << std::endl; 24 | std::cout << m1 - m2 << std::endl; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_binary_scalar.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | matrix m (3, 3); 19 | for (unsigned i = 0; i < m.size1 (); ++ i) 20 | for (unsigned j = 0; j < m.size2 (); ++ j) 21 | m (i, j) = 3 * i + j; 22 | 23 | std::cout << 2.0 * m << std::endl; 24 | std::cout << m * 2.0 << std::endl; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_column.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | matrix m (3, 3); 20 | for (unsigned j = 0; j < m.size2 (); ++ j) { 21 | matrix_column > mc (m, j); 22 | for (unsigned i = 0; i < mc.size (); ++ i) 23 | mc (i) = 3 * i + j; 24 | std::cout << mc << std::endl; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_column_project.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | matrix m (3, 3); 20 | for (unsigned j = 0; j < m.size2 (); ++ j) { 21 | for (unsigned i = 0; i < m.size1 (); ++ i) 22 | column (m, j) (i) = 3 * i + j; 23 | std::cout << column (m, j) << std::endl; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_matrix_binary.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | matrix m1 (3, 3), m2 (3, 3); 19 | for (unsigned i = 0; i < (std::min) (m1.size1 (), m2.size1 ()); ++ i) 20 | for (unsigned j = 0; j < (std::min) (m1.size2 (), m2.size2 ()); ++ j) 21 | m1 (i, j) = m2 (i, j) = 3 * i + j; 22 | 23 | std::cout << prod (m1, m2) << std::endl; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_matrix_solve.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | matrix m1 (3, 3), m2 (3, 3); 19 | for (unsigned i = 0; i < (std::min) (m1.size1 (), m2.size1 ()); ++ i) 20 | for (unsigned j = 0; j <= i; ++ j) 21 | m1 (i, j) = m2 (i, j) = 3 * i + j + 1; 22 | 23 | std::cout << solve (m1, m2, lower_tag ()) << std::endl; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_range.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | matrix m (3, 3); 20 | matrix_range > mr (m, range (0, 3), range (0, 3)); 21 | for (unsigned i = 0; i < mr.size1 (); ++ i) 22 | for (unsigned j = 0; j < mr.size2 (); ++ j) 23 | mr (i, j) = 3 * i + j; 24 | std::cout << mr << std::endl; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_range_project.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | matrix m (3, 3); 20 | for (unsigned i = 0; i < m.size1 (); ++ i) 21 | for (unsigned j = 0; j < m.size2 (); ++ j) 22 | project (m, range (0, 3), range (0, 3)) (i, j) = 3 * i + j; 23 | std::cout << project (m, range (0, 3), range (0, 3)) << std::endl; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_row.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | matrix m (3, 3); 20 | for (unsigned i = 0; i < m.size1 (); ++ i) { 21 | matrix_row > mr (m, i); 22 | for (unsigned j = 0; j < mr.size (); ++ j) 23 | mr (j) = 3 * i + j; 24 | std::cout << mr << std::endl; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_row_project.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | matrix m (3, 3); 20 | for (unsigned i = 0; i < m.size1 (); ++ i) { 21 | for (unsigned j = 0; j < m.size2 (); ++ j) 22 | row (m, i) (j) = 3 * i + j; 23 | std::cout << row (m, i) << std::endl; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_slice.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | matrix m (3, 3); 20 | matrix_slice > ms (m, slice (0, 1, 3), slice (0, 1, 3)); 21 | for (unsigned i = 0; i < ms.size1 (); ++ i) 22 | for (unsigned j = 0; j < ms.size2 (); ++ j) 23 | ms (i, j) = 3 * i + j; 24 | std::cout << ms << std::endl; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_slice_project.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | matrix m (3, 3); 20 | for (unsigned i = 0; i < m.size1 (); ++ i) 21 | for (unsigned j = 0; j < m.size2 (); ++ j) 22 | project (m, slice (0, 1, 3), slice (0, 1, 3)) (i, j) = 3 * i + j; 23 | std::cout << project (m, slice (0, 1, 3), slice (0, 1, 3)) << std::endl; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_unary.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | matrix > m (3, 3); 19 | for (unsigned i = 0; i < m.size1 (); ++ i) 20 | for (unsigned j = 0; j < m.size2 (); ++ j) 21 | m (i, j) = std::complex (3 * i + j, 3 * i + j); 22 | 23 | std::cout << - m << std::endl; 24 | std::cout << conj (m) << std::endl; 25 | std::cout << real (m) << std::endl; 26 | std::cout << imag (m) << std::endl; 27 | std::cout << trans (m) << std::endl; 28 | std::cout << herm (m) << std::endl; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_vector_binary.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | matrix m (3, 3); 19 | vector v (3); 20 | for (unsigned i = 0; i < (std::min) (m.size1 (), v.size ()); ++ i) { 21 | for (unsigned j = 0; j < m.size2 (); ++ j) 22 | m (i, j) = 3 * i + j; 23 | v (i) = i; 24 | } 25 | 26 | std::cout << prod (m, v) << std::endl; 27 | std::cout << prod (v, m) << std::endl; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_vector_range.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | matrix m (3, 3); 20 | for (unsigned i = 0; i < m.size1 (); ++ i) 21 | for (unsigned j = 0; j < m.size2 (); ++ j) 22 | m (i, j) = 3 * i + j; 23 | 24 | matrix_vector_range > mvr (m, range (0, 3), range (0, 3)); 25 | std::cout << mvr << std::endl; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_vector_slice.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | matrix m (3, 3); 20 | for (unsigned i = 0; i < m.size1 (); ++ i) 21 | for (unsigned j = 0; j < m.size2 (); ++ j) 22 | m (i, j) = 3 * i + j; 23 | 24 | matrix_vector_slice > mvs (m, slice (0, 1, 3), slice (0, 1, 3)); 25 | std::cout << mvs << std::endl; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /doc/ublas/samples/matrix_vector_solve.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | matrix m (3, 3); 19 | vector v (3); 20 | for (unsigned i = 0; i < (std::min) (m.size1 (), v.size ()); ++ i) { 21 | for (unsigned j = 0; j <= i; ++ j) 22 | m (i, j) = 3 * i + j + 1; 23 | v (i) = i; 24 | } 25 | 26 | std::cout << solve (m, v, lower_tag ()) << std::endl; 27 | std::cout << solve (v, m, lower_tag ()) << std::endl; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /doc/ublas/samples/range.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | 15 | int main () { 16 | using namespace boost::numeric::ublas; 17 | range r (0, 3); 18 | for (unsigned i = 0; i < r.size (); ++ i) { 19 | std::cout << r (i) << std::endl; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /doc/ublas/samples/slice.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | 15 | int main () { 16 | using namespace boost::numeric::ublas; 17 | slice s (0, 1, 3); 18 | for (unsigned i = 0; i < s.size (); ++ i) { 19 | std::cout << s (i) << std::endl; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /doc/ublas/samples/symmetric_adaptor.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | matrix m (3, 3); 19 | symmetric_adaptor, lower> sal (m); 20 | for (unsigned i = 0; i < sal.size1 (); ++ i) 21 | for (unsigned j = 0; j <= i; ++ j) 22 | sal (i, j) = 3 * i + j; 23 | std::cout << sal << std::endl; 24 | symmetric_adaptor, upper> sau (m); 25 | for (unsigned i = 0; i < sau.size1 (); ++ i) 26 | for (unsigned j = i; j < sau.size2 (); ++ j) 27 | sau (i, j) = 3 * i + j; 28 | std::cout << sau << std::endl; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /doc/ublas/samples/symmetric_matrix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | symmetric_matrix ml (3, 3); 19 | for (unsigned i = 0; i < ml.size1 (); ++ i) 20 | for (unsigned j = 0; j <= i; ++ j) 21 | ml (i, j) = 3 * i + j; 22 | std::cout << ml << std::endl; 23 | symmetric_matrix mu (3, 3); 24 | for (unsigned i = 0; i < mu.size1 (); ++ i) 25 | for (unsigned j = i; j < mu.size2 (); ++ j) 26 | mu (i, j) = 3 * i + j; 27 | std::cout << mu << std::endl; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /doc/ublas/samples/triangular_adaptor.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | matrix m (3, 3); 19 | triangular_adaptor, lower> tal (m); 20 | for (unsigned i = 0; i < tal.size1 (); ++ i) 21 | for (unsigned j = 0; j <= i; ++ j) 22 | tal (i, j) = 3 * i + j; 23 | std::cout << tal << std::endl; 24 | triangular_adaptor, upper> tau (m); 25 | for (unsigned i = 0; i < tau.size1 (); ++ i) 26 | for (unsigned j = i; j < tau.size2 (); ++ j) 27 | tau (i, j) = 3 * i + j; 28 | std::cout << tau << std::endl; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /doc/ublas/samples/triangular_matrix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | triangular_matrix ml (3, 3); 19 | for (unsigned i = 0; i < ml.size1 (); ++ i) 20 | for (unsigned j = 0; j <= i; ++ j) 21 | ml (i, j) = 3 * i + j; 22 | std::cout << ml << std::endl; 23 | triangular_matrix mu (3, 3); 24 | for (unsigned i = 0; i < mu.size1 (); ++ i) 25 | for (unsigned j = i; j < mu.size2 (); ++ j) 26 | mu (i, j) = 3 * i + j; 27 | std::cout << mu << std::endl; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /doc/ublas/samples/unbounded_array.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | 15 | int main () { 16 | using namespace boost::numeric::ublas; 17 | unbounded_array a (3); 18 | for (unsigned i = 0; i < a.size (); ++ i) { 19 | a [i] = i; 20 | std::cout << a [i] << std::endl; 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /doc/ublas/samples/unit_vector.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | for (int i = 0; i < 3; ++ i) { 19 | unit_vector v (3, i); 20 | std::cout << v << std::endl; 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /doc/ublas/samples/vector.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | vector v (3); 19 | for (unsigned i = 0; i < v.size (); ++ i) 20 | v (i) = i; 21 | std::cout << v << std::endl; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /doc/ublas/samples/vector_binary.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | vector v1 (3), v2 (3); 19 | for (unsigned i = 0; i < (std::min) (v1.size (), v2.size ()); ++ i) 20 | v1 (i) = v2 (i) = i; 21 | 22 | std::cout << v1 + v2 << std::endl; 23 | std::cout << v1 - v2 << std::endl; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /doc/ublas/samples/vector_binary_outer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | vector v1 (3), v2 (3); 19 | for (unsigned i = 0; i < (std::min) (v1.size (), v2.size ()); ++ i) 20 | v1 (i) = v2 (i) = i; 21 | 22 | std::cout << outer_prod (v1, v2) << std::endl; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/ublas/samples/vector_binary_redux.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | 15 | int main () { 16 | using namespace boost::numeric::ublas; 17 | vector v1 (3), v2 (3); 18 | for (unsigned i = 0; i < (std::min) (v1.size (), v2.size ()); ++ i) 19 | v1 (i) = v2 (i) = i; 20 | 21 | std::cout << inner_prod (v1, v2) << std::endl; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /doc/ublas/samples/vector_binary_scalar.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | vector v (3); 19 | for (unsigned i = 0; i < v.size (); ++ i) 20 | v (i) = i; 21 | 22 | std::cout << 2.0 * v << std::endl; 23 | std::cout << v * 2.0 << std::endl; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /doc/ublas/samples/vector_range.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | vector v (3); 20 | vector_range > vr (v, range (0, 3)); 21 | for (unsigned i = 0; i < vr.size (); ++ i) 22 | vr (i) = i; 23 | std::cout << vr << std::endl; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /doc/ublas/samples/vector_range_project.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | vector v (3); 20 | for (int i = 0; i < 3; ++ i) 21 | project (v, range (0, 3)) (i) = i; 22 | std::cout << project (v, range (0, 3)) << std::endl; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/ublas/samples/vector_slice.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | vector v (3); 20 | vector_slice > vs (v, slice (0, 1, 3)); 21 | for (unsigned i = 0; i < vs.size (); ++ i) 22 | vs (i) = i; 23 | std::cout << vs << std::endl; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /doc/ublas/samples/vector_slice_project.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main () { 18 | using namespace boost::numeric::ublas; 19 | vector v (3); 20 | for (int i = 0; i < 3; ++ i) 21 | project (v, slice (0, 1, 3)) (i) = i; 22 | std::cout << project (v, slice (0, 1, 3)) << std::endl; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/ublas/samples/vector_unary.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | vector > v (3); 19 | for (unsigned i = 0; i < v.size (); ++ i) 20 | v (i) = std::complex (i, i); 21 | 22 | std::cout << - v << std::endl; 23 | std::cout << conj (v) << std::endl; 24 | std::cout << real (v) << std::endl; 25 | std::cout << imag (v) << std::endl; 26 | std::cout << trans (v) << std::endl; 27 | std::cout << herm (v) << std::endl; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /doc/ublas/samples/vector_unary_redux.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | 15 | int main () { 16 | using namespace boost::numeric::ublas; 17 | vector v (3); 18 | for (unsigned i = 0; i < v.size (); ++ i) 19 | v (i) = i; 20 | 21 | std::cout << sum (v) << std::endl; 22 | std::cout << norm_1 (v) << std::endl; 23 | std::cout << norm_2 (v) << std::endl; 24 | std::cout << norm_inf (v) << std::endl; 25 | std::cout << index_norm_inf (v) << std::endl; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /doc/ublas/samples/zero_matrix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | zero_matrix m (3, 3); 19 | std::cout << m << std::endl; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /doc/ublas/samples/zero_vector.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | 16 | int main () { 17 | using namespace boost::numeric::ublas; 18 | zero_vector v (3); 19 | std::cout << v << std::endl; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /doc/ublas/tensor/tensor_index.adoc: -------------------------------------------------------------------------------- 1 | == Tensor Index 2 | 3 | [[toc]] 4 | 5 | === [#tensor index]#tensor_index# 6 | 7 | ==== Description 8 | 9 | The template class `tensor_index` decorates the 10 | link:../tensor.html#tensor[tensor] template class with indices for 11 | tensor contraction. 12 | 13 | ==== Example 14 | 15 | [source, cpp] 16 | .... 17 | #include 18 | 19 | int main () { 20 | using namespace boost::numeric::ublas; 21 | shape s{4,3,2}; 22 | for (auto i = 0u; i < s.size(); ++i) { 23 | std::cout << s.at(i) << std::endl; 24 | } 25 | } 26 | .... 27 | 28 | ==== Definition 29 | 30 | Defined in the header tensor/tensor_einstein.hpp. 31 | 32 | ==== Public base classes 33 | 34 | None. 35 | 36 | ==== Template parameters 37 | 38 | [cols=",,",] 39 | |=== 40 | |Parameter |Description | 41 | |`value_t` |The type of object stored in the tensor. | 42 | |`format_t` |Storage organization of the tensor. | 43 | |`storage_t` |The type of the storage array of the tensor. | 44 | |`N` |Number of indices provided. | 45 | |=== 46 | 47 | ''''' 48 | 49 | Copyright (©) 2018 Cem Bassoy + 50 | Copyright (©) 2021 Shikhar Vashistha + 51 | Use, modification and distribution are subject to the Boost Software 52 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 53 | http://www.boost.org/LICENSE_1_0.txt ). 54 | -------------------------------------------------------------------------------- /examples/tensor/Jamfile: -------------------------------------------------------------------------------- 1 | # Boost.uBLAS 2 | # 3 | # Copyright (c) 2018 Cem Bassoy 4 | # 5 | # Use, modification and distribution is subject to the Boost Software License, 6 | # Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | # http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | import ../../../../config/checks/config : requires ; 10 | 11 | # Project settings 12 | project boost-ublas-tensor-example 13 | : requirements 14 | BOOST_UBLAS_NO_EXCEPTIONS 15 | vacpp:"BOOST_UBLAS_NO_ELEMENT_PROXIES" 16 | gcc:"-Wall -pedantic -Wextra -Wno-unknown-pragmas" 17 | clang:"-Wall -pedantic -Wextra -Wno-unknown-pragmas" 18 | msvc:"/W4" # == all 19 | [ requires cxx17_if_constexpr ] 20 | ; 21 | 22 | exe access_tensor : access_tensor.cpp ; 23 | exe simple_expressions : simple_expressions.cpp ; 24 | exe multiply_tensors_product_function : multiply_tensors_product_function.cpp ; 25 | exe multiply_tensors_einstein_notation : multiply_tensors_einstein_notation.cpp ; 26 | exe instantiate_tensor : instantiate_tensor.cpp ; 27 | -------------------------------------------------------------------------------- /examples/tensor/simple_expressions.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018, Cem Bassoy, cem.bassoy@gmail.com 3 | // Copyright (c) 2019, Amit Singh, amitsingh19975@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // Google and Fraunhofer IOSB, Ettlingen, Germany 11 | // 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | int main() 20 | { 21 | namespace ublas = boost::numeric::ublas; 22 | using value = float; 23 | using tensor = ublas::tensor_dynamic; 24 | using matrix = ublas::matrix; 25 | using vector = ublas::vector; 26 | using shape = tensor::extents_type; 27 | 28 | try { 29 | 30 | 31 | auto A = tensor{3,4,2}; 32 | auto B = A = 2; 33 | 34 | // Calling overloaded operators 35 | // and using simple tensor expression templates. 36 | if( A != (B+1) ){ 37 | A += 2*B - 1; 38 | } 39 | 40 | // formatted output 41 | std::cout << "% --------------------------- " << std::endl; 42 | std::cout << "% --------------------------- " << std::endl << std::endl; 43 | std::cout << "A=" << A << ";" << std::endl << std::endl; 44 | 45 | auto n = shape{3,4}; 46 | auto D = matrix(n[0],n[1],1); 47 | auto e = vector(n[1],1); 48 | auto f = vector(n[0],2); 49 | 50 | // Calling constructor with 51 | // vector expression templates 52 | tensor C = 2*f; 53 | // formatted output 54 | std::cout << "% --------------------------- " << std::endl; 55 | std::cout << "% --------------------------- " << std::endl << std::endl; 56 | std::cout << "C=" << C << ";" << std::endl << std::endl; 57 | 58 | 59 | // Calling overloaded operators 60 | // and mixing simple tensor and matrix expression templates 61 | tensor F = 3*C + 4*prod(2*D,e); 62 | 63 | // formatted output 64 | std::cout << "% --------------------------- " << std::endl; 65 | std::cout << "% --------------------------- " << std::endl << std::endl; 66 | std::cout << "F=" << F << ";" << std::endl << std::endl; 67 | 68 | } catch (const std::exception& e) { 69 | std::cerr << "Cought exception " << e.what(); 70 | std::cerr << "in the main function of simple expression." << std::endl; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/detail/documentation.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2004 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | // this file should not contain any code, but the documentation 14 | // global to all files 15 | 16 | /** \namespace boost::numeric::ublas 17 | \brief contains all important classes and functions of uBLAS 18 | 19 | all ublas definitions ... 20 | \todo expand this section 21 | */ 22 | 23 | /** \defgroup blas1 Level 1 BLAS 24 | \brief level 1 basic linear algebra subroutines 25 | */ 26 | 27 | /** \defgroup blas2 Level 2 BLAS 28 | \brief level 2 basic linear algebra subroutines 29 | */ 30 | 31 | /** \defgroup blas3 Level 3 BLAS 32 | \brief level 3 basic linear algebra subroutines 33 | */ 34 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/detail/duff.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #ifndef _BOOST_UBLAS_DUFF_ 14 | #define _BOOST_UBLAS_DUFF_ 15 | 16 | #define DD_SWITCH(n, d, r, expr) \ 17 | { \ 18 | unsigned r = ((n) + (d) - 1) / (d); \ 19 | switch ((n) % (d)) { \ 20 | case 0: do { expr; 21 | #define DD_CASE_I(i, expr) \ 22 | case (i): expr; 23 | #define DD_WHILE(r) \ 24 | } while (-- (r) > 0); \ 25 | } \ 26 | } 27 | 28 | #define DD_1T(n, d, r, expr) \ 29 | DD_WHILE(r) 30 | #define DD_2T(n, d, r, expr) \ 31 | DD_CASE_I(1, expr) \ 32 | DD_1T(n, d, r, expr) 33 | #define DD_3T(n, d, r, expr) \ 34 | DD_CASE_I(2, expr) \ 35 | DD_2T(n, d, r, expr) 36 | #define DD_4T(n, d, r, expr) \ 37 | DD_CASE_I(3, expr) \ 38 | DD_3T(n, d, r, expr) 39 | #define DD_5T(n, d, r, expr) \ 40 | DD_CASE_I(4, expr) \ 41 | DD_4T(n, d, r, expr) 42 | #define DD_6T(n, d, r, expr) \ 43 | DD_CASE_I(5, expr) \ 44 | DD_5T(n, d, r, expr) 45 | #define DD_7T(n, d, r, expr) \ 46 | DD_CASE_I(6, expr) \ 47 | DD_6T(n, d, r, expr) 48 | #define DD_8T(n, d, r, expr) \ 49 | DD_CASE_I(7, expr) \ 50 | DD_7T(n, d, r, expr) 51 | 52 | #define DD(n, d, r, expr) \ 53 | DD_SWITCH(n, d, r, expr) \ 54 | DD_##d##T(n, d, r, expr) 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/detail/temporary.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #ifndef _BOOST_UBLAS_TEMPORARY_ 14 | #define _BOOST_UBLAS_TEMPORARY_ 15 | 16 | 17 | namespace boost { namespace numeric { namespace ublas { 18 | 19 | /// For the creation of temporary vectors in the assignment of proxies 20 | template 21 | struct vector_temporary_traits { 22 | typedef typename M::vector_temporary_type type ; 23 | }; 24 | 25 | /// For the creation of temporary vectors in the assignment of proxies 26 | template 27 | struct matrix_temporary_traits { 28 | typedef typename M::matrix_temporary_type type ; 29 | }; 30 | 31 | } } } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/opencl.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Stefan Seefeld 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or 6 | // copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef boost_numeric_ublas_opencl_hpp_ 9 | #define boost_numeric_ublas_opencl_hpp_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/opencl/library.hpp: -------------------------------------------------------------------------------- 1 | // Boost.uBLAS 2 | // 3 | // Copyright (c) 2018 Fady Essam 4 | // Copyright (c) 2018 Stefan Seefeld 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // (See accompanying file LICENSE_1_0.txt or 8 | // copy at http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | #ifndef boost_numeric_ublas_opencl_library_hpp_ 11 | #define boost_numeric_ublas_opencl_library_hpp_ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { namespace numeric { namespace ublas { namespace opencl { 18 | 19 | class library 20 | { 21 | public: 22 | library() { clblasSetup();} 23 | ~library() { clblasTeardown();} 24 | }; 25 | 26 | template 27 | struct is_numeric 28 | { 29 | static bool const value = 30 | std::is_same::value | 31 | std::is_same::value | 32 | std::is_same>::value | 33 | std::is_same>::value; 34 | }; 35 | 36 | }}}} 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/opencl/operations.hpp: -------------------------------------------------------------------------------- 1 | // Boost.uBLAS 2 | // 3 | // Copyright (c) 2018 Fady Essam 4 | // Copyright (c) 2018 Stefan Seefeld 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // (See accompanying file LICENSE_1_0.txt or 8 | // copy at http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | #ifndef boost_numeric_ublas_opencl_operations_hpp_ 11 | #define boost_numeric_ublas_opencl_operations_hpp_ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/opencl/vector.hpp: -------------------------------------------------------------------------------- 1 | // Boost.uBLAS 2 | // 3 | // Copyright (c) 2018 Fady Essam 4 | // Copyright (c) 2018 Stefan Seefeld 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // (See accompanying file LICENSE_1_0.txt or 8 | // copy at http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | #ifndef boost_numeric_ublas_opencl_vector_hpp_ 11 | #define boost_numeric_ublas_opencl_vector_hpp_ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { namespace numeric { namespace ublas { namespace opencl { 21 | 22 | class storage; 23 | 24 | namespace compute = boost::compute; 25 | 26 | } // namespace opencl 27 | 28 | template 29 | class vector : public boost::compute::vector 30 | { 31 | typedef std::size_t size_type; 32 | public: 33 | vector() : compute::vector() {} 34 | vector(size_type size, compute::context context) 35 | : compute::vector(size, context) 36 | { device_ = context.get_device();} 37 | vector(size_type size, T value, compute::command_queue queue) 38 | : compute::vector(size, value, queue.get_context()) 39 | { 40 | queue.finish(); 41 | device_ = queue.get_device(); 42 | } 43 | 44 | template 45 | vector(vector const &v, compute::command_queue &queue) 46 | : vector(v.size(), queue.get_context()) 47 | { 48 | this->from_host(v, queue); 49 | } 50 | 51 | 52 | const compute::device device() const { return device_;} 53 | compute::device device() { return device_;} 54 | 55 | template 56 | void from_host(ublas::vector const &v, compute::command_queue & queue) 57 | { 58 | assert(this->device() == queue.get_device()); 59 | compute::copy(v.begin(), 60 | v.end(), 61 | this->begin(), 62 | queue); 63 | queue.finish(); 64 | } 65 | 66 | template 67 | void to_host(ublas::vector& v, compute::command_queue& queue) const 68 | { 69 | assert(this->device() == queue.get_device()); 70 | compute::copy(this->begin(), 71 | this->end(), 72 | v.begin(), 73 | queue); 74 | queue.finish(); 75 | } 76 | 77 | void fill(T value, compute::command_queue & queue) 78 | { 79 | assert(this->device() == queue.get_device()); 80 | compute::fill(this->begin(), this->end(), value, queue); 81 | queue.finish(); 82 | } 83 | 84 | private: 85 | compute::device device_; 86 | }; 87 | 88 | }}} 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/operation/c_array.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * -*- c++ -*- 3 | * 4 | * \file c_array.hpp 5 | * 6 | * \brief provides specializations of matrix and vector operations for c arrays and c matrices. 7 | * 8 | * Copyright (c) 2009, Gunter Winkler 9 | * 10 | * Distributed under the Boost Software License, Version 1.0. (See 11 | * accompanying file LICENSE_1_0.txt or copy at 12 | * http://www.boost.org/LICENSE_1_0.txt) 13 | * 14 | * \author Gunter Winkler (guwi17 at gmx dot de) 15 | */ 16 | 17 | #ifndef BOOST_NUMERIC_UBLAS_OPERATION_C_ARRAY_HPP 18 | #define BOOST_NUMERIC_UBLAS_OPERATION_C_ARRAY_HPP 19 | 20 | #include 21 | 22 | namespace boost { namespace numeric { namespace ublas { 23 | 24 | namespace detail { 25 | 26 | 27 | 28 | } // namespace boost::numeric::ublas::detail 29 | 30 | 31 | template 32 | BOOST_UBLAS_INLINE 33 | typename ExprT::const_iterator begin(vector_expression const& e) 34 | { 35 | return detail::begin_impl::apply(e()); 36 | } 37 | 38 | 39 | }}} // Namespace boost::numeric::ublas 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/operation/num_columns.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * -*- c++ -*- 3 | * 4 | * \file num_columns.hpp 5 | * 6 | * \brief The \c num_columns operation. 7 | * 8 | * Copyright (c) 2009, Marco Guazzone 9 | * 10 | * Distributed under the Boost Software License, Version 1.0. (See 11 | * accompanying file LICENSE_1_0.txt or copy at 12 | * http://www.boost.org/LICENSE_1_0.txt) 13 | * 14 | * \author Marco Guazzone, marco.guazzone@gmail.com 15 | */ 16 | 17 | 18 | #ifndef BOOST_NUMERIC_UBLAS_OPERATION_NUM_COLUMNS_HPP 19 | #define BOOST_NUMERIC_UBLAS_OPERATION_NUM_COLUMNS_HPP 20 | 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | 27 | namespace boost { namespace numeric { namespace ublas { 28 | 29 | /** 30 | * \brief Return the number of columns. 31 | * \tparam MatrixExprT A type which models the matrix expression concept. 32 | * \param m A matrix expression. 33 | * \return The number of columns. 34 | */ 35 | template 36 | BOOST_UBLAS_INLINE 37 | typename matrix_traits::size_type num_columns(matrix_expression const& me) 38 | { 39 | return me().size2(); 40 | } 41 | 42 | }}} // Namespace boost::numeric::ublas 43 | 44 | 45 | #endif // BOOST_NUMERIC_UBLAS_OPERATION_NUM_COLUMNS_HPP 46 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/operation/num_rows.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * -*- c++ -*- 3 | * 4 | * \file num_rows.hpp 5 | * 6 | * \brief The \c num_rows operation. 7 | * 8 | * Copyright (c) 2009-2012, Marco Guazzone 9 | * 10 | * Distributed under the Boost Software License, Version 1.0. (See 11 | * accompanying file LICENSE_1_0.txt or copy at 12 | * http://www.boost.org/LICENSE_1_0.txt) 13 | * 14 | * \author Marco Guazzone, marco.guazzone@gmail.com 15 | */ 16 | 17 | #ifndef BOOST_NUMERIC_UBLAS_OPERATION_NUM_ROWS_HPP 18 | #define BOOST_NUMERIC_UBLAS_OPERATION_NUM_ROWS_HPP 19 | 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | namespace boost { namespace numeric { namespace ublas { 27 | 28 | /** 29 | * \brief Return the number of rows. 30 | * \tparam MatrixExprT A type which models the matrix expression concept. 31 | * \param m A matrix expression. 32 | * \return The number of rows. 33 | */ 34 | template 35 | BOOST_UBLAS_INLINE 36 | typename matrix_traits::size_type num_rows(matrix_expression const& me) 37 | { 38 | return me().size1(); 39 | } 40 | 41 | }}} // Namespace boost::numeric::ublas 42 | 43 | 44 | #endif // BOOST_NUMERIC_UBLAS_OPERATION_NUM_ROWS_HPP 45 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/operations.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * -*- c++ -*- 3 | * 4 | * \file operations.hpp 5 | * 6 | * \brief This header includes several headers from the operation directory. 7 | * 8 | * Copyright (c) 2009, Gunter Winkler 9 | * 10 | * Distributed under the Boost Software License, Version 1.0. (See 11 | * accompanying file LICENSE_1_0.txt or copy at 12 | * http://www.boost.org/LICENSE_1_0.txt) 13 | * 14 | * \author Gunter Winkler (guwi17 at gmx dot de) 15 | */ 16 | 17 | #ifndef BOOST_NUMERIC_UBLAS_OPERATIONS_HPP 18 | #define BOOST_NUMERIC_UBLAS_OPERATIONS_HPP 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tags.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * -*- c++ -*- 3 | * 4 | * \file tags.hpp 5 | * 6 | * \brief Tags. 7 | * 8 | * Copyright (c) 2009, Marco Guazzone 9 | * 10 | * Distributed under the Boost Software License, Version 1.0. (See 11 | * accompanying file LICENSE_1_0.txt or copy at 12 | * http://www.boost.org/LICENSE_1_0.txt) 13 | * 14 | * \author Marco Guazzone, marco.guazzone@gmail.com 15 | */ 16 | 17 | #ifndef BOOST_NUMERIC_UBLAS_TAG_HPP 18 | #define BOOST_NUMERIC_UBLAS_TAG_HPP 19 | 20 | 21 | namespace boost { namespace numeric { namespace ublas { namespace tag { 22 | 23 | /// \brief Tag for the major dimension. 24 | struct major {}; 25 | 26 | 27 | /// \brief Tag for the minor dimension. 28 | struct minor {}; 29 | 30 | 31 | /// \brief Tag for the leading dimension. 32 | struct leading {}; 33 | 34 | }}}} // Namespace boost::numeric::ublas::tag 35 | 36 | 37 | #endif // BOOST_NUMERIC_UBLAS_TAG_HPP 38 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 Cem Bassoy 2 | // 3 | // Distributed under the Boost Software License, Version 1.0. (See 4 | // accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // The authors gratefully acknowledge the support of 8 | // Fraunhofer and Google in producing this work 9 | // which started as a Google Summer of Code project. 10 | // 11 | 12 | /// \file tensor.hpp Definition for the class vector and its derivative 13 | 14 | #ifndef BOOST_NUMERIC_UBLAS_TENSOR_HPP 15 | #define BOOST_NUMERIC_UBLAS_TENSOR_HPP 16 | 17 | #include "tensor/operators_arithmetic.hpp" 18 | #include "tensor/operators_comparison.hpp" 19 | #include "tensor/ostream.hpp" 20 | #include "tensor/functions.hpp" 21 | #include "tensor/layout.hpp" 22 | #include "tensor/tensor.hpp" 23 | 24 | #endif // BOOST_NUMERIC_UBLAS_TENSOR_HPP 25 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/concepts.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021, Cem Bassoy, cem.bassoy@gmail.com 3 | // Copyright (c) 2021, Amit Singh, amitsingh19975@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // Google and Fraunhofer IOSB, Ettlingen, Germany 11 | // 12 | 13 | #ifndef BOOST_UBLAS_TENSOR_CONCEPTS_HPP 14 | #define BOOST_UBLAS_TENSOR_CONCEPTS_HPP 15 | 16 | #include 17 | 18 | namespace boost::numeric::ublas{ 19 | 20 | template 21 | concept integral = std::is_integral_v; 22 | 23 | template 24 | concept signed_integral = integral && std::is_signed_v; 25 | 26 | template 27 | concept unsigned_integral = integral && !signed_integral; 28 | 29 | template 30 | concept floating_point = std::is_floating_point_v; 31 | 32 | } // namespace boost::numeric::ublas 33 | 34 | #endif // BOOST_UBLAS_TENSOR_CONCEPTS_BASIC_HPP 35 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/extents.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021, Cem Bassoy, cem.bassoy@gmail.com 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See 5 | // accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_UBLAS_TENSOR_EXTENTS_HPP 10 | #define BOOST_UBLAS_TENSOR_EXTENTS_HPP 11 | 12 | #include "extents/extents_base.hpp" 13 | #include "extents/extents_dynamic_size.hpp" 14 | #include "extents/extents_static_size.hpp" 15 | #include "extents/extents_static.hpp" 16 | #include "extents/extents_functions.hpp" 17 | #include "extents/extents_static_functions.hpp" 18 | 19 | 20 | template 21 | bool operator==( 22 | boost::numeric::ublas::extents const& lhs, 23 | boost::numeric::ublas::extents const& rhs ) 24 | { 25 | return size(lhs) == size(rhs) && std::equal( begin(lhs), end (lhs), begin(rhs) ); 26 | } 27 | 28 | template 29 | bool operator==( 30 | boost::numeric::ublas::extents const& lhs, 31 | boost::numeric::ublas::extents const& rhs ) 32 | { 33 | return size(lhs) == size(rhs) && std::equal( begin(lhs), end (lhs), begin(rhs) ); 34 | } 35 | 36 | template 37 | bool operator!=( 38 | boost::numeric::ublas::extents const& lhs, 39 | boost::numeric::ublas::extents const& rhs ) 40 | { 41 | return !( lhs == rhs) ; 42 | } 43 | 44 | template 45 | bool operator!=( 46 | boost::numeric::ublas::extents const& lhs, 47 | boost::numeric::ublas::extents const& rhs ) 48 | { 49 | return !( lhs == rhs) ; 50 | } 51 | 52 | 53 | #endif // BOOST_UBLAS_TENSOR_EXTENTS_HPP 54 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/extents/extents_base.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2020, Cem Bassoy, cem.bassoy@gmail.com 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See 5 | // accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | 10 | #ifndef BOOST_NUMERIC_UBLAS_TENSOR_EXTENTS_BASE_HPP 11 | #define BOOST_NUMERIC_UBLAS_TENSOR_EXTENTS_BASE_HPP 12 | 13 | #include 14 | //#include 15 | #include 16 | 17 | #include "../concepts.hpp" 18 | 19 | namespace boost::numeric::ublas { 20 | 21 | 22 | template 23 | struct extents_base 24 | { 25 | 26 | using derived_type = D; 27 | inline constexpr decltype(auto) operator()() const { return static_cast(*this); } 28 | inline constexpr decltype(auto) operator()() { return static_cast< derived_type&>(*this); } 29 | 30 | }; 31 | 32 | template 33 | class extents_core; 34 | 35 | template 36 | using extents = extents_core; 37 | 38 | template struct is_extents : std::false_type {}; 39 | template struct is_strides : std::false_type {}; 40 | template struct is_dynamic : std::false_type {}; 41 | template struct is_static : std::false_type {}; 42 | template struct is_dynamic_rank : std::false_type {}; 43 | template struct is_static_rank : std::false_type {}; 44 | 45 | template inline static constexpr bool const is_extents_v = is_extents::value; 46 | template inline static constexpr bool const is_strides_v = is_strides::value; 47 | template inline static constexpr bool const is_dynamic_v = is_dynamic::value; 48 | template inline static constexpr bool const is_static_v = is_static ::value; 49 | template inline static constexpr bool const is_dynamic_rank_v = is_dynamic_rank::value; 50 | template inline static constexpr bool const is_static_rank_v = is_static_rank::value; 51 | 52 | } // namespace boost::numeric::ublas 53 | 54 | #endif // _BOOST_NUMERIC_UBLAS_TENSOR_EXTENTS_BASE_HPP_ 55 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/function/inner_prod.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018, Cem Bassoy, cem.bassoy@gmail.com 3 | // Copyright (c) 2020, Amit Singh, amitsingh19975@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // 10 | 11 | #ifndef BOOST_NUMERIC_UBLAS_TENSOR_INNER_HPP 12 | #define BOOST_NUMERIC_UBLAS_TENSOR_INNER_HPP 13 | 14 | #include 15 | #include 16 | 17 | #include "../extents.hpp" 18 | #include "../multiplication.hpp" 19 | 20 | 21 | namespace boost::numeric::ublas 22 | { 23 | template 24 | class tensor_core; 25 | } // namespace boost::numeric::ublas 26 | 27 | namespace boost::numeric::ublas 28 | { 29 | 30 | /** @brief Computes the inner product of two tensors * 31 | * Implements c = sum(A[i1,i2,...,ip] * B[i1,i2,...,jp]) 32 | * 33 | * @note calls inner function 34 | * 35 | * @param[in] a tensor object A 36 | * @param[in] b tensor object B 37 | * 38 | * @returns a value type. 39 | */ 40 | template 41 | inline decltype(auto) inner_prod(tensor_core< TE1 > const &a, tensor_core< TE2 > const &b) 42 | { 43 | using value_type = typename tensor_core< TE1 >::value_type; 44 | 45 | static_assert( 46 | std::is_same_v::value_type>, 47 | "error in boost::numeric::ublas::inner_prod(tensor_core< TE1 > const&, tensor_core< TensorEngine2 > const&): " 48 | "Both the tensor should have the same value_type" 49 | ); 50 | 51 | if (a.rank() != b.rank()) 52 | throw std::length_error("error in boost::numeric::ublas::inner_prod: Rank of both the tensors must be the same."); 53 | 54 | if (a.empty() || b.empty()) 55 | throw std::length_error("error in boost::numeric::ublas::inner_prod: Tensors should not be empty."); 56 | 57 | //if (a.extents() != b.extents()) 58 | if (::operator!=(a.extents(),b.extents())) 59 | throw std::length_error("error in boost::numeric::ublas::inner_prod: Tensor extents should be the same."); 60 | 61 | return inner(a.rank(), a.extents().data(), 62 | a.data(), a.strides().data(), 63 | b.data(), b.strides().data(), value_type{0}); 64 | } 65 | 66 | } // namespace boost::numeric::ublas 67 | 68 | #endif // BOOST_NUMERIC_UBLAS_TENSOR_PROD_DYNAMIC_HPP 69 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/function/norm.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018, Cem Bassoy, cem.bassoy@gmail.com 3 | // Copyright (c) 2020, Amit Singh, amitsingh19975@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // 10 | 11 | #ifndef BOOST_NUMERIC_UBLAS_TENSOR_NORM_HPP 12 | #define BOOST_NUMERIC_UBLAS_TENSOR_NORM_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | #include "../traits/basic_type_traits.hpp" 20 | 21 | namespace boost::numeric::ublas 22 | { 23 | template 24 | class tensor_core; 25 | } // namespace boost::numeric::ublas 26 | 27 | namespace boost::numeric::ublas 28 | { 29 | 30 | /** 31 | * 32 | * @brief Computes the frobenius nor of a tensor 33 | * 34 | * @note Calls accumulate on the tensor. 35 | * 36 | * implements 37 | * k = sqrt( sum_(i1,...,ip) A(i1,...,ip)^2 ) 38 | * 39 | * @tparam V the data type of tensor 40 | * @tparam F the format of tensor storage 41 | * @tparam A the array_type of tensor 42 | * @param a the tensor whose norm is expected of rank p. 43 | * @return the frobenius norm of a tensor. 44 | */ 45 | template 46 | inline auto norm(tensor_core< TE > const &a) 47 | { 48 | using value_type = typename tensor_core< TE >::value_type; 49 | 50 | if (a.empty()) { 51 | throw std::runtime_error("Error in boost::numeric::ublas::norm: tensors should not be empty."); 52 | } 53 | 54 | return std::sqrt(accumulate(a.order(), a.extents().data(), a.data(), a.strides().data(), value_type{}, 55 | [](auto const &l, auto const &r) { return l + r * r; })); 56 | } 57 | 58 | } // namespace boost::numeric::ublas 59 | 60 | #endif // BOOST_NUMERIC_UBLAS_TENSOR_NORM_HPP 61 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/function/trans.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021, Cem Bassoy, cem.bassoy@gmail.com 3 | // Copyright (c) 2021, Amit Singh, amitsingh19975@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // 10 | 11 | #ifndef BOOST_NUMERIC_UBLAS_TENSOR_TRANS_HPP 12 | #define BOOST_NUMERIC_UBLAS_TENSOR_TRANS_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "../extents.hpp" 19 | #include "../traits/basic_type_traits.hpp" 20 | #include "../multiplication.hpp" 21 | 22 | 23 | namespace boost::numeric::ublas 24 | { 25 | template 26 | class tensor_core; 27 | } // namespace boost::numeric::ublas 28 | 29 | namespace boost::numeric::ublas 30 | { 31 | 32 | /** @brief Transposes a tensor according to a permutation tuple 33 | * 34 | * Implements C[tau[i1],tau[i2]...,tau[ip]] = A[i1,i2,...,ip] 35 | * 36 | * @note calls trans function 37 | * 38 | * @param[in] a tensor object of rank p 39 | * @param[in] tau one-based permutation tuple of length p 40 | * @returns a transposed tensor object with the same storage format F and allocator type A 41 | */ 42 | template > 43 | inline decltype(auto) trans(tensor_core< TensorEngine > const &a, PermuType const &tau) 44 | { 45 | 46 | using tensor_type = tensor_core< TensorEngine >; 47 | using extents_type = typename tensor_type::extents_type; 48 | 49 | static_assert( is_dynamic_v< extents_type > ); 50 | 51 | auto const p = a.rank(); 52 | auto const &na = a.extents(); 53 | typename extents_type::base_type nc; 54 | 55 | if constexpr( is_dynamic_rank_v ){ 56 | nc.resize(p); 57 | } 58 | 59 | for (auto i = 0u; i < p; ++i){ 60 | nc.at(tau.at(i) - 1) = na.at(i); 61 | } 62 | 63 | auto c = tensor_type( extents_type( std::move(nc) ) ); 64 | 65 | if (a.empty()){ 66 | return c; 67 | } 68 | 69 | trans(a.rank(), a.extents().data(), tau.data(), 70 | c.data(), c.strides().data(), 71 | a.data(), a.strides().data()); 72 | 73 | return c; 74 | } 75 | 76 | } // namespace boost::numeric::ublas 77 | 78 | #endif // BOOST_NUMERIC_UBLAS_TENSOR_PROD_DYNAMIC_HPP 79 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/functions.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018, Cem Bassoy, cem.bassoy@gmail.com 3 | // Copyright (c) 2020, Amit Singh, amitsingh19975@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | 10 | 11 | #ifndef BOOST_UBLAS_TENSOR_FUNCTIONS_HPP 12 | #define BOOST_UBLAS_TENSOR_FUNCTIONS_HPP 13 | 14 | #include "function/reshape.hpp" 15 | #include "function/inner_prod.hpp" 16 | #include "function/outer_prod.hpp" 17 | #include "function/norm.hpp" 18 | #include "function/imag.hpp" 19 | #include "function/real.hpp" 20 | #include "function/conj.hpp" 21 | #include "function/trans.hpp" 22 | #include "function/tensor_times_vector.hpp" 23 | #include "function/tensor_times_matrix.hpp" 24 | #include "function/tensor_times_tensor.hpp" 25 | #include "function/init.hpp" 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/index_functions.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021, Cem Bassoy, cem.bassoy@gmail.com 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See 5 | // accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // The authors gratefully acknowledge the support of 9 | // Google and Fraunhofer IOSB, Ettlingen, Germany 10 | // 11 | 12 | 13 | #ifndef BOOST_NUMERIC_UBLAS_TENSOR_INDEX_FUNCTIONS_HPP 14 | #define BOOST_NUMERIC_UBLAS_TENSOR_INDEX_FUNCTIONS_HPP 15 | 16 | #include 17 | #include 18 | #include 19 | #include "concepts.hpp" 20 | 21 | 22 | namespace boost::numeric::ublas::detail 23 | { 24 | 25 | /** @brief Returns relative memory index with respect to a multi-index 26 | * 27 | * @code auto j = to_index({3,4,5}, to_strides({4,2,3},first_order{})); @endcode 28 | * 29 | * @param[in] i multi-index of length p 30 | * @param[in] w stride vector of length p 31 | * @returns relative memory location depending on \c i and \c w 32 | */ 33 | template 34 | [[nodiscard]] inline constexpr auto to_index(std::vector const& w, std::vector const& i) 35 | { 36 | return std::inner_product(i.begin(), i.end(), w.begin(), T{}); 37 | } 38 | 39 | template 40 | [[nodiscard]] inline constexpr auto to_index(std::array const& w, std::array const& i) 41 | { 42 | return std::inner_product(i.begin(), i.end(), w.begin(), T{}); 43 | } 44 | 45 | template 46 | [[nodiscard]] inline constexpr auto to_index(std::array const& w, Is ... is) 47 | { 48 | static_assert(N != sizeof...(is)+2); 49 | auto ai = std::array{I(is)...}; 50 | return std::inner_product(ai.begin(), ai.end(), w.begin(), I{}); 51 | } 52 | 53 | template 54 | [[nodiscard]] inline auto to_index(std::vector const& w, Is ... is) 55 | { 56 | constexpr auto N = sizeof...(is); 57 | auto ai = std::array{I(is)...}; 58 | return std::inner_product(ai.begin(), ai.end(), w.begin(), std::size_t{}); 59 | } 60 | 61 | 62 | } // namespace boost::numeric::ublas::detail 63 | 64 | #endif // BOOST_NUMERIC_UBLAS_TENSOR_INDEX_FUNCTIONS_HPP 65 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/layout.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018-2020, Cem Bassoy, cem.bassoy@gmail.com 3 | // Copyright (c) 2019-2020, Amit Singh, amitsingh19975@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // Google and Fraunhofer IOSB, Ettlingen, Germany 11 | // 12 | 13 | #ifndef BOOST_UBLAS_TENSOR_LAYOUT_HPP 14 | #define BOOST_UBLAS_TENSOR_LAYOUT_HPP 15 | 16 | #include 17 | 18 | namespace boost::numeric::ublas::layout{ 19 | 20 | using first_order = column_major; 21 | using last_order = row_major; 22 | 23 | } // namespace boost::numeric::ublas::layout 24 | 25 | 26 | #endif // BOOST_UBLAS_TENSOR_LAYOUT_HPP 27 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/tags.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021, Cem Bassoy, cem.bassoy@gmail.com 3 | // Copyright (c) 2020, Amit Singh, amitsingh19975@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // 10 | 11 | #ifndef BOOST_UBLAS_TENSOR_TAGS_HPP 12 | #define BOOST_UBLAS_TENSOR_TAGS_HPP 13 | 14 | namespace boost::numeric::ublas{ 15 | 16 | struct tensor_tag{}; 17 | 18 | struct storage_resizable_container_tag{}; 19 | 20 | struct storage_static_container_tag{}; 21 | 22 | struct storage_seq_container_tag{}; 23 | 24 | struct storage_non_seq_container_tag{}; 25 | 26 | } // namespace boost::numeric::ublas 27 | 28 | 29 | #endif // BOOST_UBLAS_TENSOR_TAGS_HPP 30 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/tensor.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018, Cem Bassoy, cem.bassoy@gmail.com 3 | // Copyright (c) 2019, Amit Singh, amitsingh19975@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // Google and Fraunhofer IOSB, Ettlingen, Germany 11 | // 12 | 13 | #ifndef BOOST_UBLAS_TENSOR_TENSOR_HPP 14 | #define BOOST_UBLAS_TENSOR_TENSOR_HPP 15 | 16 | #include "tensor/tensor_core.hpp" 17 | #include "tensor/tensor_dynamic.hpp" 18 | #include "tensor/tensor_engine.hpp" 19 | #include "tensor/tensor_static_rank.hpp" 20 | #include "tensor/tensor_static.hpp" 21 | 22 | #endif // BOOST_UBLAS_TENSOR_TENSOR_HPP 23 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/tensor/tensor_core.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019, Amit Singh, amitsingh19975@gmail.com 3 | // Copyright (c) 2020, Cem Bassoy, cem.bassoy@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // Google and Fraunhofer IOSB, Ettlingen, Germany 11 | // 12 | 13 | 14 | /// \file tensor_core.hpp Definition for the tensor template class 15 | 16 | #ifndef BOOST_UBLAS_TENSOR_CORE_HPP 17 | #define BOOST_UBLAS_TENSOR_CORE_HPP 18 | 19 | 20 | namespace boost::numeric::ublas { 21 | 22 | template 23 | class tensor_core; 24 | 25 | } // namespace boost::numeric::ublas 26 | 27 | #endif // BOOST_UBLAS_TENSOR_CORE_HPP 28 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/tensor/tensor_engine.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2020, Amit Singh, amitsingh19975@gmail.com 3 | // Copyright (c) 2021, Cem Bassoy, cem.bassoy@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // Google and Fraunhofer IOSB, Ettlingen, Germany 11 | // 12 | 13 | #ifndef BOOST_UBLAS_TENSOR_ENGINE_HPP 14 | #define BOOST_UBLAS_TENSOR_ENGINE_HPP 15 | 16 | namespace boost::numeric::ublas{ 17 | 18 | template 19 | struct tensor_engine 20 | { 21 | using extents_type = E; 22 | using layout_type = L; 23 | using container_type = C; 24 | }; 25 | 26 | } // namespace boost::numeric::ublas 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/traits/basic_type_traits.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019, Amit Singh, amitsingh19975@gmail.com 3 | // Copyright (c) 2021, Cem Bassoy, cem.bassoy@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | 10 | #ifndef BOOST_UBLAS_TENSOR_BASIC_TYPE_TRAITS_HPP 11 | #define BOOST_UBLAS_TENSOR_BASIC_TYPE_TRAITS_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost::numeric::ublas { 19 | 20 | 21 | template 22 | struct is_complex : std::false_type{}; 23 | 24 | template 25 | struct is_complex< std::complex > : std::true_type{}; 26 | 27 | template 28 | inline static constexpr bool is_complex_v = is_complex::value; 29 | 30 | } // namespace boost::numeric::ublas 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/boost/numeric/ublas/tensor/type_traits.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018, Cem Bassoy, cem.bassoy@gmail.com 3 | // Copyright (c) 2019, Amit Singh, amitsingh19975@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // Google and Fraunhofer IOSB, Ettlingen, Germany 11 | // 12 | 13 | #ifndef BOOST_UBLAS_TENSOR_TYPE_TRAITS_HPP 14 | #define BOOST_UBLAS_TENSOR_TYPE_TRAITS_HPP 15 | 16 | #include "traits/basic_type_traits.hpp" 17 | #include "traits/storage_traits.hpp" 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | 21 | 22 |

23 | Automatic redirection failed, please go to 24 | doc/html/ublas.html. 25 |

26 | 27 | 28 | -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "numeric/ublas", 3 | "name": "uBLAS", 4 | "authors": [ 5 | "Joerg Walter", 6 | "Mathias Koch" 7 | ], 8 | "description": "uBLAS provides tensor, matrix, and vector classes as well as basic linear and multilinear algebra routines. Several dense, packed and sparse storage schemes are supported.", 9 | "category": [ 10 | "Math" 11 | ], 12 | "maintainers": [ 13 | "David Bellot ", 14 | "Cem Bassoy ", 15 | "Stefan Seefeld " 16 | ], 17 | "cxxstd": "11" 18 | } 19 | -------------------------------------------------------------------------------- /test/README: -------------------------------------------------------------------------------- 1 | Copyright (c) 2000-2011 Joerg Walter, Mathias Koch, David Bellot 2 | 3 | Distributed under the Boost Software License, Version 1.0. (See 4 | accompanying file LICENSE_1_0.txt or copy at 5 | http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | uBLAS test director 8 | Use boost::test to test various uBLAS containers and expressions 9 | 10 | The tests can be used individually or automaticaly as part of the uBLAS regression tests. 11 | 12 | The tests are broken down in directorys as follows: 13 | 14 | test1 - dense vector and matrix tests 15 | test2 - BLAS tests 16 | test3 - sparse vector and matrix tests 17 | test4 - banded/diagonal matrix tests 18 | test5 - triangular matrix tests 19 | test6 - symmetric matrix tests 20 | test7 - dense vector and matrix tests with boost::numeric::internal values 21 | 22 | Each test directory contains: 23 | testX.hpp Headers and types to be tested 24 | testX.cpp Call the test functions for the defined types 25 | testX1.cpp Implements vector tests 26 | testX2.cpp Implements vector/matrix tests 27 | testX3.cpp Implements matrix tests 28 | 29 | Missing in these tests 30 | a) Runtime result validation. 31 | b) Iterator interface tests. Only complete container expressions are tested 32 | -------------------------------------------------------------------------------- /test/concepts.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | //#include 27 | 28 | namespace ublas = boost::numeric::ublas; 29 | 30 | 31 | int main () { 32 | void (* check) (void) = ublas::concept_checks; 33 | boost::ignore_unused_variable_warning (check); 34 | } 35 | -------------------------------------------------------------------------------- /test/manual/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2006 Michael Stevens 2 | # Use, modification and distribution are subject to the 3 | # Boost Software License, Version 1.0. (See accompanying file 4 | # LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | exe sp_resize : sp_resize.cpp ; 7 | 8 | exe test_move_semantics : test_move_semantics.cpp ; 9 | -------------------------------------------------------------------------------- /test/manual/sp_resize.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006 Michael Stevens 3 | * Use, modification and distribution are subject to the 4 | * Boost Software License, Version 1.0. (See accompanying file 5 | * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | typedef double Real; 13 | 14 | template 15 | void printV(const V& v) { 16 | std::cout << "size: " << v.size() << " nnz_capacity: " << v.nnz_capacity() << " nnz: " << v.nnz() << std::endl; 17 | for (typename V::const_iterator i = v.begin(); i != v.end(); i++) { 18 | std::cout << i.index() << ":" << (*i) << " "; 19 | } 20 | std::cout << std::endl; 21 | } 22 | 23 | template 24 | void run_test() 25 | { 26 | V v(10); 27 | 28 | v[0] = 1; 29 | v[5] = 1; 30 | v[8] = 1; 31 | v[9] = 1; 32 | 33 | printV(v); 34 | 35 | v.resize(9); printV(v); 36 | v.resize(12); printV(v); 37 | v.resize(2); printV(v); 38 | v.resize(0); printV(v); 39 | 40 | v.resize(5); v[0] = 1; printV(v); 41 | v.resize(5,false); printV(v); 42 | } 43 | 44 | int main(int, char **) { 45 | 46 | std::cout << "---- MAPPED ----\n"; 47 | run_test< boost::numeric::ublas::mapped_vector >(); 48 | std::cout << "---- COMPRESSED ----\n"; 49 | run_test< boost::numeric::ublas::compressed_vector >(); 50 | std::cout << "---- COORDINATE ----\n"; 51 | run_test< boost::numeric::ublas::coordinate_vector >(); 52 | 53 | return 0; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /test/minimal_allocator_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #if !defined(BOOST_NO_CXX11_ALLOCATOR) 10 | #include 11 | #include 12 | 13 | template 14 | struct Allocator { 15 | typedef T value_type; 16 | 17 | Allocator() BOOST_NOEXCEPT { } 18 | 19 | template 20 | Allocator(const Allocator&) BOOST_NOEXCEPT { } 21 | 22 | T* allocate(std::size_t size) { 23 | return static_cast(::operator new(sizeof(T) * size)); 24 | } 25 | 26 | void deallocate(T* ptr, std::size_t) { 27 | ::operator delete(ptr); 28 | } 29 | }; 30 | 31 | template 32 | bool operator==(const Allocator&, const Allocator&) BOOST_NOEXCEPT 33 | { 34 | return true; 35 | } 36 | 37 | template 38 | bool operator!=(const Allocator&, const Allocator&) BOOST_NOEXCEPT 39 | { 40 | return false; 41 | } 42 | 43 | int main() 44 | { 45 | boost::numeric::ublas::matrix > > matrix(4, 4); 49 | matrix(1, 2) = 3; 50 | } 51 | #endif 52 | -------------------------------------------------------------------------------- /test/opencl/Jamfile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2018 Stefan Seefeld 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (See accompanying file LICENSE_1_0.txt or 6 | # copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | import ac ; 9 | 10 | # work around a bug in Boost.Build 11 | import ../../opencl ; 12 | import ../../clblas ; 13 | using opencl ; 14 | using clblas ; 15 | 16 | project boost/ublas/test/opencl 17 | : requirements 18 | gcc:-Wno-ignored-attributes 19 | clang:-Wno-ignored-attributes 20 | [ ac.check-library /clblas//clblas : /clblas//clblas /opencl//opencl : no ] 21 | ; 22 | 23 | test-suite ocl 24 | : [ run prod_test.cpp ] 25 | [ run elementwise_operations_test.cpp ] 26 | [ run inner_prod_test.cpp ] 27 | [ run outer_prod_test.cpp ] 28 | [ run transposition_test.cpp ] 29 | [ run norm_test.cpp ] 30 | [ run norm2_test.cpp ] 31 | [ run elementwise_operations_with_constants_test.cpp ] 32 | ; 33 | -------------------------------------------------------------------------------- /test/opencl/elementwise_operations_test.cpp: -------------------------------------------------------------------------------- 1 | #include "elementwise_operations_test.hpp" 2 | 3 | int main() 4 | { 5 | 6 | ///testing row major flaot elementwise operations 7 | bench_elementwise , 10, 10> b1; 8 | 9 | ///testing row major complex float elementwise operations 10 | bench_elementwise , ublas::basic_row_major<>, 10, 10> b2; 11 | 12 | ///testing row major double elementwise operations 13 | bench_elementwise , 10, 10> b5; 14 | 15 | ///testing row major complex double elementwise operations 16 | bench_elementwise , ublas::basic_row_major<>, 10, 10> b6; 17 | 18 | ///testing column major flaot elementwise operations 19 | bench_elementwise , 10, 10> b3; 20 | 21 | ///testing column major complex float elementwise operations 22 | bench_elementwise , ublas::basic_column_major<>, 10, 10> b4; 23 | 24 | ///testing column major double elementwise operations 25 | bench_elementwise , 10, 10> b7; 26 | 27 | ///testing column major complex double elementwise operations 28 | bench_elementwise , ublas::basic_column_major<>, 10, 10> b8; 29 | 30 | 31 | std::cout << "row major:" << std::endl; 32 | b1.run(); 33 | b2.run(); 34 | b5.run(); 35 | b6.run(); 36 | 37 | 38 | std::cout << "column major:" << std::endl; 39 | b3.run(); 40 | b4.run(); 41 | b7.run(); 42 | b8.run(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /test/opencl/elementwise_operations_with_constants_test.cpp: -------------------------------------------------------------------------------- 1 | #include "elementwise_operations_with_constants_test.hpp" 2 | #include 3 | 4 | int main() 5 | { 6 | 7 | ///testing row major flaot prod 8 | bench_elementwise_constant, 10, 10> b1; 9 | 10 | ///testing row major complex float prod 11 | bench_elementwise_constant, ublas::basic_row_major<>, 10, 10> b2; 12 | 13 | 14 | ///testing row major double prod 15 | bench_elementwise_constant, 10, 10> b3; 16 | 17 | ///testing row major complex float elementwise operations with constants 18 | bench_elementwise_constant, ublas::basic_row_major<>, 10, 10> b4; 19 | 20 | 21 | ///testing column major flaot elementwise operations with constants 22 | bench_elementwise_constant, 10, 10> b5; 23 | 24 | ///testing column major complex float elementwise operations with constants 25 | bench_elementwise_constant, ublas::basic_column_major<>, 10, 10> b6; 26 | 27 | ///testing column major double elementwise operations with constants 28 | bench_elementwise_constant, 10, 10> b7; 29 | 30 | ///testing column major complex double elementwise operations with constants 31 | bench_elementwise_constant, ublas::basic_column_major<>, 10, 10> b8; 32 | 33 | 34 | std::cout << "Row major:" << std::endl; 35 | b1.run(); 36 | b2.run(); 37 | b3.run(); 38 | b4.run(); 39 | 40 | std::cout << "Column major:" << std::endl; 41 | b5.run(); 42 | b6.run(); 43 | b7.run(); 44 | b8.run(); 45 | 46 | return 0; 47 | 48 | } -------------------------------------------------------------------------------- /test/opencl/elementwise_operations_with_constants_test.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEST_ELEMENT_CONSTANT_OPENCL_HH 2 | #define TEST_ELEMENT_CONSTANT_OPENCL_HH 3 | #include "test_opencl.hpp" 4 | 5 | 6 | template 7 | class bench_elementwise_constant 8 | { 9 | public: 10 | 11 | typedef test_opencl test; 12 | 13 | void run() 14 | { 15 | opencl::library lib; 16 | int passedOperations = 0; 17 | // get default device and setup context 18 | compute::device device = compute::system::default_device(); 19 | compute::context context(device); 20 | compute::command_queue queue(context, device); 21 | 22 | std::srand(time(0)); 23 | 24 | ublas::matrix m; 25 | ublas::matrix m_result_add_ublas; 26 | ublas::matrix m_result_sub_ublas; 27 | ublas::matrix m_result_add_opencl; 28 | ublas::matrix m_result_sub_opencl; 29 | ublas::vector v; 30 | ublas::vector v_result_add_ublas; 31 | ublas::vector v_result_sub_ublas; 32 | ublas::vector v_result_add_opencl; 33 | ublas::vector v_result_sub_opencl; 34 | 35 | 36 | 37 | for (int i = 0; i m_constant_holder(rows, cols, constant); 50 | ublas::vector v_constant_holder(rows, constant); 51 | 52 | m_result_add_ublas = m + m_constant_holder; 53 | m_result_sub_ublas = m - m_constant_holder; 54 | m_result_add_opencl = opencl::element_add(m, constant, queue); 55 | m_result_sub_opencl = opencl::element_sub(m, constant, queue); 56 | 57 | v_result_add_ublas = v + v_constant_holder; 58 | v_result_sub_ublas = v - v_constant_holder; 59 | v_result_add_opencl = opencl::element_add(v, constant, queue); 60 | v_result_sub_opencl = opencl::element_sub(v, constant, queue); 61 | 62 | 63 | 64 | if ((!test::compare(m_result_add_ublas, m_result_add_opencl)) 65 | || (!test::compare(m_result_sub_ublas, m_result_sub_opencl)) || 66 | (!test::compare(v_result_add_ublas, v_result_add_opencl)) 67 | || (!test::compare(v_result_sub_ublas, v_result_sub_opencl))) 68 | { 69 | std::cout << "Error in calculations" << std::endl; 70 | 71 | std::cout << "passed: " << passedOperations << std::endl; 72 | return; 73 | } 74 | 75 | passedOperations++; 76 | 77 | } 78 | std::cout << "All is well (matrix opencl elementwise operations with constants) of " << typeid(T).name() << std::endl; 79 | 80 | 81 | 82 | } 83 | 84 | }; 85 | 86 | #endif -------------------------------------------------------------------------------- /test/opencl/inner_prod_test.cpp: -------------------------------------------------------------------------------- 1 | #include "inner_prod_test.hpp" 2 | #include 3 | 4 | int main() 5 | { 6 | ///testing row major int inner prod 7 | bench_inner_prod b1; 8 | 9 | ///testing row major float inner prod 10 | bench_inner_prod b2; 11 | 12 | 13 | ///testing row major double inner prod 14 | bench_inner_prod b3; 15 | 16 | 17 | b1.run(); 18 | b2.run(); 19 | b3.run(); 20 | 21 | return 0; 22 | 23 | } -------------------------------------------------------------------------------- /test/opencl/inner_prod_test.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEST_INNER_PROD_HH 2 | #define TEST_INNER_PROD_HH 3 | #include "test_opencl.hpp" 4 | 5 | 6 | template 7 | class bench_inner_prod 8 | { 9 | public: 10 | 11 | typedef test_opencl test; 12 | 13 | void run() 14 | { 15 | opencl::library lib; 16 | int passedOperations = 0; 17 | // get default device and setup context 18 | compute::device device = compute::system::default_device(); 19 | compute::context context(device); 20 | compute::command_queue queue(context, device); 21 | 22 | std::srand(time(0)); 23 | 24 | ublas::vector va; 25 | ublas::vector vb; 26 | T result_inner_prod_ublas; 27 | T result_inner_prod_opencl; 28 | 29 | 30 | for (int i = 0; i 3 | 4 | int main() 5 | { 6 | 7 | ///testing float norm2 8 | bench_norm2 b1; 9 | 10 | 11 | ///testing double norm2 12 | bench_norm2 b2; 13 | 14 | 15 | ///testing float norm2 16 | bench_norm2, 10, 10> b3; 17 | 18 | 19 | ///testing double norm2 20 | bench_norm2, 10, 10> b4; 21 | 22 | 23 | 24 | b1.run(); 25 | b2.run(); 26 | b3.run(); 27 | b4.run(); 28 | 29 | 30 | return 0; 31 | 32 | } -------------------------------------------------------------------------------- /test/opencl/norm2_test.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEST_NORM2_OPENCL_HH 2 | #define TEST_NORM2_OPENCL_HH 3 | #include "test_opencl.hpp" 4 | 5 | 6 | template 7 | class bench_norm2 8 | { 9 | public: 10 | 11 | typedef test_opencl> test; 12 | 13 | 14 | void run() 15 | { 16 | opencl::library lib; 17 | int passedOperations = 0; 18 | // get default device and setup context 19 | compute::device device = compute::system::default_device(); 20 | compute::context context(device); 21 | compute::command_queue queue(context, device); 22 | 23 | std::srand(time(0)); 24 | 25 | ublas::vector v; 26 | 27 | 28 | for (int i = 0; i 1e-6) //precision of float 41 | { 42 | std::cout << "Error in calculations" << std::endl; 43 | 44 | std::cout << "passed: " << passedOperations << std::endl; 45 | return; 46 | } 47 | 48 | passedOperations++; 49 | 50 | } 51 | std::cout << "All is well (vector opencl a_sum) of " << typeid(T).name() << std::endl; 52 | 53 | 54 | 55 | } 56 | 57 | }; 58 | 59 | #endif -------------------------------------------------------------------------------- /test/opencl/norm_test.cpp: -------------------------------------------------------------------------------- 1 | #include "norm_test.hpp" 2 | #include 3 | 4 | int main() 5 | { 6 | 7 | ///testing float norm1 8 | bench_norm b1; 9 | 10 | 11 | ///testing double norm1 12 | bench_norm b2; 13 | 14 | 15 | 16 | b1.run(); 17 | b2.run(); 18 | 19 | 20 | return 0; 21 | 22 | } -------------------------------------------------------------------------------- /test/opencl/norm_test.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEST_NORM_OPENCL_HH 2 | #define TEST_NORM_OPENCL_HH 3 | #include "test_opencl.hpp" 4 | 5 | 6 | template 7 | class bench_norm 8 | { 9 | public: 10 | 11 | typedef test_opencl> test; 12 | 13 | 14 | void run() 15 | { 16 | opencl::library lib; 17 | int passedOperations = 0; 18 | // get default device and setup context 19 | compute::device device = compute::system::default_device(); 20 | compute::context context(device); 21 | compute::command_queue queue(context, device); 22 | 23 | std::srand(time(0)); 24 | 25 | ublas::vector v; 26 | 27 | 28 | for (int i = 0; i b1; 9 | 10 | 11 | ///testing double outer prod 12 | bench_outer_prod b2; 13 | 14 | 15 | ///testing complex of float outer prod 16 | bench_outer_prod, 10, 10> b3; 17 | 18 | 19 | ///testing complex of double outer prod 20 | bench_outer_prod, 10, 10> b4; 21 | 22 | 23 | 24 | b1.run(); 25 | b2.run(); 26 | b3.run(); 27 | b4.run(); 28 | 29 | return 0; 30 | 31 | } -------------------------------------------------------------------------------- /test/opencl/outer_prod_test.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEST_PROD_OPENCL_HH 2 | #define TEST_PROD_OPENCL_HH 3 | #include "test_opencl.hpp" 4 | 5 | 6 | template 7 | class bench_outer_prod 8 | { 9 | public: 10 | 11 | typedef test_opencl test; 12 | 13 | void run() 14 | { 15 | opencl::library lib; 16 | int passedOperations = 0; 17 | // get default device and setup context 18 | compute::device device = compute::system::default_device(); 19 | compute::context context(device); 20 | compute::command_queue queue(context, device); 21 | 22 | std::srand(time(0)); 23 | 24 | ublas::vector va; 25 | ublas::vector vb; 26 | ublas::matrix resultUBLAS; 27 | ublas::matrix resultOPENCL; 28 | 29 | 30 | for (int i = 0; i 3 | 4 | int main() 5 | { 6 | 7 | ///testing row major flaot prod 8 | bench_prod, 10, 10> b1; 9 | 10 | ///testing row major complex float prod 11 | bench_prod, ublas::basic_row_major<>, 10, 10> b2; 12 | 13 | 14 | ///testing row major double prod 15 | bench_prod, 10, 10> b3; 16 | 17 | ///testing row major complex float prod 18 | bench_prod, ublas::basic_row_major<>, 10, 10> b4; 19 | 20 | 21 | ///testing column major flaot prod 22 | bench_prod, 10, 10> b5; 23 | 24 | ///testing column major complex float prod 25 | bench_prod, ublas::basic_column_major<>, 10, 10> b6; 26 | 27 | ///testing column major double prod 28 | bench_prod, 10, 10> b7; 29 | 30 | ///testing column major complex double prod 31 | bench_prod, ublas::basic_column_major<>, 10, 10> b8; 32 | 33 | 34 | std::cout << "Row major:" << std::endl; 35 | b1.run(); 36 | b2.run(); 37 | b3.run(); 38 | b4.run(); 39 | 40 | std::cout << "Column major:" << std::endl; 41 | b5.run(); 42 | b6.run(); 43 | b7.run(); 44 | b8.run(); 45 | 46 | return 0; 47 | 48 | } -------------------------------------------------------------------------------- /test/opencl/prod_test.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEST_PROD_OPENCL_HH 2 | #define TEST_PROD_OPENCL_HH 3 | #include "test_opencl.hpp" 4 | 5 | 6 | template 7 | class bench_prod 8 | { 9 | public: 10 | 11 | typedef test_opencl test; 12 | 13 | void run() 14 | { 15 | opencl::library lib; 16 | int passedOperations = 0; 17 | // get default device and setup context 18 | compute::device device = compute::system::default_device(); 19 | compute::context context(device); 20 | compute::command_queue queue(context, device); 21 | 22 | std::srand(time(0)); 23 | 24 | ublas::matrix a; 25 | ublas::matrix b; 26 | ublas::matrix resultUBLAS; 27 | ublas::matrix resultOPENCL; 28 | ublas::vector va; 29 | ublas::vector vb; 30 | ublas::vector result_vector_ublas_mv; 31 | ublas::vector result_vector_ublas_vm; 32 | ublas::vector result_vector_opencl_mv; 33 | ublas::vector result_vector_opencl_vm; 34 | 35 | 36 | 37 | for (int i = 0; i 4 | 5 | #define BOOST_UBLAS_ENABLE_OPENCL 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | 13 | 14 | namespace ublas = boost::numeric::ublas; 15 | namespace opencl = boost::numeric::ublas::opencl; 16 | namespace compute = boost::compute; 17 | 18 | template > 19 | class test_opencl 20 | { 21 | public: 22 | static bool compare(ublas::matrix& a, ublas::matrix& b) 23 | { 24 | typedef typename ublas::matrix::size_type size_type; 25 | if ((a.size1() != b.size1()) || (a.size2() != b.size2())) 26 | return false; 27 | 28 | for (size_type i = 0; i& a, ublas::vector& b) 40 | { 41 | typedef typename ublas::vector::size_type size_type; 42 | if (a.size() != b.size()) 43 | return false; 44 | 45 | for (size_type i = 0; i& m, int max_value) 57 | { 58 | typedef typename ublas::matrix::size_type size_type; 59 | for (size_type i = 0; i < m.size1(); i++) 60 | { 61 | for (size_type j = 0; j& v, int max_value) 69 | { 70 | typedef typename ublas::vector::size_type size_type; 71 | for (size_type i = 0; i , 10, 10> b1; 8 | bench_trans, 10, 10> b2; 9 | bench_trans, ublas::basic_row_major<>, 10, 10> b3; 10 | bench_trans, ublas::basic_row_major<>, 10, 10> b4; 11 | 12 | //Column-major 13 | bench_trans, 10, 10> b5; 14 | bench_trans, 10, 10> b6; 15 | bench_trans, ublas::basic_column_major<>, 10, 10> b7; 16 | bench_trans, ublas::basic_column_major<>, 10, 10> b8; 17 | 18 | std::cout << "Row-major:" << std::endl; 19 | b1.run(); 20 | b2.run(); 21 | b3.run(); 22 | b4.run(); 23 | 24 | std::cout << std::endl << "Column-major:" << std::endl; 25 | 26 | b5.run(); 27 | b6.run(); 28 | b7.run(); 29 | b8.run(); 30 | 31 | return 0; 32 | 33 | } -------------------------------------------------------------------------------- /test/opencl/transposition_test.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEST_TRANS_OPENCL_HH 2 | #define TEST_TRANS_OPENCL_HH 3 | #include "test_opencl.hpp" 4 | 5 | 6 | template 7 | class bench_trans 8 | { 9 | public: 10 | 11 | typedef test_opencl test; 12 | 13 | void run() 14 | { 15 | opencl::library lib; 16 | int passedOperations = 0; 17 | // get default device and setup context 18 | compute::device device = compute::system::default_device(); 19 | compute::context context(device); 20 | compute::command_queue queue(context, device); 21 | 22 | std::srand(time(0)); 23 | 24 | ublas::matrix a; 25 | ublas::matrix resultUBLAS; 26 | ublas::matrix resultOPENCL; 27 | 28 | 29 | for (int i = 0; i 14 | #include 15 | #include 16 | 17 | // User defined type to capture base pointer on construction 18 | 19 | class udt { 20 | public: 21 | udt () { 22 | base_pointer = this; 23 | } 24 | ~udt () {} // required for GCC prior to 3.4 to generate cookie 25 | 26 | static udt* base_pointer; 27 | }; 28 | 29 | udt* udt::base_pointer; 30 | 31 | int main () 32 | { 33 | udt a; 34 | udt* ap = &a; 35 | 36 | // Capture placement new offsets for a udt 37 | new (ap) udt; 38 | int new_offset = int (udt::base_pointer - ap); 39 | new (ap) udt [1]; 40 | int array_new_offset = int (udt::base_pointer - ap); 41 | 42 | // Print offsets - we expect 0,0 or 0,sizeof(std::size_t) 43 | std::cout << new_offset <<','<< array_new_offset << std::endl; 44 | 45 | // Return status 46 | if (new_offset != 0) 47 | return -1; // Very bad if new has an offset 48 | 49 | #ifdef BOOST_UBLAS_USEFUL_ARRAY_PLACEMENT_NEW 50 | bool expect_array_offset = false; 51 | #else 52 | bool expect_array_offset = true; 53 | #endif 54 | // Check match between config and array 55 | if (!expect_array_offset && array_new_offset != 0) { 56 | return -2; // Bad config should not enable array new 57 | } 58 | if (expect_array_offset && array_new_offset == 0) { 59 | return -3; // Config could enable array new 60 | } 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /test/tensor/test_main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018, Cem Bassoy, cem.bassoy@gmail.com 3 | // Copyright (c) 2019, Amit Singh, amitsingh19975@gmail.com 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // Google and Fraunhofer IOSB, Ettlingen, Germany 11 | // 12 | 13 | 14 | 15 | // #include 16 | // #include 17 | 18 | #ifndef BOOST_TEST_DYN_LINK 19 | #define BOOST_TEST_DYN_LINK 20 | #endif 21 | // NOLINTNEXTLINE 22 | #define BOOST_TEST_MODULE MainTensor 23 | 24 | #include 25 | -------------------------------------------------------------------------------- /test/test1.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include "test1.hpp" 14 | 15 | int main () { 16 | test_vector (); 17 | test_matrix_vector (); 18 | test_matrix (); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/test1.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #ifndef TEST1_H 14 | #define TEST1_H 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace ublas = boost::numeric::ublas; 25 | 26 | #include "common/init.hpp" 27 | 28 | void test_vector (); 29 | void test_matrix_vector (); 30 | void test_matrix (); 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /test/test2.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include "test2.hpp" 14 | 15 | int main () { 16 | #ifdef USE_FLOAT 17 | std::cout << "float" << std::endl; 18 | test_blas_1, 3> ().test (); 19 | #endif 20 | 21 | #ifdef USE_DOUBLE 22 | std::cout << "double" << std::endl; 23 | test_blas_1, 3> ().test (); 24 | #endif 25 | 26 | #ifdef USE_STD_COMPLEX 27 | #ifdef USE_FLOAT 28 | std::cout << "std::complex" << std::endl; 29 | test_blas_1 >, 3> ().test (); 30 | #endif 31 | 32 | #ifdef USE_DOUBLE 33 | std::cout << "std::complex" << std::endl; 34 | test_blas_1 >, 3> ().test (); 35 | #endif 36 | #endif 37 | 38 | std::cout << "test_blas_2" << std::endl; 39 | 40 | #ifdef USE_FLOAT 41 | std::cout << "float" << std::endl; 42 | test_blas_2, ublas::matrix, 3> ().test (); 43 | #endif 44 | 45 | #ifdef USE_DOUBLE 46 | std::cout << "double" << std::endl; 47 | test_blas_2, ublas::matrix, 3> ().test (); 48 | #endif 49 | 50 | #ifdef USE_STD_COMPLEX 51 | #ifdef USE_FLOAT 52 | std::cout << "std::complex" << std::endl; 53 | test_blas_2 >, ublas::matrix >, 3> ().test (); 54 | #endif 55 | 56 | #ifdef USE_DOUBLE 57 | std::cout << "std::complex" << std::endl; 58 | test_blas_2 >, ublas::matrix >, 3> ().test (); 59 | #endif 60 | #endif 61 | 62 | std::cout << "test_blas_3" << std::endl; 63 | 64 | #ifdef USE_FLOAT 65 | std::cout << "float" << std::endl; 66 | test_blas_3, 3> ().test (); 67 | #endif 68 | 69 | #ifdef USE_DOUBLE 70 | std::cout << "double" << std::endl; 71 | test_blas_3, 3> ().test (); 72 | #endif 73 | 74 | #ifdef USE_STD_COMPLEX 75 | #ifdef USE_FLOAT 76 | std::cout << "std::complex" << std::endl; 77 | test_blas_3 >, 3> ().test (); 78 | #endif 79 | 80 | #ifdef USE_DOUBLE 81 | std::cout << "std::complex" << std::endl; 82 | test_blas_3 >, 3> ().test (); 83 | #endif 84 | #endif 85 | 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /test/test2.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #ifndef TEST2_H 14 | #define TEST2_H 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace ublas = boost::numeric::ublas; 25 | 26 | #include "common/init.hpp" 27 | 28 | template 29 | struct test_blas_1 { 30 | typedef typename V::value_type value_type; 31 | typedef typename ublas::type_traits::real_type real_type; 32 | 33 | void test (); 34 | }; 35 | 36 | template 37 | struct test_blas_2 { 38 | typedef typename V::value_type value_type; 39 | 40 | void test (); 41 | }; 42 | 43 | template 44 | struct test_blas_3 { 45 | typedef typename M::value_type value_type; 46 | 47 | void test (); 48 | }; 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /test/test3.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include "test3.hpp" 14 | 15 | int main () { 16 | test_vector (); 17 | test_matrix_vector (); 18 | test_matrix (); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/test3.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #ifndef TEST3_H 14 | #define TEST3_H 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #ifdef USE_GENERALIZED_VECTOR_OF_VECTOR 26 | #include 27 | #endif 28 | #include 29 | 30 | namespace ublas = boost::numeric::ublas; 31 | 32 | #include "common/init.hpp" 33 | 34 | void test_vector (); 35 | void test_matrix_vector (); 36 | void test_matrix (); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /test/test4.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include "test4.hpp" 14 | 15 | int main () { 16 | test_matrix_vector (); 17 | test_matrix (); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/test4.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #ifndef TEST4_H 14 | #define TEST4_H 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace ublas = boost::numeric::ublas; 25 | 26 | #include "common/init.hpp" 27 | 28 | //#define USE_BANDED 29 | #define USE_DIAGONAL 30 | 31 | 32 | void test_matrix_vector (); 33 | void test_matrix (); 34 | 35 | 36 | // FIXME slice are failing in assignment to zero elements 37 | #undef USE_SLICE 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /test/test5.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include "test5.hpp" 14 | 15 | int main () { 16 | test_matrix_vector (); 17 | test_matrix (); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/test5.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #ifndef TEST5_H 14 | #define TEST5_H 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace ublas = boost::numeric::ublas; 25 | 26 | #include "common/init.hpp" 27 | 28 | void test_matrix_vector (); 29 | void test_matrix (); 30 | 31 | 32 | // FIXME slice are failing in assignment to zero elements 33 | #undef USE_SLICE 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /test/test6.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include "test6.hpp" 14 | 15 | int main () { 16 | test_matrix_vector (); 17 | test_matrix (); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/test6.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #ifndef TEST6_H 14 | #define TEST6_H 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace ublas = boost::numeric::ublas; 25 | 26 | #include "common/init.hpp" 27 | 28 | void test_matrix_vector (); 29 | void test_matrix (); 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /test/test7.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "test7.hpp" 23 | 24 | // this testcase requires fix of task #2473 25 | 26 | int main () { 27 | test_vector (); 28 | test_matrix_vector (); 29 | test_matrix (); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /test/test7.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2000-2002 3 | // Joerg Walter, Mathias Koch 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // The authors gratefully acknowledge the support of 10 | // GeNeSys mbH & Co. KG in producing this work. 11 | // 12 | 13 | #ifndef TEST7_H 14 | #define TEST7_H 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace ublas = boost::numeric::ublas; 28 | 29 | #include "common/init.hpp" 30 | 31 | void test_vector (); 32 | void test_matrix_vector (); 33 | void test_matrix (); 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /test/test_coordinate_matrix_sort.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 David Bellot 2 | // 3 | // Distributed under the Boost Software License, Version 1.0. (See 4 | // accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #ifndef BOOST_UBLAS_NO_ELEMENT_PROXIES 8 | # define BOOST_UBLAS_NO_ELEMENT_PROXIES 9 | #endif 10 | 11 | #include 12 | #include 13 | 14 | #include "utils.hpp" 15 | 16 | using std::cout; 17 | using std::endl; 18 | 19 | BOOST_UBLAS_TEST_DEF( test_coordinate_matrix_sort ) 20 | { 21 | 22 | boost::numeric::ublas::coordinate_matrix matrix_mask(3, 3, 2); 23 | cout << "Setting matrix(1,1) = 2.1" << endl; 24 | matrix_mask(1,1) = 2.1; 25 | 26 | cout << "Displaying matrix(1,1)" << endl; 27 | std::cout << matrix_mask(1,1) << std::endl; 28 | 29 | BOOST_UBLAS_DEBUG_TRACE( "Displaying matrix(1,1)" << matrix_mask(1,1) ); 30 | BOOST_UBLAS_TEST_CHECK( matrix_mask(1,1) == 2.1 ); 31 | 32 | BOOST_UBLAS_TEST_CHECK( matrix_mask.index1_data()[0] == 1 ); 33 | BOOST_UBLAS_TEST_CHECK( matrix_mask.index2_data()[0] == 1 ); 34 | BOOST_UBLAS_TEST_CHECK( matrix_mask.value_data()[0] == 2.1 ); 35 | 36 | BOOST_UBLAS_DEBUG_TRACE( "Setting matrix(0,1) = 1.1" ); 37 | matrix_mask(0, 1) = 1.1; 38 | 39 | BOOST_UBLAS_TEST_CHECK( matrix_mask.index1_data()[0] == 1 ); 40 | BOOST_UBLAS_TEST_CHECK( matrix_mask.index2_data()[0] == 1 ); 41 | BOOST_UBLAS_TEST_CHECK( matrix_mask.value_data()[0] == 2.1 ); 42 | 43 | BOOST_UBLAS_TEST_CHECK( matrix_mask.index1_data()[1] == 0 ); 44 | BOOST_UBLAS_TEST_CHECK( matrix_mask.index2_data()[1] == 1 ); 45 | BOOST_UBLAS_TEST_CHECK( matrix_mask.value_data()[1] == 1.1 ); 46 | 47 | BOOST_UBLAS_DEBUG_TRACE( "Sort the matrix - this would be triggered by any element lookup." ); 48 | matrix_mask.sort(); 49 | 50 | BOOST_UBLAS_TEST_CHECK( matrix_mask.index1_data()[1] == 1 ); 51 | BOOST_UBLAS_TEST_CHECK( matrix_mask.index2_data()[1] == 1 ); 52 | BOOST_UBLAS_TEST_CHECK( matrix_mask.value_data()[1] == 2.1 ); 53 | 54 | BOOST_UBLAS_TEST_CHECK( matrix_mask.index1_data()[0] == 0 ); 55 | BOOST_UBLAS_TEST_CHECK( matrix_mask.index2_data()[0] == 1 ); 56 | BOOST_UBLAS_TEST_CHECK( matrix_mask.value_data()[0] == 1.1 ); 57 | 58 | BOOST_UBLAS_DEBUG_TRACE( "Displaying matrix(1,1)" << matrix_mask(1,1) ); 59 | BOOST_UBLAS_TEST_CHECK( matrix_mask(1,1) == 2.1 ); 60 | 61 | BOOST_UBLAS_DEBUG_TRACE( "Displaying matrix(0,1)" << matrix_mask(0,1) ); 62 | BOOST_UBLAS_TEST_CHECK( matrix_mask(0,1) == 1.1 ); 63 | 64 | } 65 | 66 | int main() 67 | { 68 | BOOST_UBLAS_TEST_BEGIN(); 69 | 70 | BOOST_UBLAS_TEST_DO( test_coordinate_matrix_sort ); 71 | 72 | BOOST_UBLAS_TEST_END(); 73 | } 74 | -------------------------------------------------------------------------------- /test/test_lu.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Gunter Winkler 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | // switch automatic singular check off 7 | #define BOOST_UBLAS_TYPE_CHECK 0 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "common/testhelper.hpp" 14 | 15 | #include 16 | #include 17 | 18 | using namespace boost::numeric::ublas; 19 | using std::string; 20 | 21 | static const string matrix_IN = "[3,3]((1,2,2),(2,3,3),(3,4,6))\0"; 22 | static const string matrix_LU = "[3,3]((3,4,6),(3.33333343e-01,6.66666627e-01,0),(6.66666687e-01,4.99999911e-01,-1))\0"; 23 | static const string matrix_INV= "[3,3]((-3,2,-7.94728621e-08),(1.50000012,0,-5.00000060e-01),(4.99999911e-01,-1,5.00000060e-01))\0"; 24 | static const string matrix_PM = "[3](2,2,2)"; 25 | 26 | int main () { 27 | 28 | typedef float TYPE; 29 | 30 | typedef matrix MATRIX; 31 | 32 | MATRIX A; 33 | MATRIX LU; 34 | MATRIX INV; 35 | 36 | { 37 | std::istringstream is(matrix_IN); 38 | is >> A; 39 | } 40 | { 41 | std::istringstream is(matrix_LU); 42 | is >> LU; 43 | } 44 | { 45 | std::istringstream is(matrix_INV); 46 | is >> INV; 47 | } 48 | permutation_matrix<>::vector_type temp; 49 | { 50 | std::istringstream is(matrix_PM); 51 | is >> temp; 52 | } 53 | permutation_matrix<> PM(temp); 54 | 55 | permutation_matrix<> pm(3); 56 | 57 | std::size_t result = lu_factorize >(A, pm); 58 | 59 | assertTrue("factorization completed: ", 0 == result); 60 | assertTrue("LU factors are correct: ", compare(A, LU)); 61 | assertTrue("permutation is correct: ", compare(pm, PM)); 62 | 63 | MATRIX B = identity_matrix(A.size2()); 64 | 65 | lu_substitute(A, pm, B); 66 | 67 | assertTrue("inverse is correct: ", compare(B, INV)); 68 | 69 | return (getResults().second > 0) ? boost::exit_failure : boost::exit_success; 70 | } 71 | -------------------------------------------------------------------------------- /test/test_scaled_norm.cpp: -------------------------------------------------------------------------------- 1 | // Distributed under the Boost Software License, Version 1.0. (See 2 | // accompanying file LICENSE_1_0.txt or copy at 3 | // http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | #include 7 | 8 | #include "utils.hpp" 9 | 10 | using namespace boost::numeric::ublas; 11 | 12 | static const double TOL(1.0e-5); ///< Used for comparing two real numbers. 13 | 14 | BOOST_UBLAS_TEST_DEF ( test_double_scaled_norm_2 ) { 15 | vector v(2); 16 | v[0] = 0; v[1] = 1.0e155; 17 | 18 | const double expected = 1.0e155; 19 | 20 | BOOST_UBLAS_DEBUG_TRACE( "norm is " << norm_2(v) ); 21 | BOOST_UBLAS_TEST_CHECK(std::abs(norm_2(v) - expected) < TOL); 22 | } 23 | 24 | BOOST_UBLAS_TEST_DEF ( test_float_scaled_norm_2 ) { 25 | vector v(2); 26 | v[0] = 0; v[1] = 1.0e20; 27 | 28 | const float expected = 1.0e20; 29 | 30 | BOOST_UBLAS_DEBUG_TRACE( "norm is " << norm_2(v) ); 31 | BOOST_UBLAS_TEST_CHECK(std::abs(norm_2(v) - expected) < TOL); 32 | } 33 | 34 | int main() { 35 | BOOST_UBLAS_TEST_BEGIN(); 36 | 37 | BOOST_UBLAS_TEST_DO( test_double_scaled_norm_2 ); 38 | BOOST_UBLAS_TEST_DO( test_float_scaled_norm_2 ); 39 | 40 | BOOST_UBLAS_TEST_END(); 41 | } 42 | --------------------------------------------------------------------------------