Blitz logo

Blitz Support :

From: Olivier Saut (novocaine_at_[hidden])
Date: 2003-11-15 08:54:44


Thanks for writing Blitz++. I am currently converting my code in quantum
optics from F90 to C++/Blitz++ (but I am far from being an experienced
C++ programmer so I hope I won't sound too stupid!). I have a few questions.

The following code does not work, I can not understand why

#include <blitz/array.h>
#include <blitz/vector.h>
#include <blitz/tinymat.h>
#include <iostream>
#include <complex>

BZ_USING_NAMESPACE(blitz)
using namespace std;

typedef Vector< TinyMatrix< complex<double>, 5,5> > densityMatrix;

int main(void) {
        densityMatrix rho(3);
        rho(0)=0;
        (rho(0))(1,1)=1515;
        rho(1)=1;
        rho(2)=2;
        
        cout << rho(1)-rho(2) << endl; // This line does not compile
}

The error is
test.cpp: In function `int main()':
test.cpp:39: error: no match for 'operator-' in '
    (&rho)->blitz::Vector<P_numtype>::operator()(int) [with P_numtype =
    blitz::TinyMatrix<std::complex<double>, 5, 5>](1) -
    (&rho)->blitz::Vector<P_numtype>::operator()(int) [with P_numtype =
    blitz::TinyMatrix<std::complex<double>, 5, 5>](2)'
/usr/local/include/blitz/vecexpr.h:262: error: candidates are:
    blitz::_bz_VecExpr<blitz::_bz_VecExprUnaryOp<blitz::Range,
    blitz::_bz_negate<int> > > blitz::operator-(blitz::Range)

In my another method, I try to compute the trace of a complex matrix with
std::complex<double> trace(const
    blitz::Array<std::complex<double>, 2>& A){
        firstIndex i;
        return sum(A(i,i), i);
}

blas.cpp: In function `std::complex<double> trace(const
    blitz::Array<std::complex<double>, 2>&)':
blas.cpp:38: error: conversion from `
 
blitz::_bz_ArrayExpr<blitz::_bz_ArrayExprReduce<blitz::_bz_ArrayExpr<blitz::ArrayIndexMapping<std::complex<double>,
    2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> >, 0,
    blitz::ReduceSum<std::complex<double>, std::complex<double> > > >' to
    non-scalar type `std::complex<double>' requested

Is it related to sum or is it just a C++ thing?

Thanks a lot!

PS I use the FreeBSD port of Blitz 0.7
(http://www.freebsd.org/cgi/cvsweb.cgi/ports/math/blitz%2b%2b/) which
uses the following dirty hack

--- doc/Makefile.in.orig Sat Nov 8 00:45:38 2003
+++ doc/Makefile.in Sat Nov 8 00:45:33 2003
@@ -155,7 +155,7 @@ SUBDIRS = examples stencils

  # install these files
  docdir = $(prefix)/doc
-doc_DATA = blitz.ps
+doc_DATA =

  AM_MAKEINFOFLAGS = --no-split
  TEXI2HTML = texi2html

to avoid installing blitz.ps in $prefix/doc, whereas the other files
from Blitz++-0.7/doc are installed in $prefix/doc/blitz. Is it possible
to install this file directly into $prefix/doc/blitz?

                        - Olivier