├── .gitattributes ├── .travis.yml ├── CMakeLists.txt ├── appveyor.yml ├── doc ├── build.jam ├── index.html ├── iterator_categories.html ├── matrix.gif ├── notes.html ├── reference.html ├── test_cases.html ├── user.html └── xml │ ├── Jamfile.v2 │ ├── MultiArray.xml │ ├── bbref.xml │ ├── const_multi_array_ref.xml │ ├── multi_array.xml │ ├── multi_array_ref.xml │ └── reference.xml ├── example ├── basic1.cpp ├── basic2.cpp ├── for_each.hpp ├── foreach_test.cpp ├── foreach_test2.cpp ├── op_paren.cpp ├── print_array.cpp ├── resize_from_other.cpp ├── subview.cpp └── subview2.cpp ├── include └── boost │ ├── multi_array.hpp │ └── multi_array │ ├── algorithm.hpp │ ├── base.hpp │ ├── collection_concept.hpp │ ├── concept_checks.hpp │ ├── copy_array.hpp │ ├── extent_gen.hpp │ ├── extent_range.hpp │ ├── index_gen.hpp │ ├── index_range.hpp │ ├── iterator.hpp │ ├── multi_array_ref.hpp │ ├── range_list.hpp │ ├── storage_order.hpp │ ├── subarray.hpp │ ├── types.hpp │ └── view.hpp ├── index.html ├── meta └── libraries.json └── test ├── Jamfile.v2 ├── access.cpp ├── allocators.cpp ├── assert.cpp ├── assign.cpp ├── assign_to_array.cpp ├── compare.cpp ├── concept_checks.cpp ├── constructors.cpp ├── dimtest.cpp ├── fail_cbracket.cpp ├── fail_cdata.cpp ├── fail_citerator.cpp ├── fail_cparen.cpp ├── fail_criterator.cpp ├── fail_csubarray.cpp ├── fail_csubarray2.cpp ├── fail_csubarray3.cpp ├── fail_cview.cpp ├── fail_cview2.cpp ├── fail_cview3.cpp ├── fail_ref_cbracket.cpp ├── fail_ref_cdata.cpp ├── fail_ref_citerator.cpp ├── fail_ref_cparen.cpp ├── fail_ref_criterator.cpp ├── fail_ref_csubarray.cpp ├── fail_ref_csubarray2.cpp ├── fail_ref_csubarray3.cpp ├── fail_ref_cview.cpp ├── fail_ref_cview2.cpp ├── fail_ref_cview3.cpp ├── generative_tests.hpp ├── idxgen1.cpp ├── index_bases.cpp ├── iterators.cpp ├── range1.cpp ├── regression.cfg ├── reshape.cpp ├── resize.cpp ├── reverse_view.cpp ├── slice.cpp ├── stl_interaction.cpp ├── storage_order.cpp ├── storage_order_convert.cpp └── vc_death.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto !eol svneol=native#text/plain 2 | *.gitattributes text svneol=native#text/plain 3 | 4 | # Scriptish formats 5 | *.bat text svneol=native#text/plain 6 | *.bsh text svneol=native#text/x-beanshell 7 | *.cgi text svneol=native#text/plain 8 | *.cmd text svneol=native#text/plain 9 | *.js text svneol=native#text/javascript 10 | *.php text svneol=native#text/x-php 11 | *.pl text svneol=native#text/x-perl 12 | *.pm text svneol=native#text/x-perl 13 | *.py text svneol=native#text/x-python 14 | *.sh eol=lf svneol=LF#text/x-sh 15 | configure eol=lf svneol=LF#text/x-sh 16 | 17 | # Image formats 18 | *.bmp binary svneol=unset#image/bmp 19 | *.gif binary svneol=unset#image/gif 20 | *.ico binary svneol=unset#image/ico 21 | *.jpeg binary svneol=unset#image/jpeg 22 | *.jpg binary svneol=unset#image/jpeg 23 | *.png binary svneol=unset#image/png 24 | *.tif binary svneol=unset#image/tiff 25 | *.tiff binary svneol=unset#image/tiff 26 | *.svg text svneol=native#image/svg%2Bxml 27 | 28 | # Data formats 29 | *.pdf binary svneol=unset#application/pdf 30 | *.avi binary svneol=unset#video/avi 31 | *.doc binary svneol=unset#application/msword 32 | *.dsp text svneol=crlf#text/plain 33 | *.dsw text svneol=crlf#text/plain 34 | *.eps binary svneol=unset#application/postscript 35 | *.gz binary svneol=unset#application/gzip 36 | *.mov binary svneol=unset#video/quicktime 37 | *.mp3 binary svneol=unset#audio/mpeg 38 | *.ppt binary svneol=unset#application/vnd.ms-powerpoint 39 | *.ps binary svneol=unset#application/postscript 40 | *.psd binary svneol=unset#application/photoshop 41 | *.rdf binary svneol=unset#text/rdf 42 | *.rss text svneol=unset#text/xml 43 | *.rtf binary svneol=unset#text/rtf 44 | *.sln text svneol=native#text/plain 45 | *.swf binary svneol=unset#application/x-shockwave-flash 46 | *.tgz binary svneol=unset#application/gzip 47 | *.vcproj text svneol=native#text/xml 48 | *.vcxproj text svneol=native#text/xml 49 | *.vsprops text svneol=native#text/xml 50 | *.wav binary svneol=unset#audio/wav 51 | *.xls binary svneol=unset#application/vnd.ms-excel 52 | *.zip binary svneol=unset#application/zip 53 | 54 | # Text formats 55 | .htaccess text svneol=native#text/plain 56 | *.bbk text svneol=native#text/xml 57 | *.cmake text svneol=native#text/plain 58 | *.css text svneol=native#text/css 59 | *.dtd text svneol=native#text/xml 60 | *.htm text svneol=native#text/html 61 | *.html text svneol=native#text/html 62 | *.ini text svneol=native#text/plain 63 | *.log text svneol=native#text/plain 64 | *.mak text svneol=native#text/plain 65 | *.qbk text svneol=native#text/plain 66 | *.rst text svneol=native#text/plain 67 | *.sql text svneol=native#text/x-sql 68 | *.txt text svneol=native#text/plain 69 | *.xhtml text svneol=native#text/xhtml%2Bxml 70 | *.xml text svneol=native#text/xml 71 | *.xsd text svneol=native#text/xml 72 | *.xsl text svneol=native#text/xml 73 | *.xslt text svneol=native#text/xml 74 | *.xul text svneol=native#text/xul 75 | *.yml text svneol=native#text/plain 76 | boost-no-inspect text svneol=native#text/plain 77 | CHANGES text svneol=native#text/plain 78 | COPYING text svneol=native#text/plain 79 | INSTALL text svneol=native#text/plain 80 | Jamfile text svneol=native#text/plain 81 | Jamroot text svneol=native#text/plain 82 | Jamfile.v2 text svneol=native#text/plain 83 | Jamrules text svneol=native#text/plain 84 | Makefile* text svneol=native#text/plain 85 | README text svneol=native#text/plain 86 | TODO text svneol=native#text/plain 87 | 88 | # Code formats 89 | *.c text svneol=native#text/plain 90 | *.cpp text svneol=native#text/plain 91 | *.h text svneol=native#text/plain 92 | *.hpp text svneol=native#text/plain 93 | *.ipp text svneol=native#text/plain 94 | *.tpp text svneol=native#text/plain 95 | *.jam text svneol=native#text/plain 96 | *.java text svneol=native#text/plain 97 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | 4 | language: cpp 5 | 6 | sudo: false 7 | 8 | dist: trusty 9 | 10 | python: "2.7" 11 | 12 | branches: 13 | only: 14 | - master 15 | - develop 16 | 17 | env: 18 | matrix: 19 | - BOGUS_JOB=true 20 | 21 | matrix: 22 | 23 | exclude: 24 | - env: BOGUS_JOB=true 25 | 26 | include: 27 | - os: linux 28 | compiler: g++ 29 | env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11 30 | 31 | - os: linux 32 | compiler: g++-4.4 33 | env: TOOLSET=gcc COMPILER=g++-4.4 CXXSTD=98,0x 34 | addons: 35 | apt: 36 | packages: 37 | - g++-4.4 38 | sources: 39 | - ubuntu-toolchain-r-test 40 | 41 | - os: linux 42 | compiler: g++-4.6 43 | env: TOOLSET=gcc COMPILER=g++-4.6 CXXSTD=03,0x 44 | addons: 45 | apt: 46 | packages: 47 | - g++-4.6 48 | sources: 49 | - ubuntu-toolchain-r-test 50 | 51 | - os: linux 52 | compiler: g++-4.7 53 | env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=03,11 54 | addons: 55 | apt: 56 | packages: 57 | - g++-4.7 58 | sources: 59 | - ubuntu-toolchain-r-test 60 | 61 | - os: linux 62 | compiler: g++-4.8 63 | env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=03,11 64 | addons: 65 | apt: 66 | packages: 67 | - g++-4.8 68 | sources: 69 | - ubuntu-toolchain-r-test 70 | 71 | - os: linux 72 | compiler: g++-4.9 73 | env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=03,11 74 | addons: 75 | apt: 76 | packages: 77 | - g++-4.9 78 | sources: 79 | - ubuntu-toolchain-r-test 80 | 81 | - os: linux 82 | compiler: g++-5 83 | env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=03,11,14,1z 84 | addons: 85 | apt: 86 | packages: 87 | - g++-5 88 | sources: 89 | - ubuntu-toolchain-r-test 90 | 91 | - os: linux 92 | compiler: g++-6 93 | env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=03,11,14,1z 94 | addons: 95 | apt: 96 | packages: 97 | - g++-6 98 | sources: 99 | - ubuntu-toolchain-r-test 100 | 101 | - os: linux 102 | compiler: g++-7 103 | env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17 104 | addons: 105 | apt: 106 | packages: 107 | - g++-7 108 | sources: 109 | - ubuntu-toolchain-r-test 110 | 111 | - os: linux 112 | compiler: g++-8 113 | env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17,2a 114 | addons: 115 | apt: 116 | packages: 117 | - g++-8 118 | sources: 119 | - ubuntu-toolchain-r-test 120 | 121 | - os: linux 122 | compiler: g++-9 123 | env: TOOLSET=gcc COMPILER=g++-9 CXXSTD=03,11,14,17,2a 124 | addons: 125 | apt: 126 | packages: 127 | - g++-9 128 | sources: 129 | - ubuntu-toolchain-r-test 130 | 131 | - os: linux 132 | compiler: clang++ 133 | env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11 134 | 135 | - os: linux 136 | compiler: /usr/bin/clang++ 137 | env: TOOLSET=clang COMPILER=/usr/bin/clang++ CXXSTD=03,11 138 | addons: 139 | apt: 140 | packages: 141 | - clang-3.3 142 | 143 | - os: linux 144 | compiler: /usr/bin/clang++ 145 | env: TOOLSET=clang COMPILER=/usr/bin/clang++ CXXSTD=03,11 146 | addons: 147 | apt: 148 | packages: 149 | - clang-3.4 150 | 151 | - os: linux 152 | compiler: clang++-3.5 153 | env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=03,11,14,1z 154 | addons: 155 | apt: 156 | packages: 157 | - clang-3.5 158 | - libstdc++-4.9-dev 159 | sources: 160 | - ubuntu-toolchain-r-test 161 | - llvm-toolchain-precise-3.5 162 | 163 | - os: linux 164 | compiler: clang++-3.6 165 | env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=03,11,14,1z 166 | addons: 167 | apt: 168 | packages: 169 | - clang-3.6 170 | sources: 171 | - ubuntu-toolchain-r-test 172 | - llvm-toolchain-precise-3.6 173 | 174 | - os: linux 175 | compiler: clang++-3.7 176 | env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=03,11,14,1z 177 | addons: 178 | apt: 179 | packages: 180 | - clang-3.7 181 | sources: 182 | - ubuntu-toolchain-r-test 183 | - llvm-toolchain-precise-3.7 184 | 185 | - os: linux 186 | compiler: clang++-3.8 187 | env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=03,11,14,1z 188 | addons: 189 | apt: 190 | packages: 191 | - clang-3.8 192 | - libstdc++-4.9-dev 193 | sources: 194 | - ubuntu-toolchain-r-test 195 | - llvm-toolchain-precise-3.8 196 | 197 | - os: linux 198 | compiler: clang++-3.9 199 | env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=03,11,14,1z 200 | addons: 201 | apt: 202 | packages: 203 | - clang-3.9 204 | - libstdc++-4.9-dev 205 | sources: 206 | - ubuntu-toolchain-r-test 207 | - llvm-toolchain-precise-3.9 208 | 209 | - os: linux 210 | compiler: clang++-4.0 211 | env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=03,11,14,1z 212 | addons: 213 | apt: 214 | packages: 215 | - clang-4.0 216 | sources: 217 | - ubuntu-toolchain-r-test 218 | - llvm-toolchain-trusty-4.0 219 | 220 | - os: linux 221 | compiler: clang++-5.0 222 | env: TOOLSET=clang COMPILER=clang++-5.0 CXXSTD=03,11,14,1z 223 | addons: 224 | apt: 225 | packages: 226 | - clang-5.0 227 | sources: 228 | - ubuntu-toolchain-r-test 229 | - llvm-toolchain-trusty-5.0 230 | 231 | - os: linux 232 | compiler: clang++-6.0 233 | env: TOOLSET=clang COMPILER=clang++-6.0 CXXSTD=03,11,14,17,2a 234 | addons: 235 | apt: 236 | packages: 237 | - clang-6.0 238 | sources: 239 | - ubuntu-toolchain-r-test 240 | - llvm-toolchain-trusty-6.0 241 | 242 | - os: linux 243 | compiler: clang++-7 244 | env: TOOLSET=clang COMPILER=clang++-7 CXXSTD=03,11,14,17,2a 245 | addons: 246 | apt: 247 | packages: 248 | - clang-7 249 | sources: 250 | - ubuntu-toolchain-r-test 251 | - llvm-toolchain-trusty-7 252 | 253 | - os: linux 254 | compiler: clang++-8 255 | env: TOOLSET=clang COMPILER=clang++-8 CXXSTD=03,11,14,17,2a 256 | addons: 257 | apt: 258 | packages: 259 | - clang-8 260 | sources: 261 | - ubuntu-toolchain-r-test 262 | - llvm-toolchain-trusty-8 263 | 264 | - os: linux 265 | compiler: clang++-libc++ 266 | env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03,11,14,1z 267 | addons: 268 | apt: 269 | packages: 270 | - libc++-dev 271 | 272 | - os: osx 273 | compiler: clang++ 274 | env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z 275 | 276 | install: 277 | - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true 278 | - cd .. 279 | - git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost 280 | - cd boost 281 | - git submodule update --init tools/build 282 | - git submodule update --init libs/config 283 | - git submodule update --init tools/boostdep 284 | - mkdir -p libs/multi_array 285 | - cp -r $TRAVIS_BUILD_DIR/* libs/multi_array 286 | - python tools/boostdep/depinst/depinst.py multi_array 287 | - ./bootstrap.sh 288 | - ./b2 headers 289 | 290 | script: 291 | - |- 292 | echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam 293 | - ./b2 -j 3 libs/multi_array/test toolset=$TOOLSET cxxstd=$CXXSTD 294 | 295 | notifications: 296 | email: 297 | on_success: always 298 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated by `boostdep --cmake multi_array` 2 | # Copyright 2020 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.5...3.16) 7 | 8 | project(boost_multi_array VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) 9 | 10 | add_library(boost_multi_array INTERFACE) 11 | add_library(Boost::multi_array ALIAS boost_multi_array) 12 | 13 | target_include_directories(boost_multi_array INTERFACE include) 14 | 15 | target_link_libraries(boost_multi_array 16 | INTERFACE 17 | Boost::array 18 | Boost::assert 19 | Boost::concept_check 20 | Boost::config 21 | Boost::core 22 | Boost::functional 23 | Boost::iterator 24 | Boost::mpl 25 | Boost::static_assert 26 | Boost::type_traits 27 | ) 28 | 29 | if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") 30 | 31 | add_subdirectory(test) 32 | 33 | endif() 34 | 35 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | 4 | version: 1.0.{build}-{branch} 5 | 6 | shallow_clone: true 7 | 8 | branches: 9 | only: 10 | - master 11 | - develop 12 | 13 | environment: 14 | matrix: 15 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 16 | TOOLSET: msvc-9.0 17 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 18 | TOOLSET: msvc-10.0 19 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 20 | TOOLSET: msvc-11.0 21 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 22 | TOOLSET: msvc-12.0 23 | ADDRMD: 32,64 24 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 25 | TOOLSET: msvc-14.0 26 | ADDRMD: 32,64 27 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 28 | TOOLSET: msvc-14.1 29 | ADDRMD: 32,64 30 | STANDARD: 14,17 31 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 32 | TOOLSET: clang-win 33 | ADDRMD: 32,64 34 | STANDARD: 14,17 35 | 36 | 37 | install: 38 | - set BOOST_BRANCH=develop 39 | - if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master 40 | - cd .. 41 | - git clone -b %BOOST_BRANCH% https://github.com/boostorg/boost.git boost 42 | - cd boost 43 | - git submodule update --init tools/build 44 | - git submodule update --init libs/config 45 | - git submodule update --init tools/boostdep 46 | - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\multi_array\ 47 | - python tools/boostdep/depinst/depinst.py multi_array 48 | - cmd /c bootstrap 49 | - b2 headers 50 | 51 | build: off 52 | 53 | test_script: 54 | - PATH=%ADDPATH%%PATH% 55 | - if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD% 56 | - b2 -j 3 libs/multi_array/test toolset=%TOOLSET% %CXXSTD% 57 | -------------------------------------------------------------------------------- /doc/build.jam: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Rene Rivera 2 | # 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # (See accompanying file LICENSE_1_0.txt or copy at 5 | # http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | ############################################################################### 8 | alias boostdoc 9 | : xml/bbref.xml 10 | : 11 | : 12 | : ; 13 | explicit boostdoc ; 14 | alias boostrelease ; 15 | explicit boostrelease ; 16 | -------------------------------------------------------------------------------- /doc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | MultiDimensional Array Libary 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
23 | boost logoHomeLibrariesPeopleFAQMore
32 |

Boost.MultiArray

33 |

Boost.MultiArray provides a generic N-dimensional array concept 34 | definition and common implementations of that interface. 35 |

36 | 37 | 43 |
44 |
45 | 46 | 47 |
Copyright © 2000-2001 48 | Ronald Garcia, 49 | Indiana University (garcia@osl.iu.edu)
51 | Jeremy Siek, 52 | Indiana University (jsiek@osl.iu.edu)
54 | Andrew Lumsdaine, 55 | Indiana University (lums@osl.iu.edu) 57 |
58 | 59 | -------------------------------------------------------------------------------- /doc/iterator_categories.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/multi_array/0c5348bef71b890c4bd06eff1ee5ebda69e7b27a/doc/iterator_categories.html -------------------------------------------------------------------------------- /doc/matrix.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/multi_array/0c5348bef71b890c4bd06eff1ee5ebda69e7b27a/doc/matrix.gif -------------------------------------------------------------------------------- /doc/notes.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 17 | 18 | Boost.MultiArray: Extra Notes 19 | 20 | 21 | 22 | 23 |

24 | boost logo 26 |
Boost.MultiArray: Extra Notes 27 |
28 |

29 | 30 | 31 | 32 |

Compiler Support

33 | 34 | Boost.MultiArray was designed with compiler support in mind. 35 | Interface compromises were kept to a minimum, but efforts were 36 | made to account for C++ Standard compliance issues in compilers 37 | that were popular at the time the library was written. That said, 38 | Boost.MultiArray has been tested with the following compilers: 39 |
    40 |
  1. Gnu C++ Compiler v2.95.2 (compile with -ftemplate-depth-50) 41 |
  2. Gnu C++ Compiler v3.0.2 42 |
  3. Kuck and Associates C++ Compiler v4.0f 43 |
  4. Microsoft Visual C++ v6.0 sp5 44 |
  5. Comeau C++ Compiler v4.2.45 beta 2 (libcomo beta 14) 45 |
  6. Intel C++ Compiler v5.0 (with MS lib v6.0 sp5) 46 |
  7. Metrowerks CodeWarrior C++ Compiler v7.1 47 |
48 | 49 | Boost.MultiArray is known to NOT work with Borland C++ v5.5.1. 50 | Support for this compiler is forthcoming. 51 | 52 | 53 |

Future Work

54 | 55 | The following is a list of work that is intended for the near future 56 | -- following the initial addition of the library to the Boost 57 | distribution: 58 |
    59 |
  1. Pursue and document performance issues related to compilers and 60 | implementation. 61 |
  2. More comprehensive examples of using the library components. 62 |
  3. Extensive rewrite of the user documentation to make it more accessible. 63 |
64 | 65 |
66 | 67 |
68 | Ronald Garcia 69 |
70 | 71 | 72 | Last modified: Wed Jan 8 18:09:46 EST 2003 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /doc/reference.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/multi_array/0c5348bef71b890c4bd06eff1ee5ebda69e7b27a/doc/reference.html -------------------------------------------------------------------------------- /doc/test_cases.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 17 | 18 | 19 | Boost.MultiArray: Test Descriptions 20 | 21 | 22 | 23 | C++ Boost 25 |

Boost.MultiArray: Test Descriptions

26 | 27 | The following is a description of the test cases that are included with 28 | Boost.Multi_Array (B.M). 29 | 30 |

Terminology

31 | The following list is to clarify the use of terms in the following 32 | descriptions: 33 | 46 | 47 |

Acceptance Tests

48 | 49 | The following tests exercise various features of Boost.Multi_Array to 50 | ensure proper operation at run time. 51 | 52 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 65 | 66 | 67 | 68 | 69 | 72 | 73 | 74 | 75 | 76 | 79 | 80 | 81 | 82 | 83 | 86 | 87 | 88 | 89 | 90 | 93 | 94 | 95 | 96 | 97 | 100 | 101 | 102 | 103 | 104 | 108 | 109 | 110 | 111 | 112 | 115 | 116 | 117 | 118 | 119 | 122 | 123 | 124 | 125 | 126 | 129 | 130 | 131 | 132 | 133 | 136 | 137 | 138 | 139 | 140 | 144 | 145 | 146 | 147 | 148 | 151 | 152 | 153 | 154 | 155 | 158 | 159 | 160 | 161 | 162 | 165 | 166 | 167 | 168 | 169 | 172 | 173 | 174 | 175 | 176 | 180 | 181 | 182 | 183 | 184 | 187 | 188 | 189 | 190 | 191 | 195 | 196 |
ProgramDescription
libs/multi_array/test/constructors.cpp 63 | Exercises all of the constructors for B.M primary components. 64 |
libs/multi_array/test/access.cpp 70 | Tests operator[] and operator() on all B.M array types. 71 |
libs/multi_array/test/compare.cpp 77 | Tests all comparison operators for the B.M primary components. 78 |
libs/multi_array/test/iterators.cpp 84 | Test all iterator traversal and access functionality for all B.M array types. 85 |
libs/multi_array/test/slice.cpp 91 | Test all variations of subview generation for all B.M array types. 92 |
libs/multi_array/test/assign.cpp 98 | Tests out operator=() on the various B.M array types. 99 |
libs/multi_array/test/assign_to_array.cpp 105 | Ensure that a multi_array can be constructed from any other 106 | array type. 107 |
libs/multi_array/test/index_bases.cpp 113 | Test re-indexing functionality for the B.M primary components. 114 |
libs/multi_array/test/storage_order_convert.cpp 120 | Test out conversions among the storage orders data types. 121 |
libs/multi_array/test/storage_order.cpp 127 | Test variations on storage_order for the B.M primary components. 128 |
libs/multi_array/test/reshape.cpp 134 | Test re-shaping functionality for the B.M primary components. 135 |
libs/multi_array/test/range1.cpp 141 | Test the various syntaxes for specifying index ranges using 142 | array::index_range. 143 |
libs/multi_array/test/idxgen1.cpp 149 | Test the array::index_gen objects. 150 |
libs/multi_array/test/stl_interaction.cpp 156 | Test interaction between array types and STL containers. 157 |
libs/multi_array/test/resize.cpp 163 | Test the multi_array class' resizing functionality. 164 |
libs/multi_array/test/concept_checks.cpp 170 | Ensure that all the array types meet the defined Concepts. 171 |
libs/multi_array/test/assert.cpp 177 | Ensure that uses of BOOST_ASSERT within the library can be customized 178 | by library users. 179 |
libs/multi_array/test/allocators.cpp 185 | Test support for custom allocators. 186 |
libs/multi_array/test/generative_tests.hpp 192 | A test harness used to simplify testing operations upon all array 193 | types. Used by slice.cpp, iterators.cpp, and access.cpp. 194 |
197 | 198 |

Compile-Fail Tests

199 | 200 | The following tests check to make sure that various constructs not 201 | accepted by the library fail to compile. Each test checks only 202 | one fault in order to more easily ensure the cause of the 203 | compilation failure. 204 |

205 | 206 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 217 | 220 | 221 | 222 | 223 | 225 | 228 | 229 | 230 | 231 | 233 | 236 | 237 | 238 | 239 | 241 | 244 | 245 | 246 | 247 | 249 | 253 | 254 | 255 | 256 | 258 | 261 | 262 | 263 | 264 | 266 | 269 | 270 | 271 | 272 | 274 | 277 | 278 | 279 | 280 | 282 | 285 | 286 | 287 | 288 | 290 | 294 | 295 | 296 | 297 | 299 | 302 | 303 | 304 |
ProgramDescription
libs/multi_array/test/fail_cbracket.cpp 216 |
libs/multi_array/test/fail_ref_cbracket.cpp
218 | operator[] on a const array must not modify elements. 219 |
libs/multi_array/test/fail_cdata.cpp 224 |
libs/multi_array/test/fail_ref_cdata.cpp
226 | array::data() const must return a pointer to const data. 227 |
libs/multi_array/test/fail_citerator.cpp 232 |
libs/multi_array/test/fail_ref_citerator.cpp
234 | const_iterator must not be convertible to iterator. 235 |
libs/multi_array/test/fail_cparen.cpp 240 |
libs/multi_array/test/fail_ref_cparen.cpp
242 | operator() on a const array must not modify elements. 243 |
libs/multi_array/test/fail_criterator.cpp 248 |
libs/multi_array/test/fail_ref_criterator.cpp
250 | const_reverse_iterator must not be convertible to 251 | reverse_iterator. 252 |
libs/multi_array/test/fail_csubarray.cpp 257 |
libs/multi_array/test/fail_ref_csubarray.cpp
259 | const_subarray must not be convertible to subarray. 260 |
libs/multi_array/test/fail_csubarray2.cpp 265 |
libs/multi_array/test/fail_ref_csubarray2.cpp
267 | array::operator[] const must not be convertible to subarray. 268 |
libs/multi_array/test/fail_csubarray3.cpp 273 |
libs/multi_array/test/fail_ref_csubarray3.cpp
275 | const_subarray into an array must not modify elements. 276 |
libs/multi_array/test/fail_cview.cpp 281 |
libs/multi_array/test/fail_ref_cview.cpp
283 | const_array_view of an array must not modify elements. 284 |
libs/multi_array/test/fail_cview2.cpp 289 |
libs/multi_array/test/fail_ref_cview2.cpp
291 | array::operator[] const must not be convertible to 292 | array_view. 293 |
libs/multi_array/test/fail_cview3.cpp 298 |
libs/multi_array/test/fail_ref_cview3.cpp
300 | const_array_view of an array must not modify elements. 301 |
305 | 306 |
307 | 308 | 309 | 310 | 319 | 320 |
Copyright © 2001Ronald Garcia, 311 | Indiana University (garcia@cs.indiana.edu)
313 | Jeremy Siek, Indiana 314 | University (jsiek@cs.indiana.edu)
316 | Andrew Lumsdaine, Indiana 317 | University (lums@cs.indiana.edu)
321 | 322 |


323 | 324 |
325 | Ronald Garcia 326 |
327 | 328 | Last modified: Wed Oct 31 19:46:44 EST 2001 329 | 330 | 331 | 332 | 333 | 334 | -------------------------------------------------------------------------------- /doc/xml/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2002 Douglas Gregor 2 | 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # (See accompanying file LICENSE_1_0.txt or copy at 5 | # http://www.boost.org/LICENSE_1_0.txt) 6 | project multi_array/doc ; 7 | import boostbook : boostbook ; 8 | 9 | path-constant here : . ; 10 | 11 | boostbook multi_array-doc 12 | : 13 | bbref.xml 14 | : 15 | boost.root=../../../../.. 16 | pdf:boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html 17 | pdf:img.src.path=$(here)/../ 18 | ; 19 | 20 | -------------------------------------------------------------------------------- /doc/xml/const_multi_array_ref.xml: -------------------------------------------------------------------------------- 1 | 2 | <literal>const_multi_array_ref</literal> 3 | 4 | 5 | const_multi_array_ref is a multi-dimensional container 6 | adaptor. It provides the MultiArray interface over any contiguous 7 | block of elements. const_multi_array_ref exports the 8 | same interface as multi_array, with the exception 9 | of the constructors. 10 | 11 | 12 | 13 | 14 | Model Of. 15 | 16 | const_multi_array_ref models 17 | MultiArray, 18 | CopyConstructible. 19 | and depending on the element type, it may also model 20 | EqualityComparable and LessThanComparable. 21 | 22 | Detailed descriptions are provided here only for operations that are 23 | not described in the multi_array reference. 24 | 25 | 26 | 27 | 28 | Synopsis 29 | 30 | 31 | 37 | class const_multi_array_ref { 38 | public: 39 | // types: 40 | typedef ValueType element; 41 | typedef *unspecified* value_type; 42 | typedef *unspecified* reference; 43 | typedef *unspecified* const_reference; 44 | typedef *unspecified* difference_type; 45 | typedef *unspecified* iterator; 46 | typedef *unspecified* const_iterator; 47 | typedef *unspecified* reverse_iterator; 48 | typedef *unspecified* const_reverse_iterator; 49 | typedef multi_array_types::size_type size_type; 50 | typedef multi_array_types::index index; 51 | typedef multi_array_types::index_gen index_gen; 52 | typedef multi_array_types::index_range index_range; 53 | typedef multi_array_types::extent_gen extent_gen; 54 | typedef multi_array_types::extent_range extent_range; 55 | typedef *unspecified* storage_order_type; 56 | 57 | // template typedefs 58 | template struct subarray; 59 | template struct const_subarray; 60 | template struct array_view; 61 | template struct const_array_view; 62 | 63 | 64 | // structors 65 | 66 | template 67 | explicit const_multi_array_ref(TPtr data, const ExtentList& sizes, 68 | const storage_order_type& store = c_storage_order()); 69 | explicit const_multi_array_ref(TPtr data, const extents_tuple& ranges, 70 | const storage_order_type& store = c_storage_order()); 71 | const_multi_array_ref(const const_multi_array_ref& x); 72 | ~const_multi_array_ref(); 73 | 74 | 75 | 76 | // iterators: 77 | const_iterator begin() const; 78 | const_iterator end() const; 79 | const_reverse_iterator rbegin() const; 80 | const_reverse_iterator rend() const; 81 | 82 | // capacity: 83 | size_type size() const; 84 | size_type num_elements() const; 85 | size_type num_dimensions() const; 86 | 87 | // element access: 88 | template 89 | const element& operator()(const IndexList& indices) const; 90 | const_reference operator[](index i) const; 91 | const_array_view::type operator[](const indices_tuple& r) const; 92 | 93 | // queries 94 | const element* data() const; 95 | const element* origin() const; 96 | const size_type* shape() const; 97 | const index* strides() const; 98 | const index* index_bases() const; 99 | const storage_order_type& storage_order() const; 100 | 101 | // comparators 102 | bool operator==(const const_multi_array_ref& rhs); 103 | bool operator!=(const const_multi_array_ref& rhs); 104 | bool operator<(const const_multi_array_ref& rhs); 105 | bool operator>(const const_multi_array_ref& rhs); 106 | bool operator>=(const const_multi_array_ref& rhs); 107 | bool operator<=(const const_multi_array_ref& rhs); 108 | 109 | // modifiers: 110 | template 111 | void reshape(const SizeList& sizes) 112 | template void reindex(const BaseList& values); 113 | void reindex(index value); 114 | }; 115 | ]]> 116 | 117 | 118 | 119 | 120 | Constructors 121 | 122 | 123 | 124 | template <typename ExtentList> 125 | explicit const_multi_array_ref(TPtr data, 126 | const ExtentList& sizes, 127 | const storage_order& store = c_storage_order()); 128 | 129 | 130 | 131 | 132 | This constructs a const_multi_array_ref using the specified 133 | parameters. sizes specifies the shape of the 134 | constructed const_multi_array_ref. store 135 | specifies the storage order or layout in memory of the array 136 | dimensions. 137 | 138 | 139 | <literal>ExtentList</literal> Requirements 140 | 141 | ExtentList must model Collection. 142 | 143 | 144 | 145 | Preconditions 146 | sizes.size() == NumDims; 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | ::type ranges, 156 | const storage_order& store = c_storage_order());]]> 157 | 158 | 159 | Effects 160 | 161 | This constructs a const_multi_array_ref using the specified 162 | parameters. ranges specifies the shape and 163 | index bases of the constructed const_multi_array_ref. It is the result of 164 | NumDims chained calls to 165 | extent_gen::operator[]. store 166 | specifies the storage order or layout in memory of the array 167 | dimensions. 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | Effects 181 | This constructs a shallow copy of x. 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /doc/xml/multi_array_ref.xml: -------------------------------------------------------------------------------- 1 | 2 | <literal>multi_array_ref</literal> 3 | 4 | 5 | multi_array_ref is a multi-dimensional container 6 | adaptor. It provides the MultiArray interface over any contiguous 7 | block of elements. multi_array_ref exports the 8 | same interface as multi_array, with the exception 9 | of the constructors. 10 | 11 | 12 | 13 | 14 | Model Of. 15 | 16 | multi_array_ref models 17 | MultiArray, 18 | CopyConstructible. 19 | and depending on the element type, it may also model 20 | EqualityComparable and LessThanComparable. 21 | Detailed descriptions are provided here only for operations that are 22 | not described in the multi_array reference. 23 | 24 | 25 | 26 | 27 | Synopsis 28 | 29 | 30 | 35 | class multi_array_ref { 36 | public: 37 | // types: 38 | typedef ValueType element; 39 | typedef *unspecified* value_type; 40 | typedef *unspecified* reference; 41 | typedef *unspecified* const_reference; 42 | typedef *unspecified* difference_type; 43 | typedef *unspecified* iterator; 44 | typedef *unspecified* const_iterator; 45 | typedef *unspecified* reverse_iterator; 46 | typedef *unspecified* const_reverse_iterator; 47 | typedef multi_array_types::size_type size_type; 48 | typedef multi_array_types::index index; 49 | typedef multi_array_types::index_gen index_gen; 50 | typedef multi_array_types::index_range index_range; 51 | typedef multi_array_types::extent_gen extent_gen; 52 | typedef multi_array_types::extent_range extent_range; 53 | typedef *unspecified* storage_order_type; 54 | 55 | // template typedefs 56 | template struct subarray; 57 | template struct const_subarray; 58 | template struct array_view; 59 | template struct const_array_view; 60 | 61 | 62 | static const std::size_t dimensionality = NumDims; 63 | 64 | 65 | // constructors and destructors 66 | 67 | template 68 | explicit multi_array_ref(element* data, const ExtentList& sizes, 69 | const storage_order_type& store = c_storage_order()); 70 | explicit multi_array_ref(element* data, const extents_tuple& ranges, 71 | const storage_order_type& store = c_storage_order()); 72 | multi_array_ref(const multi_array_ref& x); 73 | ~multi_array_ref(); 74 | 75 | // modifiers 76 | 77 | multi_array_ref& operator=(const multi_array_ref& x); 78 | template multi_array_ref& operator=(const Array& x); 79 | 80 | // iterators: 81 | iterator begin(); 82 | iterator end(); 83 | const_iterator begin() const; 84 | const_iterator end() const; 85 | reverse_iterator rbegin(); 86 | reverse_iterator rend(); 87 | const_reverse_iterator rbegin() const; 88 | const_reverse_iterator rend() const; 89 | 90 | // capacity: 91 | size_type size() const; 92 | size_type num_elements() const; 93 | size_type num_dimensions() const; 94 | 95 | // element access: 96 | template 97 | element& operator()(const IndexList& indices); 98 | template 99 | const element& operator()(const IndexList& indices) const; 100 | reference operator[](index i); 101 | const_reference operator[](index i) const; 102 | array_view::type operator[](const indices_tuple& r); 103 | const_array_view::type operator[](const indices_tuple& r) const; 104 | 105 | // queries 106 | element* data(); 107 | const element* data() const; 108 | element* origin(); 109 | const element* origin() const; 110 | const size_type* shape() const; 111 | const index* strides() const; 112 | const index* index_bases() const; 113 | const storage_order_type& storage_order() const; 114 | 115 | // comparators 116 | bool operator==(const multi_array_ref& rhs); 117 | bool operator!=(const multi_array_ref& rhs); 118 | bool operator<(const multi_array_ref& rhs); 119 | bool operator>(const multi_array_ref& rhs); 120 | bool operator>=(const multi_array_ref& rhs); 121 | bool operator<=(const multi_array_ref& rhs); 122 | 123 | // modifiers: 124 | template 125 | void assign(InputIterator begin, InputIterator end); 126 | template 127 | void reshape(const SizeList& sizes) 128 | template void reindex(const BaseList& values); 129 | void reindex(index value); 130 | }; 131 | ]]> 132 | 133 | 134 | 135 | 136 | Constructors 137 | 138 | 139 | 140 | template <typename ExtentList> 141 | explicit multi_array_ref(element* data, 142 | const ExtentList& sizes, 143 | const storage_order& store = c_storage_order(), 144 | const Allocator& alloc = Allocator()); 145 | 146 | 147 | 148 | 149 | This constructs a multi_array_ref using the specified 150 | parameters. sizes specifies the shape of the 151 | constructed multi_array_ref. store 152 | specifies the storage order or layout in memory of the array 153 | dimensions. alloc is used to 154 | allocate the contained elements. 155 | 156 | 157 | <literal>ExtentList</literal> Requirements 158 | 159 | ExtentList must model Collection. 160 | 161 | 162 | 163 | Preconditions 164 | sizes.size() == NumDims; 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | ::type ranges, 174 | const storage_order& store = c_storage_order());]]> 175 | 176 | 177 | 178 | This constructs a multi_array_ref using the specified 179 | parameters. ranges specifies the shape and 180 | index bases of the constructed multi_array_ref. It is the result of 181 | NumDims chained calls to 182 | extent_gen::operator[]. store 183 | specifies the storage order or layout in memory of the array 184 | dimensions. 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | This constructs a shallow copy of x. 196 | 197 | 198 | 199 | Complexity 200 | Constant time (for contrast, compare this to 201 | the multi_array class copy constructor. 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | Modifiers 213 | 214 | 215 | 216 | 217 | 218 | multi_array_ref& operator=(const Array& x);]]> 220 | 221 | 222 | 223 | 224 | This performs an element-wise copy of x 225 | into the current multi_array_ref. 226 | 227 | 228 | <literal>Array</literal> Requirements 229 | Array must model MultiArray. 230 | 231 | 232 | 233 | Preconditions 234 | 235 | std::equal(this->shape(),this->shape()+this->num_dimensions(), 236 | x.shape()); 237 | 238 | 239 | 240 | 241 | Postconditions 242 | 243 | (*.this) == x; 244 | 245 | 246 | 247 | 248 | Complexity 249 | The assignment operators perform 250 | O(x.num_elements()) calls to element's 251 | copy constructor. 252 | 253 | 254 | 255 | 256 | 257 | 258 | -------------------------------------------------------------------------------- /example/basic1.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #include 14 | #include "boost/multi_array.hpp" 15 | #include "boost/cstdlib.hpp" 16 | 17 | int main () { 18 | // Create a 3D array that is 3 x 4 x 2 19 | typedef boost::multi_array array; 20 | array A(boost::extents[3][4][2]); 21 | // Assign a value to an element in the array 22 | A[0][0][0] = 3.14; 23 | assert(A[0][0][0] == 3.14); 24 | return boost::exit_success; 25 | } 26 | -------------------------------------------------------------------------------- /example/basic2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | 14 | #include 15 | #include "boost/multi_array.hpp" 16 | #include "boost/array.hpp" 17 | #include "boost/cstdlib.hpp" 18 | 19 | int main () { 20 | // Create a 3D array that is 3 x 4 x 2 21 | boost::array shape = {{ 3, 4, 2 }}; 22 | boost::multi_array A(shape); 23 | // Assign a value to an element in the array 24 | A[0][0][0] = 3.14; 25 | assert(A[0][0][0] == 3.14); 26 | return boost::exit_success; 27 | } 28 | -------------------------------------------------------------------------------- /example/for_each.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef FOR_EACH_HPP 14 | #define FOR_EACH_HPP 15 | 16 | // 17 | // for_each.hpp - Writing an algorithm to transform each element of 18 | // a multi_array 19 | // 20 | 21 | #include "boost/type.hpp" 22 | 23 | template 24 | void for_each (const boost::type& type_dispatch, 25 | Array A, Functor& xform) { 26 | for_each(type_dispatch,A.begin(),A.end(),xform); 27 | } 28 | 29 | template 30 | void for_each (const boost::type&,Element& Val, Functor& xform) { 31 | Val = xform(Val); 32 | } 33 | 34 | template 35 | void for_each (const boost::type& type_dispatch, 36 | Iterator begin, Iterator end, 37 | Functor& xform) { 38 | while (begin != end) { 39 | for_each(type_dispatch,*begin,xform); 40 | ++begin; 41 | } 42 | } 43 | 44 | 45 | template 46 | void for_each (Array& A, Functor xform) { 47 | // Dispatch to the proper function 48 | for_each(boost::type(),A.begin(),A.end(),xform); 49 | } 50 | 51 | 52 | #endif // FOR_EACH_HPP 53 | -------------------------------------------------------------------------------- /example/foreach_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // foreach_test.cpp 14 | // Let's see if this stuff works 15 | 16 | #include "boost/multi_array.hpp" 17 | #include "for_each.hpp" 18 | #include 19 | 20 | struct times_five { 21 | double operator()(const int& val) { return val*5.0; } 22 | }; 23 | 24 | 25 | int main() { 26 | 27 | typedef boost::multi_array array; 28 | 29 | double data[] = { 30 | 1.0, 2.0, 3.0, 31 | 4.0, 5.0, 6.0, 32 | 7.0, 8.0, 9.0 33 | }; 34 | const int data_size=9; 35 | 36 | array A(boost::extents[3][3]); 37 | A.assign(data,data+data_size); 38 | 39 | #if 0 40 | std::copy(A.data(),A.data()+A.num_elements(), 41 | std::ostream_iterator(std::cout,",")); 42 | 43 | std::cout << "\n"; 44 | #endif 45 | for_each(A,times_five()); 46 | 47 | #if 0 48 | std::copy(A.data(),A.data()+A.num_elements(), 49 | std::ostream_iterator(std::cout,",")); 50 | 51 | std::cout << "\n"; 52 | #endif 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /example/foreach_test2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #include "boost/multi_array.hpp" 14 | #include "for_each.hpp" 15 | #include 16 | 17 | struct times_five { 18 | double operator()(const int& val) { return val*5.0; } 19 | }; 20 | 21 | 22 | int main() { 23 | 24 | typedef boost::multi_array array; 25 | 26 | double data[] = { 27 | 1.0, 2.0, 3.0, 28 | 4.0, 5.0, 6.0, 29 | 7.0, 8.0, 9.0 30 | }; 31 | const int data_size=9; 32 | 33 | array A(boost::extents[9]); 34 | A.assign(data,data+data_size); 35 | 36 | #if 0 37 | std::copy(A.begin(),A.end(), 38 | std::ostream_iterator(std::cout,",")); 39 | 40 | std::cout << "\n"; 41 | #endif 42 | 43 | for_each(A,times_five()); 44 | 45 | #if 0 46 | std::copy(A.begin(),A.end(), 47 | std::ostream_iterator(std::cout,",")); 48 | 49 | std::cout << "\n"; 50 | #endif 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /example/op_paren.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | 14 | #include 15 | #include "boost/multi_array.hpp" 16 | #include "boost/array.hpp" 17 | #include "boost/cstdlib.hpp" 18 | 19 | int main () { 20 | // Create a 3D array that is 3 x 4 x 2 21 | boost::array shape = {{ 3, 4, 2 }}; 22 | boost::multi_array A(shape); 23 | typedef boost::multi_array::index index; 24 | // Assign a value to an element in the array 25 | boost::array idx = {{ 0, 0, 0 }}; 26 | A(idx) = 3.14; 27 | assert(A(idx) == 3.14); 28 | return boost::exit_success; 29 | } 30 | -------------------------------------------------------------------------------- /example/print_array.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | 14 | #include 15 | #include "boost/multi_array.hpp" 16 | #include "boost/array.hpp" 17 | #include "boost/cstdlib.hpp" 18 | 19 | template 20 | void print(std::ostream& os, const Array& A) 21 | { 22 | typename Array::const_iterator i; 23 | os << "["; 24 | for (i = A.begin(); i != A.end(); ++i) { 25 | print(os, *i); 26 | if (boost::next(i) != A.end()) 27 | os << ','; 28 | } 29 | os << "]"; 30 | } 31 | void print(std::ostream& os, const double& x) 32 | { 33 | os << x; 34 | } 35 | int main() 36 | { 37 | typedef boost::multi_array array; 38 | double values[] = { 39 | 0, 1, 2, 40 | 3, 4, 5 41 | }; 42 | const int values_size=6; 43 | array A(boost::extents[2][3]); 44 | A.assign(values,values+values_size); 45 | print(std::cout, A); 46 | return boost::exit_success; 47 | } 48 | 49 | // The output is: 50 | // [[0,1,2],[3,4,5]] 51 | -------------------------------------------------------------------------------- /example/resize_from_other.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2008 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // resize_from_other.cpp - an experiment in writing a resize function for 15 | // multi_arrays that will use the extents from another to build itself. 16 | // 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | template 24 | void 25 | resize_from_MultiArray(boost::multi_array& marray, U& other) { 26 | 27 | // U must be a model of MultiArray 28 | boost::function_requires< 29 | boost::multi_array_concepts::ConstMultiArrayConcept >(); 30 | // U better have U::dimensionality == N 31 | BOOST_STATIC_ASSERT(U::dimensionality == N); 32 | 33 | boost::array::size_type, N> shape; 34 | 35 | std::copy(other.shape(), other.shape()+N, shape.begin()); 36 | 37 | marray.resize(shape); 38 | 39 | } 40 | 41 | #include 42 | 43 | 44 | int main () { 45 | 46 | boost::multi_array A(boost::extents[5][4]), B; 47 | boost::multi_array C; 48 | 49 | resize_from_MultiArray(B,A); 50 | 51 | #if 0 52 | resize_from_MultiArray(C,A); // Compile-time error 53 | #endif 54 | 55 | std::cout << B.shape()[0] << ", " << B.shape()[1] << '\n'; 56 | 57 | } 58 | -------------------------------------------------------------------------------- /example/subview.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | 14 | #include "boost/multi_array.hpp" 15 | #include "boost/cstdlib.hpp" 16 | 17 | int 18 | main() 19 | { 20 | const int ndims=3; 21 | typedef boost::multi_array array; 22 | 23 | int data[] = { 24 | 0,1,2,3, 25 | 4,5,6,7, 26 | 8,9,10,11, 27 | 28 | 12,13,14,15, 29 | 16,17,18,19, 30 | 20,21,22,23 31 | }; 32 | const int data_size=24; 33 | 34 | array myarray(boost::extents[2][3][4]); 35 | myarray.assign(data,data+data_size); 36 | 37 | // 38 | // array_view dims: 39 | // [base,stride,bound) 40 | // [0,1,2), [1,1,3), [0,2,4) 41 | // 42 | 43 | typedef array::index_range range; 44 | array::array_view::type myview = 45 | myarray[boost::indices[range(0,2)][range(1,3)][range(0,4,2)]]; 46 | 47 | for (array::index i = 0; i != 2; ++i) 48 | for (array::index j = 0; j != 2; ++j) 49 | for (array::index k = 0; k != 2; ++k) 50 | assert(myview[i][j][k] == myarray[i][j+1][k*2]); 51 | 52 | return boost::exit_success; 53 | } 54 | -------------------------------------------------------------------------------- /example/subview2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | 14 | #include "boost/multi_array.hpp" 15 | #include "boost/cstdlib.hpp" 16 | 17 | int 18 | main() 19 | { 20 | using boost::extents; 21 | using boost::indices; 22 | typedef boost::multi_array array; 23 | 24 | int data[] = { 25 | 0,1,2,3, 26 | 4,5,6,7, 27 | 8,9,10,11, 28 | 29 | 12,13,14,15, 30 | 16,17,18,19, 31 | 20,21,22,23 32 | }; 33 | const int data_size=24; 34 | 35 | array myarray(extents[2][3][4]); 36 | myarray.assign(data,data+data_size); 37 | 38 | // 39 | // array_view dims: 40 | // [base,stride,bound) 41 | // [0,1,2), [1,1,3), [0,2,4) 42 | // 43 | 44 | typedef boost::multi_array_types::index_range range; 45 | array::array_view<3>::type myview = 46 | myarray[indices[range(0,2)][range(1,3)][range(0,4,2)]]; 47 | 48 | for (array::index i = 0; i != 2; ++i) 49 | for (array::index j = 0; j != 2; ++j) 50 | for (array::index k = 0; k != 2; ++k) 51 | assert(myview[i][j][k] == myarray[i][j+1][k*2]); 52 | 53 | return boost::exit_success; 54 | } 55 | -------------------------------------------------------------------------------- /include/boost/multi_array/algorithm.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_MULTI_ARRAY_ALGORITHM_HPP 2 | #define BOOST_MULTI_ARRAY_ALGORITHM_HPP 3 | 4 | // 5 | // 6 | // Copyright (c) 1994 7 | // Hewlett-Packard Company 8 | // 9 | // Permission to use, copy, modify, distribute and sell this software 10 | // and its documentation for any purpose is hereby granted without fee, 11 | // provided that the above copyright notice appear in all copies and 12 | // that both that copyright notice and this permission notice appear 13 | // in supporting documentation. Hewlett-Packard Company makes no 14 | // representations about the suitability of this software for any 15 | // purpose. It is provided "as is" without express or implied warranty. 16 | // 17 | // 18 | // Copyright (c) 1996-1998 19 | // Silicon Graphics Computer Systems, Inc. 20 | // 21 | // Permission to use, copy, modify, distribute and sell this software 22 | // and its documentation for any purpose is hereby granted without fee, 23 | // provided that the above copyright notice appear in all copies and 24 | // that both that copyright notice and this permission notice appear 25 | // in supporting documentation. Silicon Graphics makes no 26 | // representations about the suitability of this software for any 27 | // purpose. It is provided "as is" without express or implied warranty. 28 | // 29 | 30 | // Copyright 2002 The Trustees of Indiana University. 31 | 32 | // Use, modification and distribution is subject to the Boost Software 33 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 34 | // http://www.boost.org/LICENSE_1_0.txt) 35 | 36 | // Boost.MultiArray Library 37 | // Authors: Ronald Garcia 38 | // Jeremy Siek 39 | // Andrew Lumsdaine 40 | // See http://www.boost.org/libs/multi_array for documentation. 41 | 42 | 43 | #include 44 | 45 | namespace boost { 46 | namespace detail { 47 | namespace multi_array { 48 | //-------------------------------------------------- 49 | // copy_n (not part of the C++ standard) 50 | #if 1 51 | 52 | template 53 | OutputIter copy_n(InputIter first, Size count, 54 | OutputIter result) { 55 | for ( ; count > 0; --count) { 56 | *result = *first; 57 | ++first; 58 | ++result; 59 | } 60 | return result; 61 | } 62 | #else // !1 63 | 64 | template 65 | OutputIter copy_n__(InputIter first, Size count, 66 | OutputIter result, 67 | std::input_iterator_tag) { 68 | for ( ; count > 0; --count) { 69 | *result = *first; 70 | ++first; 71 | ++result; 72 | } 73 | return result; 74 | } 75 | 76 | template 77 | inline OutputIter 78 | copy_n__(RAIter first, Size count, 79 | OutputIter result, 80 | std::random_access_iterator_tag) { 81 | RAIter last = first + count; 82 | return std::copy(first, last, result); 83 | } 84 | 85 | template 86 | inline OutputIter 87 | copy_n__(InputIter first, Size count, OutputIter result) { 88 | typedef typename std::iterator_traits::iterator_category cat; 89 | return copy_n__(first, count, result, cat()); 90 | } 91 | 92 | template 93 | inline OutputIter 94 | copy_n(InputIter first, Size count, OutputIter result) { 95 | return copy_n__(first, count, result); 96 | } 97 | 98 | #endif // 1 99 | } // namespace multi_array 100 | } // namespace detail 101 | } // namespace boost 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /include/boost/multi_array/collection_concept.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_MULTI_ARRAY_COLLECTION_CONCEPT_HPP 14 | #define BOOST_MULTI_ARRAY_COLLECTION_CONCEPT_HPP 15 | 16 | #include "boost/concept_check.hpp" 17 | 18 | namespace boost { 19 | namespace detail { 20 | namespace multi_array { // Old location for this 21 | using boost::CollectionConcept; 22 | } 23 | } 24 | 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /include/boost/multi_array/concept_checks.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_MULTI_ARRAY_CONCEPT_CHECKS_HPP 14 | #define BOOST_MULTI_ARRAY_CONCEPT_CHECKS_HPP 15 | 16 | // 17 | // concept-checks.hpp - Checks out Const MultiArray and MultiArray 18 | // concepts 19 | // 20 | 21 | #include "boost/concept_check.hpp" 22 | #include "boost/iterator/iterator_concepts.hpp" 23 | 24 | namespace boost { 25 | namespace multi_array_concepts { 26 | 27 | namespace detail { 28 | // 29 | // idgen_helper - 30 | // This is a helper for generating index_gen instantiations with 31 | // the right type in order to test the call to 32 | // operator[](index_gen). Since one would normally write: 33 | // A[ indices[range1][range2] ]; // or 34 | // B[ indices[index1][index2][range1] ]; 35 | // idgen helper allows us to generate the "indices" type by 36 | // creating it through recursive calls. 37 | template 38 | struct idgen_helper { 39 | 40 | template 41 | static void call(Array& a, const IdxGen& idgen, Call_Type c) { 42 | idgen_helper::call(a,idgen[c],c); 43 | } 44 | }; 45 | 46 | template <> 47 | struct idgen_helper<0> { 48 | 49 | template 50 | static void call(Array& a, const IdxGen& idgen, Call_Type) { 51 | a[ idgen ]; 52 | } 53 | }; 54 | 55 | } // namespace detail 56 | 57 | 58 | template 59 | struct ConstMultiArrayConcept 60 | { 61 | void constraints() { 62 | // function_requires< CopyConstructibleConcept >(); 63 | function_requires< boost_concepts::ForwardTraversalConcept >(); 64 | function_requires< boost_concepts::ReadableIteratorConcept >(); 65 | function_requires< boost_concepts::ForwardTraversalConcept >(); 66 | function_requires< boost_concepts::ReadableIteratorConcept >(); 67 | 68 | // RG - a( CollectionArchetype) when available... 69 | a[ id ]; 70 | // Test slicing, keeping only the first dimension, losing the rest 71 | detail::idgen_helper::call(a,idgen[range],id); 72 | 73 | // Test slicing, keeping all dimensions. 74 | detail::idgen_helper::call(a,idgen[range],range); 75 | 76 | st = a.size(); 77 | st = a.num_dimensions(); 78 | st = Array::dimensionality; 79 | st = a.num_elements(); 80 | stp = a.shape(); 81 | idp = a.strides(); 82 | idp = a.index_bases(); 83 | cit = a.begin(); 84 | cit = a.end(); 85 | crit = a.rbegin(); 86 | crit = a.rend(); 87 | eltp = a.origin(); 88 | } 89 | 90 | typedef typename Array::value_type value_type; 91 | typedef typename Array::reference reference; 92 | typedef typename Array::const_reference const_reference; 93 | typedef typename Array::size_type size_type; 94 | typedef typename Array::difference_type difference_type; 95 | typedef typename Array::iterator iterator; 96 | typedef typename Array::const_iterator const_iterator; 97 | typedef typename Array::reverse_iterator reverse_iterator; 98 | typedef typename Array::const_reverse_iterator const_reverse_iterator; 99 | typedef typename Array::element element; 100 | typedef typename Array::index index; 101 | typedef typename Array::index_gen index_gen; 102 | typedef typename Array::index_range index_range; 103 | typedef typename Array::extent_gen extent_gen; 104 | typedef typename Array::extent_range extent_range; 105 | 106 | Array a; 107 | size_type st; 108 | const size_type* stp; 109 | index id; 110 | const index* idp; 111 | const_iterator cit; 112 | const_reverse_iterator crit; 113 | const element* eltp; 114 | index_gen idgen; 115 | index_range range; 116 | }; 117 | 118 | 119 | template 120 | struct MutableMultiArrayConcept 121 | { 122 | void constraints() { 123 | // function_requires< CopyConstructibleConcept >(); 124 | 125 | function_requires< boost_concepts::ForwardTraversalConcept >(); 126 | function_requires< boost_concepts::ReadableIteratorConcept >(); 127 | function_requires< boost_concepts::WritableIteratorConcept >(); 128 | function_requires< boost_concepts::ForwardTraversalConcept >(); 129 | function_requires< boost_concepts::ReadableIteratorConcept >(); 130 | function_requires< boost::OutputIterator >(); 131 | 132 | // RG - a( CollectionArchetype) when available... 133 | value_type vt = a[ id ]; 134 | 135 | // Test slicing, keeping only the first dimension, losing the rest 136 | detail::idgen_helper::call(a,idgen[range],id); 137 | 138 | // Test slicing, keeping all dimensions. 139 | detail::idgen_helper::call(a,idgen[range],range); 140 | 141 | st = a.size(); 142 | st = a.num_dimensions(); 143 | st = a.num_elements(); 144 | stp = a.shape(); 145 | idp = a.strides(); 146 | idp = a.index_bases(); 147 | it = a.begin(); 148 | it = a.end(); 149 | rit = a.rbegin(); 150 | rit = a.rend(); 151 | eltp = a.origin(); 152 | const_constraints(a); 153 | } 154 | 155 | void const_constraints(const Array& a) { 156 | 157 | // value_type vt = a[ id ]; 158 | 159 | // Test slicing, keeping only the first dimension, losing the rest 160 | detail::idgen_helper::call(a,idgen[range],id); 161 | 162 | // Test slicing, keeping all dimensions. 163 | detail::idgen_helper::call(a,idgen[range],range); 164 | 165 | st = a.size(); 166 | st = a.num_dimensions(); 167 | st = a.num_elements(); 168 | stp = a.shape(); 169 | idp = a.strides(); 170 | idp = a.index_bases(); 171 | cit = a.begin(); 172 | cit = a.end(); 173 | crit = a.rbegin(); 174 | crit = a.rend(); 175 | eltp = a.origin(); 176 | } 177 | 178 | typedef typename Array::value_type value_type; 179 | typedef typename Array::reference reference; 180 | typedef typename Array::const_reference const_reference; 181 | typedef typename Array::size_type size_type; 182 | typedef typename Array::difference_type difference_type; 183 | typedef typename Array::iterator iterator; 184 | typedef typename Array::const_iterator const_iterator; 185 | typedef typename Array::reverse_iterator reverse_iterator; 186 | typedef typename Array::const_reverse_iterator const_reverse_iterator; 187 | typedef typename Array::element element; 188 | typedef typename Array::index index; 189 | typedef typename Array::index_gen index_gen; 190 | typedef typename Array::index_range index_range; 191 | typedef typename Array::extent_gen extent_gen; 192 | typedef typename Array::extent_range extent_range; 193 | 194 | Array a; 195 | size_type st; 196 | const size_type* stp; 197 | index id; 198 | const index* idp; 199 | iterator it; 200 | const_iterator cit; 201 | reverse_iterator rit; 202 | const_reverse_iterator crit; 203 | const element* eltp; 204 | index_gen idgen; 205 | index_range range; 206 | }; 207 | 208 | 209 | } // namespace multi_array 210 | 211 | namespace detail { 212 | namespace multi_array { // Old locations for these 213 | using boost::multi_array_concepts::ConstMultiArrayConcept; 214 | using boost::multi_array_concepts::MutableMultiArrayConcept; 215 | } 216 | } 217 | 218 | } // namespace boost 219 | 220 | 221 | #endif 222 | -------------------------------------------------------------------------------- /include/boost/multi_array/copy_array.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_MULTI_ARRAY_COPY_ARRAY_HPP 14 | #define BOOST_MULTI_ARRAY_COPY_ARRAY_HPP 15 | 16 | // 17 | // copy_array.hpp - generic code for copying the contents of one 18 | // Basic_MultiArray to another. We assume that they are of the same 19 | // shape 20 | // 21 | #include "boost/type.hpp" 22 | #include "boost/assert.hpp" 23 | 24 | namespace boost { 25 | namespace detail { 26 | namespace multi_array { 27 | 28 | template 29 | class copy_dispatch { 30 | public: 31 | template 32 | static void copy_array (SourceIterator first, SourceIterator last, 33 | DestIterator result) { 34 | while (first != last) { 35 | copy_array(*first++,*result++); 36 | } 37 | } 38 | private: 39 | // Array2 has to be passed by VALUE here because subarray 40 | // pseudo-references are temporaries created by iterator::operator*() 41 | template 42 | static void copy_array (const Array1& source, Array2 dest) { 43 | copy_array(source.begin(),source.end(),dest.begin()); 44 | } 45 | 46 | static void copy_array (const Element& source, Element& dest) { 47 | dest = source; 48 | } 49 | 50 | }; 51 | 52 | 53 | template 54 | void copy_array (Array1& source, Array2& dest) { 55 | BOOST_ASSERT(std::equal(source.shape(),source.shape()+source.num_dimensions(), 56 | dest.shape())); 57 | // Dispatch to the proper function 58 | typedef typename Array1::element element_type; 59 | copy_dispatch:: 60 | copy_array(source.begin(),source.end(),dest.begin()); 61 | } 62 | 63 | 64 | } // namespace multi_array 65 | } // namespace detail 66 | } // namespace boost 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /include/boost/multi_array/extent_gen.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_MULTI_ARRAY_EXTENT_GEN_HPP 14 | #define BOOST_MULTI_ARRAY_EXTENT_GEN_HPP 15 | 16 | #include "boost/multi_array/extent_range.hpp" 17 | #include "boost/multi_array/range_list.hpp" 18 | #include "boost/multi_array/types.hpp" 19 | #include "boost/array.hpp" 20 | #include 21 | 22 | namespace boost { 23 | namespace detail { 24 | namespace multi_array { 25 | 26 | 27 | template 28 | class extent_gen { 29 | public: 30 | typedef boost::detail::multi_array::index index; 31 | typedef boost::detail::multi_array::size_type size_type; 32 | typedef extent_range range; 33 | private: 34 | typedef typename range_list_generator::type range_list; 35 | public: 36 | template 37 | struct gen_type { 38 | typedef extent_gen type; 39 | }; 40 | 41 | range_list ranges_; 42 | 43 | extent_gen() { } 44 | 45 | // Used by operator[] to expand extent_gens 46 | extent_gen(const extent_gen& rhs, 47 | const range& a_range) 48 | { 49 | std::copy(rhs.ranges_.begin(),rhs.ranges_.end(),ranges_.begin()); 50 | *ranges_.rbegin() = a_range; 51 | } 52 | 53 | extent_gen 54 | operator[](const range& a_range) 55 | { 56 | return extent_gen(*this,a_range); 57 | } 58 | 59 | extent_gen 60 | operator[](index idx) 61 | { 62 | return extent_gen(*this,range(0,idx)); 63 | } 64 | 65 | static extent_gen<0> extents() { 66 | return extent_gen<0>(); 67 | } 68 | }; 69 | 70 | } // namespace multi_array 71 | } // namespace detail 72 | } // namespace boost 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /include/boost/multi_array/extent_range.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_MULTI_ARRAY_EXTENT_RANGE_HPP 14 | #define BOOST_MULTI_ARRAY_EXTENT_RANGE_HPP 15 | 16 | #include 17 | 18 | namespace boost { 19 | namespace detail { 20 | namespace multi_array { 21 | 22 | template 23 | class extent_range : private std::pair { 24 | typedef std::pair super_type; 25 | public: 26 | typedef Extent index; 27 | typedef SizeType size_type; 28 | 29 | extent_range(index start, index finish) : 30 | super_type(start,finish) { } 31 | 32 | extent_range(index finish) : 33 | super_type(0,finish) { } 34 | 35 | extent_range() : super_type(0,0) { } 36 | 37 | index start() const { return super_type::first; } 38 | 39 | index finish() const { return super_type::second; } 40 | 41 | size_type size() const { return super_type::second - super_type::first; } 42 | }; 43 | 44 | } // namespace multi_array 45 | } // namespace detail 46 | } // namespace boost 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /include/boost/multi_array/index_gen.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_MULTI_ARRAY_INDEX_GEN_HPP 14 | #define BOOST_MULTI_ARRAY_INDEX_GEN_HPP 15 | 16 | #include "boost/array.hpp" 17 | #include "boost/multi_array/index_range.hpp" 18 | #include "boost/multi_array/range_list.hpp" 19 | #include "boost/multi_array/types.hpp" 20 | #include 21 | #include 22 | 23 | namespace boost { 24 | namespace detail { 25 | namespace multi_array { 26 | 27 | 28 | template 29 | struct index_gen { 30 | private: 31 | typedef ::boost::detail::multi_array::index index; 32 | typedef ::boost::detail::multi_array::size_type size_type; 33 | typedef index_range range; 34 | public: 35 | template 36 | struct gen_type { 37 | typedef index_gen type; 38 | }; 39 | 40 | typedef typename range_list_generator::type range_list; 41 | range_list ranges_; 42 | 43 | index_gen() { } 44 | 45 | template 46 | explicit index_gen(const index_gen& rhs, 47 | const range& r) 48 | { 49 | std::copy(rhs.ranges_.begin(),rhs.ranges_.end(),ranges_.begin()); 50 | *ranges_.rbegin() = r; 51 | } 52 | 53 | index_gen 54 | operator[](const range& r) const 55 | { 56 | index_gen tmp; 57 | std::copy(ranges_.begin(),ranges_.end(),tmp.ranges_.begin()); 58 | *tmp.ranges_.rbegin() = r; 59 | return tmp; 60 | } 61 | 62 | index_gen 63 | operator[](index idx) const 64 | { 65 | index_gen tmp; 66 | std::copy(ranges_.begin(),ranges_.end(),tmp.ranges_.begin()); 67 | *tmp.ranges_.rbegin() = range(idx); 68 | return tmp; 69 | } 70 | 71 | static index_gen<0,0> indices() { 72 | return index_gen<0,0>(); 73 | } 74 | }; 75 | 76 | } // namespace multi_array 77 | } // namespace detail 78 | } // namespace boost 79 | 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /include/boost/multi_array/index_range.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_MULTI_ARRAY_INDEX_RANGE_HPP 14 | #define BOOST_MULTI_ARRAY_INDEX_RANGE_HPP 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | // For representing intervals, also with stride. 21 | // A degenerate range is a range with one element. 22 | 23 | // Thanks to Doug Gregor for the really cool idea of using the 24 | // comparison operators to express various interval types! 25 | 26 | // Internally, we represent the interval as half-open. 27 | 28 | namespace boost { 29 | namespace detail { 30 | namespace multi_array { 31 | 32 | template 33 | class index_range { 34 | public: 35 | typedef Index index; 36 | typedef SizeType size_type; 37 | 38 | private: 39 | static index from_start() 40 | { return (std::numeric_limits::min)(); } 41 | 42 | static index to_end() 43 | { return (std::numeric_limits::max)(); } 44 | 45 | public: 46 | 47 | index_range() 48 | { 49 | start_ = from_start(); 50 | finish_ = to_end(); 51 | stride_ = 1; 52 | degenerate_ = false; 53 | } 54 | 55 | explicit index_range(index pos) 56 | { 57 | start_ = pos; 58 | finish_ = pos+1; 59 | stride_ = 1; 60 | degenerate_ = true; 61 | } 62 | 63 | explicit index_range(index start, index finish, index stride=1) 64 | : start_(start), finish_(finish), stride_(stride), 65 | degenerate_(false) 66 | { } 67 | 68 | 69 | // These are for chaining assignments to an index_range 70 | index_range& start(index s) { 71 | start_ = s; 72 | degenerate_ = false; 73 | return *this; 74 | } 75 | 76 | index_range& finish(index f) { 77 | finish_ = f; 78 | degenerate_ = false; 79 | return *this; 80 | } 81 | 82 | index_range& stride(index s) { stride_ = s; return *this; } 83 | 84 | index start() const 85 | { 86 | return start_; 87 | } 88 | 89 | index get_start(index low_index_range = index_range::from_start()) const 90 | { 91 | if (start_ == from_start()) 92 | return low_index_range; 93 | return start_; 94 | } 95 | 96 | index finish() const 97 | { 98 | return finish_; 99 | } 100 | 101 | index get_finish(index high_index_range = index_range::to_end()) const 102 | { 103 | if (finish_ == to_end()) 104 | return high_index_range; 105 | return finish_; 106 | } 107 | 108 | index stride() const { return stride_; } 109 | 110 | size_type size(index idx) const 111 | { 112 | return (start_ == from_start() || finish_ == to_end()) 113 | ? idx : ((finish_ - start_) / stride_); 114 | } 115 | 116 | void set_index_range(index start, index finish, index stride=1) 117 | { 118 | start_ = start; 119 | finish_ = finish; 120 | stride_ = stride; 121 | } 122 | 123 | static index_range all() 124 | { return index_range(from_start(), to_end(), 1); } 125 | 126 | bool is_degenerate() const { return degenerate_; } 127 | 128 | index_range operator-(index shift) const 129 | { 130 | return index_range(start_ - shift, finish_ - shift, stride_); 131 | } 132 | 133 | index_range operator+(index shift) const 134 | { 135 | return index_range(start_ + shift, finish_ + shift, stride_); 136 | } 137 | 138 | index operator[](unsigned i) const 139 | { 140 | return start_ + i * stride_; 141 | } 142 | 143 | index operator()(unsigned i) const 144 | { 145 | return start_ + i * stride_; 146 | } 147 | 148 | // add conversion to std::slice? 149 | 150 | public: 151 | index start_, finish_, stride_; 152 | bool degenerate_; 153 | }; 154 | 155 | // Express open and closed interval end-points using the comparison 156 | // operators. 157 | 158 | // left closed 159 | template 160 | inline index_range 161 | operator<=(Index s, const index_range& r) 162 | { 163 | return index_range(s, r.finish(), r.stride()); 164 | } 165 | 166 | // left open 167 | template 168 | inline index_range 169 | operator<(Index s, const index_range& r) 170 | { 171 | return index_range(s + 1, r.finish(), r.stride()); 172 | } 173 | 174 | // right open 175 | template 176 | inline index_range 177 | operator<(const index_range& r, Index f) 178 | { 179 | return index_range(r.start(), f, r.stride()); 180 | } 181 | 182 | // right closed 183 | template 184 | inline index_range 185 | operator<=(const index_range& r, Index f) 186 | { 187 | return index_range(r.start(), f + 1, r.stride()); 188 | } 189 | 190 | } // namespace multi_array 191 | } // namespace detail 192 | } // namespace boost 193 | 194 | #endif 195 | -------------------------------------------------------------------------------- /include/boost/multi_array/iterator.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_MULTI_ARRAY_ITERATOR_HPP 14 | #define BOOST_MULTI_ARRAY_ITERATOR_HPP 15 | 16 | // 17 | // iterator.hpp - implementation of iterators for the 18 | // multi-dimensional array class 19 | // 20 | 21 | #include "boost/multi_array/base.hpp" 22 | #include "boost/iterator/iterator_facade.hpp" 23 | #include 24 | #include 25 | #include 26 | 27 | namespace boost { 28 | namespace detail { 29 | namespace multi_array { 30 | 31 | ///////////////////////////////////////////////////////////////////////// 32 | // iterator components 33 | ///////////////////////////////////////////////////////////////////////// 34 | 35 | template 36 | struct operator_arrow_proxy 37 | { 38 | operator_arrow_proxy(T const& px) : value_(px) {} 39 | T* operator->() const { return &value_; } 40 | // This function is needed for MWCW and BCC, which won't call operator-> 41 | // again automatically per 13.3.1.2 para 8 42 | operator T*() const { return &value_; } 43 | mutable T value_; 44 | }; 45 | 46 | template 48 | class array_iterator; 49 | 50 | template 52 | class array_iterator 53 | : public 54 | iterator_facade< 55 | array_iterator 56 | , typename associated_types::value_type 57 | , IteratorCategory 58 | , Reference 59 | > 60 | , private 61 | value_accessor_generator::type 62 | { 63 | friend class ::boost::iterator_core_access; 64 | typedef detail::multi_array::associated_types access_t; 65 | 66 | typedef iterator_facade< 67 | array_iterator 68 | , typename detail::multi_array::associated_types::value_type 69 | , boost::random_access_traversal_tag 70 | , Reference 71 | > facade_type; 72 | 73 | typedef typename access_t::index index; 74 | typedef typename access_t::size_type size_type; 75 | 76 | #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS 77 | template 78 | friend class array_iterator; 79 | #else 80 | public: 81 | #endif 82 | 83 | index idx_; 84 | TPtr base_; 85 | const size_type* extents_; 86 | const index* strides_; 87 | const index* index_base_; 88 | 89 | public: 90 | // Typedefs to circumvent ambiguities between parent classes 91 | typedef typename facade_type::reference reference; 92 | typedef typename facade_type::value_type value_type; 93 | typedef typename facade_type::difference_type difference_type; 94 | 95 | array_iterator() {} 96 | 97 | array_iterator(index idx, TPtr base, const size_type* extents, 98 | const index* strides, 99 | const index* index_base) : 100 | idx_(idx), base_(base), extents_(extents), 101 | strides_(strides), index_base_(index_base) { } 102 | 103 | template 104 | array_iterator( 105 | const array_iterator& rhs 106 | , typename boost::enable_if_convertible::type* = 0 107 | ) 108 | : idx_(rhs.idx_), base_(rhs.base_), extents_(rhs.extents_), 109 | strides_(rhs.strides_), index_base_(rhs.index_base_) { } 110 | 111 | 112 | // RG - we make our own operator-> 113 | operator_arrow_proxy 114 | operator->() const 115 | { 116 | return operator_arrow_proxy(this->dereference()); 117 | } 118 | 119 | 120 | reference dereference() const 121 | { 122 | typedef typename value_accessor_generator::type accessor; 123 | return accessor::access(boost::type(), 124 | idx_, 125 | base_, 126 | extents_, 127 | strides_, 128 | index_base_); 129 | } 130 | 131 | void increment() { ++idx_; } 132 | void decrement() { --idx_; } 133 | 134 | template 135 | bool equal(IteratorAdaptor& rhs) const { 136 | const std::size_t N = NumDims::value; 137 | return (idx_ == rhs.idx_) && 138 | (base_ == rhs.base_) && 139 | ( (extents_ == rhs.extents_) || 140 | std::equal(extents_,extents_+N,rhs.extents_) ) && 141 | ( (strides_ == rhs.strides_) || 142 | std::equal(strides_,strides_+N,rhs.strides_) ) && 143 | ( (index_base_ == rhs.index_base_) || 144 | std::equal(index_base_,index_base_+N,rhs.index_base_) ); 145 | } 146 | 147 | template 148 | void advance(DifferenceType n) { 149 | idx_ += n; 150 | } 151 | 152 | template 153 | typename facade_type::difference_type 154 | distance_to(IteratorAdaptor& rhs) const { 155 | return rhs.idx_ - idx_; 156 | } 157 | 158 | 159 | }; 160 | 161 | } // namespace multi_array 162 | } // namespace detail 163 | } // namespace boost 164 | 165 | #endif 166 | -------------------------------------------------------------------------------- /include/boost/multi_array/range_list.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_MULTI_ARRAY_RANGE_LIST_HPP 14 | #define BOOST_MULTI_ARRAY_RANGE_LIST_HPP 15 | // 16 | // range_list.hpp - helper to build boost::arrays for *_set types 17 | // 18 | 19 | #include "boost/array.hpp" 20 | 21 | namespace boost { 22 | namespace detail { 23 | namespace multi_array { 24 | 25 | ///////////////////////////////////////////////////////////////////////// 26 | // choose range list begins 27 | // 28 | 29 | struct choose_range_list_n { 30 | template 31 | struct bind { 32 | typedef boost::array type; 33 | }; 34 | }; 35 | 36 | struct choose_range_list_zero { 37 | template 38 | struct bind { 39 | typedef boost::array type; 40 | }; 41 | }; 42 | 43 | 44 | template 45 | struct range_list_gen_helper { 46 | typedef choose_range_list_n choice; 47 | }; 48 | 49 | template <> 50 | struct range_list_gen_helper<0> { 51 | typedef choose_range_list_zero choice; 52 | }; 53 | 54 | template 55 | struct range_list_generator { 56 | private: 57 | typedef typename range_list_gen_helper::choice Choice; 58 | public: 59 | typedef typename Choice::template bind::type type; 60 | }; 61 | 62 | // 63 | // choose range list ends 64 | ///////////////////////////////////////////////////////////////////////// 65 | 66 | } // namespace multi_array 67 | } // namespace detail 68 | } // namespace boost 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /include/boost/multi_array/storage_order.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | #ifndef BOOST_MULTI_ARRAY_STORAGE_ORDER_HPP 14 | #define BOOST_MULTI_ARRAY_STORAGE_ORDER_HPP 15 | 16 | #include "boost/multi_array/types.hpp" 17 | #include "boost/array.hpp" 18 | #include "boost/multi_array/algorithm.hpp" 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace boost { 26 | 27 | // RG - This is to make things work with VC++. So sad, so sad. 28 | class c_storage_order; 29 | class fortran_storage_order; 30 | 31 | template 32 | class general_storage_order 33 | { 34 | public: 35 | typedef detail::multi_array::size_type size_type; 36 | template 37 | general_storage_order(OrderingIter ordering, 38 | AscendingIter ascending) { 39 | boost::detail::multi_array::copy_n(ordering,NumDims,ordering_.begin()); 40 | boost::detail::multi_array::copy_n(ascending,NumDims,ascending_.begin()); 41 | } 42 | 43 | // RG - ideally these would not be necessary, but some compilers 44 | // don't like template conversion operators. I suspect that not 45 | // too many folk will feel the need to use customized 46 | // storage_order objects, I sacrifice that feature for compiler support. 47 | general_storage_order(const c_storage_order&) { 48 | for (size_type i=0; i != NumDims; ++i) { 49 | ordering_[i] = NumDims - 1 - i; 50 | } 51 | ascending_.assign(true); 52 | } 53 | 54 | general_storage_order(const fortran_storage_order&) { 55 | for (size_type i=0; i != NumDims; ++i) { 56 | ordering_[i] = i; 57 | } 58 | ascending_.assign(true); 59 | } 60 | 61 | size_type ordering(size_type dim) const { return ordering_[dim]; } 62 | bool ascending(size_type dim) const { return ascending_[dim]; } 63 | 64 | bool all_dims_ascending() const { 65 | return std::accumulate(ascending_.begin(),ascending_.end(),true, 66 | std::logical_and()); 67 | } 68 | 69 | bool operator==(general_storage_order const& rhs) const { 70 | return (ordering_ == rhs.ordering_) && 71 | (ascending_ == rhs.ascending_); 72 | } 73 | 74 | protected: 75 | boost::array ordering_; 76 | boost::array ascending_; 77 | }; 78 | 79 | class c_storage_order 80 | { 81 | typedef detail::multi_array::size_type size_type; 82 | public: 83 | // This is the idiom for creating your own custom storage orders. 84 | // Not supported by all compilers though! 85 | #ifndef __MWERKS__ // Metrowerks screams "ambiguity!" 86 | template 87 | operator general_storage_order() const { 88 | boost::array ordering; 89 | boost::array ascending; 90 | 91 | for (size_type i=0; i != NumDims; ++i) { 92 | ordering[i] = NumDims - 1 - i; 93 | ascending[i] = true; 94 | } 95 | return general_storage_order(ordering.begin(), 96 | ascending.begin()); 97 | } 98 | #endif 99 | }; 100 | 101 | class fortran_storage_order 102 | { 103 | typedef detail::multi_array::size_type size_type; 104 | public: 105 | // This is the idiom for creating your own custom storage orders. 106 | // Not supported by all compilers though! 107 | #ifndef __MWERKS__ // Metrowerks screams "ambiguity!" 108 | template 109 | operator general_storage_order() const { 110 | boost::array ordering; 111 | boost::array ascending; 112 | 113 | for (size_type i=0; i != NumDims; ++i) { 114 | ordering[i] = i; 115 | ascending[i] = true; 116 | } 117 | return general_storage_order(ordering.begin(), 118 | ascending.begin()); 119 | } 120 | #endif 121 | }; 122 | 123 | } // namespace boost 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /include/boost/multi_array/types.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | 14 | #ifndef BOOST_MULTI_ARRAY_TYPES_HPP 15 | #define BOOST_MULTI_ARRAY_TYPES_HPP 16 | 17 | // 18 | // types.hpp - supply types that are needed by several headers 19 | // 20 | #include "boost/config.hpp" 21 | #include 22 | 23 | namespace boost { 24 | namespace detail { 25 | namespace multi_array{ 26 | 27 | // needed typedefs 28 | typedef std::size_t size_type; 29 | typedef std::ptrdiff_t index; 30 | 31 | } // namespace multi_array 32 | } // namespace detail 33 | } // namespace boost 34 | 35 | 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/multi_array/0c5348bef71b890c4bd06eff1ee5ebda69e7b27a/index.html -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "multi_array", 3 | "name": "Multi-Array", 4 | "authors": [ 5 | "Ron Garcia" 6 | ], 7 | "description": "Boost.MultiArray provides a generic N-dimensional array concept definition and common implementations of that interface.", 8 | "category": [ 9 | "Containers", 10 | "Math" 11 | ], 12 | "maintainers": [ 13 | "Ronald Garcia " 14 | ], 15 | "cxxstd": "03" 16 | } 17 | -------------------------------------------------------------------------------- /test/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2003. Permission to copy, use, 2 | # modify, sell and distribute this software is granted provided this 3 | # copyright notice appears in all copies. This software is provided 4 | # "as is" without express or implied warranty, and with no claim as 5 | # to its suitability for any purpose. 6 | 7 | import testing ; 8 | 9 | compile-fail fail_cbracket.cpp ; 10 | compile-fail fail_cdata.cpp ; 11 | compile-fail fail_citerator.cpp ; 12 | compile-fail fail_cparen.cpp ; 13 | compile-fail fail_criterator.cpp ; 14 | compile-fail fail_csubarray.cpp ; 15 | compile-fail fail_csubarray2.cpp ; 16 | compile-fail fail_csubarray3.cpp ; 17 | compile-fail fail_cview.cpp ; 18 | compile-fail fail_cview2.cpp ; 19 | compile-fail fail_cview3.cpp ; 20 | compile-fail fail_ref_cbracket.cpp ; 21 | compile-fail fail_ref_cdata.cpp ; 22 | compile-fail fail_ref_citerator.cpp ; 23 | compile-fail fail_ref_cparen.cpp ; 24 | compile-fail fail_ref_criterator.cpp ; 25 | compile-fail fail_ref_csubarray.cpp ; 26 | compile-fail fail_ref_csubarray2.cpp ; 27 | compile-fail fail_ref_csubarray3.cpp ; 28 | compile-fail fail_ref_cview.cpp ; 29 | compile-fail fail_ref_cview2.cpp ; 30 | compile-fail fail_ref_cview3.cpp ; 31 | 32 | run constructors.cpp ; 33 | run access.cpp ; 34 | run compare.cpp ; 35 | run iterators.cpp ; 36 | run slice.cpp ; 37 | run assign.cpp ; 38 | run assign_to_array.cpp ; 39 | run index_bases.cpp ; 40 | run storage_order_convert.cpp ; 41 | run storage_order.cpp ; 42 | run reshape.cpp ; 43 | run range1.cpp ; 44 | run idxgen1.cpp ; 45 | run stl_interaction.cpp ; 46 | run resize.cpp ; 47 | run assert.cpp ; 48 | run reverse_view.cpp ; 49 | run allocators.cpp ; 50 | 51 | compile concept_checks.cpp ; 52 | -------------------------------------------------------------------------------- /test/access.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // access.cpp - operator[] and operator() tests with various arrays 15 | // The tests assume that they are working on an Array of shape 2x3x4 16 | // 17 | 18 | #include "generative_tests.hpp" 19 | #include 20 | 21 | template 22 | void access(Array& A, const mutable_array_tag&) { 23 | assign(A); 24 | access(A,const_array_tag()); 25 | 26 | const Array& CA = A; 27 | access(CA,const_array_tag()); 28 | } 29 | 30 | template 31 | void access(Array& A, const const_array_tag&) { 32 | const unsigned int ndims = 3; 33 | BOOST_STATIC_ASSERT((Array::dimensionality == ndims)); 34 | typedef typename Array::index index; 35 | const index idx0 = A.index_bases()[0]; 36 | const index idx1 = A.index_bases()[1]; 37 | const index idx2 = A.index_bases()[2]; 38 | 39 | // operator[] 40 | int cnum = 0; 41 | const Array& CA = A; 42 | for (index i = idx0; i != idx0+2; ++i) 43 | for (index j = idx1; j != idx1+3; ++j) 44 | for (index k = idx2; k != idx2+4; ++k) { 45 | BOOST_TEST(A[i][j][k] == cnum++); 46 | BOOST_TEST(CA[i][j][k] == A[i][j][k]); 47 | } 48 | 49 | // operator() 50 | for (index i2 = idx0; i2 != idx0+2; ++i2) 51 | for (index j2 = idx1; j2 != idx1+3; ++j2) 52 | for (index k2 = idx2; k2 != idx2+4; ++k2) { 53 | boost::array indices; 54 | indices[0] = i2; indices[1] = j2; indices[2] = k2; 55 | BOOST_TEST(A(indices) == A[i2][j2][k2]); 56 | BOOST_TEST(CA(indices) == A(indices)); 57 | } 58 | ++tests_run; 59 | } 60 | 61 | int main() { 62 | return run_generative_tests(); 63 | } 64 | -------------------------------------------------------------------------------- /test/allocators.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Glen Joseph Fernandes 2 | // (glenjofe@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | template 13 | class creator { 14 | public: 15 | typedef T value_type; 16 | typedef T* pointer; 17 | typedef std::size_t size_type; 18 | typedef std::ptrdiff_t difference_type; 19 | 20 | template 21 | struct rebind { 22 | typedef creator other; 23 | }; 24 | 25 | creator(int state) 26 | : state_(state) { } 27 | 28 | template 29 | creator(const creator& other) 30 | : state_(other.state()) { } 31 | 32 | T* allocate(std::size_t size) { 33 | return static_cast(::operator new(sizeof(T) * size)); 34 | } 35 | 36 | void deallocate(T* ptr, std::size_t) { 37 | ::operator delete(ptr); 38 | } 39 | 40 | int state() const { 41 | return state_; 42 | } 43 | 44 | private: 45 | int state_; 46 | }; 47 | 48 | template 49 | inline bool 50 | operator==(const creator& a, const creator& b) 51 | { 52 | return a.state() == b.state(); 53 | } 54 | 55 | template 56 | inline bool 57 | operator!=(const creator& a, const creator& b) 58 | { 59 | return !(a == b); 60 | } 61 | 62 | void test(const double&, std::size_t*, int*, unsigned) 63 | { 64 | } 65 | 66 | template 67 | void test(const Array& array, std::size_t* sizes, int* strides, 68 | unsigned elements) 69 | { 70 | BOOST_TEST(array.num_elements() == elements); 71 | BOOST_TEST(array.size() == *sizes); 72 | BOOST_TEST(std::equal(sizes, sizes + array.num_dimensions(), array.shape())); 73 | BOOST_TEST(std::equal(strides, strides + array.num_dimensions(), 74 | array.strides())); 75 | test(array[0], ++sizes, ++strides, elements / array.size()); 76 | } 77 | 78 | bool test(const double& a, const double& b) 79 | { 80 | return a == b; 81 | } 82 | 83 | template 84 | bool test(const A1& a1, const A2& a2) 85 | { 86 | typename A1::const_iterator i1 = a1.begin(); 87 | typename A2::const_iterator i2 = a2.begin(); 88 | for (; i1 != a1.end(); ++i1, ++i2) { 89 | if (!test(*i1, *i2)) { 90 | return false; 91 | } 92 | } 93 | return true; 94 | } 95 | 96 | int main() 97 | { 98 | typedef boost::multi_array > type; 99 | creator state(1); 100 | { 101 | type array(state); 102 | } 103 | boost::array sizes = { { 3, 3, 3 } }; 104 | type::size_type elements = 27; 105 | { 106 | int strides[] = { 9, 3, 1 }; 107 | type array(sizes, state); 108 | test(array, &sizes[0], strides, elements); 109 | } 110 | { 111 | int strides[] = { 1, 3, 9 }; 112 | type array(sizes, boost::fortran_storage_order(), state); 113 | test(array, &sizes[0], strides, elements); 114 | } 115 | { 116 | int strides[] = { 9, 3, 1 }; 117 | type::extent_gen extents; 118 | type array(extents[3][3][3], state); 119 | test(array, &sizes[0], strides, elements); 120 | } 121 | { 122 | type array1(sizes, state); 123 | std::vector values(elements, 4.5); 124 | array1.assign(values.begin(), values.end()); 125 | type array2(array1); 126 | int strides[] = { 9, 3, 1 }; 127 | test(array2, &sizes[0], strides, elements); 128 | BOOST_TEST(test(array1, array2)); 129 | } 130 | { 131 | type array1(sizes, state); 132 | type array2(sizes, state); 133 | std::vector values(elements, 4.5); 134 | array1.assign(values.begin(), values.end()); 135 | array2 = array1; 136 | int strides[] = { 9, 3, 1 }; 137 | test(array2, &sizes[0], strides, elements); 138 | BOOST_TEST(test(array1, array2)); 139 | } 140 | { 141 | type array1(sizes, state); 142 | std::vector values(elements, 4.5); 143 | array1.assign(values.begin(), values.end()); 144 | typedef type::subarray<2>::type other; 145 | other array2 = array1[1]; 146 | other::value_type value = array2[0]; 147 | BOOST_TEST(test(array1[1][0], value)); 148 | BOOST_TEST(test(array2[0], value)); 149 | } 150 | return boost::report_errors(); 151 | } 152 | -------------------------------------------------------------------------------- /test/assert.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2007 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // Using the BOOST.ASSERT mechanism to replace library assertions 15 | // with exceptions 16 | // 17 | 18 | #include 19 | 20 | #define BOOST_ENABLE_ASSERT_HANDLER 21 | #include // includes assert.hpp 22 | 23 | #include 24 | 25 | namespace boost { 26 | 27 | void assertion_failed(char const* expr, char const* function, 28 | char const* file, long line) { 29 | throw std::runtime_error(expr); 30 | } 31 | 32 | void assertion_failed_msg(char const * expr, char const * msg, 33 | char const * function, 34 | char const * file, long line) { 35 | throw std::runtime_error(msg); 36 | } 37 | 38 | } // namespace boost 39 | 40 | using namespace boost; 41 | 42 | int 43 | main() { 44 | 45 | typedef multi_array array_t; 46 | 47 | array_t A(extents[2][2]); 48 | 49 | array_t B(extents[3][3]); 50 | 51 | try { 52 | A = B; 53 | BOOST_ERROR("did not throw an exception"); 54 | } catch (std::runtime_error&) { 55 | //...all good 56 | } 57 | 58 | return boost::report_errors(); 59 | } 60 | -------------------------------------------------------------------------------- /test/assign.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // assign.cpp - Test out operator=() on the different types 15 | // 16 | // 17 | #include "generative_tests.hpp" 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | bool equal(const int& a, const int& b) 25 | { 26 | return a == b; 27 | } 28 | 29 | template 30 | bool equal(const ArrayA& A, const ArrayB& B) 31 | { 32 | typename ArrayA::const_iterator ia; 33 | typename ArrayB::const_iterator ib = B.begin(); 34 | for (ia = A.begin(); ia != A.end(); ++ia, ++ib) 35 | if (!::equal(*ia, *ib)) 36 | return false; 37 | return true; 38 | } 39 | 40 | 41 | template 42 | void access(Array& A, const mutable_array_tag&) { 43 | assign(A); 44 | typedef boost::multi_array array3; 45 | 46 | int insert[] = { 47 | 99,98,97,96, 48 | 95,94,93,92, 49 | 91,90,89,88, 50 | 51 | 87,86,85,84, 52 | 83,82,81,80, 53 | 79,78,77,76 54 | }; 55 | const int insert_size = 2*3*4; 56 | array3 filler(boost::extents[2][3][4]); 57 | filler.assign(insert,insert+insert_size); 58 | 59 | 60 | A = filler; 61 | 62 | BOOST_TEST(::equal(A,filler)); 63 | ++tests_run; 64 | } 65 | 66 | template 67 | void access(Array&, const const_array_tag&) { 68 | } 69 | 70 | 71 | int main() { 72 | return run_generative_tests(); 73 | } 74 | -------------------------------------------------------------------------------- /test/assign_to_array.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // assign_to_array.cpp - multi_array should be constructible from any other 15 | // array type in the library. 16 | // 17 | // 18 | #include "generative_tests.hpp" 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | bool equal(const int& a, const int& b) 26 | { 27 | return a == b; 28 | } 29 | 30 | template 31 | bool equal(const ArrayA& A, const ArrayB& B) 32 | { 33 | typename ArrayA::const_iterator ia; 34 | typename ArrayB::const_iterator ib = B.begin(); 35 | for (ia = A.begin(); ia != A.end(); ++ia, ++ib) 36 | if (!::equal(*ia, *ib)) 37 | return false; 38 | return true; 39 | } 40 | 41 | 42 | template 43 | void access(Array& A, const mutable_array_tag&) { 44 | 45 | assign(A); 46 | access(A,const_array_tag()); 47 | } 48 | 49 | template 50 | void access(Array& A, const const_array_tag&) { 51 | typedef boost::multi_array array3; 52 | array3 acopy(A); 53 | BOOST_TEST(::equal(acopy,A)); 54 | ++tests_run; 55 | } 56 | 57 | 58 | int main() { 59 | return run_generative_tests(); 60 | } 61 | -------------------------------------------------------------------------------- /test/compare.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | 14 | 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | 23 | int 24 | main() 25 | { 26 | typedef boost::multi_array array; 27 | typedef array::size_type size_type; 28 | boost::array sizes = { { 3, 3, 3 } }; 29 | const size_type num_elements = 27; 30 | 31 | // Copy Constructor 32 | { 33 | array A(sizes); 34 | std::vector vals(num_elements, 4.5); 35 | A.assign(vals.begin(),vals.end()); 36 | array B(A); 37 | BOOST_TEST(A == B); 38 | BOOST_TEST(B == A); 39 | BOOST_TEST(A[0] == B[0]); 40 | } 41 | // Assignment Operator 42 | { 43 | array A(sizes), B(sizes); 44 | std::vector vals(num_elements, 4.5); 45 | A.assign(vals.begin(),vals.end()); 46 | B = A; 47 | BOOST_TEST(A == B); 48 | BOOST_TEST(B == A); 49 | BOOST_TEST(B[0] == A[0]); 50 | 51 | typedef array::index_range range; 52 | array::index_gen indices; 53 | array::array_view<2>::type C = A[indices[2][range()][range()]]; 54 | array::array_view<2>::type D = B[indices[2][range()][range()]]; 55 | BOOST_TEST(C == D); 56 | } 57 | // Different Arrays 58 | { 59 | array A(sizes), B(sizes); 60 | std::vector valsA(num_elements, 4.5); 61 | std::vector valsB(num_elements, 2.5); 62 | A.assign(valsA.begin(),valsA.end()); 63 | B.assign(valsB.begin(),valsB.end()); 64 | 65 | BOOST_TEST(A != B); 66 | BOOST_TEST(B != A); 67 | BOOST_TEST(A[0] != B[0]); 68 | 69 | typedef array::index_range range; 70 | array::index_gen indices; 71 | array::array_view<2>::type C = A[indices[2][range()][range()]]; 72 | array::array_view<2>::type D = B[indices[2][range()][range()]]; 73 | BOOST_TEST(C != D); 74 | } 75 | 76 | // Comparisons galore! 77 | { 78 | array A(sizes), B(sizes); 79 | 80 | double valsA[] = { 81 | 0, 0, 0, 82 | 0, 0, 0, 83 | 0, 0, 0, 84 | 85 | 1, 1, 1, 86 | 1, 1, 1, 87 | 1, 1, 1, 88 | 89 | 2, 2, 2, 90 | 2, 2, 2, 91 | 2, 2, 2 92 | }; 93 | 94 | double valsB[] = { 95 | 0, 0, 0, 96 | 0, 0, 0, 97 | 0, 0, 0, 98 | 99 | 1, 1, 1, 100 | 1, 1, 1, 101 | 1, 1, 1, 102 | 103 | 2, 2, 2, 104 | 2, 2, 2, 105 | 2, 2, 1 106 | }; 107 | 108 | A.assign(valsA,valsA+num_elements); 109 | B.assign(valsB,valsB+num_elements); 110 | 111 | BOOST_TEST(B < A); 112 | BOOST_TEST(A > B); 113 | 114 | BOOST_TEST(B <= A); 115 | BOOST_TEST(A >= B); 116 | 117 | BOOST_TEST(B[0] == A[0]); 118 | BOOST_TEST(B[2] < A[2]); 119 | 120 | array C = A; 121 | 122 | BOOST_TEST(C <= A); 123 | BOOST_TEST(C >= A); 124 | 125 | BOOST_TEST(!(C < A)); 126 | BOOST_TEST(!(C > A)); 127 | 128 | typedef array::index_range range; 129 | array::index_gen indices; 130 | array::array_view<2>::type D = A[indices[2][range()][range()]]; 131 | array::array_view<2>::type E = B[indices[2][range()][range()]]; 132 | 133 | BOOST_TEST(E < D); 134 | BOOST_TEST(E <= D); 135 | } 136 | 137 | 138 | 139 | return boost::report_errors(); 140 | } 141 | 142 | 143 | -------------------------------------------------------------------------------- /test/concept_checks.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // concept_checks.cpp - 15 | // make sure the types meet concept requirements 16 | // 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | 28 | int 29 | main() 30 | { 31 | const int ndims=3; 32 | typedef boost::multi_array array; 33 | typedef boost::multi_array_ref array_ref; 34 | typedef boost::const_multi_array_ref const_array_ref; 35 | typedef array::array_view::type array_view; 36 | typedef array::const_array_view::type const_array_view; 37 | typedef array::subarray::type subarray; 38 | typedef array::const_subarray::type const_subarray; 39 | 40 | boost::function_requires< 41 | boost::multi_array_concepts::ConstMultiArrayConcept >(); 42 | boost::function_requires< 43 | boost::multi_array_concepts::ConstMultiArrayConcept >(); 44 | boost::function_requires< 45 | boost::multi_array_concepts::ConstMultiArrayConcept >(); 46 | boost::function_requires< 47 | boost::multi_array_concepts::ConstMultiArrayConcept >(); 48 | boost::function_requires< 49 | boost::multi_array_concepts::ConstMultiArrayConcept >(); 50 | boost::function_requires< 51 | boost::multi_array_concepts::ConstMultiArrayConcept >(); 52 | boost::function_requires< 53 | boost::multi_array_concepts::ConstMultiArrayConcept >(); 54 | 55 | boost::function_requires< 56 | boost::multi_array_concepts::MutableMultiArrayConcept >(); 57 | boost::function_requires< 58 | boost::multi_array_concepts::MutableMultiArrayConcept >(); 59 | boost::function_requires< 60 | boost::multi_array_concepts::MutableMultiArrayConcept >(); 61 | boost::function_requires< 62 | boost::multi_array_concepts::MutableMultiArrayConcept >(); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /test/constructors.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // constructors.cpp - Testing out the various constructor options 15 | // 16 | 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | void check_shape(const double&, std::size_t*, int*, unsigned int) 25 | {} 26 | 27 | template 28 | void check_shape(const Array& A, 29 | std::size_t* sizes, 30 | int* strides, 31 | unsigned int num_elements) 32 | { 33 | BOOST_TEST(A.num_elements() == num_elements); 34 | BOOST_TEST(A.size() == *sizes); 35 | BOOST_TEST(std::equal(sizes, sizes + A.num_dimensions(), A.shape())); 36 | BOOST_TEST(std::equal(strides, strides + A.num_dimensions(), A.strides())); 37 | check_shape(A[0], ++sizes, ++strides, num_elements / A.size()); 38 | } 39 | 40 | 41 | bool equal(const double& a, const double& b) 42 | { 43 | return a == b; 44 | } 45 | 46 | template 47 | bool equal(const ArrayA& A, const ArrayB& B) 48 | { 49 | typename ArrayA::const_iterator ia; 50 | typename ArrayB::const_iterator ib = B.begin(); 51 | for (ia = A.begin(); ia != A.end(); ++ia, ++ib) 52 | if (!::equal(*ia, *ib)) 53 | return false; 54 | return true; 55 | } 56 | 57 | 58 | int 59 | main() 60 | { 61 | typedef boost::multi_array::size_type size_type; 62 | boost::array sizes = { { 3, 3, 3 } }; 63 | int strides[] = { 9, 3, 1 }; 64 | size_type num_elements = 27; 65 | 66 | // Default multi_array constructor 67 | { 68 | boost::multi_array A; 69 | } 70 | 71 | // Constructor 1, default storage order and allocator 72 | { 73 | boost::multi_array A(sizes); 74 | check_shape(A, &sizes[0], strides, num_elements); 75 | 76 | double* ptr = 0; 77 | boost::multi_array_ref B(ptr,sizes); 78 | check_shape(B, &sizes[0], strides, num_elements); 79 | 80 | const double* cptr = ptr; 81 | boost::const_multi_array_ref C(cptr,sizes); 82 | check_shape(C, &sizes[0], strides, num_elements); 83 | } 84 | 85 | // Constructor 1, fortran storage order and user-supplied allocator 86 | { 87 | typedef boost::multi_array >::size_type size_type; 89 | size_type num_elements = 27; 90 | int col_strides[] = { 1, 3, 9 }; 91 | 92 | boost::multi_array > A(sizes,boost::fortran_storage_order()); 94 | check_shape(A, &sizes[0], col_strides, num_elements); 95 | 96 | double *ptr=0; 97 | boost::multi_array_ref 98 | B(ptr,sizes,boost::fortran_storage_order()); 99 | check_shape(B, &sizes[0], col_strides, num_elements); 100 | 101 | const double *cptr=ptr; 102 | boost::const_multi_array_ref 103 | C(cptr,sizes,boost::fortran_storage_order()); 104 | check_shape(C, &sizes[0], col_strides, num_elements); 105 | } 106 | 107 | // Constructor 2, default storage order and allocator 108 | { 109 | typedef boost::multi_array::size_type size_type; 110 | size_type num_elements = 27; 111 | 112 | boost::multi_array::extent_gen extents; 113 | boost::multi_array A(extents[3][3][3]); 114 | check_shape(A, &sizes[0], strides, num_elements); 115 | 116 | double *ptr=0; 117 | boost::multi_array_ref B(ptr,extents[3][3][3]); 118 | check_shape(B, &sizes[0], strides, num_elements); 119 | 120 | const double *cptr=ptr; 121 | boost::const_multi_array_ref C(cptr,extents[3][3][3]); 122 | check_shape(C, &sizes[0], strides, num_elements); 123 | } 124 | 125 | // Copy Constructors 126 | { 127 | typedef boost::multi_array::size_type size_type; 128 | size_type num_elements = 27; 129 | std::vector vals(27, 4.5); 130 | 131 | boost::multi_array A(sizes); 132 | A.assign(vals.begin(),vals.end()); 133 | boost::multi_array B(A); 134 | check_shape(B, &sizes[0], strides, num_elements); 135 | BOOST_TEST(::equal(A, B)); 136 | 137 | double ptr[27]; 138 | boost::multi_array_ref C(ptr,sizes); 139 | A.assign(vals.begin(),vals.end()); 140 | boost::multi_array_ref D(C); 141 | check_shape(D, &sizes[0], strides, num_elements); 142 | BOOST_TEST(C.data() == D.data()); 143 | 144 | const double* cptr = ptr; 145 | boost::const_multi_array_ref E(cptr,sizes); 146 | boost::const_multi_array_ref F(E); 147 | check_shape(F, &sizes[0], strides, num_elements); 148 | BOOST_TEST(E.data() == F.data()); 149 | } 150 | 151 | 152 | // Conversion construction 153 | { 154 | typedef boost::multi_array::size_type size_type; 155 | size_type num_elements = 27; 156 | std::vector vals(27, 4.5); 157 | 158 | boost::multi_array A(sizes); 159 | A.assign(vals.begin(),vals.end()); 160 | boost::multi_array_ref B(A); 161 | boost::const_multi_array_ref C(A); 162 | check_shape(B, &sizes[0], strides, num_elements); 163 | check_shape(C, &sizes[0], strides, num_elements); 164 | BOOST_TEST(B.data() == A.data()); 165 | BOOST_TEST(C.data() == A.data()); 166 | 167 | double ptr[27]; 168 | boost::multi_array_ref D(ptr,sizes); 169 | D.assign(vals.begin(),vals.end()); 170 | boost::const_multi_array_ref E(D); 171 | check_shape(E, &sizes[0], strides, num_elements); 172 | BOOST_TEST(E.data() == D.data()); 173 | } 174 | 175 | // Assignment Operator 176 | { 177 | typedef boost::multi_array::size_type size_type; 178 | size_type num_elements = 27; 179 | std::vector vals(27, 4.5); 180 | 181 | boost::multi_array A(sizes), B(sizes); 182 | A.assign(vals.begin(),vals.end()); 183 | B = A; 184 | check_shape(B, &sizes[0], strides, num_elements); 185 | BOOST_TEST(::equal(A, B)); 186 | 187 | double ptr1[27]; 188 | double ptr2[27]; 189 | boost::multi_array_ref C(ptr1,sizes), D(ptr2,sizes); 190 | C.assign(vals.begin(),vals.end()); 191 | D = C; 192 | check_shape(D, &sizes[0], strides, num_elements); 193 | BOOST_TEST(::equal(C,D)); 194 | } 195 | 196 | 197 | // subarray value_type is multi_array 198 | { 199 | typedef boost::multi_array array; 200 | typedef array::size_type size_type; 201 | size_type num_elements = 27; 202 | std::vector vals(num_elements, 4.5); 203 | 204 | boost::multi_array A(sizes); 205 | A.assign(vals.begin(),vals.end()); 206 | 207 | typedef array::subarray<2>::type subarray; 208 | subarray B = A[1]; 209 | subarray::value_type C = B[0]; 210 | 211 | // should comparisons between the types work? 212 | BOOST_TEST(::equal(A[1][0],C)); 213 | BOOST_TEST(::equal(B[0],C)); 214 | } 215 | return boost::report_errors(); 216 | } 217 | 218 | 219 | -------------------------------------------------------------------------------- /test/dimtest.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // Trying to diagnose problems under visual 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | typedef int index; 23 | typedef std::size_t size_type; 24 | 25 | template 26 | class index_range { 27 | public: 28 | 29 | index_range() 30 | { 31 | start_ = from_start(); 32 | finish_ = to_end(); 33 | stride_ = 1; 34 | degenerate_ = false; 35 | } 36 | 37 | explicit index_range(Index pos) 38 | { 39 | start_ = pos; 40 | finish_ = pos; 41 | stride_ = 1; 42 | degenerate_ = true; 43 | } 44 | 45 | explicit index_range(Index start, Index finish, Index stride=1) 46 | : start_(start), finish_(finish), stride_(stride), 47 | degenerate_(start_ == finish_) 48 | { } 49 | 50 | 51 | // These are for chaining assignments to an index_range 52 | index_range& start(Index s) { 53 | start_ = s; 54 | degenerate_ = (start_ == finish_); 55 | return *this; 56 | } 57 | 58 | index_range& finish(Index f) { 59 | finish_ = f; 60 | degenerate_ = (start_ == finish_); 61 | return *this; 62 | } 63 | 64 | index_range& stride(Index s) { stride_ = s; return *this; } 65 | 66 | Index start() const 67 | { 68 | return start_; 69 | } 70 | 71 | Index get_start(Index low_index_range = 0) const 72 | { 73 | if (start_ == from_start()) 74 | return low_index_range; 75 | return start_; 76 | } 77 | 78 | Index finish() const 79 | { 80 | return finish_; 81 | } 82 | 83 | Index get_finish(Index high_index_range = 0) const 84 | { 85 | if (finish_ == to_end()) 86 | return high_index_range; 87 | return finish_; 88 | } 89 | 90 | unsigned int size(Index recommended_length = 0) const 91 | { 92 | if ((start_ == from_start()) || (finish_ == to_end())) 93 | return recommended_length; 94 | else 95 | return (finish_ - start_) / stride_; 96 | } 97 | 98 | Index stride() const { return stride_; } 99 | 100 | bool is_ascending_contiguous() const 101 | { 102 | return (start_ < finish_) && is_unit_stride(); 103 | } 104 | 105 | void set_index_range(Index start, Index finish, Index stride=1) 106 | { 107 | start_ = start; 108 | finish_ = finish; 109 | stride_ = stride; 110 | } 111 | 112 | static index_range all() 113 | { return index_range(from_start(), to_end(), 1); } 114 | 115 | bool is_unit_stride() const 116 | { return stride_ == 1; } 117 | 118 | bool is_degenerate() const { return degenerate_; } 119 | 120 | index_range operator-(Index shift) const 121 | { 122 | return index_range(start_ - shift, finish_ - shift, stride_); 123 | } 124 | 125 | index_range operator+(Index shift) const 126 | { 127 | return index_range(start_ + shift, finish_ + shift, stride_); 128 | } 129 | 130 | Index operator[](unsigned i) const 131 | { 132 | return start_ + i * stride_; 133 | } 134 | 135 | Index operator()(unsigned i) const 136 | { 137 | return start_ + i * stride_; 138 | } 139 | 140 | // add conversion to std::slice? 141 | 142 | private: 143 | static Index from_start() 144 | { return (std::numeric_limits::min)(); } 145 | 146 | static Index to_end() 147 | { return (std::numeric_limits::max)(); } 148 | public: 149 | Index start_, finish_, stride_; 150 | bool degenerate_; 151 | }; 152 | 153 | // Express open and closed interval end-points using the comparison 154 | // operators. 155 | 156 | // left closed 157 | template 158 | inline index_range 159 | operator<=(Index s, const index_range& r) 160 | { 161 | return index_range(s, r.finish(), r.stride()); 162 | } 163 | 164 | // left open 165 | template 166 | inline index_range 167 | operator<(Index s, const index_range& r) 168 | { 169 | return index_range(s + 1, r.finish(), r.stride()); 170 | } 171 | 172 | // right open 173 | template 174 | inline index_range 175 | operator<(const index_range& r, Index f) 176 | { 177 | return index_range(r.start(), f, r.stride()); 178 | } 179 | 180 | // right closed 181 | template 182 | inline index_range 183 | operator<=(const index_range& r, Index f) 184 | { 185 | return index_range(r.start(), f + 1, r.stride()); 186 | } 187 | 188 | // 189 | // range_list.hpp - helper to build boost::arrays for *_set types 190 | // 191 | 192 | ///////////////////////////////////////////////////////////////////////// 193 | // choose range list begins 194 | // 195 | 196 | struct choose_range_list_n { 197 | template 198 | struct bind { 199 | typedef boost::array type; 200 | }; 201 | }; 202 | 203 | struct choose_range_list_zero { 204 | template 205 | struct bind { 206 | typedef boost::array type; 207 | }; 208 | }; 209 | 210 | 211 | template 212 | struct range_list_gen_helper { 213 | typedef choose_range_list_n choice; 214 | }; 215 | 216 | template <> 217 | struct range_list_gen_helper<0> { 218 | typedef choose_range_list_zero choice; 219 | }; 220 | 221 | template 222 | struct range_list_generator { 223 | private: 224 | typedef typename range_list_gen_helper::choice Choice; 225 | public: 226 | typedef typename Choice::template bind::type type; 227 | }; 228 | 229 | // 230 | // choose range list ends 231 | ///////////////////////////////////////////////////////////////////////// 232 | 233 | // 234 | // Index_gen.hpp stuff 235 | // 236 | 237 | template 238 | struct index_gen { 239 | private: 240 | typedef index Index; 241 | typedef size_type SizeType; 242 | typedef index_range range; 243 | public: 244 | typedef typename range_list_generator::type range_list; 245 | range_list ranges_; 246 | 247 | index_gen() { } 248 | 249 | template 250 | explicit index_gen(const index_gen& rhs, 251 | const index_range& range) 252 | { 253 | std::copy(rhs.ranges_.begin(),rhs.ranges_.end(),ranges_.begin()); 254 | *ranges_.rbegin() = range; 255 | } 256 | 257 | index_gen 258 | operator[](const index_range& range) const 259 | { 260 | index_gen tmp; 261 | std::copy(ranges_.begin(),ranges_.end(),tmp.ranges_.begin()); 262 | *tmp.ranges_.rbegin() = range; 263 | return tmp; 264 | } 265 | 266 | index_gen 267 | operator[](Index idx) const 268 | { 269 | index_gen tmp; 270 | std::copy(ranges_.begin(),ranges_.end(),tmp.ranges_.begin()); 271 | *tmp.ranges_.rbegin() = index_range(idx); 272 | return tmp; 273 | } 274 | }; 275 | 276 | 277 | template 278 | void accept_gen(index_gen& indices) { 279 | // do nothing 280 | } 281 | 282 | template 283 | class foo { }; 284 | 285 | class boo { 286 | 287 | template 288 | void operator[](index_gen& indices) { 289 | 290 | } 291 | }; 292 | 293 | template 294 | void take_foo(foo& f) { } 295 | 296 | int main() { 297 | 298 | index_gen<0,0> indices; 299 | typedef index_range range; 300 | 301 | take_foo(foo()); 302 | 303 | indices[range()][range()][range()]; 304 | accept_gen(indices); 305 | accept_gen(index_gen<0,0>()); 306 | accept_gen(indices[range()][range()][range()]); 307 | 308 | boo b; 309 | b[indices[range()][range()][range()]]; 310 | 311 | return 0; 312 | } 313 | -------------------------------------------------------------------------------- /test/fail_cbracket.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_cbracket.cpp - 15 | // checking constness of const operator[]. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array array; 29 | 30 | boost::array sma_dims = {{2,3,4}}; 31 | array sma(sma_dims); 32 | 33 | 34 | const array& csma = sma; 35 | 36 | // FAIL! cannot assign to csma. 37 | csma[0][0][0] = 5; 38 | 39 | return boost::report_errors(); 40 | } 41 | -------------------------------------------------------------------------------- /test/fail_cdata.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_cdata.cpp 15 | // Testing data() member function constness. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array array; 29 | 30 | boost::array sma_dims = {{2,3,4}}; 31 | int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13, 32 | 14,15,16,17,18,19,20,21,22,23}; 33 | const int data_size = 24; 34 | array sma(sma_dims); 35 | sma.assign(data,data+data_size); 36 | const array& csma = sma; 37 | 38 | // FAIL! data() returns a const int* 39 | *csma.data() = 0; 40 | return boost::report_errors(); 41 | } 42 | -------------------------------------------------------------------------------- /test/fail_citerator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_citerator.cpp - 15 | // const_iterator/iterator conversion test 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | 23 | int main() { 24 | typedef boost::multi_array array; 25 | 26 | typedef array::iterator iterator1; 27 | typedef array::const_iterator citerator1; 28 | 29 | // ILLEGAL conversion from const_iterator to iterator 30 | iterator1 in = citerator1(); 31 | 32 | return boost::report_errors(); 33 | } 34 | -------------------------------------------------------------------------------- /test/fail_cparen.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_cparen.cpp - 15 | // Testing const operator() constness. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array array; 29 | 30 | boost::array sma_dims = {{2,3,4}}; 31 | int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13, 32 | 14,15,16,17,18,19,20,21,22,23}; 33 | const int data_size = 24; 34 | array sma(sma_dims); 35 | sma.assign(data,data+data_size); 36 | 37 | const array& csma = sma; 38 | boost::array indices = {{0,0,0}}; 39 | 40 | // FAIL! Cannot assign to csma 41 | csma(indices) = 5; 42 | 43 | return boost::report_errors(); 44 | } 45 | -------------------------------------------------------------------------------- /test/fail_criterator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_criterator.cpp 15 | // const_reverse_iterator/reverse_iterator conversion test 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | 23 | int main() { 24 | typedef boost::multi_array array; 25 | 26 | typedef array::reverse_iterator riterator1; 27 | typedef array::const_reverse_iterator criterator1; 28 | 29 | // ILLEGAL conversion from const_reverse_iterator to reverse_iterator 30 | riterator1 in = criterator1(); 31 | 32 | return boost::report_errors(); 33 | } 34 | -------------------------------------------------------------------------------- /test/fail_csubarray.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_csubarray.cpp - 15 | // Testing subarray and const_subarray assignment 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array array; 29 | 30 | boost::array sma_dims = {{2,3,4}}; 31 | array sma(sma_dims); 32 | 33 | int num = 0; 34 | for (array::index i = 0; i != 2; ++i) 35 | for (array::index j = 0; j != 3; ++j) 36 | for (array::index k = 0; k != 4; ++k) 37 | sma[i][j][k] = num++; 38 | 39 | 40 | array::const_subarray::type csba = sma[0]; 41 | 42 | // FAIL! Preserve constness (no const_subarray -> subarray conversion). 43 | array::subarray::type sba = csba; 44 | 45 | return boost::report_errors(); 46 | } 47 | -------------------------------------------------------------------------------- /test/fail_csubarray2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_csubarray2.cpp 15 | // Testing constness of subarray operations. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array array; 29 | 30 | boost::array sma_dims = {{2,3,4}}; 31 | array sma(sma_dims); 32 | 33 | int num = 0; 34 | for (array::index i = 0; i != 2; ++i) 35 | for (array::index j = 0; j != 3; ++j) 36 | for (array::index k = 0; k != 4; ++k) 37 | sma[i][j][k] = num++; 38 | 39 | const array& sma_const = sma; 40 | 41 | // FAIL! preserve constness. 42 | array::subarray::type sba = sma_const[0]; 43 | 44 | return boost::report_errors(); 45 | } 46 | -------------------------------------------------------------------------------- /test/fail_csubarray3.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_csubarray3.cpp 15 | // Testing constness of subarray operations. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array array; 29 | 30 | boost::array sma_dims = {{2,3,4}}; 31 | array sma(sma_dims); 32 | 33 | int num = 0; 34 | for (array::index i = 0; i != 2; ++i) 35 | for (array::index j = 0; j != 3; ++j) 36 | for (array::index k = 0; k != 4; ++k) 37 | sma[i][j][k] = num++; 38 | 39 | const array& sma_const = sma; 40 | 41 | array::const_subarray::type sba = sma_const[0]; 42 | 43 | for (array::index j = 0; j != 3; ++j) 44 | for (array::index k = 0; k != 4; ++k) 45 | // FAIL! sba cannot be assigned to. 46 | sba[j][k] = num++; 47 | 48 | return boost::report_errors(); 49 | } 50 | -------------------------------------------------------------------------------- /test/fail_cview.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_cview.cpp - 15 | // ensure const_array_view doesn't allow element assignment. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | int 26 | main() 27 | { 28 | const int ndims=3; 29 | typedef boost::multi_array array; 30 | 31 | boost::array sma_dims = {{2,3,4}}; 32 | 33 | int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13, 34 | 14,15,16,17,18,19,20,21,22,23}; 35 | const int data_size = 24; 36 | 37 | array sma(sma_dims); 38 | sma.assign(data,data+data_size); 39 | 40 | // 41 | // subarray dims: 42 | // [base,stride,bound) 43 | // [0,1,2), [1,1,3), [0,2,4) 44 | // 45 | 46 | const array& csma = sma; 47 | typedef array::index_range range; 48 | array::index_gen indices; 49 | array::const_array_view::type csma2 = 50 | csma[indices[range(0,2)][range(1,3)][range(0,4,2)]]; 51 | 52 | boost::array elmt = {{0,0,0}}; 53 | 54 | // FAIL! const_array_view cannot be assigned to. 55 | csma2(elmt) = 5; 56 | 57 | return boost::report_errors(); 58 | } 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /test/fail_cview2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_cview2.cpp 15 | // ensure const_array_view cannot be converted to array_view 16 | // 17 | 18 | #include 19 | 20 | #define BOOST_INCLUDE_MAIN 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | int 28 | main() 29 | { 30 | const int ndims=3; 31 | typedef boost::multi_array array; 32 | 33 | boost::array sma_dims = {{2,3,4}}; 34 | 35 | int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13, 36 | 14,15,16,17,18,19,20,21,22,23}; 37 | const int data_size = 24; 38 | 39 | array sma(sma_dims); 40 | sma.assign(data,data+data_size); 41 | 42 | // 43 | // subarray dims: 44 | // [base,stride,bound) 45 | // [0,1,2), [1,1,3), [0,2,4) 46 | // 47 | 48 | const array& csma = sma; 49 | typedef array::index_range range; 50 | array::index_gen indices; 51 | // FAIL! preserve constness (no const_array_view -> array_view). 52 | array::array_view::type csma2 = 53 | csma[indices[range(0,2)][range(1,3)][range(0,4,2)]]; 54 | 55 | return boost::report_errors(); 56 | } 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /test/fail_cview3.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_cview3.cpp 15 | // ensure const_array_ref doesn't allow assignment. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | int 26 | main() 27 | { 28 | const int ndims=3; 29 | typedef boost::multi_array array; 30 | 31 | boost::array sma_dims = {{2,3,4}}; 32 | 33 | int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13, 34 | 14,15,16,17,18,19,20,21,22,23}; 35 | const int data_size = 24; 36 | 37 | array sma(sma_dims); 38 | sma.assign(data,data+data_size); 39 | 40 | // 41 | // subarray dims: 42 | // [base,stride,bound) 43 | // [0,1,2), [1,1,3), [0,2,4) 44 | // 45 | 46 | const array& csma = sma; 47 | typedef array::index_range range; 48 | array::index_gen indices; 49 | array::const_array_view::type csma2 = 50 | csma[indices[range(0,2)][range(1,3)][range(0,4,2)]]; 51 | 52 | for (array::index i = 0; i != 2; ++i) 53 | for (array::index j = 0; j != 2; ++j) 54 | for (array::index k = 0; k != 2; ++k) 55 | // FAIL! csma2 cannot be assigned to. 56 | csma2[i][j][k] = 0; 57 | 58 | return boost::report_errors(); 59 | } 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /test/fail_ref_cbracket.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_ref_cbracket.cpp 15 | // checking constness of const operator[]. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array_ref array_ref; 29 | 30 | boost::array sma_dims = {{2,3,4}}; 31 | 32 | int data[] = {77,77,77,77,77,77,77,77,77,77,77,77, 33 | 77,77,77,77,77,77,77,77,77,77,77,77}; 34 | 35 | array_ref sma(data,sma_dims); 36 | 37 | 38 | const array_ref& csma = sma; 39 | 40 | // FAIL! can't assign to const multi_array_ref. 41 | csma[0][0][0] = 5; 42 | 43 | return boost::report_errors(); 44 | } 45 | -------------------------------------------------------------------------------- /test/fail_ref_cdata.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_ref_cdata.cpp - 15 | // Testing data() member function constness. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array_ref array_ref; 29 | 30 | boost::array sma_dims = {{2,3,4}}; 31 | int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13, 32 | 14,15,16,17,18,19,20,21,22,23}; 33 | array_ref sma(data,sma_dims); 34 | 35 | const array_ref& csma = sma; 36 | 37 | // FAIL! data() returns const int*. 38 | *csma.data() = 0; 39 | return boost::report_errors(); 40 | } 41 | -------------------------------------------------------------------------------- /test/fail_ref_citerator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_ref_citerator.cpp 15 | // const_iterator/iterator conversion test 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | 23 | int main() { 24 | typedef boost::multi_array_ref array_ref; 25 | 26 | typedef array_ref::iterator iterator1; 27 | typedef array_ref::const_iterator citerator1; 28 | 29 | // FAIL! ILLEGAL conversion from const_iterator to iterator 30 | iterator1 in = citerator1(); 31 | 32 | return boost::report_errors(); 33 | } 34 | -------------------------------------------------------------------------------- /test/fail_ref_cparen.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_ref_cparen.cpp 15 | // Testing const operator() constness. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array_ref array_ref; 29 | 30 | boost::array sma_dims = {{2,3,4}}; 31 | 32 | int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13, 33 | 14,15,16,17,18,19,20,21,22,23}; 34 | 35 | array_ref sma(data,sma_dims); 36 | 37 | const array_ref& csma = sma; 38 | boost::array indices = {{0,0,0}}; 39 | 40 | // FAIL! cannot assign to a const multi_array_ref 41 | csma(indices) = 5; 42 | 43 | return boost::report_errors(); 44 | } 45 | -------------------------------------------------------------------------------- /test/fail_ref_criterator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_ref_criterator.cpp 15 | // const_reverse_iterator/reverse_iterator conversion test 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | 23 | int main() { 24 | typedef boost::multi_array_ref array_ref; 25 | 26 | typedef array_ref::reverse_iterator riterator1; 27 | typedef array_ref::const_reverse_iterator criterator1; 28 | 29 | // Fail! ILLEGAL conversion from const_reverse_iterator to reverse_iterator 30 | riterator1 in = criterator1(); 31 | 32 | return boost::report_errors(); 33 | } 34 | -------------------------------------------------------------------------------- /test/fail_ref_csubarray.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_ref_csubarray.cpp - 15 | // Testing subarray and const_subarray assignment 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array_ref array_ref; 29 | 30 | boost::array sma_dims = {{2,3,4}}; 31 | 32 | int data[] = {77,77,77,77,77,77,77,77,77,77,77,77, 33 | 77,77,77,77,77,77,77,77,77,77,77,77}; 34 | 35 | array_ref sma(data,sma_dims); 36 | 37 | int num = 0; 38 | for (array_ref::index i = 0; i != 2; ++i) 39 | for (array_ref::index j = 0; j != 3; ++j) 40 | for (array_ref::index k = 0; k != 4; ++k) 41 | sma[i][j][k] = num++; 42 | 43 | array_ref::const_subarray::type csba = sma[0]; 44 | 45 | array_ref::subarray::type sba = csba; // FAIL! preserve constness. 46 | 47 | return boost::report_errors(); 48 | } 49 | -------------------------------------------------------------------------------- /test/fail_ref_csubarray2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_ref_csubarray2.cpp - 15 | // Testing constness of subarray operations. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array_ref array_ref; 29 | 30 | boost::array sma_dims = {{2,3,4}}; 31 | 32 | int data[] = {77,77,77,77,77,77,77,77,77,77,77,77, 33 | 77,77,77,77,77,77,77,77,77,77,77,77}; 34 | 35 | array_ref sma(data,sma_dims); 36 | 37 | int num = 0; 38 | for (array_ref::index i = 0; i != 2; ++i) 39 | for (array_ref::index j = 0; j != 3; ++j) 40 | for (array_ref::index k = 0; k != 4; ++k) 41 | sma[i][j][k] = num++; 42 | 43 | const array_ref& sma_const = sma; 44 | 45 | array_ref::subarray::type sba = sma_const[0]; // FAIL! 46 | // preserve constness 47 | 48 | return boost::report_errors(); 49 | } 50 | -------------------------------------------------------------------------------- /test/fail_ref_csubarray3.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_ref_csubarray3.cpp - 15 | // Testing constness of subarray operations. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array_ref array_ref; 29 | 30 | boost::array sma_dims = {{2,3,4}}; 31 | 32 | int data[] = {77,77,77,77,77,77,77,77,77,77,77,77, 33 | 77,77,77,77,77,77,77,77,77,77,77,77}; 34 | 35 | array_ref sma(data,sma_dims); 36 | 37 | int num = 0; 38 | for (array_ref::index i = 0; i != 2; ++i) 39 | for (array_ref::index j = 0; j != 3; ++j) 40 | for (array_ref::index k = 0; k != 4; ++k) 41 | sma[i][j][k] = num++; 42 | 43 | const array_ref& sma_const = sma; 44 | 45 | array_ref::const_subarray::type sba = sma_const[0]; 46 | 47 | for (array_ref::index j = 0; j != 3; ++j) 48 | for (array_ref::index k = 0; k != 4; ++k) 49 | sba[j][k] = num++; // FAIL! can't assign to const_subarray. 50 | 51 | return boost::report_errors(); 52 | } 53 | -------------------------------------------------------------------------------- /test/fail_ref_cview.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_ref_cview.cpp 15 | // ensure const_array_view doesn't allow element assignment. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | int 26 | main() 27 | { 28 | const int ndims=3; 29 | typedef boost::multi_array_ref array_ref; 30 | 31 | boost::array sma_dims = {{2,3,4}}; 32 | 33 | int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13, 34 | 14,15,16,17,18,19,20,21,22,23}; 35 | 36 | array_ref sma(data,sma_dims); 37 | 38 | // 39 | // subarray dims: 40 | // [base,stride,bound) 41 | // [0,1,2), [1,1,3), [0,2,4) 42 | // 43 | 44 | const array_ref& csma = sma; 45 | typedef array_ref::index_range range; 46 | array_ref::index_gen indices; 47 | array_ref::const_array_view::type csma2 = 48 | csma[indices[range(0,2)][range(1,3)][range(0,4,2)]]; 49 | 50 | boost::array elmt = {{0,0,0}}; 51 | 52 | csma2(elmt) = 5; // FAIL! csma is read only 53 | 54 | return boost::report_errors(); 55 | } 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /test/fail_ref_cview2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_ref_cview2.cpp 15 | // ensure const_array_view cannot be converted to array_view 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | int 26 | main() 27 | { 28 | const int ndims=3; 29 | typedef boost::multi_array_ref array_ref; 30 | 31 | boost::array sma_dims = {{2,3,4}}; 32 | 33 | int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13, 34 | 14,15,16,17,18,19,20,21,22,23}; 35 | 36 | array_ref sma(data,sma_dims); 37 | 38 | // 39 | // subarray dims: 40 | // [base,stride,bound) 41 | // [0,1,2), [1,1,3), [0,2,4) 42 | // 43 | 44 | const array_ref& csma = sma; 45 | typedef array_ref::index_range range; 46 | array_ref::index_gen indices; 47 | array_ref::array_view::type csma2 = 48 | csma[indices[range(0,2)][range(1,3)][range(0,4,2)]]; 49 | 50 | for (array_ref::index i = 0; i != 2; ++i) 51 | for (array_ref::index j = 0; j != 2; ++j) 52 | for (array_ref::index k = 0; k != 2; ++k) 53 | csma2[i][j][k] = 0; // FAIL! csma2 is read only 54 | 55 | return boost::report_errors(); 56 | } 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /test/fail_ref_cview3.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // fail_ref_cview3.cpp - 15 | // ensure const_array_view doesn't allow assignment. 16 | // 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | int 26 | main() 27 | { 28 | const int ndims=3; 29 | typedef boost::multi_array_ref array_ref; 30 | 31 | boost::array sma_dims = {{2,3,4}}; 32 | 33 | int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13, 34 | 14,15,16,17,18,19,20,21,22,23}; 35 | 36 | array_ref sma(data,sma_dims); 37 | 38 | // 39 | // subarray dims: 40 | // [base,stride,bound) 41 | // [0,1,2), [1,1,3), [0,2,4) 42 | // 43 | 44 | const array_ref& csma = sma; 45 | 46 | typedef array_ref::index_range range; 47 | array_ref::index_gen indices; 48 | array_ref::const_array_view::type csma2 = 49 | csma[indices[range(0,2)][range(1,3)][range(0,4,2)]]; 50 | 51 | for (array_ref::index i = 0; i != 2; ++i) 52 | for (array_ref::index j = 0; j != 2; ++j) 53 | for (array_ref::index k = 0; k != 2; ++k) 54 | csma2[i][j][k] = 0; // FAIL! csma2 is read only. 55 | 56 | return boost::report_errors(); 57 | } 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /test/generative_tests.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_MULTI_ARRAY_GENERATIVE_TESTS_HPP 2 | #define BOOST_MULTI_ARRAY_GENERATIVE_TESTS_HPP 3 | 4 | // Copyright 2002 The Trustees of Indiana University. 5 | 6 | // Use, modification and distribution is subject to the Boost Software 7 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | // Boost.MultiArray Library 11 | // Authors: Ronald Garcia 12 | // Jeremy Siek 13 | // Andrew Lumsdaine 14 | // See http://www.boost.org/libs/multi_array for documentation. 15 | 16 | // 17 | // generative-tests.hpp - Framework for running tests on all the types 18 | // of multi_array 19 | // 20 | // In order to create a set of tests, you must define the following two 21 | // function signatures: 22 | // template 23 | // void access(Array& A, const mutable_array_tag&); 24 | // 25 | // template 26 | // void access(Array& A, const const_array_tag&); 27 | // 28 | // The framework will always pass 2x3x4 arrays into these functions. 29 | // The const_array_tag version of access must NOT attempt to modify 30 | // the array. Assume that the passed array has constness in this case. 31 | // 32 | // The mutable_array_tag version of access should pass the array to the 33 | // assign() function in order to set its values before running tests. 34 | // 35 | // If you wish to write your own code to assign data to the array 36 | // (ie. test the iterators by assigning data with them), you must 37 | // #define MULTIARRAY_TEST_ASSIGN before including this file. 38 | // assign() will call this function. 39 | // 40 | // If you wish to know how many tests were run, you must increment 41 | // the global variable 'tests_run' somewhere in your test code. 42 | // 43 | // Since generative-tests uses the Boost.Test framework, you must 44 | // define at least the following: 45 | // 46 | // int test_main(int,char*[]) { return run_generative_tests(); } 47 | // 48 | #include 49 | 50 | #include 51 | 52 | #include /* BOOST_NO_SFINAE */ 53 | #include 54 | #include 55 | #include 56 | 57 | namespace { 58 | unsigned int tests_run = 0; 59 | } // empty namespace 60 | 61 | struct mutable_array_tag { }; 62 | struct const_array_tag { }; 63 | 64 | template 65 | void assign_if_not_const(Array&, const const_array_tag&) { 66 | // do nothing 67 | } 68 | 69 | template 70 | void assign_if_not_const(Array& A, const mutable_array_tag&); 71 | 72 | #ifndef MULTIARRAY_TEST_ASSIGN 73 | template 74 | void assign_if_not_const(Array& A, const mutable_array_tag&) { 75 | 76 | typedef typename Array::index index; 77 | 78 | const index idx0 = A.index_bases()[0]; 79 | const index idx1 = A.index_bases()[1]; 80 | const index idx2 = A.index_bases()[2]; 81 | 82 | 83 | int num = 0; 84 | for (index i = idx0; i != idx0 + 2; ++i) 85 | for (index j = idx1; j != idx1 + 3; ++j) 86 | for (index k = idx2; k != idx2 + 4; ++k) 87 | A[i][j][k] = num++; 88 | } 89 | #endif // MULTIARRAY_TEST_ASSIGN 90 | 91 | template 92 | void assign(Array& A) { 93 | assign_if_not_const(A,mutable_array_tag()); 94 | } 95 | 96 | template 97 | void access(Array& A, const mutable_array_tag&); 98 | 99 | template 100 | void access(Array& A, const const_array_tag&); 101 | 102 | template 103 | void run_configuration(const StorageOrder3& so3, 104 | const StorageOrder4& so4, 105 | const Modifier& modifier) { 106 | // multi_array 107 | { 108 | typedef boost::multi_array array; 109 | typename array::extent_gen extents; 110 | { 111 | array A(extents[2][3][4],so3); 112 | modifier.modify(A); 113 | access(A,mutable_array_tag()); 114 | } 115 | } 116 | // multi_array_ref 117 | { 118 | typedef boost::multi_array_ref array_ref; 119 | typename array_ref::extent_gen extents; 120 | { 121 | int local[24]; 122 | array_ref A(local,extents[2][3][4],so3); 123 | modifier.modify(A); 124 | access(A,mutable_array_tag()); 125 | } 126 | } 127 | // const_multi_array_ref 128 | { 129 | typedef boost::multi_array_ref array_ref; 130 | typedef boost::const_multi_array_ref const_array_ref; 131 | typename array_ref::extent_gen extents; 132 | { 133 | int local[24]; 134 | array_ref A(local,extents[2][3][4],so3); 135 | modifier.modify(A); 136 | assign(A); 137 | 138 | const_array_ref B = A; 139 | access(B,const_array_tag()); 140 | } 141 | } 142 | // sub_array 143 | { 144 | typedef boost::multi_array array; 145 | typename array::extent_gen extents; 146 | { 147 | array A(extents[2][2][3][4],so4); 148 | modifier.modify(A); 149 | typename array::template subarray<3>::type B = A[1]; 150 | access(B,mutable_array_tag()); 151 | } 152 | } 153 | // const_sub_array 154 | { 155 | typedef boost::multi_array array; 156 | typename array::extent_gen extents; 157 | { 158 | array A(extents[2][2][3][4],so4); 159 | modifier.modify(A); 160 | typename array::template subarray<3>::type B = A[1]; 161 | assign(B); 162 | 163 | typename array::template const_subarray<3>::type C = B; 164 | access(C,const_array_tag()); 165 | } 166 | } 167 | // array_view 168 | { 169 | typedef boost::multi_array array; 170 | typedef typename array::index_range range; 171 | typename array::index_gen indices; 172 | typename array::extent_gen extents; 173 | { 174 | typedef typename array::index index; 175 | 176 | array A(extents[4][5][6],so3); 177 | modifier.modify(A); 178 | const index idx0 = A.index_bases()[0]; 179 | const index idx1 = A.index_bases()[1]; 180 | const index idx2 = A.index_bases()[2]; 181 | 182 | typename array::template array_view<3>::type B =A[ 183 | indices[range(idx0+1,idx0+3)] 184 | [range(idx1+1,idx1+4)] 185 | [range(idx2+1,idx2+5)] 186 | ]; 187 | access(B,mutable_array_tag()); 188 | } 189 | } 190 | // const_array_view 191 | { 192 | typedef boost::multi_array array; 193 | typedef typename array::index_range range; 194 | typename array::index_gen indices; 195 | typename array::extent_gen extents; 196 | { 197 | typedef typename array::index index; 198 | 199 | array A(extents[4][5][6],so3); 200 | modifier.modify(A); 201 | const index idx0 = A.index_bases()[0]; 202 | const index idx1 = A.index_bases()[1]; 203 | const index idx2 = A.index_bases()[2]; 204 | 205 | typename array::template array_view<3>::type B =A[ 206 | indices[range(idx0+1,idx0+3)] 207 | [range(idx1+1,idx1+4)] 208 | [range(idx2+1,idx2+5)] 209 | ]; 210 | assign(B); 211 | 212 | typename array::template const_array_view<3>::type C = B; 213 | access(C,const_array_tag()); 214 | } 215 | } 216 | } 217 | 218 | template 219 | void run_storage_tests(const ArrayModifier& modifier) { 220 | run_configuration(boost::c_storage_order(), 221 | boost::c_storage_order(),modifier); 222 | run_configuration(boost::fortran_storage_order(), 223 | boost::fortran_storage_order(),modifier); 224 | 225 | std::size_t ordering[] = {2,0,1,3}; 226 | bool ascending[] = {false,true,true,true}; 227 | run_configuration(boost::general_storage_order<3>(ordering,ascending), 228 | boost::general_storage_order<4>(ordering,ascending), 229 | modifier); 230 | } 231 | 232 | struct null_modifier { 233 | template 234 | void modify(Array&) const { } 235 | }; 236 | 237 | struct set_index_base_modifier { 238 | template 239 | void modify(Array& A) const { 240 | #ifdef BOOST_NO_SFINAE 241 | typedef boost::multi_array_types::index index; 242 | A.reindex(index(1)); 243 | #else 244 | A.reindex(1); 245 | #endif 246 | } 247 | }; 248 | 249 | struct reindex_modifier { 250 | template 251 | void modify(Array& A) const { 252 | boost::array bases = {{1,2,3,4}}; 253 | A.reindex(bases); 254 | } 255 | }; 256 | 257 | struct reshape_modifier { 258 | template 259 | void modify(Array& A) const { 260 | typedef typename Array::size_type size_type; 261 | std::vector old_shape(A.num_dimensions()); 262 | std::vector new_shape(A.num_dimensions()); 263 | 264 | std::copy(A.shape(),A.shape()+A.num_dimensions(),old_shape.begin()); 265 | std::copy(old_shape.rbegin(),old_shape.rend(),new_shape.begin()); 266 | 267 | A.reshape(new_shape); 268 | A.reshape(old_shape); 269 | } 270 | }; 271 | 272 | int run_generative_tests() { 273 | 274 | run_storage_tests(null_modifier()); 275 | run_storage_tests(set_index_base_modifier()); 276 | run_storage_tests(reindex_modifier()); 277 | run_storage_tests(reshape_modifier()); 278 | std::cout << "Total Tests Run: " << tests_run << '\n'; 279 | return boost::report_errors(); 280 | } 281 | 282 | #endif 283 | -------------------------------------------------------------------------------- /test/idxgen1.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // idxset1.cpp - testing the code for index_gen 15 | // 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | typedef boost::detail::multi_array::index index_type; 25 | typedef boost::detail::multi_array::size_type size_type; 26 | typedef boost::detail::multi_array::index_range range; 27 | 28 | template 29 | void check(const boost::detail::multi_array:: 30 | index_gen&) { } 31 | 32 | bool operator==(const range& lhs,const range& rhs) { 33 | return lhs.start_ == rhs.start_ && 34 | lhs.finish_ == rhs.finish_ && 35 | lhs.stride_ == rhs.stride_ && 36 | lhs.degenerate_ == rhs.degenerate_; 37 | } 38 | 39 | int 40 | main() 41 | { 42 | 43 | boost::detail::multi_array::index_gen<0,0> indices; 44 | 45 | 46 | check<1,1>(indices[range()]); 47 | check<2,2>(indices[range()][range()]); 48 | check<3,3>(indices[range()][range()][range()]); 49 | 50 | check<1,0>(indices[0]); 51 | check<2,0>(indices[0][0]); 52 | check<2,1>(indices[range()][0]); 53 | check<2,1>(indices[0][range()]); 54 | check<3,0>(indices[0][0][0]); 55 | check<3,1>(indices[range()][0][0]); 56 | check<3,1>(indices[0][range()][0]); 57 | check<3,1>(indices[0][0][range()]); 58 | check<3,2>(indices[range()][range()][0]); 59 | check<3,2>(indices[range()][0][range()]); 60 | check<3,2>(indices[0][range()][range()]); 61 | 62 | { 63 | boost::detail::multi_array::index_gen<3,3> is1 = 64 | indices[range(0,1,2)][range(1,2,3)][range(2,3,4)]; 65 | BOOST_TEST(is1.ranges_[0] == range(0,1,2)); 66 | BOOST_TEST(is1.ranges_[1] == range(1,2,3)); 67 | BOOST_TEST(is1.ranges_[2] == range(2,3,4)); 68 | } 69 | 70 | { 71 | boost::detail::multi_array::index_gen<3,2> is2 = 72 | indices[range(0,1,2)][2][range(2,3,4)]; 73 | BOOST_TEST(is2.ranges_[0] == range(0,1,2)); 74 | BOOST_TEST(is2.ranges_[1] == range(2)); 75 | BOOST_TEST(is2.ranges_[1].is_degenerate()); 76 | BOOST_TEST(is2.ranges_[2] == range(2,3,4)); 77 | } 78 | 79 | return boost::report_errors(); 80 | } 81 | 82 | -------------------------------------------------------------------------------- /test/index_bases.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // index_bases - test of the index_base modifying facilities. 15 | // 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | int 25 | main() 26 | { 27 | typedef boost::multi_array array; 28 | typedef boost::multi_array_ref array_ref; 29 | typedef boost::const_multi_array_ref const_array_ref; 30 | typedef array::array_view<3>::type array_view; 31 | 32 | typedef array::size_type size_type; 33 | typedef array::extent_range range; 34 | typedef array::index_range irange; 35 | 36 | array::extent_gen extents; 37 | array::index_gen indices; 38 | 39 | // Construct with nonzero bases 40 | { 41 | 42 | array A(extents[range(1,4)][range(2,5)][range(3,6)]); 43 | array B(extents[3][3][3]); 44 | 45 | double ptr[27]; 46 | array_ref 47 | C(ptr,extents[range(1,4)][range(2,5)][range(3,6)]); 48 | 49 | const_array_ref 50 | D(ptr,extents[range(1,4)][range(2,5)][range(3,6)]); 51 | 52 | array_view E = A[indices[irange()][irange()][irange()]]; 53 | 54 | std::vector vals; 55 | for (int i = 0; i < 27; ++i) 56 | vals.push_back(i); 57 | 58 | A.assign(vals.begin(),vals.end()); 59 | B.assign(vals.begin(),vals.end()); 60 | C.assign(vals.begin(),vals.end()); 61 | 62 | boost::array bases = { { 1, 2, 3 } }; 63 | for (size_type a = 0; a < A.shape()[0]; ++a) 64 | for (size_type b = 0; b < A.shape()[1]; ++b) 65 | for (size_type c = 0; c < A.shape()[2]; ++c) { 66 | BOOST_TEST(A[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]); 67 | BOOST_TEST(C[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]); 68 | BOOST_TEST(D[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]); 69 | // Test that E does not inherit A's index_base 70 | BOOST_TEST(E[a][b][c] == B[a][b][c]); 71 | } 72 | } 73 | 74 | // Reindex 75 | { 76 | typedef array::size_type size_type; 77 | array A(extents[3][3][3]), B(extents[3][3][3]); 78 | 79 | double ptr[27]; 80 | array_ref C(ptr,extents[3][3][3]); 81 | const_array_ref D(ptr,extents[3][3][3]); 82 | 83 | array_view E = B[indices[irange()][irange()][irange()]]; 84 | 85 | std::vector vals; 86 | for (int i = 0; i < 27; ++i) 87 | vals.push_back(i); 88 | 89 | A.assign(vals.begin(),vals.end()); 90 | B.assign(vals.begin(),vals.end()); 91 | C.assign(vals.begin(),vals.end()); 92 | 93 | boost::array bases = { { 1, 2, 3 } }; 94 | 95 | A.reindex(bases); 96 | C.reindex(bases); 97 | D.reindex(bases); 98 | E.reindex(bases); 99 | 100 | for (size_type a = 0; a < A.shape()[0]; ++a) 101 | for (size_type b = 0; b < A.shape()[1]; ++b) 102 | for (size_type c = 0; c < A.shape()[2]; ++c) { 103 | BOOST_TEST(A[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]); 104 | BOOST_TEST(C[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]); 105 | BOOST_TEST(D[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]); 106 | BOOST_TEST(E[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]); 107 | } 108 | } 109 | 110 | // Set Index Base 111 | { 112 | typedef array::size_type size_type; 113 | array A(extents[3][3][3]), B(extents[3][3][3]); 114 | 115 | double ptr[27]; 116 | array_ref C(ptr,extents[3][3][3]); 117 | const_array_ref D(ptr,extents[3][3][3]); 118 | 119 | array_view E = B[indices[irange()][irange()][irange()]]; 120 | 121 | std::vector vals; 122 | for (int i = 0; i < 27; ++i) 123 | vals.push_back(i); 124 | 125 | A.assign(vals.begin(),vals.end()); 126 | B.assign(vals.begin(),vals.end()); 127 | C.assign(vals.begin(),vals.end()); 128 | 129 | #ifdef BOOST_NO_SFINAE 130 | typedef boost::multi_array_types::index index; 131 | A.reindex(index(1)); 132 | C.reindex(index(1)); 133 | D.reindex(index(1)); 134 | E.reindex(index(1)); 135 | #else 136 | A.reindex(1); 137 | C.reindex(1); 138 | D.reindex(1); 139 | E.reindex(1); 140 | #endif 141 | 142 | for (size_type a = 0; a < A.shape()[0]; ++a) 143 | for (size_type b = 0; b < A.shape()[1]; ++b) 144 | for (size_type c = 0; c < A.shape()[2]; ++c) { 145 | BOOST_TEST(A[a+1][b+1][c+1] == B[a][b][c]); 146 | BOOST_TEST(C[a+1][b+1][c+1] == B[a][b][c]); 147 | BOOST_TEST(D[a+1][b+1][c+1] == B[a][b][c]); 148 | BOOST_TEST(E[a+1][b+1][c+1] == B[a][b][c]); 149 | } 150 | } 151 | 152 | return boost::report_errors(); 153 | } 154 | -------------------------------------------------------------------------------- /test/iterators.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // iterators.cpp - checking out iterator stuffs. 15 | // The tests assume that the array has shape 2x3x4 16 | // 17 | 18 | #define MULTIARRAY_TEST_ASSIGN 19 | #include "generative_tests.hpp" 20 | #include // for ignore_unused_variable_warning 21 | #include 22 | #include 23 | 24 | // iterator-test-specific code 25 | 26 | template 27 | void assign_if_not_const(Array& A, const mutable_array_tag&) { 28 | 29 | typedef typename Array::iterator iterator3; 30 | typedef typename Array::template subarray<2>::type::iterator iterator2; 31 | typedef typename Array::template subarray<1>::type::iterator iterator1; 32 | 33 | int num = 0; 34 | for (iterator3 i = A.begin(); i != A.end(); ++i) 35 | for(iterator2 ii = (*i).begin(); ii != (*i).end(); ++ii) 36 | for(iterator1 iii = (*ii).begin(); iii != (*ii).end(); ++iii) 37 | *iii = num++; 38 | } 39 | 40 | 41 | template 42 | struct ittraits_const { 43 | typedef typename Array::const_iterator iterator3; 44 | typedef typename boost::subarray_gen::type::const_iterator 45 | iterator2; 46 | typedef typename boost::subarray_gen::type::const_iterator 47 | iterator1; 48 | 49 | typedef typename Array::const_reverse_iterator riterator3; 50 | typedef typename boost::subarray_gen::type::const_reverse_iterator 51 | riterator2; 52 | typedef typename boost::subarray_gen::type::const_reverse_iterator 53 | riterator1; 54 | }; 55 | 56 | template 57 | struct ittraits_mutable { 58 | typedef typename Array::iterator iterator3; 59 | typedef typename boost::subarray_gen::type::iterator iterator2; 60 | typedef typename boost::subarray_gen::type::iterator iterator1; 61 | 62 | typedef typename Array::reverse_iterator riterator3; 63 | typedef typename boost::subarray_gen::type::reverse_iterator 64 | riterator2; 65 | typedef typename boost::subarray_gen::type::reverse_iterator 66 | riterator1; 67 | }; 68 | 69 | 70 | // Meta-program chooses ittraits implementation. 71 | template 72 | struct ittraits_generator : 73 | boost::mpl::if_< boost::is_same, 74 | ittraits_const, 75 | ittraits_mutable > 76 | {}; 77 | 78 | 79 | template 80 | void construct_iterators(Array&) { 81 | 82 | // Default constructed iterators and 83 | // const iterators constructed from iterators. 84 | { 85 | typename Array::iterator i1; 86 | typename Array::const_iterator ci1; 87 | typename Array::reverse_iterator r1; 88 | typename Array::const_reverse_iterator cr1; 89 | 90 | #if 0 // RG - MSVC fails to compile these 91 | typename Array::const_iterator ci2 = 92 | typename Array::iterator(); 93 | typename Array::const_reverse_iterator cr2 = 94 | typename Array::reverse_iterator(); 95 | #endif 96 | typename Array::const_iterator ci2 = i1; 97 | typename Array::const_reverse_iterator cr2 = cr1; 98 | boost::ignore_unused_variable_warning(cr2); 99 | } 100 | } 101 | 102 | template 103 | void test_iterators(Array& A, const IterTraits&) { 104 | 105 | // Iterator comparison and arithmetic 106 | { 107 | typedef typename IterTraits::iterator3 iterator; 108 | iterator i1 = A.begin(); 109 | iterator i2 = A.end(); 110 | BOOST_TEST(i1 < i2); 111 | BOOST_TEST((i2 - i1) == typename iterator::difference_type(2)); 112 | } 113 | 114 | // Standard Array Iteration 115 | { 116 | typedef typename IterTraits::iterator3 iterator3; 117 | typedef typename IterTraits::iterator2 iterator2; 118 | typedef typename IterTraits::iterator1 iterator1; 119 | 120 | int vals = 0; 121 | for (iterator3 i = A.begin(); i != A.end(); ++i) 122 | for(iterator2 ii = (*i).begin(); ii != (*i).end(); ++ii) 123 | for(iterator1 iii = (*ii).begin(); iii != (*ii).end(); ++iii) 124 | BOOST_TEST(*iii == vals++); 125 | } 126 | 127 | // Using operator->() on iterators 128 | { 129 | typedef typename IterTraits::iterator3 iterator3; 130 | typedef typename IterTraits::iterator2 iterator2; 131 | typedef typename IterTraits::iterator1 iterator1; 132 | 133 | int vals = 0; 134 | for (iterator3 i = A.begin(); i != A.end(); ++i) 135 | for(iterator2 ii = i->begin(); ii != i->end(); ++ii) 136 | for(iterator1 iii = ii->begin(); iii != ii->end(); ++iii) 137 | BOOST_TEST(*iii == vals++); 138 | } 139 | 140 | // Reverse Iterator Hierarchy Test 141 | { 142 | typedef typename IterTraits::riterator3 riterator3; 143 | typedef typename IterTraits::riterator2 riterator2; 144 | typedef typename IterTraits::riterator1 riterator1; 145 | 146 | int check_iter_val = A.num_elements()-1; 147 | for (riterator3 i = A.rbegin(); i != (riterator3)A.rend(); ++i) 148 | for(riterator2 ii = (*i).rbegin(); ii != (riterator2)(*i).rend(); ++ii) 149 | for(riterator1 iii = (*ii).rbegin(); iii != (riterator1)(*ii).rend(); 150 | ++iii) 151 | BOOST_TEST(*iii == check_iter_val--); 152 | } 153 | ++tests_run; 154 | } 155 | 156 | 157 | template 158 | void access(Array& A, const mutable_array_tag&) { 159 | assign(A); 160 | 161 | construct_iterators(A); 162 | 163 | typedef typename ittraits_generator::type 164 | m_iter_traits; 165 | 166 | typedef typename ittraits_generator::type 167 | c_iter_traits; 168 | test_iterators(A,m_iter_traits()); 169 | test_iterators(A,c_iter_traits()); 170 | 171 | const Array& CA = A; 172 | test_iterators(CA,c_iter_traits()); 173 | } 174 | 175 | template 176 | void access(Array& A, const const_array_tag&) { 177 | construct_iterators(A); 178 | typedef typename ittraits_generator::type 179 | c_iter_traits; 180 | test_iterators(A,c_iter_traits()); 181 | } 182 | 183 | 184 | int 185 | main() 186 | { 187 | return run_generative_tests(); 188 | } 189 | -------------------------------------------------------------------------------- /test/range1.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // range1.cpp - test of index_range 15 | // 16 | 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | int 26 | main() 27 | { 28 | typedef boost::detail::multi_array::index_range range; 29 | 30 | { 31 | // typical range creation and extraction 32 | range r1(-3,5); 33 | BOOST_TEST(r1.start() == -3); 34 | BOOST_TEST(r1.finish() == 5); 35 | BOOST_TEST(r1.stride() == 1); 36 | BOOST_TEST(r1.size(0) == 8); 37 | BOOST_TEST(!r1.is_degenerate()); 38 | BOOST_TEST(r1.get_start(0) == -3); 39 | BOOST_TEST(r1.get_finish(100) == 5); 40 | } 41 | 42 | { 43 | range r2(-3,5,2); 44 | BOOST_TEST(r2.start() == -3); 45 | BOOST_TEST(r2.finish() == 5); 46 | BOOST_TEST(r2.stride() == 2); 47 | BOOST_TEST(r2.size(0) == 4); 48 | BOOST_TEST(!r2.is_degenerate()); 49 | } 50 | 51 | { 52 | // degenerate creation 53 | range r3(5); 54 | BOOST_TEST(r3.start() == 5); 55 | BOOST_TEST(r3.finish() == 6); 56 | BOOST_TEST(r3.stride() == 1); 57 | BOOST_TEST(r3.size(0) == 1); 58 | BOOST_TEST(r3.is_degenerate()); 59 | } 60 | 61 | { 62 | // default range creation 63 | range r4; 64 | BOOST_TEST(r4.get_start(0) == 0); 65 | BOOST_TEST(r4.get_finish(100) == 100); 66 | BOOST_TEST(r4.stride() == 1); 67 | BOOST_TEST(r4.size(0) == 0); 68 | } 69 | 70 | { 71 | // create a range using the setter methods 72 | range r5 = range().stride(2).start(-3).finish(7); 73 | BOOST_TEST(r5.start() == -3); 74 | BOOST_TEST(r5.stride() == 2); 75 | BOOST_TEST(r5.finish() == 7); 76 | BOOST_TEST(r5.size(0) == 5); 77 | } 78 | 79 | // try out all the comparison operators 80 | { 81 | range r6 = -3 <= range().stride(2) < 7; 82 | BOOST_TEST(r6.start() == -3); 83 | BOOST_TEST(r6.stride() == 2); 84 | BOOST_TEST(r6.finish() == 7); 85 | BOOST_TEST(r6.size(0) == 5); 86 | } 87 | 88 | { 89 | range r7 = -3 < range() <= 7; 90 | BOOST_TEST(r7.start() == -2); 91 | BOOST_TEST(r7.stride() == 1); 92 | BOOST_TEST(r7.finish() == 8); 93 | BOOST_TEST(r7.size(0) == 10); 94 | } 95 | 96 | // arithmetic operators 97 | { 98 | range r8 = range(0,5) + 2; 99 | BOOST_TEST(r8.start() == 2); 100 | BOOST_TEST(r8.stride() == 1); 101 | BOOST_TEST(r8.finish() == 7); 102 | BOOST_TEST(r8.size(0) == 5); 103 | } 104 | 105 | { 106 | range r9 = range(0,5) - 2; 107 | BOOST_TEST(r9.start() == -2); 108 | BOOST_TEST(r9.stride() == 1); 109 | BOOST_TEST(r9.finish() == 3); 110 | BOOST_TEST(r9.size(0) == 5); 111 | } 112 | 113 | return boost::report_errors(); 114 | } 115 | -------------------------------------------------------------------------------- /test/regression.cfg: -------------------------------------------------------------------------------- 1 | // Regression suite file for boost::multi_array 2 | 3 | run libs/multi_array/test/constructors.cpp 4 | run libs/multi_array/test/access.cpp 5 | run libs/multi_array/test/compare.cpp 6 | run libs/multi_array/test/iterators.cpp 7 | run libs/multi_array/test/slice.cpp 8 | run libs/multi_array/test/assign.cpp 9 | run libs/multi_array/test/index_bases.cpp 10 | run libs/multi_array/test/storage_order.cpp 11 | run libs/multi_array/test/reshape.cpp 12 | run libs/multi_array/test/range1.cpp 13 | run libs/multi_array/test/idxgen1.cpp 14 | run libs/multi_array/test/stl_interaction.cpp 15 | compile libs/multi_array/test/concept_checks.cpp 16 | 17 | compile-fail libs/multi_array/test/fail_cbracket.cpp 18 | compile-fail libs/multi_array/test/fail_cdata.cpp 19 | compile-fail libs/multi_array/test/fail_citerator.cpp 20 | compile-fail libs/multi_array/test/fail_cparen.cpp 21 | compile-fail libs/multi_array/test/fail_criterator.cpp 22 | compile-fail libs/multi_array/test/fail_csubarray.cpp 23 | compile-fail libs/multi_array/test/fail_csubarray2.cpp 24 | compile-fail libs/multi_array/test/fail_csubarray3.cpp 25 | compile-fail libs/multi_array/test/fail_cview.cpp 26 | compile-fail libs/multi_array/test/fail_cview2.cpp 27 | compile-fail libs/multi_array/test/fail_cview3.cpp 28 | compile-fail libs/multi_array/test/fail_ref_cbracket.cpp 29 | compile-fail libs/multi_array/test/fail_ref_cdata.cpp 30 | compile-fail libs/multi_array/test/fail_ref_citerator.cpp 31 | compile-fail libs/multi_array/test/fail_ref_cparen.cpp 32 | compile-fail libs/multi_array/test/fail_ref_criterator.cpp 33 | compile-fail libs/multi_array/test/fail_ref_csubarray.cpp 34 | compile-fail libs/multi_array/test/fail_ref_csubarray2.cpp 35 | compile-fail libs/multi_array/test/fail_ref_csubarray3.cpp 36 | compile-fail libs/multi_array/test/fail_ref_cview.cpp 37 | compile-fail libs/multi_array/test/fail_ref_cview2.cpp 38 | compile-fail libs/multi_array/test/fail_ref_cview3.cpp 39 | -------------------------------------------------------------------------------- /test/reshape.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // reshape.cpp - testing reshaping functionality 15 | // 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | int 25 | main() 26 | { 27 | const int ndims=3; 28 | typedef boost::multi_array array; 29 | typedef boost::multi_array_ref array_ref; 30 | typedef boost::const_multi_array_ref const_array_ref; 31 | 32 | boost::array dims = {{2,3,4}}; 33 | boost::array new_dims = {{4,3,2}}; 34 | 35 | int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13, 36 | 14,15,16,17,18,19,20,21,22,23}; 37 | const int data_size=24; 38 | 39 | // Basic reshape test 40 | { 41 | array A(dims); 42 | A.assign(data,data+data_size); 43 | 44 | array_ref B(data,dims); 45 | const_array_ref C(data,dims); 46 | 47 | A.reshape(new_dims); 48 | B.reshape(new_dims); 49 | C.reshape(new_dims); 50 | 51 | int* ptr = data; 52 | for (array::index i = 0; i != 4; ++i) 53 | for (array::index j = 0; j != 3; ++j) 54 | for (array::index k = 0; k != 2; ++k) { 55 | BOOST_TEST(A[i][j][k] == *ptr); 56 | BOOST_TEST(B[i][j][k] == *ptr); 57 | BOOST_TEST(C[i][j][k] == *ptr++); 58 | } 59 | } 60 | 61 | // Ensure that index bases are preserved over reshape 62 | { 63 | boost::array bases = {{0, 1, -1}}; 64 | 65 | array A(dims); 66 | A.assign(data,data+data_size); 67 | 68 | array_ref B(data,dims); 69 | const_array_ref C(data,dims); 70 | 71 | A.reindex(bases); 72 | B.reindex(bases); 73 | C.reindex(bases); 74 | 75 | A.reshape(new_dims); 76 | B.reshape(new_dims); 77 | C.reshape(new_dims); 78 | 79 | int* ptr = data; 80 | for (array::index i = 0; i != 4; ++i) 81 | for (array::index j = 1; j != 4; ++j) 82 | for (array::index k = -1; k != 1; ++k) { 83 | BOOST_TEST(A[i][j][k] == *ptr); 84 | BOOST_TEST(B[i][j][k] == *ptr); 85 | BOOST_TEST(C[i][j][k] == *ptr++); 86 | } 87 | } 88 | 89 | return boost::report_errors(); 90 | } 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /test/resize.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // resize.cpp - Test of resizing multi_arrays 15 | // 16 | 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | 23 | int main() { 24 | 25 | typedef boost::multi_array marray; 26 | 27 | 28 | int A_data[] = { 29 | 0,1,2,3, 30 | 4,5,6,7, 31 | 8,9,10,11, 32 | 33 | 12,13,14,15, 34 | 16,17,18,19, 35 | 20,21,22,23 36 | }; 37 | 38 | int A_resize[] = { 39 | 0,1, 40 | 4,5, 41 | 8,9, 42 | 43 | 12,13, 44 | 16,17, 45 | 20,21, 46 | 47 | 0,0, 48 | 0,0, 49 | 0,0, 50 | 51 | 0,0, 52 | 0,0, 53 | 0,0 54 | }; 55 | 56 | // resize through the extent_gen interface 57 | { 58 | marray A(boost::extents[2][3][4]); 59 | A.assign(A_data,A_data+(2*3*4)); 60 | A.resize(boost::extents[4][3][2]); 61 | BOOST_TEST(std::equal(A_resize,A_resize+(4*3*2),A.data())); 62 | } 63 | 64 | // resize through the Collection 65 | { 66 | marray A(boost::extents[2][3][4]); 67 | A.assign(A_data,A_data+(2*3*4)); 68 | boost::array new_extents = {{4,3,2}}; 69 | A.resize(new_extents); 70 | BOOST_TEST(std::equal(A_resize,A_resize+(4*3*2),A.data())); 71 | } 72 | 73 | // default construct all the new elements (in this case, all elements) 74 | { 75 | marray defaultA; 76 | defaultA.resize(boost::extents[2][3][4]); 77 | BOOST_TEST(std::accumulate(defaultA.data(), 78 | defaultA.data()+(2*3*4),0) == 0); 79 | } 80 | 81 | 82 | 83 | // verify the preservation of storage order 84 | { 85 | int tiling_graph_storage_order[] = {2, 0, 1}; 86 | bool tiling_graph_index_order[] = {true, true, true}; 87 | 88 | marray A(boost::extents[3][4][2], 89 | boost::general_storage_order<3>(tiling_graph_storage_order, 90 | tiling_graph_index_order)); 91 | 92 | 93 | int value = 0; 94 | for (int i = 0; i < 3; i++) { 95 | for (int j = 0; j < 4; j++) { 96 | for (int k = 0; k < 2; k++) { 97 | *(A.data() + value) = value; 98 | ++value; 99 | } 100 | } 101 | } 102 | 103 | // "Resize" to the same size 104 | A.resize(boost::extents[3][4][2]); 105 | 106 | int check = 0; 107 | for (int x = 0; x < 3; x++) { 108 | for (int y = 0; y < 4; y++) { 109 | for (int z = 0; z < 2; z++) { 110 | BOOST_TEST(*(A.data() + check) == check); 111 | ++check; 112 | } 113 | } 114 | } 115 | } 116 | 117 | // Resizing that changes index bases too (impl bug caused an assert) 118 | { 119 | typedef boost::multi_array ar_t; 120 | typedef ar_t::extent_range range; 121 | ar_t ar; 122 | ar.resize(boost::extents[range(-3, 3)]); 123 | } 124 | 125 | 126 | return boost::report_errors(); 127 | } 128 | -------------------------------------------------------------------------------- /test/reverse_view.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // reverse_view.cpp - a small test of creating a view with negative strides 15 | // 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | int 22 | main() 23 | { 24 | using namespace boost; 25 | 26 | 27 | // One-dimensional array with views 28 | double data[] = { 1, 2, 3, 4 }; 29 | double rdata[] = { 4, 3, 2, 1 }; 30 | 31 | typedef multi_array< double, 1 > array; 32 | array A(extents[4]); 33 | A.assign(data,data+4); 34 | 35 | typedef array::index_range range; 36 | array::array_view<1>::type B = A[indices[range(3, -1, -1)]]; 37 | 38 | for(multi_array_types::size_type i = 0; i != B.size(); ++i) { 39 | BOOST_TEST(B[i] == rdata[i]); 40 | } 41 | 42 | return boost::report_errors(); 43 | } 44 | -------------------------------------------------------------------------------- /test/slice.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // slice.cpp - testing out slicing on a matrices 15 | // 16 | 17 | #include "generative_tests.hpp" 18 | #include 19 | #include 20 | #include 21 | 22 | template 23 | struct view_traits_mutable { 24 | public: 25 | #if 0 // RG - MSVC can't handle templates nested in templates. Use traits 26 | typedef typename Array::template array_view<3>::type array_view3; 27 | typedef typename Array::template array_view<2>::type array_view2; 28 | #endif 29 | typedef typename boost::array_view_gen::type array_view3; 30 | typedef typename boost::array_view_gen::type array_view2; 31 | }; 32 | 33 | template 34 | struct view_traits_const { 35 | #if 0 // RG - MSVC can't handle templates nested in templates. Use traits 36 | typedef typename Array::template const_array_view<3>::type array_view3; 37 | typedef typename Array::template const_array_view<2>::type array_view2; 38 | #endif 39 | typedef typename boost::const_array_view_gen::type array_view3; 40 | typedef typename boost::const_array_view_gen::type array_view2; 41 | }; 42 | 43 | 44 | // Meta-program selects the proper view_traits implementation. 45 | template 46 | struct view_traits_generator : 47 | boost::mpl::if_< boost::is_same, 48 | view_traits_const, 49 | view_traits_mutable > 50 | {}; 51 | 52 | 53 | template 54 | void test_views(Array& A, const ViewTraits&) { 55 | typedef typename Array::index index; 56 | typedef typename Array::index_range range; 57 | typename Array::index_gen indices; 58 | 59 | const index idx0 = A.index_bases()[0]; 60 | const index idx1 = A.index_bases()[1]; 61 | const index idx2 = A.index_bases()[2]; 62 | 63 | // Standard View 64 | { 65 | typename ViewTraits::array_view3 B = A[ 66 | indices[range(idx0+0,idx0+2)] 67 | [range(idx1+1,idx1+3)] 68 | [range(idx2+0,idx2+4,2)] 69 | ]; 70 | 71 | for (index i = 0; i != 2; ++i) 72 | for (index j = 0; j != 2; ++j) 73 | for (index k = 0; k != 2; ++k) { 74 | BOOST_TEST(B[i][j][k] == A[idx0+i][idx1+j+1][idx2+k*2]); 75 | boost::array elmts; 76 | elmts[0]=i; elmts[1]=j; elmts[2]=k; 77 | BOOST_TEST(B(elmts) == A[idx0+i][idx1+j+1][idx2+k*2]); 78 | } 79 | } 80 | // Degenerate dimensions 81 | { 82 | typename ViewTraits::array_view2 B = 83 | A[indices[range(idx0+0,idx0+2)][idx1+1][range(idx2+0,idx2+4,2)]]; 84 | 85 | for (index i = 0; i != 2; ++i) 86 | for (index j = 0; j != 2; ++j) { 87 | BOOST_TEST(B[i][j] == A[idx0+i][idx1+1][idx2+j*2]); 88 | boost::array elmts; 89 | elmts[0]=i; elmts[1]=j; 90 | BOOST_TEST(B(elmts) == A[idx0+i][idx1+1][idx2+j*2]); 91 | } 92 | } 93 | 94 | // Flip the third dimension 95 | { 96 | typename ViewTraits::array_view3 B = A[ 97 | indices[range(idx0+0,idx0+2)] 98 | [range(idx1+0,idx1+2)] 99 | [range(idx2+2,idx2+0,-1)] 100 | ]; 101 | 102 | // typename ViewTraits::array_view3 B = 103 | // A[indices[range(idx0+0,idx0+2)][idx1+1][range(idx2+0,idx2+4,2)]]; 104 | 105 | for (index i = 0; i != 2; ++i) 106 | for (index j = 0; j != 2; ++j) 107 | for (index k = 0; k != 2; ++k) { 108 | BOOST_TEST(B[i][j][k] == A[idx0+i][idx1+j][idx2+2-k]); 109 | boost::array elmts; 110 | elmts[0]=i; elmts[1]=j; elmts[2]=k; 111 | BOOST_TEST(B(elmts) == A[idx0+i][idx1+j][idx2+2-k]); 112 | } 113 | } 114 | 115 | ++tests_run; 116 | } 117 | 118 | 119 | template 120 | void access(Array& A, const mutable_array_tag&) { 121 | assign(A); 122 | 123 | typedef typename view_traits_generator::type 124 | m_view_traits; 125 | 126 | typedef typename view_traits_generator::type 127 | c_view_traits; 128 | 129 | test_views(A,m_view_traits()); 130 | test_views(A,c_view_traits()); 131 | 132 | const Array& CA = A; 133 | test_views(CA,c_view_traits()); 134 | } 135 | 136 | template 137 | void access(Array& A, const const_array_tag&) { 138 | typedef typename view_traits_generator::type 139 | c_view_traits; 140 | test_views(A,c_view_traits()); 141 | } 142 | 143 | 144 | int main() { 145 | return run_generative_tests(); 146 | } 147 | -------------------------------------------------------------------------------- /test/stl_interaction.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // stl_interaction.cpp - Make sure multi_arrays work with STL containers. 15 | // 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | int 24 | main() 25 | { 26 | using boost::extents; 27 | using boost::indices; 28 | typedef boost::multi_array_types::index_range range; 29 | typedef boost::multi_array array3; 30 | typedef boost::multi_array array2; 31 | 32 | typedef std::vector array3vec; 33 | 34 | int data[] = { 35 | 0,1,2,3, 36 | 4,5,6,7, 37 | 8,9,10,11, 38 | 39 | 12,13,14,15, 40 | 16,17,18,19, 41 | 20,21,22,23 42 | }; 43 | const int data_size = 24; 44 | 45 | int insert[] = { 46 | 99,98, 47 | 97,96, 48 | }; 49 | const int insert_size = 4; 50 | array3 myarray(extents[2][3][4]); 51 | myarray.assign(data,data+data_size); 52 | 53 | array3vec myvec(5,myarray); 54 | BOOST_TEST(myarray == myvec[1]); 55 | 56 | array3::array_view<2>::type myview = 57 | myarray[indices[1][range(0,2)][range(1,3)]]; 58 | 59 | array2 filler(extents[2][2]); 60 | filler.assign(insert,insert+insert_size); 61 | 62 | // Modify a portion of myarray through a view (myview) 63 | myview = filler; 64 | 65 | 66 | myvec.push_back(myarray); 67 | 68 | BOOST_TEST(myarray != myvec[1]); 69 | BOOST_TEST(myarray == myvec[5]); 70 | 71 | return boost::report_errors(); 72 | } 73 | -------------------------------------------------------------------------------- /test/storage_order.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // storage_order.cpp - testing storage_order-isms. 15 | // 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | 23 | int 24 | main() 25 | { 26 | const int ndims=3; 27 | 28 | int data_row[] = { 29 | 0,1,2,3, 30 | 4,5,6,7, 31 | 8,9,10,11, 32 | 33 | 12,13,14,15, 34 | 16,17,18,19, 35 | 20,21,22,23 36 | }; 37 | 38 | int data_col[] = { 39 | 0,12, 40 | 4,16, 41 | 8,20, 42 | 43 | 1,13, 44 | 5,17, 45 | 9,21, 46 | 47 | 2,14, 48 | 6,18, 49 | 10,22, 50 | 51 | 3,15, 52 | 7,19, 53 | 11,23 54 | }; 55 | const int num_elements = 24; 56 | 57 | // fortran storage order 58 | { 59 | typedef boost::multi_array array; 60 | 61 | array::extent_gen extents; 62 | array A(extents[2][3][4],boost::fortran_storage_order()); 63 | 64 | A.assign(data_col,data_col+num_elements); 65 | 66 | int* num = data_row; 67 | for (array::index i = 0; i != 2; ++i) 68 | for (array::index j = 0; j != 3; ++j) 69 | for (array::index k = 0; k != 4; ++k) 70 | BOOST_TEST(A[i][j][k] == *num++); 71 | } 72 | 73 | // Mimic fortran_storage_order using 74 | // general_storage_order data placement 75 | { 76 | typedef boost::general_storage_order storage; 77 | typedef boost::multi_array array; 78 | 79 | array::size_type ordering[] = {0,1,2}; 80 | bool ascending[] = {true,true,true}; 81 | 82 | array::extent_gen extents; 83 | array A(extents[2][3][4], storage(ordering,ascending)); 84 | 85 | A.assign(data_col,data_col+num_elements); 86 | 87 | int* num = data_row; 88 | for (array::index i = 0; i != 2; ++i) 89 | for (array::index j = 0; j != 3; ++j) 90 | for (array::index k = 0; k != 4; ++k) 91 | BOOST_TEST(A[i][j][k] == *num++); 92 | } 93 | 94 | // general_storage_order with arbitrary storage order 95 | { 96 | typedef boost::general_storage_order storage; 97 | typedef boost::multi_array array; 98 | 99 | array::size_type ordering[] = {2,0,1}; 100 | bool ascending[] = {true,true,true}; 101 | 102 | array::extent_gen extents; 103 | array A(extents[2][3][4], storage(ordering,ascending)); 104 | 105 | int data_arb[] = { 106 | 0,1,2,3, 107 | 12,13,14,15, 108 | 109 | 4,5,6,7, 110 | 16,17,18,19, 111 | 112 | 8,9,10,11, 113 | 20,21,22,23 114 | }; 115 | 116 | A.assign(data_arb,data_arb+num_elements); 117 | 118 | int* num = data_row; 119 | for (array::index i = 0; i != 2; ++i) 120 | for (array::index j = 0; j != 3; ++j) 121 | for (array::index k = 0; k != 4; ++k) 122 | BOOST_TEST(A[i][j][k] == *num++); 123 | } 124 | 125 | 126 | // general_storage_order with descending dimensions. 127 | { 128 | const int ndims=3; 129 | typedef boost::general_storage_order storage; 130 | typedef boost::multi_array array; 131 | 132 | array::size_type ordering[] = {2,0,1}; 133 | bool ascending[] = {false,true,true}; 134 | 135 | array::extent_gen extents; 136 | array A(extents[2][3][4], storage(ordering,ascending)); 137 | 138 | int data_arb[] = { 139 | 12,13,14,15, 140 | 0,1,2,3, 141 | 142 | 16,17,18,19, 143 | 4,5,6,7, 144 | 145 | 20,21,22,23, 146 | 8,9,10,11 147 | }; 148 | 149 | A.assign(data_arb,data_arb+num_elements); 150 | 151 | int* num = data_row; 152 | for (array::index i = 0; i != 2; ++i) 153 | for (array::index j = 0; j != 3; ++j) 154 | for (array::index k = 0; k != 4; ++k) 155 | BOOST_TEST(A[i][j][k] == *num++); 156 | } 157 | 158 | return boost::report_errors(); 159 | } 160 | -------------------------------------------------------------------------------- /test/storage_order_convert.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // test out my new storage_order stuff 15 | // 16 | 17 | #include 18 | 19 | #include 20 | 21 | int 22 | main() { 23 | 24 | using namespace boost; 25 | 26 | array c_ordering = {{4,3,2,1,0}};; 27 | array fortran_ordering = {{0,1,2,3,4}}; 28 | array ascending = {{true,true,true,true,true}}; 29 | general_storage_order<5> c_storage(c_ordering.begin(), 30 | ascending.begin()); 31 | general_storage_order<5> fortran_storage(fortran_ordering.begin(), 32 | ascending.begin()); 33 | 34 | BOOST_TEST(c_storage == (general_storage_order<5>) c_storage_order()); 35 | BOOST_TEST(fortran_storage == 36 | (general_storage_order<5>) fortran_storage_order()); 37 | 38 | return boost::report_errors(); 39 | } 40 | -------------------------------------------------------------------------------- /test/vc_death.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2002 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Boost.MultiArray Library 8 | // Authors: Ronald Garcia 9 | // Jeremy Siek 10 | // Andrew Lumsdaine 11 | // See http://www.boost.org/libs/multi_array for documentation. 12 | 13 | // 14 | // index_bases - test of the index_base modifying facilities. 15 | // 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | int 25 | main() 26 | { 27 | typedef boost::multi_array array; 28 | typedef array::array_view<3>::type array_view; 29 | 30 | typedef array::extent_range erange; 31 | typedef array::index_range irange; 32 | 33 | array::extent_gen extents; 34 | array::index_gen indices; 35 | 36 | // Construct with nonzero bases 37 | { 38 | 39 | array A(extents[erange(1,4)][erange(2,5)][erange(3,6)]); 40 | array_view E = A[indices[irange(1,2)][irange(1,2)][irange(1,2)]]; 41 | 42 | } 43 | return boost::report_errors(); 44 | } 45 | --------------------------------------------------------------------------------