├── .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 |
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 |
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 |
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 | Gnu C++ Compiler v2.95.2 (compile with -ftemplate-depth-50 )
41 | Gnu C++ Compiler v3.0.2
42 | Kuck and Associates C++ Compiler v4.0f
43 | Microsoft Visual C++ v6.0 sp5
44 | Comeau C++ Compiler v4.2.45 beta 2 (libcomo beta 14)
45 | Intel C++ Compiler v5.0 (with MS lib v6.0 sp5)
46 | 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 | Pursue and document performance issues related to compilers and
60 | implementation.
61 | More comprehensive examples of using the library components.
62 | 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 |
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 |
34 | B.M - abbreviation for Boost.MultiArray.
35 |
36 | primary components - refers to boost::multi_array ,
37 | boost::const_multi_array_ref , and
38 | boost::multi_array_ref .
39 |
40 | array types - refers to all the primary components, plus for each
41 | primary component "array", the types array::const_subarray ,
42 | array::subarray , array::const_array_view , and
43 | array::array_view
44 |
45 |
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 |
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 |
305 |
306 |
307 |
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 | const_multi_array_ref
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 | ExtentList 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 | multi_array_ref
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 | ExtentList 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 | Array 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