Skip to content

Features

Sylwester Arabas edited this page May 9, 2019 · 20 revisions

THIS PAGE IS WORK IN PROGRESS (COMMENTS AND CONTRIBUTIONS MORE THAN WELCOME!) WOULD BE GREAT TO COMPARE THE FEATURE LIST WITH OTHER PACKAGES

Major features:

Header-only multi-dimensional (up to 11) matrix/array/tensor containers

#include <blitz/array.h>

int main()
{
  blitz::Array<int, 1> intvec;
  blitz::Array<bool, 2> binmtx;
  blitz::Array<double, 3> dblarr;
  blitz::Array<float, 11> ftensor;
}
$ g++ example.cpp
$ ./a.out 
Initialisation with single value or comma-delimited list of values

#include <blitz/array.h>

int main()
{
  blitz::Array<double,2> a(2,2), b(4,4);
  a = 0;
  b = 1, 0, 0, 0,
      0, 1, 0, 0,
      0, 0, 1, 0,
      0, 0, 0, 1;
  std::cout << a << b;
}
$ g++ example.cpp
$ ./a.out
(0,1) x (0,1)
[ 0 0 
  0 0 ]
(0,3) x (0,3)
[ 1 0 0 0 
  0 1 0 0 
  0 0 1 0 
  0 0 0 1 ]
(TODO) Initialisation from an expression

Tensor notation (using blitz::tensor namespace members requires linking with lblitz)

#include <blitz/array.h>                                                    

int main()                                                                  
{                                                                           
  blitz::Array<float,2> psi(4,4);                                           
  {                                                                         
    using namespace blitz::tensor;                                          
    psi = sqrt(i*i + j*j);                                                  
  }                                                                         
  std::cout << psi;                                                         
}
$ g++ -lblitz example.cpp
$ ./a.out
(0,3) x (0,3)
[ 0 1 2 3 
  1 1.41421 2.23607 3.16228 
  2 2.23607 2.82843 3.60555 
  3 3.16228 3.60555 4.24264 ]
(TODO) Shared views of another array's data

(TODO) Partial evaluation / lack of temporary objects with loop-free array arithmetics

(TODO) Arbitrary ordering including C-style and Fortran-style

Boundary checks in debug mode (requires linking with lblitz)

#include <blitz/array.h>

int main()
{
  blitz::Array<float, 2> A(4,4);
  A(4,4) = 1.0;
}
$ g++ -DBZ_DEBUG -lblitz example.cpp
$ ./a.out
[Blitz++] Precondition failure: Module /usr/include/blitz/array-impl.h line 1338
Array index out of range: (4, 4)
Lower bounds: (0,0)
Length:       (4,4)

a.out: /usr/include/blitz/array-impl.h:1338: bool blitz::Array<P_numtype, N_rank>::assertInRange(int, int) const [with P_numtype = float; int N_rank = 2]: Assertion `0' failed.
Aborted
(TODO) Multi-dimensional indexing/slicing with ints and Ranges

(TODO) Multi-dimensional indexing/slicing with single object (RectDomain) + rationale for overloading

(TODO) Operations on externally allocated memory (and dimension-ordering flexibility)

(TODO) Reference counting (optionally thread-safe)

(TODO) Array-expression-valued functions (incl. reference counting)

Elemental functions

#include <blitz/array.h>                                                    

struct func                                                                 
{                                                                           
  float a = .25, b = .1;                                                    

  float operator()(float x) const                                           
  {                                                                         
    return a * x + b;                                                       
  }                                                                         

  BZ_DECLARE_FUNCTOR(func);                                                 
};                                                                          

int main()                                                                  
{                                                                           
  blitz::Array<float, 1> psi(10), x(10);                                    

  x = blitz::tensor::i;                                                     
  psi = func()(x);

  std::cout << psi;
}
$ g++ -lblitz -std=c++11 example.cpp
$ ./a.out
(0,9)
[ 0.1 0.35 0.6 0.85 1.1 1.35 1.6 1.85 2.1 2.35 ]
(TODO) Stencils

(TODO) Reductions, ternary-like operator

(TODO) Random Number Generators

(TODO) Vectorization

(TODO) Boost.MPI and Boost.serialization support

(TODO) Tau profiler integration

Clone this wiki locally