Академический Документы
Профессиональный Документы
Культура Документы
A C++ class library for scientic computing for version 0.9, 11 October 2005
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. Copyright c 19962003 Free Software Foundation, Inc.
Table of Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 1.2 About this document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Platform/compiler notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.1 KAI C++ for Linux/Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.2 Intel C++ for x86 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.3 Microsoft VS.NET 2003 for Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.4 gcc for Linux/Unix/Darwin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.5 PathScale for x86 64 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.6 PGI for Linux x86 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.7 Absoft for Mac OS X. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.8 Metrowerks for Mac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.9 Compaq Alpha . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.10 IBM RS6000/IBM PowerPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.11 SGI MIPSpro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.12 Sun SPARC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.13 Cray T3E/Cray T90/Cray C90/Cray J90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.14 Fujitsu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.3 How to download Blitz++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4 Installation and porting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4.2 The Blitz++ directory tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4.3 Porting Blitz++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5 Compiling with Blitz++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.1 Header les . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.2 Linking to the Blitz++ library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.3 An example Makele . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.4 Explicit instantiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.6 Licensing terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.7 Mailing lists and support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.7.1 How to get help. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.7.2 How to subscribe to a mailing list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.7.3 blitz-devel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.7.4 blitz-support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 dierent 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 20 20 20 21 21 25 27 27 27 29 29 29 29 30 30 31 31 32 32 32 33
Array Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.1 3.2 3.3 Expression evaluation order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Expression operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Array operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using subarrays in an expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Mixing arrays with dierent storage formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4 Expression operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.5 Assignment operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.6 Index placeholders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.7 Type promotion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Type promotion for user-dened types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Manual casts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.8 Single-argument math functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ANSI C++ math functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . IEEE/System V math functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.9 Two-argument math functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ANSI C++ math functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . IEEE/System V math functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.10 Declaring your own math functions on arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.11 Tensor notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.12 Array reductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 Motivation: a nicer notation for stencils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Declaring stencil objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Automatic determination of stencil extent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stencil operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.1 Central dierences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.2 Forward dierences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.3 Backward dierences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.4 Laplacian ( 2 ) operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.5 Gradient ( ) operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.6 Jacobian operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.7 Grad-squared operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.8 Curl ( ) operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.9 Divergence ( ) operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.10 Mixed partial derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.5 Declaring your own stencil operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.6 Applying a stencil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 51 52 52 53 54 55 56 56 56 57 57 57 58 58 59
Indirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
6.1 6.2 6.3 Indirection using lists of array positions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Cartesian-product indirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Indirection with lists of strips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
TinyVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 Template parameters and types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Member functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Assignment operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Global functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arrays of TinyVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Input/output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 69 69 70 70 70 70 70
iv
Blitz++
10
Numeric properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Function descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10.1 10.2
11
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
ii
Blitz++
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 congure script will attempt to nd an appropriate compiler for the current platform.) By default, the congure 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 congure script with the option --help to see all the available options. Once the congure script is done, you can do any of these things: make lib Check the compiler and create libblitz.a.
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 Do all of the above. This may take a long time.
make install Build the blitz library and documentation and install, along with the blitz header les, in prex directory. Building the benchmark programs requires both a Fortran 77 and Fortran 90 compiler.
Chapter 1: Introduction
Blitz++
$(CXX) $(CXXFLAGS) -c $*.cpp $(TARGETS): $(CXX) $(LDFLAGS) $@.o -o $@ $(LIBS) all: $(TARGETS) myprogram1: myprogram2: myprogram1.o myprogram2.o
There are more example makeles 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 le 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.
Blitz++
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, exible expression handling, and many other useful features.
10
Blitz++
Nested homogeneous arrays using TinyVector and TinyMatrix, in which each element is a xed-size vector or array. For example, Array<TinyVector<float,3>,3> is a threedimensional vector eld. Nested heterogeneous arrays, such as Array<Array<int,1>,1>, in which each element is a variable-length array.
0 8 9
7 0 9 ]
0 10 9
7 2 9 ]
Chapter 2: Arrays
11
array is laid out in memory. By altering the contents of a GeneralArrayStorage<N> object, you can lay out your arrays any way you want: the dimensions can be ordered arbitrarily and stored in ascending or descending order, and the starting indices can be arbitrary. Creating custom array storage formats is described in a later section (Section 2.9 [Array storage], page 29).
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 species 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 lled in using the last provided argument. However, for code clarity, it makes sense to provide all N_rank parameters.
12
Blitz++
Array(int extent1, GeneralArrayStorage<N_rank> storage); Array(int extent1, int extent2, GeneralArrayStorage<N_rank> storage); ... For high-rank arrays, it may be convenient to use this constructor: Array(const TinyVector<int, N_rank>& extent); Array(const TinyVector<int, N_rank>& extent, GeneralArrayStorage<N_rank> storage); The argument extent is a vector containing the extent (length) of the array in each dimension. The optional second parameter indicates a storage format. Note that you can construct TinyVector<int,N> objects on the y with the shape(i1,i2,...) global function. For example, Array<int,2> A(shape(3,5)) will create a 3x5 array. A similar constructor lets you provide both a vector of base index values (lbounds) and extents: Array(const TinyVector<int, N_rank>& lbound, const TinyVector<int, N_rank>& extent); Array(const TinyVector<int, N_rank>& lbound, const TinyVector<int, N_rank>& extent, GeneralArrayStorage<N_rank> storage); The argument lbound is a vector containing the base index value (or lbound) of the array in each dimension. The argument extent is a vector containing the extent (length) of the array in each dimension. The optional third parameter indicates a storage format. As with the above constructor, you can use the shape(i1,i2,...) global function to create the lbound and extent parameters.
For example, this code: Array<int,2> A(Range(10,20), Range(20,30)); will create an 11x11 array whose indices are 10..20 and 20..30. An optional last parameter provides a storage order: Array(Range r1, GeneralArrayStorage<N_rank> storage); Array(Range r1, Range r2, GeneralArrayStorage<N_rank> storage); ...
Chapter 2: Arrays
13
14
Blitz++
Array(T_numtype* _bz_restrict dataFirst, TinyVector<int, N_rank> shape, TinyVector<int, N_rank> stride, preexistingMemoryPolicy deletePolicy, GeneralArrayStorage<N_rank> storage = GeneralArrayStorage<N_rank>())
Chapter 2: Arrays
Declaration of the array object:
15
A(7,0,0)
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++
Array<int,2> D(Range(1,5), Range(1,5)); // 1..5, 1..5 Array<int,2> E = D(Range(2,3), Range(2,3)); // 1..2, 1..2 An array can be used on both sides of an expression only if the subarrays dont overlap. If the arrays overlap, the result may depend on the order in which the array is traversed.
Chapter 2: Arrays
17
int stride(int i) const; Range operator[](int rank) const; void shrink(int amount); void shrink(int dim, int amount); void expand(int amount); void expand(int dim, int amount); };
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. Note: 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 dened 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());
2 4 6 ]
return 0; }
The optional third constructor argument species 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++
using namespace blitz; int main() { Array<int,2> A(8,8); A = 0; Array<int,2> B = A(Range(1,7,3), Range(1,5,2)); B = 1; cout << "A = " << A << endl; return 0; }
Chapter 2: Arrays
19
(or alias) to the rhs. To further confuse the issue, the copy constructor for arrays does have reference semantics. Heres an example which should clarify things: Array<int,1> A(5), B(10); A = B(Range(0,4)); // Statement 1 Array<int,1> C = B(Range(0,4)); // Statement 2 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, Range::toEnd), Range::all()) = 0; // Set the bottom right element to 8 A(5,5) = 8; cout << "A = " << A << endl; return 0; }
The output:
A = 6 x 6 [ 5 5 5 1 0 0 5 5 5 1 0 0 5 5 5 1 0 0 1 0 0 1 0 0 0 1 0 1 0 0 0 0 1 1 0 8 ]
20
Blitz++
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 1282 Array index out of range: (4, 4) Lower bounds: 2 [ 0 0 ] Length: 2 [ 4 4 ] debug: ../../blitz/array-impl.h:1282: bool blitz::Array<T, N>::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
= 0; = 1; = 2;
These symbols should be used in place of the numerals 0, 1, ... N_rank-1. For example: 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 nd firstDim, secondDim, ... aesthetically unpleasing, there are equivalent symbols firstRank, secondRank, thirdRank, ..., eleventhRank.
The base of a dimension is the rst valid index value. A typical C-style array will have base of zero; a Fortran-style array will have base of one. The base can be dierent for each dimension, but only if you deliberately use a Range-argument constructor or design a custom storage ordering. The rst version returns a reference to the vector of base values. The second version returns the base for just one dimension; its equivalent to the lbound() member function. See the note on dimension parameters such as firstDim above. Array<T,N>::iterator Array<T,N>::const_iterator begin(); begin() const;
These functions return STL-style forward and input iterators, respectively, positioned at the rst element of the array. Note that the array data is traversed in memory order (i.e. by rows for C-style arrays, and by columns for Fortran-style arrays). The Array<T,N>::const_iterator has these methods: const_iterator(const Array<T,N>&); T operator*() const; const T* [restrict] operator->() const; const_iterator& operator++(); void operator++(int); bool operator==(const const_iterator<T,N>&) const; bool operator!=(const const_iterator<T,N>&) const; const TinyVector<int,N>& position() const; Note that postx ++ returns void (this is not STL-compliant, but is done for eciency). The method position() returns a vector containing current index positions of the iterator. The Array<T,N>::iterator has the same methods as const_iterator, with these exceptions: iterator& operator++(); T& operator*(); T* [restrict] operator->(); The iterator type may be used to modify array elements. To obtain iterator positioned at the end of the array, use the end() methods.
22
Blitz++
int cols() const; int columns() const; Both of these functions return the extent of the array in the second dimension. Equivalent to extent(secondDim). See also rows() and depth(). Array<T_numtype, N_rank> copy() const; This method creates a copy of the arrays data, using the same storage ordering as the current array. The returned array is guaranteed to be stored contiguously in memory, and to be the only object referring to its memory block (i.e. the data isnt shared with any other array object). const T_numtype* [restrict] data() const; T_numtype* [restrict] data(); const T_numtype* [restrict] dataZero() const; T_numtype* [restrict] dataZero(); const T_numtype* [restrict] dataFirst() const; T_numtype* [restrict] dataFirst(); These member functions all return pointers to the array data. The NCEG restrict qualier is used only if your compiler supports it. If youre working with the default storage order (C-style arrays with base zero), youll only need to use data(). Otherwise, things get complicated: data() returns a pointer to the element whose indices are equal to the array base. With a C-style array, this means the element (0,0,...,0); with a Fortran-style array, this means the element (1,1,...,1). If A is an array object, A.data() is equivalent to (&A(A.base(rstDim), A.base(secondDim), ...)). If any of the dimensions are stored in reverse order, data() will not refer to the element which comes rst in memory. dataZero() returns a pointer to the element (0,0,...,0), even if such an element does not exist in the array. Whats the point of having such a pointer? Say you want to access the element (i,j,k). If you add to the pointer the dot product of (i,j,k) with the stride vector (A.stride()), you get a pointer to the element (i,j,k). dataFirst() returns a pointer to the element of the array which comes rst in memory. Note however, that under some circumstances (e.g. subarrays), the data will not be stored contiguously in memory. You have to be very careful when meddling directly with an arrays data. Other relevant functions are: isStorageContiguous() and zeroOffset(). int depth() const; Returns the extent of the array in the third dimension. This function is equivalent to extent(thirdDim). See also rows() and columns(). int dimensions() const; Returns the number of dimensions (rank) of the array. The return value is the second template parameter (N_rank) of the Array object. Same as rank(). RectDomain<N_rank> domain() const; Returns the domain of the array. The domain consists of a vector of lower bounds and a vector of upper bounds for the indices. NEEDS WORK need a section to explain methods of RectDomain<N>. Array<T,N>::iterator end(); Array<T,N>::const_iterator end() const; Returns STL-style forward and input iterators (respectively) for the array, positioned at the end of the array. int extent(int dimension) const; The rst version the extent (length) of the array in the specied dimension. See the note about dimension parameters such as firstDim in the previous section.
Chapter 2: Arrays
23
Array<T_numtype2,N_rank>
This method returns an array view of a single component of a multicomponent array. In a multicomponent array, each element is a tuple of xed size. The components are numbered 0, 1, ..., numComponents-1. Example: Array<TinyVector<int,3>,2> A(128,128); // A 128x128 array of int[3]
Array<int,2> B = A.extractComponent(int(), 1, 3); 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 rst 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 bool isMinorRank(int dimension) const; isRankStoredAscending(int dimension) const; Returns true if the dimension does not have the largest stride. See also isMajorRank(). 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 TinyVector<int,N_rank> lbound(int dimension) const; lbound() const;
The rst 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 rst 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 dierent 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>& int ordering() const; ordering(int storageRankIndex) const;
24
Blitz++
These member functions return information about how the data is ordered in memory. The rst 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. 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 rst version reindexes the array, and the second just returns a reindexed view of the array, leaving the original array unmodied. void resize(int extent1, ...); void resize(const TinyVector<int,N_rank>&); These functions resize an array to the specied size. If the array is already the size specied, 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 specied size. If the array is already the size specied, 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 specied 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 rst 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 rst 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.
Chapter 2: Arrays
25
const TinyVector<int, N_rank>& stride() const; int stride(int dimension) const; The rst 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. 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 rst 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 rst 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 rst 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 dierent 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 clarication. The return value of zeroOffset() is the distance from the rst element in the array to the (possibly nonexistant) element (0,0,...,0). In this context, rst element returns to the element (base(firstDim),base(secondDim),...).
26
Blitz++
#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] =
j
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 . 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 void void void cycleArrays(Array<T,N>& cycleArrays(Array<T,N>& Array<T,N>& cycleArrays(Array<T,N>& Array<T,N>& cycleArrays(Array<T,N>& Array<T,N>& Array<T,N>& A, Array<T,N>& A, Array<T,N>& C); A, Array<T,N>& C, Array<T,N>& A, Array<T,N>& C, Array<T,N>& E); B); B, B, D); B, D,
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 void find(Array<TinyVector<int,Expr::rank>,1>& indices, const _bz_ArrayExpr<Expr>& expr); 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> void imag(Array<complex<T>,N>&); interlaceArrays(TinyVector<int,N>& shape, Array<T,N>& A, Array<T,N>& B, ...); This method returns a view of the imaginary portion of the array.
This function is similar to allocateArrays() above, except that the arrays are always interlaced, regardless of the setting of the BZ_INTERLACE_ARRAYS ag. Array<T,N> real(Array<complex<T>,N>&); This method returns a view of the real portion of the array.
Chapter 2: Arrays
27
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.
1 0.99005 0.980199 0.970446 0.960789 0.951229 0.941765 0.932394 0.923116 0.913931 0.904837 0.895834 0.88692 0.878095 0.869358 0.860708 0.852144 0.843665 0.83527 0.826959 ]
28
Blitz++
The symbol [ indicating the start of the array data The array elements, listed in memory storage order The symbol ] indicating the end of the array data The operator prototype is: template<class T, int N> istream& operator>>(istream&, Array<T,N>&); Here is an example of saving and restoring arrays from les. You can nd this example in the Blitz++ distribution as examples/io.cpp.
#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;
Chapter 2: Arrays
29
Note: 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;
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 rst valid index value is called the base. To account for a non-zero base, its necessary to include an oset term in addition to the linear combination. Heres the mapping for a C-style array with i=0..3 and j=0..3:
2
Taking a linear combination is sucient for dense, asymmetric arrays, such as are provided by the Blitz++ Array class.
30
Blitz++
memory offset =
0 + 3*i + 1*j
No oset 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: Array<int,2> A(3, 3, FortranArray<2>()); The third parameter, FortranArray<2>(), tells the Array constructor to use a storage format appropriate for two-dimensional Fortran arrays (base one, column major ordering). A similar object, ColumnMajor<N>, tells the Array constructor to use column major ordering, with base zero: Array<int,2> B(3, 3, ColumnMajor<2>()); This creates a 3x3 array with indices i=0..2 and j=0..2. In addition to supporting the 0 and 1 conventions for C and Fortran-style arrays, Blitz++ allows you to choose arbitrary bases, possibly dierent for each dimension. For example, this declaration creates an array whose indices have ranges i=5..8 and j=2..5: Array<int,2> A(Range(5,8), Range(2,5));
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 rst 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 memory memory memory offset offset offset offset = = = = 1*i 3*i 3*i 9*i + + + + 9*j 1*j 9*j 1*j + + + + 3*k 9*k 1*k 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>:
Chapter 2: Arrays
31
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 rst dimension being 1 rather than 0, a set of symbols (rstDim, 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: storage.ordering() = thirdDim, secondDim, firstDim; meaning that the third index (k) is associated with the smallest stride, and the rst index (i) is associated with the largest stride. A Fortran-style array would have: storage.ordering() = firstDim, secondDim, thirdDim;
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++
function
Chapter 2: Arrays
33
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; }
34
Blitz++
2 5 8
3 6 9 ]
2 5 8
3 6 9 ]
Dump of Array<i, 2>: ordering_ = 2 [ ascendingFlag_ = 2 [ base_ = 2 [ length_ = 2 [ stride_ = 2 [ zeroOffset_ = 0 numElements() = 9 isStorageContiguous() Dump of Array<i, 2>: ordering_ = 2 [ ascendingFlag_ = 2 [ base_ = 2 [ length_ = 2 [ stride_ = 2 [ zeroOffset_ = 0 numElements() = 9 isStorageContiguous() Dump of Array<i, 2>: ordering_ = 2 [ ascendingFlag_ = 2 [ base_ = 2 [ length_ = 2 [ stride_ = 2 [ zeroOffset_ = 6 numElements() = 9 isStorageContiguous() Dump of Array<i, 2>: ordering_ = 2 [ ascendingFlag_ = 2 [ base_ = 2 [ length_ = 2 [ stride_ = 2 [ zeroOffset_ = 0 numElements() = 9 isStorageContiguous() D = 3 x 3 [ 3 6 12 15 21 24
1 1 0 3 3
0 1 0 3 1
] ] ] ] ]
= 1 0 1 0 3 1 1 1 0 3 3 ] ] ] ] ]
= 1 0 1 0 3 1 1 0 0 3 -3 ] ] ] ] ]
= 1 1 1 0 3 3 0 1 0 3 1 ] ] ] ] ]
= 1 9 18 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 oating 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++
float tau = - 10.0 / N; // Index placeholders firstIndex i; secondIndex j; // Fill the array F = cos(omega * sqrt(pow2(i-midpoint) + pow2(j-midpoint))) * exp(tau * sqrt(pow2(i-midpoint) + pow2(j-midpoint))); Heres a plot of the resulting array:
Array lled using an index placeholder expression. You can use index placeholder expressions in up to 11 dimensions. Heres a three dimensional example: // Fill a three-dimensional array with a Gaussian function Array<float,3> A(16,16,16); firstIndex i; secondIndex j; thirdIndex k; float midpoint = 15/2.; float c = - 1/3.0; A = exp(c * (sqr(i-midpoint) + sqr(j-midpoint) + sqr(k-midpoint)));
39
You can mix array operands and index placeholders: Array<int,1> A(5), B(5); firstIndex i; A = 0, 1, 1, 0, 2; B = i * A;
// 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 les (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 1 1 0 ]
The usual solution to this problem is to cast one of the operands to a oating 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 1.5 0.714 ] The rst 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.
41
Hyperbolic cosine. Works for complex<T>. Complex square root; same as sqrt(). Exponential. Works for complex<T>. Same as abs(). Floor function: largest oating-point integer value not greater than the argument. Natural logarithm. Works for complex<T>. Base 10 logarithm. Works for complex<T>.
pow2(), pow3(), pow4(), pow5(), pow6(), pow7(), pow8() These functions compute an integer power. They expand to a series of multiplications, so they can be used on any type for which multiplication is well-dened. sin() sinh() sqr() sqrt() tan() tanh() Sine. Works for complex<T>. Hyperbolic sine. Works for complex<T>. Same as pow2(). Computes x*x. Works for complex<T>. Square root. Works for complex<T>. Tangent. Works for complex<T>. Hyperbolic tangent. Works for complex<T>.
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 innity FP_MINUS_INF Negative innity FP_NANS FP_NANQ cbrt() expm1() erf() Cubic root Computes exp(x)-1 Computes the error function: 2 erf(x) =
x 0
et dt
Note that for large values of the parameter, calculating can result in extreme loss of accuracy. Instead, use erfc(). erfc() finite() ilogb() Computes the complementary error function erfc(x) = 1 erf(x). Returns a nonzero integer if the parameter is a nite number (i.e. not +INF, -INF, NaNQ or NaNS). Returns an integer which is equal to the unbiased exponent of the parameter.
blitz_isnan() Returns a nonzero integer if the parameter is NaNQ or NaNS (quiet or signalling Not a Number). itrunc() j0() j1() lgamma() Round a oating-point number to a signed integer. Returns the nearest signed integer to the parameter in the direction of 0. Bessel function of the rst kind, order 0. Bessel function of the rst kind, order 1. Natural logarithm of the gamma function. The gamma function is dened as:
Gamma(x) =
0
et tx1 dt
Returns a oating-point double that is equal to the unbiased exponent of the parameter. Calculates log(1+x), where x is the parameter. Returns the nearest oating-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 oating-point integer value. Whether rint() rounds up or down or to the nearest integer depends on the current oating-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(). Reciprocal square root. Returns the nearest unsigned integer to the parameter in the direction of zero.
Bessel function of the second kind, order 0. Bessel function of the second kind, order 1.
There may be better descriptions of these functions in your system man pages.
44
Blitz++
hypot(x,y) Computes so that underow does not occur and overow occurs only if the nal 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 oating-point comparison between x and y would be unordered. Otherwise, it returns zero.
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 dierent 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 dierent type, such as: int g(double x, double y);
45
= A(i,j) *
x(k)
+ A(j,k) * y(i)
Examples of array indexing, subarrays, and slicing. Heres an example which computes an outer product of two one-dimensional arrays:
#include <blitz/array.h> using namespace blitz; int main() { Array<float,1> x(4), y(4); Array<float,2> A(4,4); x = 1, 2, 3, 4; y = 1, 0, 0, 1; firstIndex i; secondIndex j; A = x(i) * y(j); cout << A << endl;
46
Blitz++
return 0; }
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 =
k
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 eciency 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
for (int n=0; n < 4; ++n) for (int m=0; m < 4; ++m) A(n,m) = cos(x(n)) * sin(y(m)); The functions cos and sin will be invoked sixteen times each. Its possible that a good optimizing compiler could hoist the cos evaluation out of the inner loop, but dont hold your breath theres a lot of complicated machinery behind the scenes to handle tensor notation, and most optimizing compilers are easily confused. In a situation like the above, you are probably best o manually creating temporaries for cos(x) and sin(y) rst.
Note: minIndex() and maxIndex() return TinyVectors, even when the rank of the array (or array expression) is 1. 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.
48
Blitz++
49
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 rst 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;
Array<float, 1> z; firstIndex i; secondIndex j; z = sum(A(j,i), j); The array z now contains the sum of A along each column: [ 10 5 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 rst() 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)); // Do two reductions in a row C = sum(sum(A, k), j); Note that this is not allowed:
// ...
50
Blitz++
Array<int,2> A; firstIndex i; secondIndex j; // Completely sum the array? int result = sum(sum(A, j), i); You cannot reduce an array to zero dimensions! Instead, use one of the global functions described in the previous section.
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 oset (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 nite dierences 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 dened in blitz/array/stencilops.h if you wish to see the implementation.
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).
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 specied component (Components are numbered 0, 1, ... N-1).
Chapter 4: Stencils
55
backward32(A,dimension) 3rd derivative, 2nd order accurate. Factor: 2h3 -4 3 -3 -14 -2 24 -1 -18 0 5
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 specied component (Components are numbered 0, 1, ... N-1).
56
Blitz++
4.4.4 Laplacian (
) operators
Laplacian3D(A) 2nd order accurate, 3-dimensional laplacian. Factor: h2 Laplacian2D4(A) 4th order accurate, 2-dimensional laplacian. Factor: 12h2 -2 -2 -1 0 1 2 -1 0 -1 16 -60 16 -1 1 2
-1
16
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 .
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
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) div2D4(V) 2nd order div operator on a 2D vector eld, using the central14 operator. Factor: 12h div3D(V) div3D4(V) 2nd order div operator on a 3D vector eld using the central14 operator. Factor: 12h These are available in normalized versions divn, div4n, div2Dn, div2D4n, div3Dn, and div3D4n which have factors of h. 2nd order div operator on a 3D vector eld, using the central12 operator. Factor: 2h 2nd order div operator on a 2D vector eld, using the central12 operator. Factor: 2h
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 dierence 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.
60
Blitz++
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); ...
// Extract a greyscale version of the image Array<unsigned char,2> A_greyscale = A[HSV24::value]; // Bump up the saturation component to get a // pastel effect A[HSV24::saturation] *= 1.3; // Brighten up the middle of the image Range middle(32,96); A[HSV24::value](middle,middle) *= 1.2; }
63
Note: Blitz++ provides numerous math functions dened 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;
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 dened for FixedPoint. Heres the program output:
B = 4 x 4 [ 0.55 0.15 0.05 0.25 0.35 0.35 0.05 0.35 0.85 0.25 0.75 0.85 0.25 0.95 0.45 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 eciency, 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;
Three styles of indirection.1 In all cases, Blitz++ expects a Standard Template Library container. Some useful STL containers are list<>, vector<>, deque<> and set<>. Documentation of these classes is often provided with your compiler, or see also the good documentation at http://www.sgi.com/Technology/STL/. STL containers are used because they are widely available and provide easier manipulation of sets than Blitz++ arrays. For example, you can easily expand and merge sets which are stored in STL containers; doing this is not so easy with Blitz++ arrays, which are designed for numerical work. STL containers are generally included by writing
1
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++
// // // //
The [] operator is overloaded on arrays so that the syntax array[container] provides an indirect view of the array. So far, this indirect view may only be used as an lvalue (i.e. on the left-hand side of an assignment statement). The examples in the next sections are available in the Blitz++ distribution in <examples/indirect.cpp>.
(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>.
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.
Returns an STL-style iterator for the vector, positioned at the beginning of the data.
Returns an STL-style iterator for the vector, positioned at the end of the data.
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.
71
72
Blitz++
73
Exponential Exponential with specied mean DiscreteUniform Integers uniformly distributed over a specied range. Beta Gamma F Beta distribution 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> using namespace ranlib; All the generators are inside the namespace ranlib, so a using namespace ranlib directive is required (alternately, you can write e.g. ranlib::Uniform<>). These generators are all class templates. The rst template parameter is the number type you want to generate: oat, double or long double for continuous distributions, and integer for discrete distributions. This parameter defaults to float for continuous distributions, and unsigned int for discrete distributions. The constructors are: Uniform(); Normal(T mean, T standardDeviation); Exponential(T mean); DiscreteUniform(T n); // range is 0 .. n-1 Beta(T a, T b); Gamma(T mean); ChiSquare(T df); F(T dfn, T dfd); where T is the rst template parameter (float, double, or long double). To obtain a random number, use the method random(). Here is an example of constructing and using a Normal generator: #include <random/normal.h> using namespace ranlib;
74
Blitz++
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.keio.ac.jp/~matumoto/emt.html, http://www.acm.org/pubs/citations/journals/tomacs/1998-8-1/p3-matsumoto/). This generator has a period of 219937 1 , passed several stringent statistical tests (including the
75
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 specied 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 specied 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 specied 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 specied. 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 (oat, double, int, bool, unsigned int, etc.). To use these functions, you must rst 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 nite representable value. Equivalent to CHAR_MAX, SHRT_ MAX, FLT_MAX, etc. For oating types with denormalization, the maximum positive normalized value is returned. T infinity(T) throw; Returns the representation of positive innity, 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 nite. 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; oating-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 oating 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 oating 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, nite oating 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, nite oating 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 oating 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 oating point numbers. T neghuge(T); This returns the maximally negative value for a type. For integers, this is the same as min(). For oating-point types, it is -huge(T()).
79
T one(T); Returns a representation for 1 int precision(T); Same as digits10(). T quiet_NaN(T) throw; Returns the representation for a quiet (non-signalling) Not A Number (NaN), if available. You should check availability using the has_quiet_NaN(T) function rst. int radix(T); For oating-point types, this returns the radix (base) of the exponent. For integers, it species the base of the representation. Range range(T); Returns Range(min_exponent10(T()), max_exponent10(T())), i.e. the range of representable base-10 exponents. T round_error(T) throw; Returns a measure of the maximum rounding error for oating-point types. This will typically be 0.5. std::float_round_style round_style(T); Returns the current rounding style for oating-point arithmetic. The possibilities are: round_indeterminate (i.e. dont have a clue), round_toward_zero, round_ to_nearest (round to nearest representable value), round_toward_infinity (round toward positive innity), and round_neg_infinity (round toward negative innity). T signaling_NaN(T) throw; Returns the representation for a signalling Not A Number (NaN), if available. You should check availability by calling has_signalling_NaN(T) rst. T signalling_NaN(T) throw; Same as signaling_NaN(). T tiny(T); For integer types, this returns the minimum nite value, which may be negative. For oating types, it returns the minimum positive value. For oating types with denormalization, the function returns the minimum positive normalized value. T tinyness_before(T); True if tinyness is detected before rounding. Other than this description, I dont have a clue what this means; anyone have a copy of IEC 559/IEEE 754 oating around? T traps(T); True if trapping is implemented for this type. T zero(T); Returns a representation for zero.
80
Blitz++
81
82
Blitz++
This problem can be xed 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 xed 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 x. 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 inecient. 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 dene 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.
84
Blitz++
85
_class() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
A
abs() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 acos() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 acosh() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 allocateArrays() . . . . . . . . . . . . . . . . . . . . . . . . . . 14, 25 arg() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 asin() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 asinh() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 atan() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 atan2() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 atanh() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
E
end() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . epsilon() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . erf() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . erfc() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . exp() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . expm1() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . extent() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . extractComponent() . . . . . . . . . . . . . . . . . . . . . . . . . . . 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
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 22 43 40 41 41 26
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
D
data() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . dataFirst() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . dataZero() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . deleteDataWhenDone . . . . . . . . . . . . . . . . . . . . . . . . . . . denorm_min() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . depth() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . digits() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . digits10() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . dimensions() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . domain() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 22 22 13 77 22 77 77 22 22
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
Blitz++
78 23 23 42 23 23 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() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 75 75 79 24 26 16 67 71 24 24 44 24 24 24 43 79 79 24 43
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
S
scalb() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . secondDim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . secondIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . seed() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . set_new_handler() . . . . . . . . . . . . . . . . . . . . . . . . . . . . shape() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13, signaling_NaN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . signalling_NaN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sin() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sinh() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . size() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sqr() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sqrt() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . stride() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . StridedDomain. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . strip() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . swap() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 20 37 75 82 27 79 79 41 41 24 41 41 24 16 67 27
M
makeUnique() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . max_exponent() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . max_exponent10() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . min_exponent() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . min_exponent10() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 78 78 78 78
N
namespace blitz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 nearest() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 neghuge() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 neverDeleteData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 nextafter() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 numElements(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 numinquire.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
O
one() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 ordering() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
T
tan() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . tanh() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . thirdDim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . thirdIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . tiny() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . tinyness_before() . . . . . . . . . . . . . . . . . . . . . . . . . . . . TinyVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . transpose(), transposeSelf() . . . . . . . . . . . . . . . . . traps() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 41 20 37 79 79 69 25 79
P
polar() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . pow() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . pow?() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . pow2() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . pow3() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . precision() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . preexistingMemoryPolicy . . . . . . . . . . . . . . . . . . . . . . promote_trait. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 43 41 41 41 79 13 39
U
ubound() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 uitrunc() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 unordered() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 using namespace blitz . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Q
quiet_NaN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
87
X
XOPEN_SOURCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 XOPEN_SOURCE_EXTENDED . . . . . . . . . . . . . . . . . . . . . . . . 41
y1() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Z Y
y0() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 zero() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 zeroOffset() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
88
Blitz++
89
Concept Index
<
<< operator, bitshift . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Array indirection list of positions . . . . . . . . . . . . . . . . 66 Array indirection list of strips . . . . . . . . . . . . . . . . . . . 67 Array inputting from istream . . . . . . . . . . . . . . . . . . . 27 Array interlacing . . . . . . . . . . . . . . . . . . . . . . . . . . . 14, 25 Array iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Array making unique copy . . . . . . . . . . . . . . . . . . . . . . 23 Array member functions . . . . . . . . . . . . . . . . . . . . . . . . 21 Array member functions base() . . . . . . . . . . . . . . . . . 21 Array member functions begin() . . . . . . . . . . . . . . . . 21 Array member functions cols() . . . . . . . . . . . . . . . . . 21 Array member functions columns(). . . . . . . . . . . . . . 21 Array member functions copy() . . . . . . . . . . . . . . . . . 22 Array member functions data() . . . . . . . . . . . . . . . . . 22 Array member functions dataFirst() . . . . . . . . . . . 22 Array member functions dataZero() . . . . . . . . . . . . 22 Array member functions depth() . . . . . . . . . . . . . . . . 22 Array member functions dimensions() . . . . . . . . . . 22 Array member functions domain() . . . . . . . . . . . . . . . 22 Array member functions end() . . . . . . . . . . . . . . . . . . 22 Array member functions extent() . . . . . . . . . . . . . . . 22 Array member functions extractComponent() . . . . 22 Array member functions free() . . . . . . . . . . . . . . . . . 23 Array member functions isMajorRank() . . . . . . . . . 23 Array member functions isMinorRank() . . . . . . . . . 23 Array member functions isRankStoredAscending() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Array member functions isStorageContiguous() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Array member functions lbound() . . . . . . . . . . . . . . . 23 Array member functions makeUnique() . . . . . . . . . . 23 Array member functions numElements() . . . . . . . . . 23 Array member functions ordering() . . . . . . . . . . . . 23 Array member functions rank() . . . . . . . . . . . . . . . . . 24 Array member functions reference() . . . . . . . . . . . 24 Array member functions reindex(). . . . . . . . . . . . . . 24 Array member functions reindexSelf() . . . . . . . . . 24 Array member functions resize() . . . . . . . . . . . . . . . 24 Array member functions resizeAndPreserve() . . . 24 Array member functions reverse(). . . . . . . . . . . . . . 24 Array member functions reverseSelf() . . . . . . . . . 24 Array member functions rows() . . . . . . . . . . . . . . . . . 24 Array member functions shape() . . . . . . . . . . . . . . . . 24 Array member functions size() . . . . . . . . . . . . . . . . . 24 Array member functions stride() . . . . . . . . . . . . . . . 24 Array member functions transpose() . . . . . . . . . . . 25 Array member functions transposeSelf() . . . . . . . 25 Array member functions ubound() . . . . . . . . . . . . . . . 25 Array member functions zeroOffset() . . . . . . . . . . 25 Array multicomponent. . . . . . . . . . . . . . . . . . . . . . . . . . 61 Array nested . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Array nested heterogeneous . . . . . . . . . . . . . . . . . . . . . . 9 Array nested homogeneous . . . . . . . . . . . . . . . . . . . . . . . 9 Array no temporaries . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Array number of elements in . . . . . . . . . . . . . . . . . . . . 23 Array obtaining domain of . . . . . . . . . . . . . . . . . . . . . . 22 Array of Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Array of TinyMatrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Array of TinyVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Array of user-dened types . . . . . . . . . . . . . . . . . . . . . . 9 Array of your own types . . . . . . . . . . . . . . . . . . . . . . . . 63 Array operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
=
=, 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 . . . . . . . . . . . . . . . . . . . . . . . . . 20 Array casts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Array column major . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Array complex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Array complex arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Array convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Array copying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 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 dierent storage formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Array extracting components . . . . . . . . . . . . . . . . 22, 61 Array fortran-style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Array freeing an . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Array getting pointer to array data . . . . . . . . . . . . . . 22 Array high-rank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Array index placeholders . . . . . . . . . . . . . . . . . . . . . . . 37 Array indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Array indirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Array indirection Cartesian-product . . . . . . . . . . . . . 67
90
Blitz++
Array operators applied elementwise . . . . . . . . . . . . . 36 Array output formatting . . . . . . . . . . . . . . . . . . . . . . . . 27 Array overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Array persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Array persistence format. . . . . . . . . . . . . . . . . . . . . . . . 27 Array rank parameter . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Array reductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Array reductions chaining. . . . . . . . . . . . . . . . . . . . . . . 49 Array reductions complete . . . . . . . . . . . . . . . . . . . . . . 47 Array reductions partial . . . . . . . . . . . . . . . . . . . . . . . . 48 Array reference counting . . . . . . . . . . . . . . . . . . . . . . . . 14 Array referencing another . . . . . . . . . . . . . . . . . . . . . . . 24 Array referencing another array . . . . . . . . . . . . . . . . . 12 Array reindexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Array requirements for using operators . . . . . . . . . . 36 Array resizing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Array restoring from istream . . . . . . . . . . . . . . . . . . . . 27 Array reversing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Array row major . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Array saving to output stream . . . . . . . . . . . . . . . . . . 27 Array scalar arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Array shape of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Array slicing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Array stencils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Array storage formats . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Array storage order . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Array storage order, creating your own . . . . . . . . . . 30 Array storage ordering of . . . . . . . . . . . . . . . . . . . . . . . 23 Array strides of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Array subarrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Array template parameters . . . . . . . . . . . . . . . . . . . . . . 9 Array temporaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Array tensor notation . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Array transposing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Array type promotion . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Array type promotion for user-dened types . . . . . . 39 Array types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Array using subarrays in expressions . . . . . . . . . . . . . 36 Array writing to output stream . . . . . . . . . . . . . . . . . 27 Array zipping expressions . . . . . . . . . . . . . . . . . . . . . . . 63 assignment operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 autoconf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
complex math functions . . . . . . . . . . . . . . . . . . . . . 40, 43 Conguration/Install errors under Mac OS X. . . . . 81 congure script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 constness problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 contraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 contributing to Blitz++ . . . . . . . . . . . . . . . . . . . . . . . . . . 7 convolution, 1-D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 count() reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Cray CC compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 CRC error in .tar.gz . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 curl operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
D
debugging mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . denormalization loss . . . . . . . . . . . . . . . . . . . . . . . . . . . . denormalized values . . . . . . . . . . . . . . . . . . . . . . . . . . . . dimension parameters . . . . . . . . . . . . . . . . . . . . . . . . . . DiscreteUniform RNG . . . . . . . . . . . . . . . . . . . . . . . . . . divergence operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 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 dierences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Fujitsu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 functional if (where) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
B
backward dierences . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Bessel functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Beta RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 bitshift operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 blitz header les . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 blitz namespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 blitz-devel list. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 blitz-support list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 bounds checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
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 les, convention . . . . . . . . . . . . . . . . . . . . . . . . . . 5 help, obtaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 HSV24 example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
C
casts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 central dierences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 ChiSquare RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 column major . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Compaq cxx compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 complete reductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 complex arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9, 62
I
i (index placeholder) . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 IBM xlC compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
91
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 innity 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
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
O
operator <<, bitshift . . . . . . . . . . . . . . . . . . . . . . . . . . . . operator >>, bitshift . . . . . . . . . . . . . . . . . . . . . . . . . . . . operators, array expressions . . . . . . . . . . . . . . . . . . . . . order of expression evaluation . . . . . . . . . . . . . . . . . . . out of memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . out of virtual memory, gcc . . . . . . . . . . . . . . . . . . . . . . outer product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . output formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 83 36 35 82 81 45 27
J
j (index placeholder) . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Jacobian operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
K
k (index placeholder) . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 KCC compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 kronecker product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
P
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
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 makele, example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 makeles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 nite value tiny() . . . . . . . . . . . . . . . . . . 79 minIndex() reduction . . . . . . . . . . . . . . . . . . . . . . . . . . 47 mixed partial operators . . . . . . . . . . . . . . . . . . . . . . . . . 58
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, oating point drem() . . . . . . . . . . . . . . . . 43 restoring arrays from an input stream. . . . . . . . . . . . 27 RGB24 example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 RNGs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
92
Blitz++
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
temporaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . tensor contraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . tensor namespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . tensor notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . tensor notation eciency issues . . . . . . . . . . . . . . . . . tensor product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . thread safety . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . time-stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TinyVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TinyVector of Range (use RectDomain). . . . . . . . . . . transposing arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . traversal order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . type promotion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . type promotion for user-dened types . . . . . . . . . . . .
35 46 39 45 46 45 71 26 69 16 25 35 39 39
U
Undened references . . . . . . . . . . . . . . . . . . . . . . . . . . . Uniform RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . UniformClosed RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . UniformClosedOpen RNG . . . . . . . . . . . . . . . . . . . . . . UniformOpen RNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . UniformOpenClosed RNG . . . . . . . . . . . . . . . . . . . . . . 81 75 75 75 75 75
V
vector eld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 virtual memory problems, gcc . . . . . . . . . . . . . . . . . . . 81
W
where statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 writing arrays to output streams . . . . . . . . . . . . . . . . 27
T
template instantiation resulted in an unexpected... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 templates with C linkage, DECcxx . . . . . . . . . . . . . . 82
Z
zipping expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63