/*****************************************************************************
* matmult.cpp Blitz++ tensor notation example
*****************************************************************************
* This example illustrates the tensor-like notation provided by Blitz++.
*/
#include <blitz/array.h>
#include <iostream>
using namespace blitz;
int main()
{
// Create two 4x4 arrays. We want them to look like matrices, so
// we'll make the valid index range 1..4 (rather than 0..3 which is
// the default).
Range r(1,4);
Array<float,2> A(r,r), B(r,r);
// The first will be a Hilbert matrix:
//
// a = 1
// ij -----
// i+j-1
//
// Blitz++ provides a set of types { firstIndex, secondIndex, ... }
// which act as placeholders for indices. These can be used directly
// in expressions. For example, we can fill out the A matrix like this:
firstIndex i; // Placeholder for the first index
secondIndex j; // Placeholder for the second index
A = 1.0 / (i+j-1);
cout << "A = " << A << endl;
// A = 4 x 4
// 1 0.5 0.333333 0.25
// 0.5 0.333333 0.25 0.2
// 0.333333 0.25 0.2 0.166667
// 0.25