![]() |
Blitz Support : |
From: Marcel Loose (loose_at_[hidden])
Date: 2004-08-13 05:37:39
Hi,
I was wondering if there is a concise way to do a circular shift on the
contents of an Array (1D, 2D, etc).
For example, suppose I have the following 1D Array:
Array<int, 1> v(5);
v = tensor::i + 1;
which looks like this (obviously):
[ 1 2 3 4 5 ]
Now, I would like to do a circular right shift of 3 on the elements of
v and store the results in vv.
Vector vv should then contain:
[ 3 4 5 1 2 ]
I tried to do it as follows:
Array<int, 1> vv(v.copy());
vv = v((tensor::i+3)%v.rows());
However, this will not compile. The compiler (g++ 3.2.2) diagnostics
start with:
no match for call to `(blitz::Array<int, 1>) (
blitz::_bz_ArrayExpr<blitz::_bz_ArrayExprOp<blitz::_bz_ArrayExpr<blitz::_bz_A
rrayExprOp<blitz::IndexPlaceholder<0>,
blitz::_bz_ArrayExprConstant<int>, blitz::Add<int, int> > >,
blitz::_bz_ArrayExprConstant<int>, blitz::Modulo<int, int> > >)'
Is there a way to accomplish a circular shift (also in 2D), other than
using a for-loop or swap ranges??
And if not, what is the best way to do this?
Kind regards,
Marcel Loose