![]() |
Blitz Support : |
From: Derrick Bass (derrick_at_[hidden])
Date: 2005-04-27 22:18:48
> for (int j = 0, norm1 = 0; j < M.columns(); ++j) {
> norm1 = max(norm1, sum(abs(M(Range::all(), j))));
> }
> I see in the mail archives that (as usual) performance
> is very sensitive to implementation, so since I'm a newbie,
> if this isn't optimal, how does one do it in the best
> blitzian way?
>
>
How about
norm1 = max( sum(abs( M(tensor::j, tensor::i) ), tensor::j ) )
(You'll have to check to make sure I got my indices right. sum() can
only sum over the last index, so I transposed the matrix.) I suspect
this will not be any more efficient than your version, since there is
very little choice with respect to the order in which the array
elements are visited. Also, your version, of course, will not handle
arrays whose column indices don't begin at 0.
> Second puzzle is how to efficiently permute the rows of a
> matrix, given say an Array<int,1> of permuted rows
> handed back by lapack routines. I see transpose and reindex
> but these appear to reorder dimensions, not rows.
> Any hints?
>
You just have to do it manually. Blitz accesses arrays via a stride
vector, so any ordering that can be expressed as
offset of element (i,j) = i * stride1 + j * stride2
can be handled by Blitz. In particular this means that for each row,
the first element is offset from that of the previous row by the same
amount. So arbitrary re-ordering of rows can't be handled directly in
Blitz. You can just access the elements via the permutation vector,
e.g. a( perm(i), j ), or explicitly create a reordered array:
for (int i=a.lbound(firstDim); i<=a.ubound(firstDim); ++i)
reordered( i, Range::all() ) = a( perm(i), Range::all() );
You can also reorder in place, if need be, but that would be tricky to
code correctly.
Derrick