Blitz User Manual
Blitz User Manual
Blitz User Manual
Todd Veldhuizen
The Blitz++ library is licensed under both the GPL and the more permissive Blitz++ Artistic
License. Take your pick. They are detailed in GPL and LICENSE, respectively. The artistic
license is more appropriate for commercial use, since it lacks the viral properties of the GPL.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
c 19962003 Free Software Foundation, Inc.
Copyright
Table of Contents
1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1
1.2
1
1
1
1
1
2
2
2
2
2
2
2
2
3
3
3
3
3
3
4
5
5
5
5
5
6
6
6
6
7
7
7
Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1.1 Template parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1.2 Array types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1.3 A simple example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.1.4 Storage orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2 Public types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3 Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.1 Default constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.2 Creating an array from an expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.3 Constructors which take extent parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.4 Constructors with Range arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.3.5 Referencing another array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.3.6 Constructing an array from an expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
ii
Blitz++
2.3.7 Creating an array from pre-existing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3.8 Interlacing arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3.9 A note about reference counting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4 Indexing, subarrays, and slicing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.1 Indexing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.2 Subarrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.3 RectDomain and StridedDomain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.4 Slicing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.5 More about Range objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.6 A note about assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.7 An example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5 Debug mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.6 Member functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.6.1 A note about dimension parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Why stop at eleven? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.6.2 Member function descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.7 Global functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.8 Inputting and Outputting Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.8.1 Output formatting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.8.2 Inputting arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.9 Array storage orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.9.1 Fortran and C-style arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Row major vs. column major . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Bases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.9.2 Creating custom storage orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
In higher dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Reversed dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Setting the base vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Working simultaneously with different storage orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Debug dumps of storage order information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A note about storage orders and initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.9.3 Storage orders example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
14
14
14
15
15
16
17
17
18
19
19
20
20
21
21
25
27
27
27
29
29
29
29
30
30
31
31
31
32
32
32
Array Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.1
3.2
3.3
35
35
36
36
36
36
37
37
39
39
40
40
40
41
43
43
43
44
45
47
iii
3.13
3.14
3.15
Complete reductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Partial Reductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
where statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Stencils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4.1
4.2
4.3
4.4
TinyVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7.1
7.2
7.3
7.4
7.5
7.6
7.7
7.8
61
61
62
63
63
Indirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
6.1
6.2
6.3
51
51
52
52
53
54
55
56
56
56
57
57
57
58
58
59
69
69
69
70
70
70
70
70
iv
Blitz++
10
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Note: Parallel random number generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Seeding a random number generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Detailed description of RNGs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Template parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Member functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Detailed listing of RNGs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.7.1 random/uniform.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.7.2 random/normal.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.7.3 random/exponential.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.7.4 random/beta.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.7.5 random/chisquare.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.7.6 random/gamma.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.7.7 random/F.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.7.8 random/discrete-uniform.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Numeric properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10.1
10.2
11
73
74
74
74
75
75
75
75
75
76
76
76
76
76
76
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Function descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
11.1
11.2
Short Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3 Array Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4 Stencils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5 Multicomponent, complex, and user type Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . 61
6 Indirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
7 TinyVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
8 Parallel Computing with Blitz++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
9 Random Number Generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
10 Numeric properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
11 Frequently Asked Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Blitz Keyword Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Concept Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Chapter 1: Introduction
1 Introduction
1.1 About this document
To use the Blitz++ library, you will need a compiler with near-ISO/ANSI C++ syntax support
(see the following section for possible compilers). Information on what platforms are supported
is available from http://oonumerics.org/blitz/platforms/. To download Blitz++, please go
to the download page at http://oonumerics.org/blitz/download/.
If you need to do something that Blitz++ doesnt support, see a possible improvement, or
notice an error in the documentation, please send a note to one of the Blitz++ mailing lists
(described later).
Blitz++
Blitz++ and are not supported. Blitz can be compiled under Visual Studio by using the Intel
plug-in C++ compiler for Windows.
Chapter 1: Introduction
1.2.14 Fujitsu
This platform and compiler are no longer being actively supported.
Blitz++
.
.
Then go into the blitz-VERSION directory, and type:
./configure CXX=[compiler]
where [compiler] is one of xlc++, icpc, pathCC, xlC, cxx, aCC, CC, g++, KCC, pgCC or FCC.
(If you do not choose a C++ compiler, the configure script will attempt to find an appropriate
compiler for the current platform.)
By default, the configure script will use a particular set of options with each C++ compiler.
You can disable these default settings and then substitute your own preferred compiler options
with the CXXFLAGS variable, using this syntax:
./configure CXX=g++ --disable-cxx-flags-preset CXXFLAGS="-ftemplate-depth-50"
If you are interested in benchmarking, you may want to use the option --with-blas=...
to specify the path where the blas library is found. Run the configure script with the option
--help to see all the available options.
Once the configure script is done, you can do any of these things:
make lib
make check-testsuite
Make the blitz library plus build and run the testsuite.
make check-examples
Make the blitz library plus build and run the examples.
make check-benchmarks
Make the blitz library plus build and run the benchmarks.
make all
make install
Build the blitz library and documentation and install, along with the blitz header
files, in prefix directory.
Building the benchmark programs requires both a Fortran 77 and Fortran 90 compiler.
random
src
lib
Location of libblitz.a
doc
testsuite
Testsuite programs
examples
Example programs
benchmarks
Benchmark programs
Chapter 1: Introduction
Blitz++
myprogram1.o
myprogram2.o
clean:
-rm -f *.o $(TARGETS)
There are more example makefiles in the examples, testsuite, and benchmarks directories of
the distribution.
Chapter 1: Introduction
if you continue to experience a problem with using Blitz++, there is a Bugs link that allows you
to file a bug report and check the status of existing bug reports.
1.7.3 blitz-devel
Blitz++ is in open development: anyone can contribute features and code to the library. If you
are interested in helping out with coding or porting, you should start by subscribing to the
blitz-devel mailing list.
This list is also an appropriate place to send suggestions for features; just send email to
blitz-devel@lists.sourceforge.net. We cant implement it if you dont suggest it.
Archives of this list are available from the Blitz++ web site.
1.7.4 blitz-support
This mailing list is for posting and answering questions about using the Blitz++ library. Anyone
can post questions; anyone can answer.
Chapter 2: Arrays
2 Arrays
2.1 Getting started
Currently, Blitz++ provides a single array class, called Array<T_numtype,N_rank>. This array
class provides a dynamically allocated N-dimensional array, with reference counting, arbitrary
storage ordering, subarrays and slicing, flexible expression handling, and many other useful
features.
The contents of a newly-created array are garbage. To initialize the array, you can write:
y = 0;
and all the elements of the array will be set to zero. If the contents of the array are known,
you can initialize it using a comma-delimited list of values. For example, this code excerpt sets
y equal to a 4x4 identity matrix:
y = 1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1;
then
10
Blitz++
Nested homogeneous arrays using TinyVector and TinyMatrix, in which each element
is a fixed-size vector or array. For example, Array<TinyVector<float,3>,3> is a threedimensional vector field.
Nested heterogeneous arrays, such as Array<Array<int,1>,1>, in which each element is a
variable-length array.
Chapter 2: Arrays
11
2.3 Constructors
2.3.1 Default constructor
Array();
Array(GeneralArrayStorage<N_rank> storage)
The default constructor creates a C-style array of zero size. Any attempt to access data in
the array may result in a run-time error, because there isnt any data to access!
An optional argument specifies a storage order for the array.
Arrays created using the default constructor can subsequently be given data by the resize(),
resizeAndPreserve(), or reference() member functions.
If you provide fewer than N_rank arguments, the missing arguments will be filled in using the last provided
argument. However, for code clarity, it makes sense to provide all N_rank parameters.
12
Blitz++
r1);
r1, Range r2);
r1, Range r2, Range r3);
r1, Range r2, Range r3, ..., Range r11);
Chapter 2: Arrays
13
14
Blitz++
Chapter 2: Arrays
15
secondRank
A(7,0,0)
thirdRank
firstRank
2.4.1 Indexing
There are two ways to get a single element from an array. The simplest is to provide a set of
integer operands to operator():
A(7,0,0) = 5;
cout << "A(7,0,0) = " << A(7,0,0) << endl;
This version of indexing is available for arrays of rank one through eleven. If the array object
isnt const, the return type of operator() is a reference; if the array object is const, the return
type is a value.
You can also get an element by providing an operand of type TinyVector<int,N_rank>
where N_rank is the rank of the array object:
TinyVector<int,3> index;
index = 7, 0, 0;
A(index) = 5;
cout << "A(7,0,0) = " << A(index) << endl;
This version of operator() is also available in a const-overloaded version.
Its possible to use fewer than N_rank indices. However, missing indices are assumed to be
zero, which will cause bounds errors if the valid index range does not include zero (e.g. Fortran
arrays). For this reason, and for code clarity, its a bad idea to omit indices.
2.4.2 Subarrays
You can obtain a subarray by providing Range operands to operator(). A Range object represents a set of regularly spaced index values. For example,
Array<int,3> B = A(Range(5,7), Range(5,7), Range(0,2));
The object B now refers to elements (5..7,5..7,0..2) of the array A.
The returned subarray is of type Array<T_numtype,N_rank>. This means that subarrays
can be used wherever arrays can be: in expressions, as lvalues, etc. Some examples:
// A three-dimensional stencil (used in solving PDEs)
Range I(1,6), J(1,6), K(1,6);
B = (A(I,J,K) + A(I+1,J,K) + A(I-1,J,K) + A(I,J+1,K)
+ A(I,J-1,K) + A(I,J+1,K) + A(I,J,K+1) + A(I,J,K-1)) / 7.0;
// Set a subarray of A to zero
A(Range(5,7), Range(5,7), Range(5,7)) = 0.;
The bases of the subarray are equal to the bases of the original array:
16
Blitz++
// 4..7, 8..11
Chapter 2: Arrays
17
2.4.4 Slicing
A combination of integer and Range operands produces a slice. Each integer operand reduces
the rank of the array by one. For example:
Array<int,2> F = A(Range::all(), 2, Range::all());
Array<int,1> G = A(2,
7, Range::all());
Range and integer operands can be used in any combination, for arrays up to rank 11.
Caution: Using a combination of integer and Range operands requires a newer language
feature (partial ordering of member templates) which not all compilers support. If your compiler
does provide this feature, BZ_PARTIAL_ORDERING will be defined in <blitz/config.h>. If not,
you can use this workaround:
Array<int,3> F = A(Range::all(), Range(2,2), Range::all());
Array<int,3> G = A(Range(2,2),
Range(7,7), Range::all());
[
[
[
[
[
[
0 1
3 4
3 4
0 1
1 3
5 3
//
2
5
5
2
5
1
[
3
]
6
3
]
]
0
4 5 6 ]
]
]
2 4 6 ]
return 0;
}
The optional third constructor argument specifies a stride. For example, Range(1,5,2) refers
to elements [1 3 5]. Strides can also be negative: Range(5,1,-2) refers to elements [5 3 1].
Note that if you use the same Range frequently, you can just construct one object and use it
multiple times. For example:
Range all = Range::all();
A(0,all,all) = A(N-1,all,all);
A(all,0,all) = A(all,N-1,all);
A(all,all,0) = A(all,all,N-1);
Heres an example of using strides with a two-dimensional array:
#include <blitz/array.h>
18
Blitz++
0
1
2
3
4
A
5
6
7
0
1 2
0
1
B
2
x
0
0
0
0
0
0
0
0
(0,7)
0 0 0
1 0 0
0 0 0
0 0 0
1 0 0
0 0 0
0 0 0
1 0 0 ]
// Statement 1
// Statement 2
Chapter 2: Arrays
19
Statement 1 results in a portion of Bs data being copied into A. After Statement 1, both
A and B have their own (nonoverlapping) blocks of data. Contrast this behaviour with that of
Statement 2, which is not an assignment (it uses the copy constructor). After Statement 2 is
executed, the array C is a reference (or alias) to Bs data.
So to summarize: If you want to copy the rhs, use an assignment operator. If you want to
reference (or alias) the rhs, use the copy constructor (or alternately, the reference() member
function in Section 2.6 [Array members], page 20).
Very important: whenever you have an assignment operator (=, +=, -=, etc.) the lhs must
have the same shape as the rhs. If you want the array on the left hand side to be resized to the
proper shape, you must do so by calling the resize method, for example:
A.resize(B.shape());
// Make A the same size as B
A = B;
2.4.7 An example
#include <blitz/array.h>
using namespace blitz;
int main()
{
Array<int,2> A(6,6), B(3,3);
// Set the upper left quadrant of A to 5
A(Range(0,2), Range(0,2)) = 5;
// Set the upper right quadrant of A to an identity matrix
B = 1, 0, 0,
0, 1, 0,
0, 0, 1;
A(Range(0,2), Range(3,5)) = B;
// Set the fourth row to 1
A(3, Range::all()) = 1;
// Set the last two rows to 0
A(Range(4, toEnd), Range::all()) = 0;
// Set the bottom right element to 8
A(5,5) = 8;
cout << "A = " << A << endl;
return 0;
}
The output:
A = (0,5)
[ 5 5 5 1
5 5 5 0
5 5 5 0
1 1 1 1
0 0 0 0
0 0 0 0
x
0
1
0
1
0
0
(0,5)
0
0
1
1
0
8 ]
20
Blitz++
In debugging mode, your programs will run very slowly. This is because Blitz++ is doing lots
of precondition checking and bounds checking. When it detects something fishy, it will likely
halt your program and display an error message.
For example, this program attempts to access an element of a 4x4 array which doesnt exist:
#include <blitz/array.h>
using namespace blitz;
int main()
{
Array<complex<float>, 2> Z(4,4);
Z = complex<float>(0.0, 1.0);
Z(4,4) = complex<float>(1.0, 0.0);
return 0;
}
When compiled with -DBZ_DEBUG, the out of bounds indices are detected and an error message
results:
[Blitz++] Precondition failure: Module ../../blitz/array-impl.h line 1339
Array index out of range: (4, 4)
Lower bounds: (0,0)
Length:
(4,4)
debug: ../../blitz/array-impl.h:1339: bool blitz::Array<P_numtype,
N_rank>::assertInRange(int, int) const [with P_numtype = std::complex<float>,
int N_rank = 2]: Assertion 0 failed.
Precondition failures send their error messages to the standard error stream (cerr). After
displaying the error message, assert(0) is invoked.
Chapter 2: Arrays
21
A.reverse(thirdDim);
This code is clearer: you can see that the parameter refers to a dimension, and it isnt much
of a leap to realize that its reversing the element ordering in the third dimension.
If you find firstDim, secondDim, ... aesthetically unpleasing, there are equivalent symbols
firstRank, secondRank, thirdRank, ..., eleventhRank.
22
Blitz++
Chapter 2: Arrays
23
Now the B array refers to the 2nd component of every element in A. Note: for complex
arrays, special global functions real(A) and imag(A) are provided to obtain real and imaginary
components of an array. See the Global Functions section.
void
free();
This method resizes an array to zero size. If the array data is not being shared with another
array object, then it is freed.
bool
isMajorRank(int dimension) const;
Returns true if the dimension has the largest stride. For C-style arrays (the default), the first
dimension always has the largest stride. For Fortran-style arrays, the last dimension has the
largest stride. See also isMinorRank() below and the note about dimension parameters such as
firstDim in the previous section.
bool
isMinorRank(int dimension) const;
Returns true if the dimension does not have the largest stride. See also isMajorRank().
bool
isRankStoredAscending(int dimension) const;
Returns true if the dimension is stored in ascending order in memory. This is the default.
It will only return false if you have reversed a dimension using reverse() or have created a
custom storage order with a descending dimension.
bool
isStorageContiguous() const;
Returns true if the array data is stored contiguously in memory. If you slice the array or
work on subarrays, there can be skips the array data is interspersed with other data not part
of the array. See also the various data..() functions. If you need to ensure that the storage is
contiguous, try reference(copy()).
int
lbound(int dimension) const;
TinyVector<int,N_rank>
lbound() const;
The first version returns the lower bound of the valid index range for a dimension. The second
version returns a vector of lower bounds for all dimensions. The lower bound is the first valid
index value. If youre using a C-style array (the default), the lbound will be zero; Fortran-style
arrays have lbound equal to one. The lbound can be different for each dimension, but only if you
deliberately set them that way using a Range constructor or a custom storage ordering. This
function is equivalent to base(dimension). See the note about dimension parameters such as
firstDim in the previous section.
void
makeUnique();
If the arrays data is being shared with another Blitz++ array object, this member function
creates a copy so the array object has a unique view of the data.
int
numElements() const;
Returns the total number of elements in the array, calculated by taking the product of the
extent in each dimension. Same as size().
const TinyVector<int, N_rank>&
ordering() const;
int
ordering(int storageRankIndex) const;
These member functions return information about how the data is ordered in memory. The
first version returns the complete ordering vector; the second version returns a single element
from the ordering vector. The argument for the second version must be in the range 0 .. N_
rank-1. The ordering vector is a list of dimensions in increasing order of stride; ordering(0)
will return the dimension number with the smallest stride, and ordering(N_rank-1) will return
the dimension number with largest stride. For a C-style array, the ordering vector contains the
elements (N_rank-1, N_rank-2, ..., 0). For a Fortran-style array, the ordering vector is (0, 1,
..., N_rank-1). See also the description of custom storage orders in section Section 2.9 [Array
storage], page 29.
24
Blitz++
int
rank() const;
Returns the rank (number of dimensions) of the array. The return value is equal to N_rank.
Equivalent to dimensions().
void
reference(Array<T_numtype,N_rank>& A);
This causes the array to adopt another arrays data as its own. After this member function
is used, the array object and the array A are indistinguishable they have identical sizes, index
ranges, and data. The data is shared between the two arrays.
void
reindexSelf(const TinyVector<int,N_rank>&);
Array<T,N>
reindex(const TinyVector<int,N_rank>&);
These methods reindex an array to use a new base vector. The first version reindexes the
array, and the second just returns a reindexed view of the array, leaving the original array
unmodified.
void
resize(int extent1, ...);
void
resize(const TinyVector<int,N_rank>&);
These functions resize an array to the specified size. If the array is already the size specified,
then no memory is allocated. After resizing, the contents of the array are garbage. See also
resizeAndPreserve().
void
resizeAndPreserve(int extent1, ...);
void
resizeAndPreserve(const TinyVector<int,N_rank>&);
These functions resize an array to the specified size. If the array is already the size specified,
then no change occurs (the array is not reallocated and copied). The contents of the array are
preserved whenever possible; if the new array size is smaller, then some data will be lost. Any
new elements created by resizing the array are left uninitialized.
Array<T,N>
reverse(int dimension);
void
reverseSelf(int dimension);
This method reverses the array in the specified dimension.
For example, if
reverse(firstDim) is invoked on a 2-dimensional array, then the ordering of rows in the array
will be reversed; reverse(secondDim) would reverse the order of the columns. Note that this
is implemented by twiddling the strides of the array, and doesnt cause any data copying. The
first version returns a reversed view of the array data; the second version applies the reversal
to the array itself.
int
rows() const;
Returns the extent (length) of the array in the first dimension. This function is equivalent
to extent(firstDim). See also columns(), and depth().
int
size() const;
Returns the total number of elements in the array, calculated by taking the product of the
extent in each dimension. Same as numElements().
const TinyVector<int, N_rank>&
shape() const;
Returns the vector of extents (lengths) of the array.
const TinyVector<int, N_rank>&
stride() const;
int
stride(int dimension) const;
The first version returns the stride vector; the second version returns the stride associated
with a dimension. A stride is the distance between pointers to two array elements which
are adjacent in a dimension. For example, A.stride(firstDim) is equal to &A(1,0,0) &A(0,0,0). The stride for the second dimension, A.stride(secondDim), is equal to &A(0,1,0)
- &A(0,0,0), and so on. For more information about strides, see the description of custom
storage formats in Section Section 2.9 [Array storage], page 29. See also the description of
parameters like firstDim and secondDim in the previous section.
Chapter 2: Arrays
25
Array<T,N>
transpose(int dimension1,
int dimension2, ...);
void
transposeSelf(int dimension1,
int dimension2, ...);
These methods permute the dimensions of the array. The dimensions of the array are reordered so that the first dimension is dimension1, the second is dimension2, and so on. The
arguments should be a permutation of the symbols firstDim, secondDim, .... Note that this
is implemented by twiddling the strides of the array, and doesnt cause any data copying. The
first version returns a transposed view of the array data; the second version transposes the
array itself.
int
ubound(int dimension) const;
TinyVector<int,N_rank>
ubound() const;
The first version returns the upper bound of the valid index range for a dimension. The
second version returns a vector of upper bounds for all dimensions. The upper bound is the last
valid index value. If youre using a C-style array (the default), the ubound will be equal to the
extent(dimension)-1. Fortran-style arrays will have ubound equal to extent(dimension).
The ubound can be different for each dimension. The return value of ubound(dimension) will
always be equal to lbound(dimension)+extent(dimension)-1. See the note about dimension
parameters such as firstDim in the previous section.
int
zeroOffset() const;
This function has to do with the storage of arrays in memory. You may want to refer to the
description of the data..() member functions and of custom storage orders in Section Section 2.9
[Array storage], page 29 for clarification. The return value of zeroOffset() is the distance from
the first element in the array to the (possibly nonexistant) element (0,0,...,0). In this context,
first element returns to the element (base(firstDim),base(secondDim),...).
allocateArrays(TinyVector<int,N>& shape,
Array<T,N>& A,
Array<T,N>& B, ...);
This function will allocate interlaced arrays, but only if interlacing is desirable for your
architecture. This is controlled by the BZ_INTERLACE_ARRAYS flag in blitz/tuning.h. You
can provide up to 11 arrays as parameters. Any views currently associated with the array objects
are lost. Here is a typical use:
Array<int,2> A, B, C;
allocateArrays(shape(64,64),A,B,C);
If array interlacing is enabled, then the arrays are stored in memory like this: A(0,0), B(0,0),
C(0,0), A(0,1), B(0,1), ... If interlacing is disabled, then the arrays are allocated in the normal
fashion: each array has its own block of memory. Once interlaced arrays are allocated, they can
be used just like regular arrays.
#include <blitz/array/convolve.h>
Array<T,1>
convolve(const Array<T,1>& B,
const Array<T,1>& C);
This function computes the 1-D convolution of the arrays B and C:
A[i] =
B[j]C[i j]
If the array B has domain bl . . . bh , and array C has domain cl . . . ch , then the resulting array
has domain al . . . ah , with l = bl + cl and ah = bh + ch .
26
Blitz++
A new array is allocated to contain the result. To avoid copying the result array, you should
use it as a constructor argument. For example: Array<float,1> A = convolve(B,C); The
convolution is computed in the spatial domain. Frequency-domain transforms are not used. If
you are convolving two large arrays, then this will be slower than using a Fourier transform.
Note that if you need a cross-correlation, you can use the convolve function with one of the
arrays reversed. For example:
Array<float,1> A = convolve(B,C.reverse());
Autocorrelation can be performed using the same approach.
void
cycleArrays(Array<T,N>& A, Array<T,N>& B);
void
cycleArrays(Array<T,N>& A, Array<T,N>& B,
Array<T,N>& C);
void
cycleArrays(Array<T,N>& A, Array<T,N>& B,
Array<T,N>& C, Array<T,N>& D);
void
cycleArrays(Array<T,N>& A, Array<T,N>& B,
Array<T,N>& C, Array<T,N>& D,
Array<T,N>& E);
These routines are useful for time-stepping PDEs. They take a set of arrays such as [A,B,C,D]
and cyclically rotate them to [B,C,D,A]; i.e. the A array then refers to what was Bs data, the B
array refers to what was Cs data, and the D array refers to what was As data. These functions
operate in constant time, since only the handles change (i.e. no data is copied; only pointers
change).
void
find(Array<TinyVector<int,Expr::rank>,1>& indices,
const _bz_ArrayExpr<Expr>& expr);
void
find(Array<TinyVector<int,N>,1>& indices,
const Array<bool,N>& exprVals);
This is an analogue to the Matlab find() method, which takes a boolean array expression or
an array of bools and returns a 1d array of indices for all locations where the array or expression
is true.
Array<T,N>
imag(Array<complex<T>,N>&);
This method returns a view of the imaginary portion of the array.
void
interlaceArrays(TinyVector<int,N>& shape,
Array<T,N>& A,
Array<T,N>& B, ...);
This function is similar to allocateArrays() above, except that the arrays are always interlaced, regardless of the setting of the BZ_INTERLACE_ARRAYS flag.
Array<T,N>
real(Array<complex<T>,N>&);
This method returns a view of the real portion of the array.
TinyVector<int,1>
shape(int L);
TinyVector<int,2>
shape(int L, int M);
TinyVector<int,3>
shape(int L, int M, int N);
TinyVector<int,4>
shape(int L, int M, int N, int O);
... [up to 11 dimensions]
These functions may be used to create shape parameters. They package the set of integer
arguments as a TinyVector of appropriate length. For an example use, see allocateArrays()
above.
void
swap(Array<T,N>& A, Array<T,N>& B);
This function swaps the storage of two arrays, just like the std::swap() function does for
STL container types. This is a synonym for the two-argument version of cycleArrays() above.
Chapter 2: Arrays
27
28
Blitz++
#include <blitz/array.h>
#ifdef BZ_HAVE_STD
#include <fstream>
#else
#include <fstream.h>
#endif
BZ_USING_NAMESPACE(blitz)
const char* filename = "io.data";
void write_arrays()
{
ofstream ofs(filename);
if (ofs.bad())
{
cerr << "Unable to write to file: " << filename << endl;
exit(1);
}
Array<float,3> A(3,4,5);
A = 111 + tensor::i + 10 * tensor::j + 100 * tensor::k;
ofs << A << endl;
Array<float,2> B(3,4);
B = 11 + tensor::i + 10 * tensor::j;
ofs << B << endl;
Array<float,1> C(4);
C = 1 + tensor::i;
ofs << C << endl;
}
int main()
{
write_arrays();
ifstream ifs(filename);
if (ifs.bad())
{
cerr << "Unable to open file: " << filename << endl;
exit(1);
}
Array<float,3> A;
Array<float,2> B;
Array<float,1> C;
ifs >> A >> B >> C;
cout << "Arrays restored from file: " << A << B << C << endl;
return 0;
}
Caution: The storage order and starting indices are not restored from the input stream. If
you are restoring (for example) a Fortran-style array, you must create a Fortran-style array, and
then restore it. For example, this code restores a Fortran-style array from the standard input
stream:
Array<float,2> B(fortranArray);
cin >> B;
Chapter 2: Arrays
29
Bases
To throw another complication into this scheme, C-style arrays have indices which start at zero,
and Fortran-style arrays have indices which start at one. The first valid index value is called
the base. To account for a non-zero base, its necessary to include an offset term in addition to
the linear combination. Heres the mapping for a C-style array with i=0..3 and j=0..3:
memory offset =
0 + 3*i + 1*j
No offset is necessary since the indices start at zero for C-style arrays. For a Fortran-style
array with i=1..4 and j=1..4, the mapping would be:
memory offset = -4 + 3*i + 1*j
By default, Blitz++ creates arrays in the C-style storage format (base zero, row major ordering). To create a Fortran-style array, you can use this syntax:
2
Taking a linear combination is sufficient for dense, asymmetric arrays, such as are provided by the Blitz++
Array class.
30
Blitz++
In higher dimensions
In more than two dimensions, the choice of storage order becomes more complicated. Suppose
we had a 3x3x3 array. To map the indices (i,j,k) into memory, we might choose one of these
mappings:
memory offset = 9*i + 3*j + 1*k
memory offset = 1*i + 3*j + 9*k
The first corresponds to a C-style array, and the second to a Fortran-style array. But there
are other choices; we can permute the strides (1,3,9) any which way:
memory offset = 1*i + 9*j + 3*k
memory offset = 3*i + 1*j + 9*k
memory offset = 3*i + 9*j + 1*k
memory offset = 9*i + 1*j + 3*k
For an N dimensional array, there are N! such permutations. Blitz++ allows you to select any
permutation of the dimensions as a storage order. First you need to create an object of type
GeneralArrayStorage<N_rank>:
GeneralArrayStorage<3> storage;
GeneralArrayStorage<N_rank> contains a vector called ordering which controls the order
in which dimensions are stored in memory. The ordering vector will contain a permutation of
the numbers 0, 1, ..., N rank-1. Since some people are used to the first dimension being 1 rather
than 0, a set of symbols (firstDim, secondDim, ..., eleventhDim) are provided which make the
code more legible.
The ordering vector lists the dimensions in increasing order of stride. You can access this
vector using the member function ordering(). A C-style array, the default, would have:
Chapter 2: Arrays
31
Reversed dimensions
To add yet another wrinkle, there are some applications where the rows or columns need to be
stored in reverse order.3
Blitz++ allows you to store each dimension in either ascending or descending order. By default, arrays are always stored in ascending order. The GeneralArrayStorage<N_rank> object
contains a vector called ascendingFlag which indicates whether each dimension is stored ascending (true) or descending (false). To alter the contents of this vector, use the ascendingFlag()
method:
// Store the third dimension in descending order
storage.ascendingFlag() = true, true, false;
// Store all the dimensions in descending order
storage.ascendingFlag() = false, false, false;
For example, certain bitmap formats store image rows from bottom to top rather than top to bottom.
32
Blitz++
You may not mix arrays with different domains in the same expression. For example, adding a
base zero to a base one array is a no-no. The reason for this restriction is that certain expressions
become ambiguous, for example:
Array<int,1> A(Range(0,5)), B(Range(1,6));
A=0;
B=0;
using namespace blitz::tensor;
int result = sum(A+B+i);
Should the index i take its domain from array A or array B? To avoid such ambiguities, users
are forbidden from mixing arrays with different domains in an expression.
Chapter 2: Arrays
Set
[ 1
[ 4
[ 7
A = 1, 2, 3,
4, 5, 6,
7, 8, 9;
cout << "A = " << A << endl;
// Comma-delimited lists initialize in memory-storage order only.
// Hence we list the values in column-major order to initialize B:
B = 1, 4, 7, 2, 5, 8, 3, 6, 9;
cout << "B = " << B << endl;
// Array C is stored in column major, plus the columns are stored
// in descending order!
C = 3, 6, 9, 2, 5, 8, 1, 4, 7;
cout << "C = " << C << endl;
Array<int,2> D(3,3);
D = A + B + C;
#ifdef BZ_DEBUG
A.dumpStructureInformation();
B.dumpStructureInformation();
C.dumpStructureInformation();
D.dumpStructureInformation();
#endif
cout << "D = " << D << endl;
return 0;
}
33
34
Blitz++
7 8 9 ]
C = (0,2) x (0,2)
[ 1 2 3
4 5 6
7 8 9 ]
Dump of Array<i, 2>:
ordering_
= (1,0)
ascendingFlag_ = (1,1)
base_
= (0,0)
length_
= (3,3)
stride_
= (3,1)
zeroOffset_
= 0
numElements() = 9
isStorageContiguous() =
Dump of Array<i, 2>:
ordering_
= (0,1)
ascendingFlag_ = (1,1)
base_
= (0,0)
length_
= (3,3)
stride_
= (1,3)
zeroOffset_
= 0
numElements() = 9
isStorageContiguous() =
Dump of Array<i, 2>:
ordering_
= (0,1)
ascendingFlag_ = (1,0)
base_
= (0,0)
length_
= (3,3)
stride_
= (1,-3)
zeroOffset_
= 6
numElements() = 9
isStorageContiguous() =
Dump of Array<i, 2>:
ordering_
= (1,0)
ascendingFlag_ = (1,1)
base_
= (0,0)
length_
= (3,3)
stride_
= (3,1)
zeroOffset_
= 0
numElements() = 9
isStorageContiguous() =
D = (0,2) x (0,2)
[ 3 6 9
12 15 18
21 24 27 ]
35
3 Array Expressions
Array expressions in Blitz++ are implemented using the expression templates technique. Unless
otherwise noted, expression evaluation will never generate temporaries or multiple loops; an
expression such as
Array<int,1> A, B, C, D;
// ...
A = B + C + D;
will result in code similar to
for (int i=A.lbound(firstDim); i <= A.ubound(firstDim); ++i)
A[i] = B[i] + C[i] + D[i];
36
Blitz++
// ...
// ...
Bitwise XOR is not meaningful on floating point types, so this code will generate a compiler
error:
Array<float,1> A, B, C;
C = B ^ C;
// ...
Heres the compiler error generated by KAI C++ for the above code:
"../../blitz/ops.h", line 85: error: expression must have integral or enum type
BZ_DEFINE_OP(BitwiseXor,^);
^
detected during:
instantiation of "blitz::BitwiseXor<float, float>::T_numtype
blitz::BitwiseXor<float, float>::apply(float, float)" at
line 210 of "../../blitz/arrayexpr.h"
instantiation of ...
.
.
37
If you are creating arrays using a type you have created yourself, you will need to overload
whatever operators you want to use on arrays. For example, if I create a class Polynomial, and
want to write code such as:
Array<Polynomial,2> A, B, C;
// ...
C = A * B;
I would have to provide operator* for Polynomial by implementing
Polynomial Polynomial::operator*(Polynomial);)
or
Polynomial operator*(Polynomial, Polynomial);)
38
Blitz++
1
0.8
0.6
0.4
0.2
0
0.2
0.4
80
80
60
60
40
40
20
20
0
39
// Results in [ 0, 1, 2, 0, 8 ]
For your convenience, there is a namespace within blitz called tensor which declares all the
index placeholders:
namespace blitz {
namespace tensor {
firstIndex i;
secondIndex j;
thirdIndex k;
...
eleventhIndex t;
}
}
So instead of declaring your own index placeholder objects, you can just say
namespace blitz::tensor;
when you would like to use them. Alternately, you can just preface all the index placeholders
with tensor::, for example:
A = sin(2 * M_PI * tensor::i / 16.);
This will make your code more readable, since it is immediately clear that i is an index
placeholder, rather than a scalar value.
40
Blitz++
If type promotion does depend on the type of operation, then you will need to specialize
the appropriate function objects in <blitz/ops.h>.
Note that you can do these specializations in your own header files (you dont have to edit
promote.h or ops.h).
Manual casts
There are some inconvenient aspects of C-style type promotion. For example, when you divide
two integers in C, the result gets truncated. The same problem occurs when dividing two integer
arrays in Blitz++:
Array<int,1> A(4), B(4);
Array<float,1> C(4);
A = 1, 2, 3, 5;
B = 2, 2, 2, 7;
C = A / B;
// Result:
[ 0
0 ]
The usual solution to this problem is to cast one of the operands to a floating type. For
this purpose, Blitz++ provides a function cast(expr,type) which will cast the result of expr as
type:
C = A / cast(B, float());
// Result: [ 0.5
1.5
0.714 ]
The first argument to cast() is an array or expression. The second argument is a dummy
object of the type to which you want to cast. Once compilers support templates more thoroughly,
it will be possible to use this cast syntax:
C = A / cast<float>(B);
But this is not yet supported.
//
Absolute value
acos()
Inverse cosine. For real arguments, the return value is in the range [0, ].
arg()
asin()
Inverse sine. For real arguments, the return value is in the range [/2, /2].
atan()
Inverse tangent. For real arguments, the return value is in the range [/2, /2].
See also atan2() in section Section 3.9 [Math functions 2], page 43.
ceil()
Ceiling function: smallest floating-point integer value not less than the argument.
cexp()
conj()
cos()
41
cosh()
csqrt()
exp()
fabs()
Same as abs().
floor()
Floor function: largest floating-point integer value not greater than the argument.
log()
log10()
sinh()
sqr()
sqrt()
tan()
tanh()
asinh()
atanh()
_class()
Classification of floating point values. The return type is integer and will be one of:
FP_PLUS_NORM
Positive normalized, nonzero
FP_MINUS_NORM
Negative normalized, nonzero
42
Blitz++
FP_PLUS_DENORM
Positive denormalized, nonzero
FP_MINUS_DENORM
Negative denormalized, nonzero
FP_PLUS_ZERO
+0.0
FP_MINUS_ZERO
-0.0
FP_PLUS_INF
Positive infinity
FP_MINUS_INF
Negative infinity
FP_NANS
FP_NANQ
cbrt()
Cubic root
expm1()
Computes exp(x)-1
erf()
et dt
Note that for large values of the parameter, calculating can result in extreme loss
of accuracy. Instead, use erfc().
erfc()
finite()
Returns a nonzero integer if the parameter is a finite number (i.e. not +INF, -INF,
NaNQ or NaNS).
ilogb()
blitz_isnan()
Returns a nonzero integer if the parameter is NaNQ or NaNS (quiet or signalling
Not a Number).
itrunc()
j0()
j1()
lgamma()
Natural logarithm of the gamma function. The gamma function is defined as:
Z
Gamma(x) =
et tx1 dt
logb()
Returns a floating-point double that is equal to the unbiased exponent of the parameter.
log1p()
nearest()
Returns the nearest floating-point integer value to the parameter. If the parameter
is exactly halfway between two integer values, an even value is returned.
43
rint()
Rounds the parameter and returns a floating-point integer value. Whether rint()
rounds up or down or to the nearest integer depends on the current floating-point
rounding mode. If you havent altered the rounding mode, rint() should be equivalent to nearest(). If rounding mode is set to round towards +INF, rint() is
equivalent to ceil(). If the mode is round toward -INF, rint() is equivalent to
floor(). If the mode is round toward zero, rint() is equivalent to trunc().
rsqrt()
uitrunc()
Returns the nearest unsigned integer to the parameter in the direction of zero.
y0()
y1()
There may be better descriptions of these functions in your system man pages.
44
Blitz++
hypot(x,y)
Computes so that underflow does not occur and overflow occurs only if the final
result warrants it.
nextafter(x,y)
Returns the next representable number after x in the direction of y.
remainder(x,y)
Equivalent to drem(x,y).
scalb(x,y)
Calculates.
unordered(x,y)
Returns a nonzero value if a floating-point comparison between x and y would be
unordered. Otherwise, it returns zero.
//
//
//
//
1
2
3
4
Use version 1 when you have a function which takes one argument and returns a result of
the same type. For example:
#include <blitz/array.h>
using namespace blitz;
double myFunction(double x)
{
return 1.0 / (1 + x);
}
BZ_DECLARE_FUNCTION(myFunction)
int main()
{
Array<double,2> A(4,4), B(4,4);
B = myFunction(A);
}
// ...
Use version 2 when you have a one argument function whose return type is different than
the argument type, such as
int g(double x);
Use version 3 for a function which takes two arguments and returns a result of the same type,
such as:
double g(double x, double y);
Use version 4 for a function of two arguments which returns a different type, such as:
int g(double x, double y);
45
= A(i,j) *
x(k)
+ A(j,k) * y(i)
46
Blitz++
return 0;
}
x
0
0
0
0
(0,3)
1
2
3
4 ]
Index placeholders can not be used on the left-hand side of an expression. If you need to
reorder the indices, you must do this on the right-hand side.
In real-world tensor notation, repeated indices imply a contraction (or summation). For
example, this tensor expression computes a matrix-matrix product:
C ij = Aik B kj
The repeated k index is interpreted as meaning
cij =
aik bkj
In Blitz++, repeated indices do not imply contraction. If you want to contract (sum along)
an index, you must use the sum() function:
Array<float,2> A, B, C;
// ...
firstIndex i;
secondIndex j;
thirdIndex k;
C = sum(A(i,k) * B(k,j), k);
The sum() function is an example of an array reduction, described in the next section.
Index placeholders can be used in any order in an expression. This example computes a
kronecker product of a pair of two-dimensional arrays, and permutes the indices along the way:
Array<float,2> A, B;
// ...
Array<float,4> C;
// ...
fourthIndex l;
C = A(l,j) * B(k,i);
This is equivalent to the tensor notation
C ijkl = Alj B ki
Tensor-like notation can be mixed with other array notations:
Array<float,2> A, B; // ...
Array<double,4> C;
// ...
C = cos(A(l,j)) * sin(B(k,i)) + 1./(i+j+k+l);
An important efficiency note about tensor-like notation: the right-hand side of an expression
is completely evaluated for every element in the destination array. For example, in this code:
Array<float,1> x(4), y(4);
Array<float,2> A(4,4):
A = cos(x(i)) * sin(y(j));
The resulting implementation will look something like this:
47
product()
Product
mean()
min()
Minimum value
max()
Maximum value
minmax()
minIndex()
Index of the minimum value (TinyVector<int,N_rank>)
maxIndex()
Index of the maximum value (TinyVector<int,N_rank>)
count()
any()
all()
Caution: minIndex() and maxIndex() return TinyVectors, even when the rank of the array
(or array expression) is 1.
48
Blitz++
Reductions can be combined with where expressions (Section 3.15 [Where expr], page 50)
to reduce over some part of an array. For example, sum(where(A > 0, A, 0)) sums only the
positive elements in an array.
Summation
product()
Product
mean()
min()
Minimum value
max()
Maximum value
minIndex()
Index of the minimum value (int)
maxIndex()
Index of the maximum value (int)
count()
any()
49
all()
first()
First index at which the expression is logical true (int); if the expression is logical
true nowhere, then tiny(int()) (INT MIN) is returned.
last()
Last index at which the expression is logical true (int); if the expression is logical
true nowhere, then huge(int()) (INT MAX) is returned.
The reductions any(), all(), and first() have short-circuit semantics: the reduction will
halt as soon as the answer is known. For example, if you use any(), scanning of the expression
will stop as soon as the first true value is encountered.
To illustrate, heres an example:
Array<int, 2> A(4,4);
A =
3,
1,
2,
4,
8,
-1,
-5,
3,
0,
9,
-1,
4,
1,
3,
1,
2;
12
7 ]
This table shows what the result stored in z would be if sum() were replaced with other
reductions:
sum
mean
min
minIndex
max
maxIndex
first((A < 0), j)
product
count((A(j,i) > 0), j)
any(abs(A(j,i)) > 4, j)
all(A(j,i) > 0, j)
[
10
[
2.5
[
1
[
1
[
4
[
3
[ -2147483648
[
24
[
4
[
0
[
1
5
1.25
-5
2
8
0
1
120
2
1
0
12
7 ]
3
1.75 ]
-1
1 ]
2
0 ]
9
3 ]
1
1 ]
2 -2147483648 ]
0
6 ]
2
4 ]
1
0 ]
0
1 ]
Note: the odd numbers for first() are tiny(int()) i.e. the smallest number representable by
an int. The exact value is machine-dependent.
The result of a reduction is an array expression, so reductions can be used as operands in an
array expression:
Array<int,3> A;
Array<int,2> B;
Array<int,1> C;
// ...
secondIndex j;
thirdIndex k;
B = sqrt(sum(sqr(A), k));
50
Blitz++
Chapter 4: Stencils
51
4 Stencils
Blitz++ provides an implementation of stencil objects which is currently experimental. This
means that the exact details of how they are declared and used may change in future releases.
Use at your own risk.
52
Blitz++
BZ_END_STENCIL
BZ_DECLARE_STENCIL3(smooth2Db,A,B,c)
if ((c > 0.0) && (c < 1.0))
A = c * (B(0,0) + B(0,1) + B(0,-1) + B(1,0) + B(-1,0)) / 5.0
+ (1-c)*B;
else
A = 0;
BZ_END_STENCIL
Currently, a stencil can take up to 11 array parameters.
You can use the notation A(i,j,k) to read the element at an offset (i,j,k) from the current
element. If you omit the parentheses (i.e. as in A then the current element is read.
You can invoke stencil operators which calculate finite differences and laplacians.
Chapter 4: Stencils
53
The factor terms always consist of an integer multiplier (often 1) and a power of h. For
ease of use, all of the operators listed below are provided in a second normalized version in
which the integer multiplier is 1. The normalized versions have an n appended to the name, for
example central12n is the normalized version of central12, and has factor h instead of 2h.
These operators are defined in blitz/array/stencilops.h if you wish to see the implementation.
1
1
central22(A,dimension)
2nd derivative, 2nd order accurate. Factor: h2
-1
1
0
-2
1
1
central32(A,dimension)
3rd derivative, 2nd order accurate. Factor: 2h3
-2
-1
-1
2
1
-2
2
1
central42(A,dimension)
4th derivative, 2nd order accurate. Factor: h4
-2
1
-1
-4
0
6
1
-4
2
1
central14(A,dimension)
1st derivative, 4th order accurate. Factor: 12h
-2
1
-1
-8
1
8
2
-1
central24(A,dimension)
2nd derivative, 4th order accurate. Factor: 12h2
-2
-1
-1
16
0
-30
1
16
2
-1
central34(A,dimension)
3rd derivative, 4th order accurate. Factor: 8h3
-2
-8
-1
13
1
-13
2
8
central44(A,dimension)
4th derivative, 4th order accurate. Factor: 6h4
-2
12
-1
-39
0
56
1
-39
2
12
Note that the above are available in normalized versions central12n, central22n, ...,
central44n which have factors of h, h2 , h3 , or h4 as appropriate.
54
Blitz++
These
are
available
in
multicomponent
versions:
central12(A,component,dimension) gives the central12 operator
component (Components are numbered 0, 1, ... N-1).
for
example,
for the specified
1
1
forward21(A,dimension)
2nd derivative, 1st order accurate. Factor: h2
0
1
1
-2
2
1
forward31(A,dimension)
3rd derivative, 1st order accurate. Factor: h3
0
-1
1
3
2
-3
3
1
forward41(A,dimension)
4th derivative, 1st order accurate. Factor: h4
0
1
1
-4
2
6
3
-4
4
1
forward12(A,dimension)
1st derivative, 2nd order accurate. Factor: 2h
0
-3
1
4
2
-1
forward22(A,dimension)
2nd derivative, 2nd order accurate. Factor: h2
0
2
1
-5
2
4
3
-1
forward32(A,dimension)
3rd derivative, 2nd order accurate. Factor: 2h3
0
-5
1
18
2
-24
3
14
4
-3
forward42(A,dimension)
4th derivative, 2nd order accurate. Factor: h4
0
3
1
-14
2
26
3
-24
4
11
5
-2
Note that the above are available in normalized versions forward11n, forward21n, ...,
forward42n which have factors of h, h2 , h3 , or h4 as appropriate.
These
are
available
in
multicomponent
versions:
for
example,
forward11(A,component,dimension) gives the forward11 operator for the specified
component (Components are numbered 0, 1, ... N-1).
Chapter 4: Stencils
55
0
1
backward21(A,dimension)
2nd derivative, 1st order accurate. Factor: h2
-2
1
-1
-2
0
1
backward31(A,dimension)
3rd derivative, 1st order accurate. Factor: h3
-3
-1
-2
3
-1
-3
0
1
backward41(A,dimension)
4th derivative, 1st order accurate. Factor: h4
-4
1
-3
-4
-2
6
-1
-4
0
1
backward12(A,dimension)
1st derivative, 2nd order accurate. Factor: 2h
-2
1
-1
-4
0
3
backward22(A,dimension)
2nd derivative, 2nd order accurate. Factor: h2
-3
-1
-2
4
-1
-5
0
2
backward32(A,dimension)
3rd derivative, 2nd order accurate. Factor: 2h3
-4
3
-3
-14
-2
24
-1
-18
0
5
backward42(A,dimension)
4th derivative, 2nd order accurate. Factor: h4
-5
-2
-4
11
-3
-24
-2
26
-1
-14
0
3
Note that the above are available in normalized versions backward11n, backward21n, ...,
backward42n which have factors of h, h2 , h3 , or h4 as appropriate.
These
are
available
in
multicomponent
versions:
for
example,
backward42(A,component,dimension) gives the backward42 operator for the specified component (Components are numbered 0, 1, ... N-1).
56
Blitz++
0
1
-4
1
1
1
Laplacian3D(A)
2nd order accurate, 3-dimensional laplacian. Factor: h2
Laplacian2D4(A)
4th order accurate, 2-dimensional laplacian. Factor: 12h2
-2
-1
0
1
2
-2
-1
-1
16
0
-1
16
-60
16
-1
16
-1
Laplacian3D4(A)
4th order accurate, 3-dimensional laplacian. Factor: 12h2
Note that the above are available in normalized versions Laplacian2D4n, Laplacian3D4n
which have factors h2 .
defined
over
3D
vector
fields
only
(e.g.
They return a TinyMatrix<T,3,3> where T is
Jacobian3D(A)
2nd order, 3-dimensional Jacobian using the central12 operator. Factor: 2h.
Jacobian3D4(A)
4th order, 3-dimensional Jacobian using the central14 operator. Factor: 12h.
These are also available in normalized versions Jacobian3Dn and Jacobain3D4n which have
factors h.
Chapter 4: Stencils
57
curl4(V)
4th order curl operator on a 3D vector field, using the central14 operator. Factor:
12h
Note that the above are available in normalized versions curln and curl4n, which have
factors of h.
58
Blitz++
div4(Vx,Vy)
4th order div operator using the central14 operator. Factor: 12h
div(Vx,Vy,Vz)
2nd order div operator using the central12 operator. Factor: 2h
div4(Vx,Vy,Vz)
4th order div operator using the central14 operator. Factor: 12h
div2D(V)
2nd order div operator on a 2D vector field, using the central12 operator. Factor:
2h
div2D4(V)
2nd order div operator on a 2D vector field, using the central14 operator. Factor:
12h
div3D(V)
2nd order div operator on a 3D vector field, using the central12 operator. Factor:
2h
div3D4(V)
2nd order div operator on a 3D vector field using the central14 operator. Factor:
12h
These are available in normalized versions divn, div4n, div2Dn, div2D4n, div3Dn, and
div3D4n which have factors of h.
Chapter 4: Stencils
59
}
The template parameter T is an iterator type for arrays.
You are encouraged to use the macros when possible, because it is possible the implementation
could be changed in the future.
To declare a difference operator, use this syntax:
BZ_DECLARE_DIFF(central12,A) {
return A.shift(1,dim) - A.shift(-1,dim);
}
The method shift(offset,dim) retrieves the element at offset in dimension dim.
Stencil operator declarations cannot occur inside a function. If declared inside a class, they
are scoped by the class.
61
62
Blitz++
class HSV24 {
public:
// These constants will makes the code below cleaner; we can
// refer to the components by name, rather than number.
static const int hue=0, saturation=1, value=2;
HSV24() { }
HSV24(int hue, int saturation, int value)
: h_(hue), s_(saturation), v_(value)
{ }
// Some other stuff here, obviously
private:
unsigned char h_, s_, v_;
};
Right after the class declaration, we will invoke the macro BZ_DECLARE_MULTICOMPONENT_
TYPE to tell Blitz++ about HSV24:
// HSV24 has 3 components of type unsigned char
BZ_DECLARE_MULTICOMPONENT_TYPE(HSV24, unsigned char, 3);
Now we can create HSV images and modify the individual components:
int main()
{
Array<HSV24,2> A(128,128);
...
63
Note: Blitz++ provides numerous math functions defined over complex-valued arrays, such
as conj, polar, arg, abs, cos, pow, etc. See the section on math functions (Section 3.8 [Math
functions 1], page 40) for details.
64
Blitz++
FixedPoint operator+(FixedPoint x)
{ return FixedPoint(mantissa_ + x.mantissa_); }
double value() const
{ return mantissa_ / double(huge(T_mantissa())); }
private:
T_mantissa mantissa_;
};
ostream& operator<<(ostream& os, const FixedPoint& a)
{
os << a.value();
return os;
}
The function huge(T) returns the largest representable value for type T; in the example
above, its equal to UINT_MAX.
The FixedPoint class declares three useful operations: conversion from double, addition,
and outputing to an ostream. We can use all of these operations on an Array<FixedPoint>
object:
#include <fixed-point.h> // FixedPoint class
int main()
{
// Create an array using the FixedPoint class:
Array<FixedPoint, 2> A(4,4), B(4,4);
A = 0.5,
0.1,
0.0,
0.2,
0.3,
0.3,
1.0,
0.3,
0.8,
0.2,
0.7,
0.8,
0.2,
0.9,
0.4,
0.4;
B = A + 0.05;
cout << "B = " << B << endl;
return 0;
}
Note that the array A is initialized using a comma-delimited list of double; this
makes use of the constructor FixedPoint(double). The assignment B = A + 0.05 uses
FixedPoint::operator+(FixedPoint), with an implicit conversion from double to
FixedPoint. Formatting the array B onto the standard output stream is done using the output
operator defined for FixedPoint.
Heres the program output:
B = (0,3) x
[ 0.55 0.35
0.15 0.35
0.05 0.05
0.25 0.35
(0,3)
0.85 0.25
0.25 0.95
0.75 0.45
0.85 0.45 ]
Chapter 6: Indirection
65
6 Indirection
Indirection is the ability to modify or access an array at a set of selected index values. Blitz++
provides several forms of indirection:
Using a list of array positions: this approach is useful if you need to modify an array at a
set of scattered points.
Cartesian-product indirection: as an example, for a two-dimensional array you might have
a list I of rows and a list J of columns, and you want to modify the array at all (i,j) positions
where i is in I and j is in J. This is a cartesian product of the index sets I and J.
Over a set of strips: for efficiency, you can represent an arbitrarily-shaped subset of an array
as a list of one-dimensional strips. This is a useful way of handling Regions Of Interest
(ROIs).
list<TinyVector<int,2>> I;
.
.
A[I] = 0;
list<int> I, J;
.
.
A[indexSet(I,J)] = 0;
list<RectDomain<2>> ROI;
.
.
A[ROI] = 0;
From top to bottom: (1) using a list of array positions; (2) Cartesian-product indirection; (3) using a set of
strips to represent an arbitrarily-shaped subset of an array.
66
Blitz++
#include
#include
#include
#include
<list>
<vector>
<deque>
<set>
//
//
//
//
for
for
for
for
list<>
vector<>
deque<>
set<>
0
11
0
0
0
0
22
0
0
0
0
0
(The tensor::i notation is explained in the section on index placeholders Section 3.6 [Index
placeholders], page 37).
Chapter 6: Indirection
67
68
Blitz++
TinyVector<int,2> start(2,5);
RectDomain<2> myStrip = strip(start,secondDim,9);
Here is a more substantial example which creates a list of strips representing a circle subset
of an array:
const int N = 7;
Array<int,2> A(N,N), B(N,N);
typedef TinyVector<int,2> coord;
A = 0;
B = 1;
double centre_i = (N-1)/2.0;
double centre_j = (N-1)/2.0;
double radius = 0.8 * N/2.0;
// circle will contain a list of strips which represent a circular
// subdomain.
list<RectDomain<2> > circle;
for (int i=0; i < N; ++i)
{
double jdist2 = pow2(radius) - pow2(i-centre_i);
if (jdist2 < 0.0)
continue;
int jdist = int(sqrt(jdist2));
coord startPos(i, int(centre_j - jdist));
circle.push_back(strip(startPos, secondDim, int(centre_j + jdist)));
}
// Set only those points in the circle subdomain to 1
A[circle] = B;
After this code, the A array contains:
0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 0 1 1 1 0 0
0 0 0 0 0 0 0
Chapter 7: TinyVector
69
7 TinyVector
The TinyVector class provides a small, lightweight vector object whose size is known at compile
time. It is included via the header <blitz/tinyvec.h>.
Note that TinyVector lives in the blitz namespace, so you will need to refer to it as
blitz::TinyVector, or use the directive using namespace blitz;.
The Blitz++ Array object uses TinyVector internally, so if you include <blitz/array.h>,
the TinyVector header is automatically included. However, to use TinyVector expressions, you
will need to include <blitz/tinyvec-et.h>.
is the numeric type of the vector (float, double, int, complex<float>, etc.;
T_numtype
is the numeric type stored in the vector (the template parameter T)
T_vector
iterator
is an STL-style iterator.
constIterator
is an STL-style const iterator.
7.2 Constructors
TinyVector();
The elements of the vector are left uninitialized.
TinyVector(const TinyVector<T,N>& x);
The elements of vector x are copied.
TinyVector(T value);
All elements are initialized to value.
TinyVector(T value1, T value2, ...);
The vector is initialized with the list of values given. These constructors are provided for up
to N=11.
begin();
begin() const;
Returns an STL-style iterator for the vector, positioned at the beginning of the data.
TinyVector<T,N>::iterator
TinyVector<T,N>::const_iterator
end();
end() const;
Returns an STL-style iterator for the vector, positioned at the end of the data.
T_numtype* [restrict]
const T_numtype* [restrict]
Returns a pointer to the first element in the vector.
data();
data() const;
70
Blitz++
int
length() const;
Returns the length of the vector (the template parameter N).
T_numtype
operator()(int i) const;
T_numtype&
operator()(int i);
T_numtype
operator[](int i) const;
T_numtype&
operator[](int i);
Returns the ith element of the vector. If the code is compiled with debugging enabled
(-DBZ_DEBUG), bounds checking is performed.
7.5 Expressions
Expressions involving tiny vectors may contain any combination of the operators
+ - * / % ^ & | >> <<
with operands of type TinyVector, scalar, or vector expressions. The usual math functions
(see the Array documentation) are supported on TinyVector. Please note that to use TinyVector
expressions, you will need to include header <blitz/tinyvec-et.h> in your code.
7.8 Input/output
ostream& operator<<(ostream&, const TinyVector<T,N>& x);
This function outputs a TinyVector onto a stream. Heres an illustration of the format for
a length 3 vector:
[
0.5
0.2
0.9 ]
71
73
Normal
Exponential
Exponential with specified mean
DiscreteUniform
Integers uniformly distributed over a specified range.
Beta
Beta distribution
Gamma
Gamma distribution
F distribution
To use these generators, you need to include some subset of these headers:
#include <random/uniform.h>
#include <random/normal.h>
#include <random/exponential.h>
#include <random/discrete-uniform.h>
#include <random/beta.h>
#include <random/gamma.h>
#include <random/chisquare.h>
#include <random/F.h>
74
Blitz++
void foo()
{
Normal<double> normalGen(0.5,0.25); // mean = 0.5, std dev = 0.25
double x = normalGen.random();
// x is a normal random number
}
RNGs
By default, the Integer RNG used is a faithful adaptation of the Mersenne Twister MT19937
Nishimura (see ACM Transactions on Modeling and Computer Simulation, Vol. 8, No. 1,
January 1998, pp 3-30, http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html,
http://www.acm.org/pubs/citations/journals/tomacs/1998-8-1/p3-matsumoto/). This
75
generator has a period of 219937 1 , passed several stringent statistical tests (including the
http://stat.fsu.edu/~geo/diehard.html tests), and has speed comparable to other modern
generators.
is the type of random number to generate (one of float, double, or long double
for continuous distributions; an integer type for discrete distributions). Note that
generating double and long double RNGs takes longer, because filling the entire
mantissa with random bits requires several random integers. The default parameter
for most generators is float.
IRNG
stateTag
9.7.1 random/uniform.h
Uniform<>()
Continuous uniform distribution
UniformClosedOpen<>()
Continuous uniform distribution
UniformClosed<>()
Continuous uniform distribution
UniformOpen<>()
Continuous uniform distribution
UniformOpenClosed<>()
Continuous uniform distribution
on [0,1).
on [0,1). Same as Uniform<>.
on [0,1].
on (0,1).
on (0,1].
9.7.2 random/normal.h
NormalUnit<>()
Continuous normal distribution with mean 0 and variance 1.
Normal<>(T mean, T standardDeviation)
Continuous normal distribution with specified mean and standard deviation.
76
Blitz++
9.7.3 random/exponential.h
ExponentialUnit<>()
Continuous exponential distribution with mean 1.
Exponential<>(T mean)
Continuous exponential distribution with specified mean.
9.7.4 random/beta.h
Beta<>(T a, T b)
Beta distribution with parameters a and b. The mean of the distribution is a/(a + b) and its
variance is ab/((a + b)2 (a + b + 1)). Use the method setParameters(T a, T b) to change the
parameters.
9.7.5 random/chisquare.h
ChiSquare<>(T df)
distribution with df degrees of freedom. The parameter df must be positive. Use the
method setDF(T df) to change the degrees of freedom.
2
9.7.6 random/gamma.h
Gamma<>(T mean)
Gamma distribution with specified mean. The mean must be positive. Use the method
setMean(T mean) to change the mean.
9.7.7 random/F.h
F<>(T numeratorDF, T denominatorDF)
F distribution with numerator and denominator degrees of freedom specified. Both these
parameters must be positive. Use setDF(T dfn, T dfd) to change the degrees of freedom.
9.7.8 random/discrete-uniform.h
DiscreteUniform<>(T n)
Discrete uniform distribution over 0, 1, . . . , n 1.
77
10 Numeric properties
10.1 Introduction
Blitz++ provides a set of functions to access numeric properties of intrinsic types. They are
provided as an alternative to the somewhat klunky numeric_limits<T>::yadda_yadda syntax
provided by the ISO/ANSI C++ standard. Where a similar Fortran 90 function exists, the same
name has been used.
The argument in all cases is a dummy of the appropriate type.
All functions described in this section assume that numeric_limits<T> has been specialized
for the appropriate case. If not, the results are not useful. The standard requires that numeric_
limits<T> be specialized for all the intrinsic numeric types (float, double, int, bool, unsigned
int, etc.).
To use these functions, you must first include the header <blitz/numinquire.h>. Also,
note that these functions may be unavailable if your compiler is non-ANSI compliant. If the
preprocessor symbol BZ_HAVE_NUMERIC_LIMITS is false, then these functions are unavailable.
78
Blitz++
T huge(T) throw;
Returns the maximum finite representable value. Equivalent to CHAR_MAX, SHRT_
MAX, FLT_MAX, etc. For floating types with denormalization, the maximum positive
normalized value is returned.
T infinity(T) throw;
Returns the representation of positive infinity, if available. Note that you should
check availability with has_infinity(T) before calling this function.
bool is_bounded(T);
True if the set of values represented by the type is finite. All built-in types are
bounded. (This function was provided so that e.g. arbitrary precision types could
be distinguished).
bool is_exact(T);
True if the representation is exact. All integer types are exact; floating-point types
generally arent. A rational arithmetic type could be exact.
bool is_iec559(T);
True if the type conforms to the IEC 559 standard. IEC is the International Electrotechnical Commission. Note that IEC 559 is the same as IEEE 754. Only relevant
for floating types.
bool is_integer(T);
True if the type is integer.
bool is_modulo(T);
True if the type is modulo. Integer types are usually modulo: if you add two integers,
they might wrap around and give you a small result. (Some special kinds of integers
dont wrap around, but stop at an upper or lower bound; this is called saturating
arithmetic). This is false for floating types.
bool is_signed(T);
True if the type is signed (i.e. can handle both positive and negative values).
int max_exponent(T);
The maximum exponent (Max_exp) is the maximum positive integer such that the
radix (read: 2) raised to the power Max_exp-1 is a representable, finite floating point
number. Floating types only.
int max_exponent10(T);
The maximum base-10 exponent (Max_exp10) is the maximum positive integer such
that 10 raised to the power Max_exp10 is a representable, finite floating point number. Floating types only.
int min_exponent(T);
The minimum exponent (Min_exp) is the minimum negative integer such that the
radix (read: 2) raised to the power Min_exp-1 is a normalized floating point number.
Floating types only.
int min_exponent10(T);
The minimum base-10 exponent (Min_exp10) is the minimum negative integer such
that 10 raised to the power Min_exp10 is in the range of normalized floating point
numbers.
T neghuge(T);
This returns the maximally negative value for a type. For integers, this is the same
as min(). For floating-point types, it is -huge(T()).
79
81
82
Blitz++
This problem can be fixed by installing the gnu linker and binutils. Peter Nordlund found that
by using gnu-binutils-2.9.1, this problem disappeared. You can read a detailed discussion
at http://oonumerics.org/blitz/support/blitz-support/archive/0029.html.
I am using gcc under Solaris, and the assembler gives me an error that a symbol is too
long.
This problem can also be fixed by installing the gnu linker and binutils. See the above
question.
DECcxx reports problems about templates with C linkage
This problem was caused by a problem in some versions of DECcxxs math.h header:
XOPEN SOURCE EXTENDED was causing an extern "C" { ... } section to have no closing
brace. There is a kludge which is included in recent versions of Blitz++.
On some platforms (especially SGI) the testsuite program minsumpow fails with the error:
Template instantiation resulted in an unexpected function type of...
This is a known bug in the older versions of the EDG front end, which many C++ compilers
use. There is no known fix. Most of Blitz++ will work, but you wont be able to use some array
reductions.
83
void my_new_handler()
{
cerr << "Out of memory" << endl;
cerr.flush();
abort();
}
...
// First line in main():
set_new_handler(my_new_handler);
When I pass arrays by value, the function which receives them can modify the array data.
Why?
Its a result of reference-counting. You have to think of array objects as being handles
to underlying arrays. The function doesnt receive a copy of the array data, but rather a copy
of the handle. The alternative would be to copy the array data when passing by value, which
would be grossly inefficient.
Why cant I use e.g. A >> 3 to do bitshifting on arrays?
The operators << and >> are used for input/ouput of arrays. It would cause problems with
the expression templates implementation to also use them for bitshifting. However, it is easy
enough to define your own bitshifting function see Section 3.10 [User et], page 44.
When I write TinyMatrix * TinyVector I get an error.
Try product(d2,d1). This works for matrix-matrix and matrix-vector products.
85
_class() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
drem() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
duplicateData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
abs() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
acos() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
acosh(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
allocateArrays(). . . . . . . . . . . . . . . . . . . . . . . . . . . . 14, 25
arg() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
asin() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
asinh(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
atan() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
atan2(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
atanh(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
end() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
epsilon() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
erf() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
erfc() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
exp() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
expm1(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
extent() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
extractComponent() . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
B
bad_alloc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
base() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
begin(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
blitz::tensor namespace. . . . . . . . . . . . . . . . . . . . . . . .
blitz_isnan() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
BZ_DECLARE_FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . .
BZ_DECLARE_MULTICOMPONENT_TYPE . . . . . . . . . . . . . . .
BZ_DECLARE_STENCIL . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
BZ_MUTEX_... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
BZ_THREADSAFE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
82
21
21
39
42
44
61
51
71
71
C
cast() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cbrt() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ceil() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cexp() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cols() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
columns() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
conj() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
const_iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
convolve() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
copy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
copysign() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cos() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cosh() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
csqrt(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
cycleArrays() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
40
42
40
40
21
21
40
21
25
21
43
40
41
41
26
D
data() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
dataFirst() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
dataZero() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
deleteDataWhenDone . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
denorm_min() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
depth(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
digits() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
digits10() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
dimensions() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
domain() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21
21
21
13
77
22
77
77
22
22
22
77
42
42
41
42
22
22
F
fabs() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
find() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
finite() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
firstDim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
firstIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
floor(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
fmod() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
fortranArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
fourthDim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
fourthIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FP_MINUS_DENORM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FP_MINUS_INF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FP_MINUS_NORM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FP_MINUS_ZERO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FP_NANQ. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FP_NANS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FP_PLUS_DENORM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FP_PLUS_INF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FP_PLUS_NORM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FP_PLUS_ZERO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
free() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
41
26
42
20
37
41
43
10
20
37
42
42
41
42
42
42
42
42
41
42
23
H
has_denorm() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
has_denorm_loss() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
has_infinity() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
has_quiet_NaN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
has_signaling_NaN() . . . . . . . . . . . . . . . . . . . . . . . . . . . .
has_signalling_NaN() . . . . . . . . . . . . . . . . . . . . . . . . . . .
huge() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
hypot(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
77
77
77
77
77
77
78
44
I
ilogb(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
imag() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
infinity() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
interlaceArrays() . . . . . . . . . . . . . . . . . . . . . . . . . . 14,
is_bounded() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
is_exact() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
is_iec559() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
is_integer() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
is_modulo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
26
78
26
78
78
78
78
78
86
is_signed() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
isMajorRank() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
isMinorRank() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
isnan(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
isRankStoredAscending() . . . . . . . . . . . . . . . . . . . . . . .
isStorageContiguous() . . . . . . . . . . . . . . . . . . . . . . . . .
itrunc() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Blitz++
78
23
23
42
23
23
42
J
j0() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
j1() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
L
lbound() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
lgamma() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
libblitz.a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
libm.a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
libmsaa.a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
log() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
log10(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
log1p(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
logb() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
R
radix(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
random() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
random/uniform.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
range(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
rank() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
real() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
RectDomain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
RectDomain<N> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
REENTRANT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
reference() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
reindex(), reindexSelf() . . . . . . . . . . . . . . . . . . . . . .
remainder() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
resize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
resizeAndPreserve() . . . . . . . . . . . . . . . . . . . . . . . . . . . .
reverse(), reverseSelf() . . . . . . . . . . . . . . . . . . . . . .
rint() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
round_error() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
round_style() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
rows() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
rsqrt(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
namespace blitz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
nearest() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
neghuge() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
neverDeleteData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
nextafter() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
numElements() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
numinquire.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
scalb(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
secondDim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
secondIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
seed() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
set_new_handler() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
shape() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13,
signaling_NaN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
signalling_NaN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
sin() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
sinh() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
size() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
sqr() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
sqrt() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
stride() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
StridedDomain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
strip(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
swap() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
one() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
ordering() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
tan() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
tanh() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
thirdDim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
thirdIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
tiny() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
tinyness_before() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
TinyVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
transpose(), transposeSelf() . . . . . . . . . . . . . . . . . .
traps(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
M
makeUnique() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
max_exponent() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
max_exponent10() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
min_exponent() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
min_exponent10() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
78
78
78
78
P
polar(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
pow() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
pow?() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
pow2() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
pow3() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
precision() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
preexistingMemoryPolicy . . . . . . . . . . . . . . . . . . . . . . .
promote_trait . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
43
43
41
41
41
79
13
39
Q
quiet_NaN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
79
75
75
79
23
26
16
67
71
24
24
44
24
24
24
43
79
79
24
43
44
20
37
75
82
26
79
79
41
41
24
41
41
24
16
67
26
41
41
20
37
79
79
69
24
79
U
ubound() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
uitrunc() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
unordered() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
using namespace blitz . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
87
y1() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
XOPEN_SOURCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
XOPEN_SOURCE_EXTENDED . . . . . . . . . . . . . . . . . . . . . . . . . 41
Z
Y
y0() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
zero() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
zeroOffset() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Concept Index
89
Concept Index
<
<< operator, bitshift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
=
=, meaning of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
>
>> operator, bitshift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
[
[] operator, for indirection . . . . . . . . . . . . . . . . . . . . . . . . 66
Array undeclared . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
A
Absoft xlc++ compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
all() reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
any() reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Array =, meaning of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Array arrays of user type . . . . . . . . . . . . . . . . . . . . . . . . . 36
Array assignment operators . . . . . . . . . . . . . . . . . . . . . . 37
Array bounds checking . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Array casts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Array column major . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Array complex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Array complex arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Array convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Array copying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Array correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Array creating a reference of another array . . . . 12, 13
Array creating from Fortran arrays . . . . . . . . . . . . . . . 13
Array creating from pre-existing data . . . . . . . . . . . . . 13
Array ctor with Range args . . . . . . . . . . . . . . . . . . . . . . 12
Array ctors with extent parameters . . . . . . . . . . . . . . . 11
Array declaring your own math functions on . . . . . . 44
Array default ctor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Array dimension parameters . . . . . . . . . . . . . . . . . . . . . . 20
Array explicit instantiation . . . . . . . . . . . . . . . . . . . . . . . . 6
Array expression evaluation order . . . . . . . . . . . . . . . . 35
Array expression operands . . . . . . . . . . . . . . . . . . . . . . . 35
Array expression operators . . . . . . . . . . . . . . . . . . . . . . . 36
Array expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Array expressions which mix arrays of different
storage formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Array extracting components . . . . . . . . . . . . . . . . . 22, 61
Array fortran-style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Array freeing an . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Array getting pointer to array data . . . . . . . . . . . . . . . 21
Array high-rank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Array index placeholders . . . . . . . . . . . . . . . . . . . . . . . . . 37
Array indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Array indirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Array indirection Cartesian-product . . . . . . . . . . . . . . 67
90
B
backward differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Bessel functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Beta RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
bitshift operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
blitz header files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
blitz namespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
blitz-devel list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
blitz-support list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
bounds checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
C
casts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
central differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
ChiSquare RNG. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
column major . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Compaq cxx compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
complete reductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
complex arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9, 62
Blitz++
D
debugging mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
denormalization loss. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
denormalized values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
dimension parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DiscreteUniform RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . .
divergence operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19
77
77
20
76
57
E
eigenvector decomposition . . . . . . . . . . . . . . . . . . . . . . . . 82
eleven, end of the universe at . . . . . . . . . . . . . . . . . . . . . 21
explicit instantiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Exponential RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
ExponentialUnit RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
expression evaluation order . . . . . . . . . . . . . . . . . . . . . . . 35
expression templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
external symbol relocation, Solaris . . . . . . . . . . . . . . . . 81
extracting components . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
F
F distribution RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Fortran compiler requirement. . . . . . . . . . . . . . . . . . . . . 81
forward differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Fujitsu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
functional if (where) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
G
g++ compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Gamma function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Gamma RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
gcc memory hog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Grad-squared operators . . . . . . . . . . . . . . . . . . . . . . . . . . 57
gradient operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
H
handling out of memory . . . . . . . . . . . . . . . . . . . . . . . . . . 82
header files, convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
help, obtaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
HSV24 example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
I
i (index placeholder) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
IBM xlC compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Concept Index
IEC 559 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
IEEE math functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
if (where) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
image processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
index placeholders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
index placeholders multiple . . . . . . . . . . . . . . . . . . . . . . . 37
index placeholders used for tensor notation . . . . . . . 45
indexing an array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
indirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
indirection Cartesian-product . . . . . . . . . . . . . . . . . . . . 67
indirection list of positions . . . . . . . . . . . . . . . . . . . . . . . 66
indirection list of strips . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
infinity has_infinity() . . . . . . . . . . . . . . . . . . . . . . . . 77
inputting arrays from an input stream . . . . . . . . . . . . 27
installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Integer RNGs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Intel C++ compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
interlacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
invalid compressed data . . . . . . . . . . . . . . . . . . . . . . . . . . 81
IRNGs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
iterators for arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
91
N
n (index placeholder) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
NaN has_quiet_NaN() . . . . . . . . . . . . . . . . . . . . . . . . . 77
NaN has_signaling_NaN() . . . . . . . . . . . . . . . . . . . . . 77
NaN quiet_NaN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
nested arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
nested arrays heterogeneous . . . . . . . . . . . . . . . . . . . . . . . 9
nested arrays homogeneous . . . . . . . . . . . . . . . . . . . . . . . . 9
new handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
No match for TinyVector operators . . . . . . . . . . . . . . . 81
Normal RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
NormalUnit RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
numeric limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
k (index placeholder) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
KCC compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
kronecker product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
J
j (index placeholder) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Jacobian operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
L
l (index placeholder) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Laplacian operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
library (libblitz.a) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
linear algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
locking (thread safety) . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
M
m (index placeholder) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
mailing lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
makefile, example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
math functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40, 43
math functions declaring your own . . . . . . . . . . . . . . . 44
matrix inversion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
matrix multiply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
max() reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
maximally negative value neghuge() . . . . . . . . . . . . 78
maximum value of a type. . . . . . . . . . . . . . . . . . . . . . . . . 78
maxIndex() reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
mean() reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
memory hog, gcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
MersenneTwister due to Matsumoto and . . . . . . . . . 74
Metrowerks compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Microsoft VS.NET 2003 C++ compiler . . . . . . . . . . . . . 1
min() reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
minimum finite value tiny() . . . . . . . . . . . . . . . . . . . 79
minIndex() reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
minmax() reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
83
83
36
35
82
81
45
27
parallel computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
partial reductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
partial reductions chaining . . . . . . . . . . . . . . . . . . . . . . . 49
passing arrays by value . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
PathScale pathCC compiler . . . . . . . . . . . . . . . . . . . . . . . 2
persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
PGI pgCC compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
porting Blitz++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
product() reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
R
Random Number Generators . . . . . . . . . . . . . . . . . . . . . 73
Random Number Generators details . . . . . . . . . . . . . . 74
Random Number Generators list of . . . . . . . . . . . . . . . 75
Random Number Generators member functions . . . 75
Random Number Generators overview . . . . . . . . . . . . 73
Random Number Generators seeding . . . . . . . . . . . . . 74
Range objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15, 17
rank parameter of arrays . . . . . . . . . . . . . . . . . . . . . . . . . . 9
rank-1 update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
ranlib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
RectDomain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
reductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
reductions chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
reductions complete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
reductions partial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
reference counting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
remainder, floating point drem() . . . . . . . . . . . . . . . . . 43
restoring arrays from an input stream . . . . . . . . . . . . 27
RGB24 example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
92
RNGs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
rounding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
row major . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
S
saving arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
seeding a RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
SGI CC compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
shallow copies, see also reference() . . . . . . . . . . . . . . . . 18
shape() (Array method) . . . . . . . . . . . . . . . . . . . . . . . . . 24
signed is_signed() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
slicing arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
solving linear systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
stateTag (RNGs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
stencil objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
stencil objects applying . . . . . . . . . . . . . . . . . . . . . . . . . . 59
stencil objects declaring . . . . . . . . . . . . . . . . . . . . . . . . . . 51
stencil operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
stencil operators declaring your own . . . . . . . . . . . . . . 58
STL iterators for arrays . . . . . . . . . . . . . . . . . . . . . . . . . . 21
STL, for indirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
storage of arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
storage order, creating your own . . . . . . . . . . . . . . . . . . 30
storage orders for arrays. . . . . . . . . . . . . . . . . . . . . . . . . . 10
StridedDomain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
subarrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
sum() reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Sun Studio CC compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
support, obtaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
symbol too long, Solaris as . . . . . . . . . . . . . . . . . . . . . . . 82
System V math functions . . . . . . . . . . . . . . . . . . . . . . . . 41
T
template instantiation resulted in an unexpected...
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
templates with C linkage, DECcxx . . . . . . . . . . . . . . . 82
Blitz++
temporaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
tensor contraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
tensor namespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
tensor notation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
tensor notation efficiency issues . . . . . . . . . . . . . . . . . . .
tensor product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
thread safety . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
time-stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
TinyVector. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
TinyVector of Range (use RectDomain) . . . . . . . . . . .
transposing arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
traversal order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
type promotion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
type promotion for user-defined types . . . . . . . . . . . .
35
46
39
45
46
45
71
26
69
16
24
35
39
39
U
Undefined references . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Uniform RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
UniformClosed RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
UniformClosedOpen RNG . . . . . . . . . . . . . . . . . . . . . . . .
UniformOpen RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
UniformOpenClosed RNG . . . . . . . . . . . . . . . . . . . . . . . .
81
75
75
75
75
75
V
vector field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
virtual memory problems, gcc . . . . . . . . . . . . . . . . . . . . 81
W
where statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
writing arrays to output streams . . . . . . . . . . . . . . . . . 27
Z
zipping expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63