Added blitz
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/asexpr.h Declaration of the asExpr helper functions
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
***************************************************************************/
|
||||
#ifndef BZ_ASEXPR_CC
|
||||
#define BZ_ASEXPR_CC
|
||||
|
||||
#include <blitz/array/asexpr.h>
|
||||
#include <blitz/array-impl.h>
|
||||
#include <blitz/levicivita.h>
|
||||
#include <blitz/range.h>
|
||||
#include <blitz/array/expr.h>
|
||||
|
||||
// implementations of asexpr functions.
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// default to scalar
|
||||
template <typename T>
|
||||
_bz_typename asExpr<T>::T_expr asExpr<T>::getExpr(const T& x)
|
||||
{ return T_expr(x); }
|
||||
|
||||
// expression template term just returns itself
|
||||
template <typename T>
|
||||
const _bz_typename asExpr<_bz_ArrayExpr<T> >::T_expr&
|
||||
asExpr<_bz_ArrayExpr<T> >::getExpr(const T_expr& x)
|
||||
{ return x; }
|
||||
|
||||
// array operand returns iterator
|
||||
template <typename T,int N>
|
||||
_bz_typename asExpr<Array<T,N> >::T_expr
|
||||
asExpr<Array<T,N> >::getExpr(const Array<T,N>& x)
|
||||
{ return x.beginFast(); }
|
||||
|
||||
// tinyvector operand returns iterator
|
||||
template <typename T,int N>
|
||||
_bz_typename asExpr<TinyVector<T,N> >::T_expr
|
||||
asExpr<TinyVector<T,N> >::getExpr(const TinyVector<T,N>& x)
|
||||
{ return x.beginFast(); }
|
||||
|
||||
// tinymatrix operands returns iterator
|
||||
template <typename T,int Nr, int Nc>
|
||||
_bz_typename asExpr<TinyMatrix<T,Nr, Nc> >::T_expr
|
||||
asExpr<TinyMatrix<T,Nr, Nc> >::getExpr(const TinyMatrix<T,Nr,Nc>& x)
|
||||
{ return x.beginFast(); }
|
||||
|
||||
// Index placeholder returns itself
|
||||
template <int N>
|
||||
_bz_typename asExpr<IndexPlaceholder<N> >::T_expr
|
||||
asExpr<IndexPlaceholder<N> >::getExpr(const T_expr& x)
|
||||
{ return x; }
|
||||
|
||||
// the levi-civita symbol
|
||||
inline asExpr<LeviCivita>::T_expr
|
||||
asExpr<LeviCivita>::getExpr(T_expr x)
|
||||
{ return T_expr(x); }
|
||||
|
||||
// Range
|
||||
inline asExpr<Range>::T_expr
|
||||
asExpr<Range>::getExpr(T_expr x)
|
||||
{ return T_expr(x); }
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,304 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/asexpr.h Declaration of the asExpr helper functions
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
***************************************************************************/
|
||||
#ifndef BZ_ASEXPR_H
|
||||
#define BZ_ASEXPR_H
|
||||
|
||||
#include <blitz/et-forward.h>
|
||||
#include <blitz/numtrait.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// The traits class asExpr converts arbitrary things to
|
||||
// expression templatable operands.
|
||||
|
||||
// Default to scalar.
|
||||
template <typename T>
|
||||
struct asExpr {
|
||||
typedef _bz_ArrayExpr<_bz_ArrayExprConstant<T> > T_expr;
|
||||
static T_expr getExpr(const T& x);
|
||||
};
|
||||
|
||||
// Already an expression template term
|
||||
template <typename T>
|
||||
struct asExpr<_bz_ArrayExpr<T> > {
|
||||
typedef _bz_ArrayExpr<T> T_expr;
|
||||
static const T_expr& getExpr(const T_expr& x);
|
||||
};
|
||||
|
||||
// Specialization of asExpr for array operands
|
||||
// why doesn't it wrap iterators in an ArrayExpr?
|
||||
template <typename T,int N>
|
||||
struct asExpr<Array<T,N> > {
|
||||
//typedef FastArrayIterator<T,N> T_expr;
|
||||
typedef _bz_ArrayExpr<FastArrayIterator<T,N> > T_expr;
|
||||
static T_expr getExpr(const Array<T,N>& x);
|
||||
};
|
||||
|
||||
// Specialization of asExpr for tinyvector operands
|
||||
template <typename T,int N>
|
||||
struct asExpr<TinyVector<T,N> > {
|
||||
typedef _bz_ArrayExpr<FastTV2Iterator<T,N> > T_expr;
|
||||
static T_expr getExpr(const TinyVector<T,N>& x);
|
||||
};
|
||||
|
||||
// Specialization of asExpr for tinymatrix operands
|
||||
template <typename T,int Nr, int Nc>
|
||||
struct asExpr<TinyMatrix<T,Nr, Nc> > {
|
||||
typedef _bz_ArrayExpr<FastTM2Iterator<T,Nr, Nc> > T_expr;
|
||||
static T_expr getExpr(const TinyMatrix<T,Nr,Nc>& x);
|
||||
};
|
||||
|
||||
// Index placeholder
|
||||
template <int N>
|
||||
struct asExpr<IndexPlaceholder<N> > {
|
||||
// typedef _bz_ArrayExpr<IndexPlaceholder<N> > T_expr;
|
||||
typedef _bz_ArrayExpr<IndexPlaceholder<N> > T_expr;
|
||||
static T_expr getExpr(const T_expr& x);
|
||||
};
|
||||
|
||||
// the levi-civita symbol
|
||||
template <>
|
||||
struct asExpr<LeviCivita> {
|
||||
typedef _bz_ArrayExpr<LeviCivita> T_expr;
|
||||
static T_expr getExpr(T_expr x);
|
||||
};
|
||||
|
||||
// Range
|
||||
template <>
|
||||
struct asExpr<Range> {
|
||||
typedef _bz_ArrayExpr<Range> T_expr;
|
||||
static T_expr getExpr(T_expr x);
|
||||
};
|
||||
|
||||
|
||||
// traits class that transforms ETBase subclasses into the
|
||||
// ET<>-wrapped superclass and corresponding expression, but unlike
|
||||
// the asExpr class it leaves POD types alone. This is necessary so
|
||||
// operators on multicomponent arrays can resolve properly.
|
||||
template<typename T>
|
||||
struct asET {
|
||||
typedef T T_wrapped;
|
||||
typedef T T_expr;
|
||||
};
|
||||
template<typename T>
|
||||
struct asET<ETBase<T> > {
|
||||
typedef ETBase<typename asExpr<T>::T_expr> T_wrapped;
|
||||
typedef typename asExpr<T>::T_expr T_expr;
|
||||
};
|
||||
template<typename T, int N>
|
||||
struct asET<Array<T,N> > {
|
||||
typedef ETBase<typename asExpr<Array<T,N> >::T_expr> T_wrapped;
|
||||
typedef typename asExpr<Array<T,N> >::T_expr T_expr;
|
||||
};
|
||||
template<typename T, int N>
|
||||
struct asET<TinyVector<T,N> > {
|
||||
typedef ETBase<typename asExpr<TinyVector<T,N> >::T_expr> T_wrapped;
|
||||
typedef typename asExpr<TinyVector<T,N> >::T_expr T_expr;
|
||||
};
|
||||
template<typename T, int Nr, int Nc>
|
||||
struct asET<TinyMatrix<T,Nr,Nc> > {
|
||||
typedef ETBase<typename asExpr<TinyMatrix<T,Nr,Nc> >::T_expr> T_wrapped;
|
||||
typedef typename asExpr<TinyMatrix<T,Nr,Nc> >::T_expr T_expr;
|
||||
};
|
||||
|
||||
// traits class that unwraps an ETBase type, otherwise leaves it untouched.
|
||||
template<typename T>
|
||||
struct unwrapET {
|
||||
typedef T T_unwrapped;
|
||||
};
|
||||
template<typename T>
|
||||
struct unwrapET<ETBase<T> > {
|
||||
typedef T T_unwrapped;
|
||||
};
|
||||
|
||||
// traits classes that are used to switch between an ET type or an
|
||||
// unknown type. If the supplied type T is an ET type, T_selected will
|
||||
// be T_ifET, otherwise T.
|
||||
template<typename T, typename T_ifnotET, typename T_ifET>
|
||||
struct selectET {
|
||||
typedef T_ifnotET T_selected;
|
||||
};
|
||||
template<typename T, typename T_ifnotET, typename T_ifET>
|
||||
struct selectET<ETBase<T>, T_ifnotET, T_ifET> {
|
||||
typedef ETBase<T_ifET> T_selected;
|
||||
};
|
||||
|
||||
// for binary exprs, it is more complicated. if T1 or T2 are an ET,
|
||||
// T_ifET is selected, otherwise T_ifnotET.
|
||||
template<typename T1, typename T2, typename T_ifnotET, typename T_ifET>
|
||||
struct selectET2 {
|
||||
typedef T_ifnotET T_selected;
|
||||
};
|
||||
template<typename T1, typename T2, typename T_ifnotET, typename T_ifET>
|
||||
struct selectET2<ETBase<T1>, T2, T_ifnotET, T_ifET> {
|
||||
typedef ETBase<T_ifET> T_selected;
|
||||
};
|
||||
template<typename T1, typename T2, typename T_ifnotET, typename T_ifET>
|
||||
struct selectET2<T1, ETBase<T2>, T_ifnotET, T_ifET> {
|
||||
typedef ETBase<T_ifET> T_selected;
|
||||
};
|
||||
template<typename T1, typename T2, typename T_ifnotET, typename T_ifET>
|
||||
struct selectET2<ETBase<T1>, ETBase<T2>, T_ifnotET, T_ifET> {
|
||||
typedef ETBase<T_ifET> T_selected;
|
||||
};
|
||||
|
||||
|
||||
// traits class that resolves to the ultimate numeric datatype used
|
||||
// for operations on the container. This is necessary because for
|
||||
// multicomponent containers we need to determine what the ultimate
|
||||
// POD data type is.
|
||||
template<typename T>
|
||||
struct opType {
|
||||
typedef T T_optype;
|
||||
};
|
||||
template<typename T>
|
||||
struct opType<ETBase<T> > {
|
||||
typedef typename opType<T>::T_optype T_optype;
|
||||
};
|
||||
template<typename T, int N>
|
||||
struct opType<Array<T,N> > {
|
||||
typedef typename opType<T>::T_optype T_optype;
|
||||
};
|
||||
template<typename T, int N>
|
||||
struct opType<TinyVector<T,N> > {
|
||||
typedef typename opType<T>::T_optype T_optype;
|
||||
};
|
||||
template<typename T, int Nr, int Nc>
|
||||
struct opType<TinyMatrix<T,Nr,Nc> > {
|
||||
typedef typename opType<T>::T_optype T_optype;
|
||||
};
|
||||
|
||||
|
||||
#ifdef BZ_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS
|
||||
|
||||
// traits classes that provide the return type of operations
|
||||
|
||||
template <template <typename T1> class OP, typename O1>
|
||||
struct BzUnaryExprResult {
|
||||
typedef _bz_ArrayExpr<
|
||||
_bz_ArrayExprUnaryOp<
|
||||
typename asExpr<O1>::T_expr,
|
||||
OP<
|
||||
typename asExpr<O1>::T_expr::T_optype
|
||||
>
|
||||
> > T_result;
|
||||
};
|
||||
|
||||
template <template <typename T1, typename T2> class OP,
|
||||
typename O1, typename O2>
|
||||
struct BzBinaryExprResult {
|
||||
typedef _bz_ArrayExpr<_bz_ArrayExprBinaryOp<
|
||||
typename asExpr<O1>::T_expr,
|
||||
typename asExpr<O2>::T_expr,
|
||||
OP<
|
||||
typename asExpr<O1>::T_expr::T_optype,
|
||||
typename asExpr<O2>::T_expr::T_optype
|
||||
> > > T_result;
|
||||
};
|
||||
|
||||
template <template <typename T1, typename T2, typename T3> class OP,
|
||||
typename O1, typename O2, typename O3>
|
||||
struct BzTernaryExprResult {
|
||||
typedef _bz_ArrayExpr<_bz_ArrayExprTernaryOp<
|
||||
typename asExpr<O1>::T_expr,
|
||||
typename asExpr<O2>::T_expr,
|
||||
typename asExpr<O3>::T_expr,
|
||||
OP<
|
||||
typename asExpr<O1>::T_expr::T_optype,
|
||||
typename asExpr<O2>::T_expr::T_optype,
|
||||
typename asExpr<O3>::T_expr::T_optype
|
||||
> > > T_result;
|
||||
};
|
||||
|
||||
template <template <typename T1, typename T2, typename T3, typename T4> class OP,
|
||||
typename O1, typename O2, typename O3, typename O4>
|
||||
struct BzQuaternaryExprResult {
|
||||
typedef _bz_ArrayExpr<_bz_ArrayExprQuaternaryOp<
|
||||
typename asExpr<O1>::T_expr,
|
||||
typename asExpr<O2>::T_expr,
|
||||
typename asExpr<O3>::T_expr,
|
||||
typename asExpr<O4>::T_expr,
|
||||
OP<
|
||||
typename asExpr<O1>::T_expr::T_optype,
|
||||
typename asExpr<O2>::T_expr::T_optype,
|
||||
typename asExpr<O3>::T_expr::T_optype,
|
||||
typename asExpr<O4>::T_expr::T_optype
|
||||
> > > T_result;
|
||||
};
|
||||
|
||||
template <template <typename T1, typename T2> class RED, int N, typename O1,
|
||||
typename P_result = BZ_SUMTYPE(typename asExpr<O1>::T_expr::T_optype)>
|
||||
struct BzReductionResult {
|
||||
typedef _bz_ArrayExpr<
|
||||
_bz_ArrayExprReduce<
|
||||
typename asExpr<O1>::T_expr,
|
||||
N,
|
||||
RED<typename asExpr<O1>::T_expr::T_optype, P_result>
|
||||
> > T_result;
|
||||
};
|
||||
|
||||
template<typename O1, int N0, int N1=0, int N2=0, int N3=0, int N4=0,
|
||||
int N5=0, int N6=0, int N7=0, int N8=0, int N9=0, int N10=0>
|
||||
struct BzIndexmapResult {
|
||||
typedef _bz_ArrayExpr<
|
||||
ArrayIndexMapping<
|
||||
typename asExpr<O1>::T_expr,
|
||||
N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10
|
||||
>
|
||||
> T_result;
|
||||
};
|
||||
|
||||
template<template <typename T> class STENCIL, typename O1>
|
||||
struct BzStencilResult {
|
||||
typedef _bz_ArrayExpr<
|
||||
STENCIL<
|
||||
typename asExpr<O1>::T_expr::T_range_result
|
||||
>
|
||||
> T_result;
|
||||
};
|
||||
|
||||
template<template <typename T1, typename T2, typename T3> class STENCIL,
|
||||
typename O1, typename O2, typename P_result>
|
||||
struct BzBinaryStencilResult {
|
||||
typedef _bz_ArrayExpr<
|
||||
STENCIL<
|
||||
typename asExpr<O1>::T_expr::T_range_result,
|
||||
typename asExpr<O2>::T_expr::T_range_result,
|
||||
P_result
|
||||
> > T_result;
|
||||
};
|
||||
|
||||
|
||||
#endif /* BZ_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS */
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,347 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/cartesian.h Cartesian product of indirection containers
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAY_CARTESIAN_H
|
||||
#define BZ_ARRAY_CARTESIAN_H
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* CartesianProduct<T_tuple,T_container> is an adaptor which represents
|
||||
* the cartesian product of several containers.
|
||||
*/
|
||||
|
||||
// forward declaration of iterator
|
||||
template<typename T_tuple, typename T_container, int N_containers>
|
||||
class CartesianProductIterator;
|
||||
|
||||
struct _cp_end_tag { };
|
||||
|
||||
template<typename T_tuple, typename T_container, int N_containers>
|
||||
class CartesianProduct {
|
||||
public:
|
||||
typedef T_tuple value_type;
|
||||
typedef T_tuple& reference;
|
||||
typedef const T_tuple& const_reference;
|
||||
typedef CartesianProductIterator<T_tuple,T_container,N_containers> iterator;
|
||||
|
||||
iterator begin()
|
||||
{ return iterator(*this); }
|
||||
|
||||
iterator end()
|
||||
{ return iterator(_cp_end_tag()); }
|
||||
|
||||
CartesianProduct(const T_container& container0,
|
||||
const T_container& container1)
|
||||
{
|
||||
BZPRECONDITION(N_containers == 2);
|
||||
containers_[0] = &container0;
|
||||
containers_[1] = &container1;
|
||||
}
|
||||
|
||||
CartesianProduct(const T_container& container0,
|
||||
const T_container& container1,
|
||||
const T_container& container2)
|
||||
{
|
||||
BZPRECONDITION(N_containers == 3);
|
||||
containers_[0] = &container0;
|
||||
containers_[1] = &container1;
|
||||
containers_[2] = &container2;
|
||||
}
|
||||
|
||||
CartesianProduct(const T_container& container0,
|
||||
const T_container& container1,
|
||||
const T_container& container2,
|
||||
const T_container& container3)
|
||||
{
|
||||
BZPRECONDITION(N_containers == 4);
|
||||
containers_[0] = &container0;
|
||||
containers_[1] = &container1;
|
||||
containers_[2] = &container2;
|
||||
containers_[3] = &container3;
|
||||
}
|
||||
|
||||
CartesianProduct(const T_container& container0,
|
||||
const T_container& container1,
|
||||
const T_container& container2,
|
||||
const T_container& container3,
|
||||
const T_container& container4)
|
||||
{
|
||||
BZPRECONDITION(N_containers == 5);
|
||||
containers_[0] = &container0;
|
||||
containers_[1] = &container1;
|
||||
containers_[2] = &container2;
|
||||
containers_[3] = &container3;
|
||||
containers_[4] = &container4;
|
||||
}
|
||||
|
||||
CartesianProduct(const T_container& container0,
|
||||
const T_container& container1,
|
||||
const T_container& container2,
|
||||
const T_container& container3,
|
||||
const T_container& container4,
|
||||
const T_container& container5)
|
||||
{
|
||||
BZPRECONDITION(N_containers == 6);
|
||||
containers_[0] = &container0;
|
||||
containers_[1] = &container1;
|
||||
containers_[2] = &container2;
|
||||
containers_[3] = &container3;
|
||||
containers_[4] = &container4;
|
||||
containers_[5] = &container5;
|
||||
}
|
||||
|
||||
CartesianProduct(const T_container& container0,
|
||||
const T_container& container1,
|
||||
const T_container& container2,
|
||||
const T_container& container3,
|
||||
const T_container& container4,
|
||||
const T_container& container5,
|
||||
const T_container& container6)
|
||||
{
|
||||
BZPRECONDITION(N_containers == 7);
|
||||
containers_[0] = &container0;
|
||||
containers_[1] = &container1;
|
||||
containers_[2] = &container2;
|
||||
containers_[3] = &container3;
|
||||
containers_[4] = &container4;
|
||||
containers_[5] = &container5;
|
||||
containers_[6] = &container6;
|
||||
}
|
||||
|
||||
CartesianProduct(const T_container& container0,
|
||||
const T_container& container1,
|
||||
const T_container& container2,
|
||||
const T_container& container3,
|
||||
const T_container& container4,
|
||||
const T_container& container5,
|
||||
const T_container& container6,
|
||||
const T_container& container7)
|
||||
{
|
||||
BZPRECONDITION(N_containers == 8);
|
||||
containers_[0] = &container0;
|
||||
containers_[1] = &container1;
|
||||
containers_[2] = &container2;
|
||||
containers_[3] = &container3;
|
||||
containers_[4] = &container4;
|
||||
containers_[5] = &container5;
|
||||
containers_[6] = &container6;
|
||||
containers_[7] = &container7;
|
||||
}
|
||||
|
||||
CartesianProduct(const T_container& container0,
|
||||
const T_container& container1,
|
||||
const T_container& container2,
|
||||
const T_container& container3,
|
||||
const T_container& container4,
|
||||
const T_container& container5,
|
||||
const T_container& container6,
|
||||
const T_container& container7,
|
||||
const T_container& container8)
|
||||
{
|
||||
BZPRECONDITION(N_containers == 9);
|
||||
containers_[0] = &container0;
|
||||
containers_[1] = &container1;
|
||||
containers_[2] = &container2;
|
||||
containers_[3] = &container3;
|
||||
containers_[4] = &container4;
|
||||
containers_[5] = &container5;
|
||||
containers_[6] = &container6;
|
||||
containers_[7] = &container7;
|
||||
containers_[8] = &container8;
|
||||
}
|
||||
|
||||
CartesianProduct(const T_container& container0,
|
||||
const T_container& container1,
|
||||
const T_container& container2,
|
||||
const T_container& container3,
|
||||
const T_container& container4,
|
||||
const T_container& container5,
|
||||
const T_container& container6,
|
||||
const T_container& container7,
|
||||
const T_container& container8,
|
||||
const T_container& container9)
|
||||
{
|
||||
BZPRECONDITION(N_containers == 10);
|
||||
containers_[0] = &container0;
|
||||
containers_[1] = &container1;
|
||||
containers_[2] = &container2;
|
||||
containers_[3] = &container3;
|
||||
containers_[4] = &container4;
|
||||
containers_[5] = &container5;
|
||||
containers_[6] = &container6;
|
||||
containers_[7] = &container7;
|
||||
containers_[8] = &container8;
|
||||
containers_[9] = &container9;
|
||||
}
|
||||
|
||||
CartesianProduct(const T_container& container0,
|
||||
const T_container& container1,
|
||||
const T_container& container2,
|
||||
const T_container& container3,
|
||||
const T_container& container4,
|
||||
const T_container& container5,
|
||||
const T_container& container6,
|
||||
const T_container& container7,
|
||||
const T_container& container8,
|
||||
const T_container& container9,
|
||||
const T_container& container10)
|
||||
{
|
||||
BZPRECONDITION(N_containers == 11);
|
||||
containers_[0] = &container0;
|
||||
containers_[1] = &container1;
|
||||
containers_[2] = &container2;
|
||||
containers_[3] = &container3;
|
||||
containers_[4] = &container4;
|
||||
containers_[5] = &container5;
|
||||
containers_[6] = &container6;
|
||||
containers_[7] = &container7;
|
||||
containers_[8] = &container8;
|
||||
containers_[9] = &container9;
|
||||
containers_[10] = &container10;
|
||||
}
|
||||
|
||||
const T_container& operator[](int i)
|
||||
{ return *(containers_[i]); }
|
||||
|
||||
void debugDump();
|
||||
|
||||
protected:
|
||||
const T_container* containers_[N_containers];
|
||||
};
|
||||
|
||||
template<typename T_tuple, typename T_container, int N_containers>
|
||||
void CartesianProduct<T_tuple,T_container,N_containers>::debugDump()
|
||||
{
|
||||
cout << "Dump of CartesianProduct<..,..," << N_containers << ">" << endl;
|
||||
for (int i=0; i < N_containers; ++i)
|
||||
{
|
||||
cout << "Container " << (i+1) << ": ";
|
||||
_bz_typename T_container::const_iterator iter = containers_[i]->begin(),
|
||||
end = containers_[i]->end();
|
||||
for (; iter != end; ++iter)
|
||||
cout << (*iter) << '\t';
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T_tuple, typename T_container, int N_containers>
|
||||
class CartesianProductIterator {
|
||||
public:
|
||||
typedef _bz_typename T_container::const_iterator citerator;
|
||||
typedef CartesianProductIterator<T_tuple,T_container,N_containers> iterator;
|
||||
typedef CartesianProduct<T_tuple,T_container,N_containers> T_cp;
|
||||
|
||||
CartesianProductIterator(T_cp& container)
|
||||
{
|
||||
for (int i=0; i < N_containers; ++i)
|
||||
{
|
||||
firstiters_[i] = container[i].begin();
|
||||
iters_[i] = firstiters_[i];
|
||||
enditers_[i] = container[i].end();
|
||||
tuple_[i] = *iters_[i];
|
||||
}
|
||||
|
||||
endflag_ = false;
|
||||
}
|
||||
|
||||
void operator++();
|
||||
|
||||
CartesianProductIterator(_cp_end_tag)
|
||||
{
|
||||
endflag_ = true;
|
||||
}
|
||||
|
||||
bool operator==(const iterator& x) const
|
||||
{
|
||||
return (endflag_ == x.endflag_);
|
||||
}
|
||||
|
||||
bool operator!=(const iterator& x) const
|
||||
{
|
||||
return endflag_ != x.endflag_;
|
||||
}
|
||||
|
||||
const T_tuple& operator*() const
|
||||
{ return tuple_; }
|
||||
|
||||
protected:
|
||||
citerator iters_[N_containers];
|
||||
citerator firstiters_[N_containers];
|
||||
citerator enditers_[N_containers];
|
||||
T_tuple tuple_;
|
||||
bool endflag_;
|
||||
};
|
||||
|
||||
template<typename T_tuple, typename T_container, int N_containers>
|
||||
void CartesianProductIterator<T_tuple, T_container,
|
||||
N_containers>::operator++()
|
||||
{
|
||||
// Usual stack-style increment
|
||||
const int Nminus1 = N_containers - 1;
|
||||
|
||||
int i = Nminus1;
|
||||
|
||||
// Short-circuit for most common case
|
||||
// (just increment the last iterator)
|
||||
|
||||
if((++iters_[i]) != enditers_[i])
|
||||
{
|
||||
tuple_[i] = *iters_[i];
|
||||
return;
|
||||
}
|
||||
|
||||
// Less common cases
|
||||
|
||||
for (--i; i >= 0; --i)
|
||||
{
|
||||
++iters_[i];
|
||||
if (iters_[i] != enditers_[i])
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == -1)
|
||||
{
|
||||
endflag_ = true;
|
||||
return;
|
||||
}
|
||||
|
||||
tuple_[i] = *iters_[i];
|
||||
|
||||
for (++i; i < N_containers; ++i)
|
||||
{
|
||||
iters_[i] = firstiters_[i];
|
||||
tuple_[i] = *iters_[i];
|
||||
}
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAY_CARTESIAN_H
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/cgsolve.h Basic conjugate gradient solver for linear systems
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_CGSOLVE_H
|
||||
#define BZ_CGSOLVE_H
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename T_numtype>
|
||||
void dump(const char* name, Array<T_numtype,3>& A)
|
||||
{
|
||||
T_numtype normA = 0;
|
||||
|
||||
for (int i=A.lbound(0); i <= A.ubound(0); ++i)
|
||||
{
|
||||
for (int j=A.lbound(1); j <= A.ubound(1); ++j)
|
||||
{
|
||||
for (int k=A.lbound(2); k <= A.ubound(2); ++k)
|
||||
{
|
||||
T_numtype tmp = A(i,j,k);
|
||||
normA += BZ_MATHFN_SCOPE(fabs)(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
normA /= A.numElements();
|
||||
cout << "Average magnitude of " << name << " is " << normA << endl;
|
||||
}
|
||||
|
||||
template<typename T_stencil, typename T_numtype, int N_rank, typename T_BCs>
|
||||
int conjugateGradientSolver(T_stencil stencil,
|
||||
Array<T_numtype,N_rank>& x,
|
||||
Array<T_numtype,N_rank>& rhs, double haltrho,
|
||||
const T_BCs& boundaryConditions)
|
||||
{
|
||||
// NEEDS_WORK: only apply CG updates over interior; need to handle
|
||||
// BCs separately.
|
||||
|
||||
// x = unknowns being solved for (initial guess assumed)
|
||||
// r = residual
|
||||
// p = descent direction for x
|
||||
// q = descent direction for r
|
||||
|
||||
RectDomain<N_rank> interior = interiorDomain(stencil, x, rhs);
|
||||
|
||||
cout << "Interior: " << interior.lbound() << ", " << interior.ubound()
|
||||
<< endl;
|
||||
|
||||
// Calculate initial residual
|
||||
Array<T_numtype,N_rank> r = rhs.copy();
|
||||
r *= -1.0;
|
||||
|
||||
boundaryConditions.applyBCs(x);
|
||||
|
||||
applyStencil(stencil, r, x);
|
||||
|
||||
dump("r after stencil", r);
|
||||
cout << "Slice through r: " << endl << r(23,17,Range::all()) << endl;
|
||||
cout << "Slice through x: " << endl << x(23,17,Range::all()) << endl;
|
||||
cout << "Slice through rhs: " << endl << rhs(23,17,Range::all()) << endl;
|
||||
|
||||
r *= -1.0;
|
||||
|
||||
dump("r", r);
|
||||
|
||||
// Allocate the descent direction arrays
|
||||
Array<T_numtype,N_rank> p, q;
|
||||
allocateArrays(x.shape(), p, q);
|
||||
|
||||
int iteration = 0;
|
||||
int converged = 0;
|
||||
T_numtype rho = 0.;
|
||||
T_numtype oldrho = 0.;
|
||||
|
||||
const int maxIterations = 1000;
|
||||
|
||||
// Get views of interior of arrays (without boundaries)
|
||||
Array<T_numtype,N_rank> rint = r(interior);
|
||||
Array<T_numtype,N_rank> pint = p(interior);
|
||||
Array<T_numtype,N_rank> qint = q(interior);
|
||||
Array<T_numtype,N_rank> xint = x(interior);
|
||||
|
||||
while (iteration < maxIterations)
|
||||
{
|
||||
rho = sum(r * r);
|
||||
|
||||
if ((iteration % 20) == 0)
|
||||
cout << "CG: Iter " << iteration << "\t rho = " << rho << endl;
|
||||
|
||||
// Check halting condition
|
||||
if (rho < haltrho)
|
||||
{
|
||||
converged = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (iteration == 0)
|
||||
{
|
||||
p = r;
|
||||
}
|
||||
else {
|
||||
T_numtype beta = rho / oldrho;
|
||||
p = beta * p + r;
|
||||
}
|
||||
|
||||
q = 0.;
|
||||
// boundaryConditions.applyBCs(p);
|
||||
applyStencil(stencil, q, p);
|
||||
|
||||
T_numtype pq = sum(p*q);
|
||||
|
||||
T_numtype alpha = rho / pq;
|
||||
|
||||
x += alpha * p;
|
||||
r -= alpha * q;
|
||||
|
||||
oldrho = rho;
|
||||
++iteration;
|
||||
}
|
||||
|
||||
if (!converged)
|
||||
cout << "Warning: CG solver did not converge" << endl;
|
||||
|
||||
return iteration;
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_CGSOLVE_H
|
||||
@@ -0,0 +1,61 @@
|
||||
/***************************************************************************
|
||||
* blitz/array/complex.cc Special functions for complex arrays
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYCOMPLEX_CC
|
||||
#define BZ_ARRAYCOMPLEX_CC
|
||||
|
||||
// Special functions for complex arrays
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/complex.cc> must be included via <blitz/array/array.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
inline Array<T_numtype, N_rank> real(const Array<complex<T_numtype>,N_rank>& A)
|
||||
{
|
||||
return A.extractComponent(T_numtype(), 0, 2);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
inline Array<T_numtype, N_rank> imag(const Array<complex<T_numtype>,N_rank>& A)
|
||||
{
|
||||
return A.extractComponent(T_numtype(), 1, 2);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYCOMPLEX_CC
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/***************************************************************************
|
||||
* blitz/array/convolve.cc One-dimensional convolution
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef BZ_ARRAY_CONVOLVE_CC
|
||||
#define BZ_ARRAY_CONVOLVE_CC
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename T>
|
||||
Array<T,1> convolve(const Array<T,1>& B, const Array<T,1>& C)
|
||||
{
|
||||
int Bl = B.lbound(0), Bh = B.ubound(0);
|
||||
int Cl = C.lbound(0), Ch = C.ubound(0);
|
||||
|
||||
int lbound = Bl + Cl;
|
||||
int ubound = Bh + Ch;
|
||||
|
||||
Array<T,1> A(Range(lbound,ubound));
|
||||
|
||||
T result;
|
||||
for (int i=lbound; i <= ubound; ++i)
|
||||
{
|
||||
int jl = i - Ch;
|
||||
if (jl < Bl)
|
||||
jl = Bl;
|
||||
|
||||
int jh = i - Cl;
|
||||
if (jh > Bh)
|
||||
jh = Bh;
|
||||
|
||||
result = 0;
|
||||
for (int j=jl; j <= jh; ++j)
|
||||
result += B(j) * C(i-j);
|
||||
|
||||
A(i) = result;
|
||||
}
|
||||
|
||||
return A;
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAY_CONVOLVE_CC
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/convolve.h One-dimensional convolution
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAY_CONVOLVE_H
|
||||
#define BZ_ARRAY_CONVOLVE_H
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/convolve.h> must be included after <blitz/array.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename T>
|
||||
Array<T,1> convolve(const Array<T,1>& B, const Array<T,1>& C);
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#include <blitz/array/convolve.cc>
|
||||
|
||||
#endif // BZ_ARRAY_CONVOLVE_H
|
||||
@@ -0,0 +1,83 @@
|
||||
/***************************************************************************
|
||||
* blitz/array/cycle.cc Cycle arrays for time-stepping of PDEs.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYCYCLE_CC
|
||||
#define BZ_ARRAYCYCLE_CC
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/cycle.cc> must be included via <blitz/array.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void cycleArrays(Array<T_numtype, N_rank>& a, Array<T_numtype, N_rank>& b)
|
||||
{
|
||||
Array<T_numtype, N_rank> tmp(a);
|
||||
a.reference(b);
|
||||
b.reference(tmp);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void cycleArrays(Array<T_numtype, N_rank>& a, Array<T_numtype, N_rank>& b,
|
||||
Array<T_numtype, N_rank>& c)
|
||||
{
|
||||
Array<T_numtype, N_rank> tmp(a);
|
||||
a.reference(b);
|
||||
b.reference(c);
|
||||
c.reference(tmp);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void cycleArrays(Array<T_numtype, N_rank>& a, Array<T_numtype, N_rank>& b,
|
||||
Array<T_numtype, N_rank>& c, Array<T_numtype, N_rank>& d)
|
||||
{
|
||||
Array<T_numtype, N_rank> tmp(a);
|
||||
a.reference(b);
|
||||
b.reference(c);
|
||||
c.reference(d);
|
||||
d.reference(tmp);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void cycleArrays(Array<T_numtype, N_rank>& a, Array<T_numtype, N_rank>& b,
|
||||
Array<T_numtype, N_rank>& c, Array<T_numtype, N_rank>& d,
|
||||
Array<T_numtype, N_rank>& e)
|
||||
{
|
||||
Array<T_numtype, N_rank> tmp(a);
|
||||
a.reference(b);
|
||||
b.reference(c);
|
||||
c.reference(d);
|
||||
d.reference(e);
|
||||
e.reference(tmp);
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYCYCLE_CC
|
||||
@@ -0,0 +1,173 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/domain.h Declaration of the RectDomain class
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_DOMAIN_H
|
||||
#define BZ_DOMAIN_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/et-forward.h>
|
||||
#include <blitz/range.h>
|
||||
|
||||
/*
|
||||
* Portions of this class were inspired by the "RectDomain" class
|
||||
* provided by the Titanium language (UC Berkeley).
|
||||
*/
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<int N_rank>
|
||||
class RectDomain {
|
||||
|
||||
typedef TinyVector<int,N_rank> Bounds;
|
||||
|
||||
public:
|
||||
|
||||
RectDomain() { }
|
||||
RectDomain(const Bounds& lbound,const Bounds& ubound): lbound_(lbound),ubound_(ubound) { }
|
||||
RectDomain(const TinyVector<Range,N_rank>& bndrange): lbound_(),ubound_() {
|
||||
for (int i=0;i<N_rank;++i) {
|
||||
lbound_(i) = bndrange(i).first();
|
||||
ubound_(i) = bndrange(i).last();
|
||||
}
|
||||
}
|
||||
|
||||
// NEEDS_WORK: better constructors
|
||||
// RectDomain(Range, Range, ...)
|
||||
// RectDomain with any combination of Range and int
|
||||
|
||||
Bounds& lbound() { return lbound_; }
|
||||
Bounds& ubound() { return ubound_; }
|
||||
const Bounds& lbound() const { return lbound_; }
|
||||
const Bounds& ubound() const { return ubound_; }
|
||||
|
||||
int& lbound(const int i) { return lbound_(i); }
|
||||
int& ubound(const int i) { return ubound_(i); }
|
||||
int lbound(const int i) const { return lbound_(i); }
|
||||
int ubound(const int i) const { return ubound_(i); }
|
||||
|
||||
Range operator[](const int rank) const { return Range(lbound_(rank), ubound_(rank)); }
|
||||
|
||||
void shrink(const int amount) {
|
||||
lbound_ += amount;
|
||||
ubound_ -= amount;
|
||||
}
|
||||
|
||||
void shrink(const int dim,const int amount) {
|
||||
lbound_(dim) += amount;
|
||||
ubound_(dim) -= amount;
|
||||
}
|
||||
|
||||
void expand(const int amount) {
|
||||
lbound_ -= amount;
|
||||
ubound_ += amount;
|
||||
}
|
||||
|
||||
void expand(const int dim,const int amount) {
|
||||
lbound_(dim) -= amount;
|
||||
ubound_(dim) += amount;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Bounds lbound_;
|
||||
Bounds ubound_;
|
||||
};
|
||||
|
||||
/*
|
||||
* StridedDomain added by Julian Cummings
|
||||
*/
|
||||
|
||||
template<int N_rank>
|
||||
class StridedDomain {
|
||||
|
||||
typedef TinyVector<int,N_rank> Bounds;
|
||||
typedef TinyVector<diffType,N_rank> Strides;
|
||||
|
||||
public:
|
||||
|
||||
StridedDomain(const Bounds& lbound,const Bounds& ubound,const Strides& stride):
|
||||
lbound_(lbound),ubound_(ubound),stride_(stride) { }
|
||||
|
||||
// NEEDS_WORK: better constructors
|
||||
// StridedDomain(Range, Range, ...)
|
||||
// StridedDomain with any combination of Range and int
|
||||
|
||||
const Bounds& lbound() const { return lbound_; }
|
||||
const Bounds& ubound() const { return ubound_; }
|
||||
const Strides& stride() const { return stride_; }
|
||||
|
||||
int lbound(const int i) const { return lbound_(i); }
|
||||
int ubound(const int i) const { return ubound_(i); }
|
||||
diffType stride(const int i) const { return stride_(i); }
|
||||
|
||||
Range operator[](const int rank) const { return Range(lbound_(rank),ubound_(rank),stride_(rank)); }
|
||||
|
||||
void shrink(const int amount) {
|
||||
lbound_ += amount*stride_;
|
||||
ubound_ -= amount*stride_;
|
||||
}
|
||||
|
||||
void shrink(const int dim,const int amount) {
|
||||
lbound_(dim) += amount*stride_(dim);
|
||||
ubound_(dim) -= amount*stride_(dim);
|
||||
}
|
||||
|
||||
void expand(const int amount) {
|
||||
lbound_ -= amount*stride_;
|
||||
ubound_ += amount*stride_;
|
||||
}
|
||||
|
||||
void expand(const int dim,const int amount) {
|
||||
lbound_(dim) -= amount*stride_(dim);
|
||||
ubound_(dim) += amount*stride_(dim);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Bounds lbound_;
|
||||
Bounds ubound_;
|
||||
Strides stride_;
|
||||
};
|
||||
|
||||
|
||||
template<int N_rank>
|
||||
inline RectDomain<N_rank>
|
||||
strip(const TinyVector<int,N_rank>& startPosition,const int stripDimension,const int ubound) {
|
||||
BZPRECONDITION((stripDimension >= 0) && (stripDimension < N_rank));
|
||||
BZPRECONDITION(ubound >= startPosition(stripDimension));
|
||||
|
||||
TinyVector<int,N_rank> endPosition = startPosition;
|
||||
endPosition(stripDimension) = ubound;
|
||||
return RectDomain<N_rank>(startPosition, endPosition);
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_DOMAIN_H
|
||||
@@ -0,0 +1,42 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/et.h Include expression templates implementation for arrays
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAY_ET_H
|
||||
#define BZ_ARRAY_ET_H
|
||||
|
||||
#ifdef BZ_NEW_EXPRESSION_TEMPLATES
|
||||
#include <blitz/array/newet.h> // Expression templates
|
||||
#else
|
||||
#include <blitz/array/bops.cc> // Expression templates, two operands
|
||||
#include <blitz/array/uops.cc> // Expression templates, math functions
|
||||
#include <blitz/array/misc.cc> // Expression templates, miscellaneous
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef BZ_EXPR_CC
|
||||
#define BZ_EXPR_CC
|
||||
|
||||
#include <blitz/array/expr.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename P_numtype>
|
||||
inline RectDomain<12>
|
||||
_bz_ArrayExprConstant<P_numtype>::domain() const
|
||||
{
|
||||
TinyVector<int, 12> lb(lbound(0)), ub(ubound(0));
|
||||
return RectDomain<12>(lb,ub);
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,489 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/fastiter.h Declaration of FastArrayIterator<P_numtype,N_rank>
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAY_FASTITER_H
|
||||
#define BZ_ARRAY_FASTITER_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/array/slice.h>
|
||||
#include <blitz/constpointerstack.h>
|
||||
#include <blitz/prettyprint.h>
|
||||
#include <blitz/simdtypes.h>
|
||||
#include <blitz/et-forward.h>
|
||||
#include <blitz/array/domain.h>
|
||||
#include <blitz/array/asexpr.h>
|
||||
|
||||
#ifdef BZ_HAVE_STD
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// Wrapper to turn expressions with FAIs to FACIs so they can be
|
||||
// returned from a function.
|
||||
template<typename T>
|
||||
typename T::T_range_result safeToReturn(const T& expr) {
|
||||
return expr(expr.domain());
|
||||
}
|
||||
|
||||
|
||||
// forward declaration
|
||||
template<typename, int> class FastArrayIterator;
|
||||
template<typename, int> class FastArrayCopyIterator;
|
||||
|
||||
|
||||
template<typename P_numtype, int N_rank, typename P_arraytype>
|
||||
class FastArrayIteratorBase {
|
||||
public:
|
||||
typedef P_numtype T_numtype;
|
||||
typedef typename opType<T_numtype>::T_optype T_optype;
|
||||
// if T_numtype is POD, then T_result is T_numtype, but if T_numtype
|
||||
// is an ET class, T_result will be the array class for that class.
|
||||
typedef typename asET<T_numtype>::T_wrapped T_typeprop;
|
||||
typedef typename unwrapET<T_typeprop>::T_unwrapped T_result;
|
||||
|
||||
/// Result type for fastRead_tv is a FastTVIterator.
|
||||
typedef ETBase<FastTV2Iterator<T_numtype,
|
||||
simdTypes<T_numtype>::vecWidth> > T_tvtypeprop;
|
||||
typedef typename unwrapET<T_tvtypeprop>::T_unwrapped T_tvresult;
|
||||
|
||||
typedef Array<T_numtype, N_rank> T_array;
|
||||
typedef FastArrayIteratorBase<T_numtype, N_rank, P_arraytype> T_iterator;
|
||||
typedef const T_array& T_ctorArg1;
|
||||
typedef int T_ctorArg2; // dummy
|
||||
typedef FastArrayCopyIterator<T_numtype, N_rank> T_range_result;
|
||||
|
||||
static const int
|
||||
numArrayOperands = 1,
|
||||
numTVOperands = 0,
|
||||
numTMOperands = 0,
|
||||
numIndexPlaceholders = 0,
|
||||
minWidth = simdTypes<T_numtype>::vecWidth,
|
||||
maxWidth = simdTypes<T_numtype>::vecWidth,
|
||||
rank_ = N_rank;
|
||||
|
||||
/** For an iterator, the vectorized result for width N is always a
|
||||
TinyVector<T_numtype, N>. */
|
||||
template<int N> struct tvresult {
|
||||
typedef FastTV2Iterator<T_numtype, N> Type;
|
||||
};
|
||||
|
||||
// NB: this ctor does NOT preserve stack and stride
|
||||
// parameters. This is for speed purposes.
|
||||
FastArrayIteratorBase(const T_iterator& x)
|
||||
: data_(x.data_), array_(x.array_)
|
||||
{ }
|
||||
|
||||
void operator=(const T_iterator& x)
|
||||
{
|
||||
// doesn't this copy the data in x.array_ and then make data_
|
||||
// point to x's array? doesn't seem right
|
||||
array_ = x.array_;
|
||||
data_ = x.data_;
|
||||
stack_ = x.stack_;
|
||||
stride_ = x.stride_;
|
||||
}
|
||||
|
||||
FastArrayIteratorBase(const T_array& array)
|
||||
: array_(array)
|
||||
{
|
||||
data_ = array_.data();
|
||||
}
|
||||
|
||||
~FastArrayIteratorBase()
|
||||
{ }
|
||||
|
||||
#ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
|
||||
T_result operator()(TinyVector<int, N_rank> i) const
|
||||
{ return array_(i); }
|
||||
#else
|
||||
T_result operator()(const TinyVector<int, N_rank>& i) const
|
||||
{ return array_(i); }
|
||||
#endif
|
||||
|
||||
int ascending(const int rank) const
|
||||
{
|
||||
if (rank < N_rank)
|
||||
return array_.isRankStoredAscending(rank);
|
||||
else
|
||||
return INT_MIN; // tiny(int());
|
||||
}
|
||||
|
||||
int ordering(const int rank) const
|
||||
{
|
||||
if (rank < N_rank)
|
||||
return array_.ordering(rank);
|
||||
else
|
||||
return INT_MIN; // tiny(int());
|
||||
}
|
||||
|
||||
int lbound(const int rank) const
|
||||
{
|
||||
if (rank < N_rank)
|
||||
return array_.lbound(rank);
|
||||
else
|
||||
return INT_MIN; // tiny(int());
|
||||
}
|
||||
|
||||
int ubound(const int rank) const
|
||||
{
|
||||
if (rank < N_rank)
|
||||
return array_.ubound(rank);
|
||||
else
|
||||
return INT_MAX; // huge(int());
|
||||
}
|
||||
|
||||
RectDomain<rank_> domain() const { return array_.domain(); };
|
||||
|
||||
T_result first_value() const { return *data_; }
|
||||
|
||||
T_result operator*() const
|
||||
{ return *data_; }
|
||||
|
||||
template<int N>
|
||||
T_range_result operator()(const RectDomain<N>& d) const
|
||||
{
|
||||
return T_range_result(array_(d));
|
||||
}
|
||||
|
||||
T_result operator[](int i) const
|
||||
{ return data_[i * stride_]; }
|
||||
|
||||
T_result fastRead(diffType i) const
|
||||
{ return data_[i]; }
|
||||
|
||||
/** Returns a TinyVector "view" of the data at i, with a vector
|
||||
length specified by the template parameter N. This makes it
|
||||
possible to convert a small part of an arbitrary expression into
|
||||
a TinyVector expression, which is efficiently vectorized. */
|
||||
template<int N>
|
||||
typename tvresult<N>::Type fastRead_tv(diffType i) const
|
||||
{
|
||||
return typename tvresult<N>::Type(*reinterpret_cast<const TinyVector<T_numtype,N>*>(&data_[i])); }
|
||||
|
||||
/** Returns true if the iterator data is aligned on a simd
|
||||
vector. */
|
||||
bool isVectorAligned(diffType offset) const
|
||||
{ return simdTypes<T_numtype>::isVectorAligned(data_ + offset); };
|
||||
|
||||
int suggestStride(int rank) const
|
||||
{ return array_.stride(rank); }
|
||||
|
||||
bool isStride(int rank, diffType stride) const
|
||||
{ return array_.stride(rank) == stride; }
|
||||
|
||||
void push(int position)
|
||||
{
|
||||
stack_[position] = data_;
|
||||
}
|
||||
|
||||
void pop(int position)
|
||||
{
|
||||
data_ = stack_[position];
|
||||
}
|
||||
|
||||
void advance()
|
||||
{
|
||||
data_ += stride_;
|
||||
}
|
||||
|
||||
void advance(int n)
|
||||
{
|
||||
data_ += n * stride_;
|
||||
}
|
||||
|
||||
void loadStride(int rank)
|
||||
{
|
||||
stride_ = array_.stride(rank);
|
||||
}
|
||||
|
||||
// returns the lvalue, ie a pointer to the data
|
||||
const T_numtype * restrict data() const
|
||||
{ return data_; }
|
||||
|
||||
const T_array& array() const
|
||||
{ return array_; }
|
||||
|
||||
void _bz_setData(const T_numtype* ptr)
|
||||
{ data_ = ptr; }
|
||||
|
||||
// this is needed for the stencil expression fastRead to work
|
||||
void _bz_offsetData(sizeType i)
|
||||
{ data_ += i;}
|
||||
|
||||
// and these are needed for stencil expression shift to work
|
||||
void _bz_offsetData(sizeType offset, int dim)
|
||||
{ data_ += offset*array_.stride(dim); }
|
||||
|
||||
void _bz_offsetData(sizeType offset1, int dim1, sizeType offset2, int dim2)
|
||||
{ data_ += offset1*array_.stride(dim1);
|
||||
data_ += offset2*array_.stride(dim2); }
|
||||
|
||||
int stride() const
|
||||
{ return stride_; }
|
||||
|
||||
/** Returns true if the Array has unit stride in the rank. */
|
||||
bool isUnitStride(int rank) const
|
||||
{ return array_.stride(rank) == 1; }
|
||||
|
||||
/** Returns true if the loaded iterator stride is 1. */
|
||||
bool isUnitStride() const
|
||||
{ return stride() == 1; }
|
||||
|
||||
void advanceUnitStride()
|
||||
{ ++data_; }
|
||||
|
||||
bool canCollapse(int outerLoopRank, int innerLoopRank) const
|
||||
{ return array_.canCollapse(outerLoopRank, innerLoopRank); }
|
||||
|
||||
void prettyPrint(BZ_STD_SCOPE(string) &str,
|
||||
prettyPrintFormat& format) const
|
||||
{
|
||||
if (format.tersePrintingSelected())
|
||||
str += format.nextArrayOperandSymbol();
|
||||
else if (format.dumpArrayShapesMode())
|
||||
{
|
||||
#ifdef BZ_HAVE_STD
|
||||
BZ_STD_SCOPE(ostringstream) ostr;
|
||||
#else
|
||||
ostrstream ostr;
|
||||
#endif
|
||||
ostr << array_.shape();
|
||||
str += ostr.str();
|
||||
}
|
||||
else {
|
||||
str += "Array<";
|
||||
str += BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(T_numtype);
|
||||
str += ",";
|
||||
|
||||
char tmpBuf[10];
|
||||
sprintf(tmpBuf, "%d", N_rank);
|
||||
|
||||
str += tmpBuf;
|
||||
str += ">";
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T_shape>
|
||||
bool shapeCheck(const T_shape& shape) const
|
||||
{ return areShapesConformable(shape, array_.length()); }
|
||||
|
||||
|
||||
// Experimental
|
||||
T_numtype& operator()(int i) const
|
||||
{
|
||||
return (T_numtype&)data_[i*array_.stride(0)];
|
||||
}
|
||||
|
||||
// Experimental
|
||||
T_numtype& operator()(int i, int j) const
|
||||
{
|
||||
return (T_numtype&)data_[i*array_.stride(0) + j*array_.stride(1)];
|
||||
}
|
||||
|
||||
// Experimental
|
||||
T_numtype& operator()(int i, int j, int k) const
|
||||
{
|
||||
return (T_numtype&)data_[i*array_.stride(0)
|
||||
+ j*array_.stride(1)
|
||||
+ k*array_.stride(2)];
|
||||
}
|
||||
|
||||
// Experimental
|
||||
|
||||
void moveTo(int i)
|
||||
{
|
||||
data_ = &const_cast<T_array&>(array_)(i);
|
||||
}
|
||||
|
||||
void moveTo(int i, int j)
|
||||
{
|
||||
data_ = &const_cast<T_array&>(array_)(i,j);
|
||||
}
|
||||
|
||||
void moveTo(int i, int j, int k)
|
||||
{
|
||||
data_ = &const_cast<T_array&>(array_)(i,j,k);
|
||||
}
|
||||
|
||||
template<int N_rank2>
|
||||
void moveTo(const TinyVector<int,N_rank2>& i)
|
||||
{
|
||||
data_ = &const_cast<T_array&>(array_)(i);
|
||||
}
|
||||
|
||||
// Experimental
|
||||
void operator=(T_numtype x)
|
||||
{ *const_cast<T_numtype*>(data_) = x; }
|
||||
|
||||
// Experimental
|
||||
template<typename T_value>
|
||||
void operator=(T_value x)
|
||||
{ *const_cast<T_numtype*>(data_) = x; }
|
||||
|
||||
// Experimental
|
||||
template<typename T_value>
|
||||
void operator+=(T_value x)
|
||||
{ *const_cast<P_numtype*>(data_) += x; }
|
||||
|
||||
// NEEDS_WORK: other operators
|
||||
|
||||
// Experimental
|
||||
operator T_numtype() const
|
||||
{ return *data_; }
|
||||
|
||||
// Experimental
|
||||
T_result shift(int offset, int dim) const
|
||||
{
|
||||
return data_[offset*array_.stride(dim)];
|
||||
}
|
||||
|
||||
// Experimental
|
||||
T_result shift(int offset1, int dim1, int offset2, int dim2) const
|
||||
{
|
||||
return data_[offset1*array_.stride(dim1)
|
||||
+ offset2*array_.stride(dim2)];
|
||||
}
|
||||
|
||||
// sliceinfo for expressions
|
||||
template<typename T1, typename T2 = nilArraySection,
|
||||
class T3 = nilArraySection, typename T4 = nilArraySection,
|
||||
class T5 = nilArraySection, typename T6 = nilArraySection,
|
||||
class T7 = nilArraySection, typename T8 = nilArraySection,
|
||||
class T9 = nilArraySection, typename T10 = nilArraySection,
|
||||
class T11 = nilArraySection>
|
||||
class SliceInfo {
|
||||
public:
|
||||
typedef FastArrayCopyIterator<P_numtype, blitz::SliceInfo<P_numtype, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::rank> T_slice;
|
||||
};
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9, typename T10, typename T11>
|
||||
typename SliceInfo<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_slice
|
||||
operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6, T7 r7, T8 r8, T9 r9, T10 r10, T11 r11) const
|
||||
{
|
||||
return typename SliceInfo<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_slice(array_(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11));
|
||||
}
|
||||
|
||||
protected:
|
||||
const P_numtype * restrict data_;
|
||||
P_arraytype array_;
|
||||
ConstPointerStack<P_numtype,N_rank> stack_;
|
||||
diffType stride_;
|
||||
};
|
||||
|
||||
|
||||
template<typename P_numtype, int N_rank> class FastArrayCopyIterator;
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
class FastArrayIterator :
|
||||
public FastArrayIteratorBase<P_numtype, N_rank, const Array<P_numtype, N_rank>&>
|
||||
{
|
||||
public:
|
||||
typedef FastArrayIteratorBase<P_numtype, N_rank,
|
||||
const Array<P_numtype, N_rank>&> T_base;
|
||||
typedef typename T_base::T_numtype T_numtype;
|
||||
typedef typename T_base::T_array T_array;
|
||||
typedef typename T_base::T_iterator T_iterator;
|
||||
typedef typename T_base::T_ctorArg1 T_ctorArg1;
|
||||
typedef typename T_base::T_ctorArg2 T_ctorArg2;
|
||||
typedef typename T_base::T_range_result T_range_result;
|
||||
|
||||
using T_base::rank_;
|
||||
using T_base::numArrayOperands;
|
||||
using T_base::numTVOperands;
|
||||
using T_base::numTMOperands;
|
||||
using T_base::numIndexPlaceholders;
|
||||
|
||||
// NB: this ctor does NOT preserve stack and stride
|
||||
// parameters. This is for speed purposes.
|
||||
FastArrayIterator(const FastArrayIterator<P_numtype, N_rank>& x)
|
||||
: T_base(x)
|
||||
{ }
|
||||
|
||||
FastArrayIterator(const T_array& array) : T_base(array) {}
|
||||
|
||||
using T_base::operator=;
|
||||
void operator=(const FastArrayIterator<P_numtype, N_rank>& x)
|
||||
{
|
||||
T_base::operator=(x);
|
||||
}
|
||||
|
||||
using T_base::operator();
|
||||
};
|
||||
|
||||
/* This version of the FastArrayIterator makes a COPY of the array
|
||||
it's pointing to. This makes it possible to return expressions of
|
||||
arrays that have gone out of scope, or to slice expressions. */
|
||||
template<typename P_numtype, int N_rank>
|
||||
class FastArrayCopyIterator :
|
||||
public FastArrayIteratorBase<P_numtype, N_rank, const Array<P_numtype, N_rank> >
|
||||
{
|
||||
public:
|
||||
typedef FastArrayIteratorBase<P_numtype, N_rank,
|
||||
const Array<P_numtype, N_rank> > T_base;
|
||||
typedef typename T_base::T_numtype T_numtype;
|
||||
typedef typename T_base::T_array T_array;
|
||||
typedef typename T_base::T_iterator T_iterator;
|
||||
typedef typename T_base::T_ctorArg1 T_ctorArg1;
|
||||
typedef typename T_base::T_ctorArg2 T_ctorArg2;
|
||||
typedef typename T_base::T_range_result T_range_result;
|
||||
|
||||
using T_base::rank_;
|
||||
using T_base::numArrayOperands;
|
||||
using T_base::numTVOperands;
|
||||
using T_base::numTMOperands;
|
||||
using T_base::numIndexPlaceholders;
|
||||
|
||||
|
||||
// NB: this ctor does NOT preserve stack and stride
|
||||
// parameters. This is for speed purposes.
|
||||
FastArrayCopyIterator(const FastArrayCopyIterator<P_numtype, N_rank>& x)
|
||||
: T_base(x)
|
||||
{ }
|
||||
|
||||
FastArrayCopyIterator(const T_array& array) : T_base(array) { }
|
||||
|
||||
using T_base::operator=;
|
||||
void operator=(const FastArrayCopyIterator& x)
|
||||
{
|
||||
T_base::operator=(x);
|
||||
}
|
||||
|
||||
using T_base::operator();
|
||||
|
||||
};
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAY_FASTITER_H
|
||||
@@ -0,0 +1,313 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/funcs.h Math functions on arrays
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAY_FUNCS_H
|
||||
#define BZ_ARRAY_FUNCS_H
|
||||
|
||||
#include <blitz/funcs.h>
|
||||
#include <blitz/array/newet-macros.h>
|
||||
#include <blitz/array/reduce.h>
|
||||
#include <blitz/levicivita.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/* This file contains definitions of the math functions for ETBase
|
||||
types. Note that these definitions are in the blitz namespace and
|
||||
will hide the definitions of the builtin math functions in the
|
||||
global namespace. For this reason, the calls to the builtin math
|
||||
functions in the functors' apply() methods must explicitly qualify
|
||||
the namespace.
|
||||
*/
|
||||
|
||||
|
||||
// unary functions
|
||||
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(abs, Fn_abs)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(acos, Fn_acos)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(asin, Fn_asin)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(atan, Fn_atan)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(ceil, Fn_ceil)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(cexp, Fn_exp)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(cos, Fn_cos)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(cosh, Fn_cosh)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(csqrt, Fn_sqrt)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(cube, Fn_cube)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(exp, Fn_exp)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(fabs, Fn_fabs)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(floor, Fn_floor)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(log, Fn_log)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(log10, Fn_log10)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(pow2, Fn_sqr)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(pow3, Fn_cube)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(pow4, Fn_pow4)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(pow5, Fn_pow5)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(pow6, Fn_pow6)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(pow7, Fn_pow7)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(pow8, Fn_pow8)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(sin, Fn_sin)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(sinh, Fn_sinh)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(sqr, Fn_sqr)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(sqrt, Fn_sqrt)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(tan, Fn_tan)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(tanh, Fn_tanh)
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX_FCNS
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(arg, Fn_arg)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(conj, Fn_conj)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(imag, Fn_imag)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(norm, Fn_norm)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(real, Fn_real)
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_IEEE_MATH
|
||||
// finite and trunc omitted: blitz-bugs/archive/0189.html
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(acosh, Fn_acosh)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(asinh, Fn_asinh)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(atanh, Fn_atanh)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(cbrt, Fn_cbrt)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(erf, Fn_erf)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(erfc, Fn_erfc)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(expm1, Fn_expm1)
|
||||
// BZ_DECLARE_ARRAY_ET_UNARY(finite, Fn_finite)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(ilogb, Fn_ilogb)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(blitz_isnan, Fn_isnan)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(j0, Fn_j0)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(j1, Fn_j1)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(lgamma, Fn_lgamma)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(logb, Fn_logb)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(log1p, Fn_log1p)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(rint, Fn_rint)
|
||||
// BZ_DECLARE_ARRAY_ET_UNARY(trunc, Fn_trunc)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(y0, Fn_y0)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(y1, Fn_y1)
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_SYSTEM_V_MATH
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(_class, Fn__class)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(itrunc, Fn_itrunc)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(nearest, Fn_nearest)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(rsqrt, Fn_rsqrt)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(uitrunc, Fn_uitrunc)
|
||||
#endif
|
||||
|
||||
// cast() function
|
||||
|
||||
template<typename T_cast, typename T1>
|
||||
_bz_inline_et
|
||||
_bz_ArrayExpr<_bz_ArrayExprUnaryOp<_bz_typename asExpr<T1>::T_expr,
|
||||
Cast<_bz_typename asExpr<T1>::T_expr::T_numtype, T_cast> > >
|
||||
cast(const ETBase<T1>& expr)
|
||||
{
|
||||
return _bz_ArrayExpr<_bz_ArrayExprUnaryOp<
|
||||
_bz_typename asExpr<T1>::T_expr,
|
||||
Cast<_bz_typename asExpr<T1>::T_expr::T_numtype,T_cast> > >
|
||||
(expr.unwrap());
|
||||
}
|
||||
|
||||
// binary functions
|
||||
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(atan2, Fn_atan2)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(fmod, Fn_fmod)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(pow, Fn_pow)
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX_FCNS
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(polar, Fn_polar)
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_SYSTEM_V_MATH
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(copysign, Fn_copysign)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(drem, Fn_drem)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(hypot, Fn_hypot)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(nextafter, Fn_nextafter)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(remainder, Fn_remainder)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(scalb, Fn_scalb)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(unordered, Fn_unordered)
|
||||
#endif
|
||||
|
||||
BZ_DECLARE_ARRAY_ET_BINARY((min), Min)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY((max), Max)
|
||||
|
||||
#ifdef BZ_HAVE_SYSTEM_V_MATH
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_SCALAR_FUNCS(sca) \
|
||||
\
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(atan2, Fn_atan2, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(fmod, Fn_fmod, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(pow, Fn_pow, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(copysign, Fn_copysign, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(drem, Fn_drem, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(hypot, Fn_hypot, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(nextafter, Fn_nextafter, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(remainder, Fn_remainder, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(scalb, Fn_scalb, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(unordered, Fn_unordered, sca) \
|
||||
|
||||
#else
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_SCALAR_FUNCS(sca) \
|
||||
\
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(atan2, Fn_atan2, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(fmod, Fn_fmod, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(pow, Fn_pow, sca) \
|
||||
|
||||
#endif
|
||||
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_FUNCS(int)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_FUNCS(float)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_FUNCS(double)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_FUNCS(long double)
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX_FCNS
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(polar, Fn_polar, int)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(polar, Fn_polar, float)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(polar, Fn_polar, double)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(polar, Fn_polar, long double)
|
||||
|
||||
template<typename T1, typename T2>
|
||||
inline _bz_ArrayExprBinaryOp<
|
||||
typename asExpr<complex<T1> >::T_expr,
|
||||
typename asExpr<T2>::T_expr,
|
||||
Fn_pow<complex<T1>,typename asExpr<T2>::T_expr::T_numtype> >
|
||||
pow(const complex<T1> d1, const ETBase<T2>& d2)
|
||||
{
|
||||
return _bz_ArrayExprBinaryOp<
|
||||
typename asExpr<complex<T1> >::T_expr,
|
||||
typename asExpr<T2>::T_expr,
|
||||
Fn_pow<complex<T1>,typename asExpr<T2>::T_expr::T_numtype> >
|
||||
(asExpr<complex<T1> >::getExpr(d1),
|
||||
asExpr<T2>::getExpr(d2.unwrap()));
|
||||
}
|
||||
|
||||
|
||||
// global functions that don't fit anywhere else
|
||||
|
||||
// we define a generalized dot product for all classes as sum(a*b)
|
||||
template<typename T1, typename T2>
|
||||
inline
|
||||
_bz_typename ReduceSum<_bz_typename BZ_BLITZ_SCOPE(BzBinaryExprResult)<Multiply,T1,T2>::T_result::T_numtype
|
||||
>::T_resulttype
|
||||
dot(const ETBase<T1>& d1, const ETBase<T2>& d2)
|
||||
{
|
||||
return sum(d1 * d2);
|
||||
}
|
||||
|
||||
// we define a generalized cross product for all classes using the
|
||||
// Levi-Civita symbol. Return type is nice (ever heard of "write-once
|
||||
// code")... it took 10 times longer to figure out how to write the
|
||||
// return type than to do everything else...
|
||||
|
||||
template<typename T1, typename T2>
|
||||
inline
|
||||
|
||||
_bz_ArrayExpr<
|
||||
_bz_ArrayExprReduce<
|
||||
_bz_ArrayExpr<
|
||||
_bz_ArrayExprReduce<
|
||||
_bz_typename BzBinaryExprResult<
|
||||
Multiply,
|
||||
_bz_typename BzBinaryExprResult<
|
||||
Multiply,
|
||||
_bz_ArrayExpr<LeviCivita>,
|
||||
_bz_ArrayExpr<
|
||||
ArrayIndexMapping<
|
||||
_bz_typename asExpr<T1>::T_expr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>
|
||||
>
|
||||
>::T_result,
|
||||
_bz_ArrayExpr<
|
||||
ArrayIndexMapping<
|
||||
_bz_typename asExpr<T2>::T_expr, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>
|
||||
>
|
||||
>::T_result,
|
||||
2,
|
||||
ReduceSum<
|
||||
_bz_typename BzBinaryExprResult<Multiply,_bz_typename BzBinaryExprResult<Multiply,_bz_ArrayExpr<LeviCivita>,_bz_ArrayExpr<ArrayIndexMapping<_bz_typename asExpr<T1>::T_expr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> > >::T_result,_bz_ArrayExpr<ArrayIndexMapping<_bz_typename asExpr<T2>::T_expr, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> > > ::T_result::T_numtype,
|
||||
BZ_SUMTYPE(bzCC(_bz_typename BzBinaryExprResult<Multiply,_bz_typename BzBinaryExprResult<Multiply,_bz_ArrayExpr<LeviCivita>,_bz_ArrayExpr<ArrayIndexMapping<_bz_typename asExpr<T1>::T_expr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> > >::T_result,_bz_ArrayExpr<ArrayIndexMapping<_bz_typename asExpr<T2>::T_expr, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> > > ::T_result::T_numtype))>
|
||||
>
|
||||
>,
|
||||
1,
|
||||
ReduceSum<BZ_SUMTYPE(bzCC(_bz_typename BzBinaryExprResult<Multiply,_bz_typename BzBinaryExprResult<Multiply,_bz_ArrayExpr<LeviCivita>,_bz_ArrayExpr<ArrayIndexMapping<_bz_typename asExpr<T1>::T_expr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> > >::T_result,_bz_ArrayExpr<ArrayIndexMapping<_bz_typename asExpr<T2>::T_expr, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> > > ::T_result::T_numtype))>
|
||||
>
|
||||
>
|
||||
|
||||
//int
|
||||
cross(const ETBase<T1>& d1, const ETBase<T2>& d2)
|
||||
{
|
||||
_bz_ArrayExpr<
|
||||
_bz_ArrayExprReduce<
|
||||
_bz_ArrayExpr<
|
||||
_bz_ArrayExprReduce<
|
||||
_bz_typename BzBinaryExprResult<
|
||||
Multiply,
|
||||
_bz_typename BzBinaryExprResult<
|
||||
Multiply,
|
||||
_bz_ArrayExpr<LeviCivita>,
|
||||
_bz_ArrayExpr<
|
||||
ArrayIndexMapping<
|
||||
_bz_typename asExpr<T1>::T_expr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>
|
||||
>
|
||||
>::T_result,
|
||||
_bz_ArrayExpr<
|
||||
ArrayIndexMapping<
|
||||
_bz_typename asExpr<T2>::T_expr, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>
|
||||
>
|
||||
>::T_result,
|
||||
2,
|
||||
ReduceSum<
|
||||
_bz_typename BzBinaryExprResult<Multiply,_bz_typename BzBinaryExprResult<Multiply,_bz_ArrayExpr<LeviCivita>,_bz_ArrayExpr<ArrayIndexMapping<_bz_typename asExpr<T1>::T_expr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> > >::T_result,_bz_ArrayExpr<ArrayIndexMapping<_bz_typename asExpr<T2>::T_expr, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> > > ::T_result::T_numtype,
|
||||
BZ_SUMTYPE(bzCC(_bz_typename BzBinaryExprResult<Multiply,_bz_typename BzBinaryExprResult<Multiply,_bz_ArrayExpr<LeviCivita>,_bz_ArrayExpr<ArrayIndexMapping<_bz_typename asExpr<T1>::T_expr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> > >::T_result,_bz_ArrayExpr<ArrayIndexMapping<_bz_typename asExpr<T2>::T_expr, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> > > ::T_result::T_numtype))>
|
||||
>
|
||||
>,
|
||||
1,
|
||||
ReduceSum<BZ_SUMTYPE(bzCC(_bz_typename BzBinaryExprResult<Multiply,_bz_typename BzBinaryExprResult<Multiply,_bz_ArrayExpr<LeviCivita>,_bz_ArrayExpr<ArrayIndexMapping<_bz_typename asExpr<T1>::T_expr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> > >::T_result,_bz_ArrayExpr<ArrayIndexMapping<_bz_typename asExpr<T2>::T_expr, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0> > > ::T_result::T_numtype))>
|
||||
>
|
||||
>* x;
|
||||
//int a=*x;
|
||||
return sum(sum(LeviCivita()*d1.unwrap()(tensor::j)*d2.unwrap()(tensor::k),
|
||||
tensor::k),
|
||||
tensor::j);
|
||||
}
|
||||
|
||||
|
||||
// "scalar" function converts something into a scalar expression. this
|
||||
// is used to prevent parsing of multicomponent expressions as bitwise
|
||||
// expressions between dissimilar containers.
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
_bz_ArrayExpr<_bz_ArrayExprConstant<T> >
|
||||
scalar(const T& x) {
|
||||
return _bz_ArrayExpr<_bz_ArrayExprConstant<T> >(x);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAY_FUNCS_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,112 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/geometry.h Basic mapping from Array to physical geometry,
|
||||
* used for some stencil operations.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_GEOMETRY_H
|
||||
#define BZ_GEOMETRY_H
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/geometry.h> must be included after <blitz/array.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
typedef double T_defaultSpatialCoordinate;
|
||||
|
||||
template<int N_dim, typename T = T_defaultSpatialCoordinate>
|
||||
class UniformOrthoGeometry {
|
||||
public:
|
||||
};
|
||||
|
||||
template<int N_dim, typename T = T_defaultSpatialCoordinate>
|
||||
class UniformCubicGeometry {
|
||||
T h_;
|
||||
T recip_h_;
|
||||
T recip2_h_;
|
||||
T recip3_h_;
|
||||
TinyVector<T,N_dim> zero_;
|
||||
|
||||
public:
|
||||
typedef T T_coord;
|
||||
|
||||
UniformCubicGeometry()
|
||||
{
|
||||
h_ = 0.0;
|
||||
recip_h_ = 0.0;
|
||||
recip2_h_ = 0.0;
|
||||
recip3_h_ = 0.0;
|
||||
zero_ = 0.0;
|
||||
}
|
||||
|
||||
UniformCubicGeometry(T spatialStep)
|
||||
{
|
||||
h_ = spatialStep;
|
||||
zero_ = T(0);
|
||||
setup();
|
||||
}
|
||||
|
||||
UniformCubicGeometry(T spatialStep, TinyVector<T,N_dim> zeroCoordinates)
|
||||
{
|
||||
h_ = spatialStep;
|
||||
zero_ = zeroCoordinates;
|
||||
setup();
|
||||
}
|
||||
|
||||
TinyVector<T,N_dim> toSpatial(TinyVector<int,N_dim> logicalCoord) const
|
||||
{
|
||||
return zero_ + h_ * logicalCoord;
|
||||
}
|
||||
|
||||
T spatialStep() const
|
||||
{ return h_; }
|
||||
|
||||
T recipSpatialStep() const
|
||||
{ return recip_h_; }
|
||||
|
||||
T recipSpatialStepPow2() const
|
||||
{ return recip2_h_; }
|
||||
|
||||
private:
|
||||
void setup()
|
||||
{
|
||||
recip_h_ = 1.0 / h_;
|
||||
recip2_h_ = 1.0 / pow2(h_);
|
||||
recip3_h_ = 1.0 / pow3(h_);
|
||||
}
|
||||
};
|
||||
|
||||
template<int N_dim, typename T = T_defaultSpatialCoordinate>
|
||||
class TensorProductGeometry {
|
||||
public:
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_GEOMETRY_H
|
||||
@@ -0,0 +1,613 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/indirect.h Array indirection
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef BZ_ARRAY_INDIRECT_H
|
||||
#define BZ_ARRAY_INDIRECT_H
|
||||
|
||||
#include <blitz/array/asexpr.h>
|
||||
#include <blitz/array/cartesian.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename T_array, typename T_index>
|
||||
class IndirectArray {
|
||||
|
||||
public:
|
||||
IndirectArray(T_array& array, T_index& index)
|
||||
: array_(array), index_(index)
|
||||
{ }
|
||||
|
||||
template<typename T_expr>
|
||||
void operator=(T_expr expr);
|
||||
|
||||
protected:
|
||||
T_array& array_;
|
||||
T_index& index_;
|
||||
};
|
||||
|
||||
// Forward declarations
|
||||
template<typename T_array, typename T_arrayiter, typename T_subdomain, typename T_expr>
|
||||
inline void applyOverSubdomain(const T_array& array, T_arrayiter& arrayIter,
|
||||
T_subdomain subdomain, T_expr expr);
|
||||
template<typename T_array, typename T_arrayiter, int N_rank, typename T_expr>
|
||||
inline void applyOverSubdomain(const T_array& array, T_arrayiter& arrayIter,
|
||||
RectDomain<N_rank> subdomain,
|
||||
T_expr expr);
|
||||
|
||||
template<typename T_array, typename T_index> template<typename T_rhs>
|
||||
void IndirectArray<T_array, T_index>::operator=(T_rhs rhs)
|
||||
{
|
||||
typedef _bz_typename asExpr<T_rhs>::T_expr T_expr;
|
||||
T_expr expr(rhs);
|
||||
|
||||
_bz_typename T_array::T_iterator arrayIter(array_);
|
||||
|
||||
_bz_typename T_index::iterator iter = index_.begin(),
|
||||
end = index_.end();
|
||||
|
||||
for (; iter != end; ++iter)
|
||||
{
|
||||
_bz_typename T_index::value_type subdomain = *iter;
|
||||
applyOverSubdomain(array_, arrayIter, subdomain, expr);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T_array, typename T_arrayiter, typename T_subdomain, typename T_expr>
|
||||
inline void applyOverSubdomain(const T_array& BZ_DEBUG_PARAM(array), T_arrayiter& arrayIter,
|
||||
T_subdomain subdomain, T_expr expr)
|
||||
{
|
||||
BZPRECHECK(array.isInRange(subdomain),
|
||||
"In indirection using an STL container of TinyVector<int,"
|
||||
<< array.rank() << ">, one of the" << endl << "positions is out of"
|
||||
" range: " << endl << subdomain << endl
|
||||
<< "Array lower bounds: " << array.lbound() << endl
|
||||
<< "Array upper bounds: " << array.ubound() << endl)
|
||||
|
||||
arrayIter.moveTo(subdomain);
|
||||
expr.moveTo(subdomain);
|
||||
|
||||
*const_cast<_bz_typename T_arrayiter::T_numtype*>(arrayIter.data()) = *expr;
|
||||
}
|
||||
|
||||
// Specialization for RectDomain<N>
|
||||
template<typename T_array, typename T_arrayiter, int N_rank, typename T_expr>
|
||||
inline void applyOverSubdomain(const T_array& BZ_DEBUG_PARAM(array), T_arrayiter& arrayIter,
|
||||
RectDomain<N_rank> subdomain,
|
||||
T_expr expr)
|
||||
{
|
||||
typedef _bz_typename T_array::T_numtype T_numtype;
|
||||
|
||||
// Assume that the RectDomain<N_rank> is a 1-D strip.
|
||||
// Find the dimension in which the strip is oriented. This
|
||||
// variable is static so that we cache the value; likely to be
|
||||
// the same for all strips within a container.
|
||||
|
||||
static int stripDim = 0;
|
||||
|
||||
if (subdomain.lbound(stripDim) == subdomain.ubound(stripDim))
|
||||
{
|
||||
// Cached value was wrong, find the correct value of stripDim
|
||||
for (stripDim=0; stripDim < N_rank; ++stripDim)
|
||||
if (subdomain.lbound(stripDim) != subdomain.ubound(stripDim))
|
||||
break;
|
||||
|
||||
// Handle case where the strip is just a single point
|
||||
if (stripDim == N_rank)
|
||||
stripDim = 0;
|
||||
}
|
||||
|
||||
#ifdef BZ_DEBUG
|
||||
// Check that this is in fact a 1D strip
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
if ((i != stripDim) && (subdomain.lbound(i) != subdomain.ubound(i)))
|
||||
BZPRECHECK(0, "In indirection using an STL container of RectDomain<"
|
||||
<< N_rank << ">, one of" << endl << "the RectDomain objects was not"
|
||||
" a one-dimensional strip:" << endl << "RectDomain<" << N_rank
|
||||
<< ">::lbound() = " << subdomain.lbound() << endl
|
||||
<< "RectDomain<" << N_rank << ">::ubound() = " << subdomain.ubound())
|
||||
#endif
|
||||
|
||||
// Check that the start and end position are in range
|
||||
BZPRECHECK(array.isInRange(subdomain.lbound()),
|
||||
"In indirection using an STL container of RectDomain<"
|
||||
<< N_rank << ">, one of" << endl << "the RectDomain objects has a"
|
||||
" lbound which is out of range:" << endl
|
||||
<< subdomain.lbound() << endl
|
||||
<< "Array lower bounds: " << array.lbound() << endl
|
||||
<< "Array upper bounds: " << array.ubound() << endl)
|
||||
|
||||
BZPRECHECK(array.isInRange(subdomain.ubound()),
|
||||
"In indirection using an STL container of RectDomain<"
|
||||
<< N_rank << ">, one of" << endl << "the RectDomain objects has a"
|
||||
" ubound which is out of range:" << endl
|
||||
<< subdomain.lbound() << endl
|
||||
<< "Array lower bounds: " << array.lbound() << endl
|
||||
<< "Array upper bounds: " << array.ubound() << endl)
|
||||
|
||||
// Position at the beginning of the strip
|
||||
arrayIter.moveTo(subdomain.lbound());
|
||||
expr.moveTo(subdomain.lbound());
|
||||
|
||||
// Loop through the strip
|
||||
|
||||
#ifdef BZ_USE_FAST_READ_ARRAY_EXPR
|
||||
|
||||
bool useUnitStride = arrayIter.isUnitStride(stripDim)
|
||||
&& expr.isUnitStride(stripDim);
|
||||
|
||||
int lbound = subdomain.lbound(stripDim);
|
||||
int ubound = subdomain.ubound(stripDim);
|
||||
|
||||
if (useUnitStride)
|
||||
{
|
||||
T_numtype* restrict data = const_cast<T_numtype*>(arrayIter.data());
|
||||
|
||||
int length = ubound - lbound + 1;
|
||||
for (int i=0; i < length; ++i)
|
||||
*data++ = expr.fastRead(i);
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
|
||||
arrayIter.loadStride(stripDim);
|
||||
expr.loadStride(stripDim);
|
||||
|
||||
for (int i=lbound; i <= ubound; ++i)
|
||||
{
|
||||
*const_cast<_bz_typename T_arrayiter::T_numtype*>(arrayIter.data())
|
||||
= *expr;
|
||||
expr.advance();
|
||||
arrayIter.advance();
|
||||
}
|
||||
|
||||
#ifdef BZ_USE_FAST_READ_ARRAY_EXPR
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Global functions for cartesian product of index sets
|
||||
template<typename T_container>
|
||||
CartesianProduct<TinyVector<int,2>,T_container,2>
|
||||
indexSet(const T_container& container0, const T_container& container1)
|
||||
{
|
||||
return CartesianProduct<TinyVector<int,2>,T_container,2>(
|
||||
const_cast<T_container&>(container0),
|
||||
const_cast<T_container&>(container1));
|
||||
}
|
||||
|
||||
template<typename T_container>
|
||||
CartesianProduct<TinyVector<int,3>,T_container,3>
|
||||
indexSet(const T_container& container0, const T_container& container1,
|
||||
const T_container& container2)
|
||||
{
|
||||
return CartesianProduct<TinyVector<int,3>,T_container,3>(
|
||||
const_cast<T_container&>(container0),
|
||||
const_cast<T_container&>(container1),
|
||||
const_cast<T_container&>(container2));
|
||||
}
|
||||
|
||||
template<typename T_container>
|
||||
CartesianProduct<TinyVector<int,4>,T_container,4>
|
||||
indexSet(const T_container& container0, const T_container& container1,
|
||||
const T_container& container2, const T_container& container3)
|
||||
{
|
||||
return CartesianProduct<TinyVector<int,4>,T_container,4>(
|
||||
const_cast<T_container&>(container0),
|
||||
const_cast<T_container&>(container1),
|
||||
const_cast<T_container&>(container2),
|
||||
const_cast<T_container&>(container3));
|
||||
}
|
||||
|
||||
template<typename T_container>
|
||||
CartesianProduct<TinyVector<int,5>,T_container,5>
|
||||
indexSet(const T_container& container0, const T_container& container1,
|
||||
const T_container& container2, const T_container& container3,
|
||||
const T_container& container4)
|
||||
{
|
||||
return CartesianProduct<TinyVector<int,5>,T_container,5>(
|
||||
const_cast<T_container&>(container0),
|
||||
const_cast<T_container&>(container1),
|
||||
const_cast<T_container&>(container2),
|
||||
const_cast<T_container&>(container3),
|
||||
const_cast<T_container&>(container4));
|
||||
}
|
||||
|
||||
template<typename T_container>
|
||||
CartesianProduct<TinyVector<int,6>,T_container,6>
|
||||
indexSet(const T_container& container0, const T_container& container1,
|
||||
const T_container& container2, const T_container& container3,
|
||||
const T_container& container4, const T_container& container5)
|
||||
{
|
||||
return CartesianProduct<TinyVector<int,6>,T_container,6>(
|
||||
const_cast<T_container&>(container0),
|
||||
const_cast<T_container&>(container1),
|
||||
const_cast<T_container&>(container2),
|
||||
const_cast<T_container&>(container3),
|
||||
const_cast<T_container&>(container4),
|
||||
const_cast<T_container&>(container5));
|
||||
}
|
||||
|
||||
template<typename T_container>
|
||||
CartesianProduct<TinyVector<int,7>,T_container,7>
|
||||
indexSet(const T_container& container0, const T_container& container1,
|
||||
const T_container& container2, const T_container& container3,
|
||||
const T_container& container4, const T_container& container5,
|
||||
const T_container& container6)
|
||||
{
|
||||
return CartesianProduct<TinyVector<int,7>,T_container,7>(
|
||||
const_cast<T_container&>(container0),
|
||||
const_cast<T_container&>(container1),
|
||||
const_cast<T_container&>(container2),
|
||||
const_cast<T_container&>(container3),
|
||||
const_cast<T_container&>(container4),
|
||||
const_cast<T_container&>(container5),
|
||||
const_cast<T_container&>(container6));
|
||||
}
|
||||
|
||||
template<typename T_container>
|
||||
CartesianProduct<TinyVector<int,8>,T_container,8>
|
||||
indexSet(const T_container& container0, const T_container& container1,
|
||||
const T_container& container2, const T_container& container3,
|
||||
const T_container& container4, const T_container& container5,
|
||||
const T_container& container6, const T_container& container7)
|
||||
{
|
||||
return CartesianProduct<TinyVector<int,8>,T_container,8>(
|
||||
const_cast<T_container&>(container0),
|
||||
const_cast<T_container&>(container1),
|
||||
const_cast<T_container&>(container2),
|
||||
const_cast<T_container&>(container3),
|
||||
const_cast<T_container&>(container4),
|
||||
const_cast<T_container&>(container5),
|
||||
const_cast<T_container&>(container6),
|
||||
const_cast<T_container&>(container7));
|
||||
}
|
||||
|
||||
template<typename T_container>
|
||||
CartesianProduct<TinyVector<int,9>,T_container,9>
|
||||
indexSet(const T_container& container0, const T_container& container1,
|
||||
const T_container& container2, const T_container& container3,
|
||||
const T_container& container4, const T_container& container5,
|
||||
const T_container& container6, const T_container& container7,
|
||||
const T_container& container8)
|
||||
{
|
||||
return CartesianProduct<TinyVector<int,9>,T_container,9>(
|
||||
const_cast<T_container&>(container0),
|
||||
const_cast<T_container&>(container1),
|
||||
const_cast<T_container&>(container2),
|
||||
const_cast<T_container&>(container3),
|
||||
const_cast<T_container&>(container4),
|
||||
const_cast<T_container&>(container5),
|
||||
const_cast<T_container&>(container6),
|
||||
const_cast<T_container&>(container7),
|
||||
const_cast<T_container&>(container8));
|
||||
}
|
||||
|
||||
template<typename T_container>
|
||||
CartesianProduct<TinyVector<int,10>,T_container,10>
|
||||
indexSet(const T_container& container0, const T_container& container1,
|
||||
const T_container& container2, const T_container& container3,
|
||||
const T_container& container4, const T_container& container5,
|
||||
const T_container& container6, const T_container& container7,
|
||||
const T_container& container8, const T_container& container9)
|
||||
{
|
||||
return CartesianProduct<TinyVector<int,10>,T_container,10>(
|
||||
const_cast<T_container&>(container0),
|
||||
const_cast<T_container&>(container1),
|
||||
const_cast<T_container&>(container2),
|
||||
const_cast<T_container&>(container3),
|
||||
const_cast<T_container&>(container4),
|
||||
const_cast<T_container&>(container5),
|
||||
const_cast<T_container&>(container6),
|
||||
const_cast<T_container&>(container7),
|
||||
const_cast<T_container&>(container8),
|
||||
const_cast<T_container&>(container9));
|
||||
}
|
||||
|
||||
template<typename T_container>
|
||||
CartesianProduct<TinyVector<int,11>,T_container,11>
|
||||
indexSet(const T_container& container0, const T_container& container1,
|
||||
const T_container& container2, const T_container& container3,
|
||||
const T_container& container4, const T_container& container5,
|
||||
const T_container& container6, const T_container& container7,
|
||||
const T_container& container8, const T_container& container9,
|
||||
const T_container& container10)
|
||||
{
|
||||
return CartesianProduct<TinyVector<int,11>,T_container,11>(
|
||||
const_cast<T_container&>(container0),
|
||||
const_cast<T_container&>(container1),
|
||||
const_cast<T_container&>(container2),
|
||||
const_cast<T_container&>(container3),
|
||||
const_cast<T_container&>(container4),
|
||||
const_cast<T_container&>(container5),
|
||||
const_cast<T_container&>(container6),
|
||||
const_cast<T_container&>(container7),
|
||||
const_cast<T_container&>(container8),
|
||||
const_cast<T_container&>(container9),
|
||||
const_cast<T_container&>(container10));
|
||||
}
|
||||
|
||||
// Mixture of singletons and containers, e.g. A[indexSet(I,3,K)]
|
||||
|
||||
// cp_findContainerType<T1,T2,T3,...,Tn>::T_container
|
||||
// The set of parameters T1, T2, T3, ... Tn is a mixture of
|
||||
// int and T_container. This traits class finds the container
|
||||
// type, and sets T_container.
|
||||
//
|
||||
// e.g. cp_findContainerType<int,int,list<int>,int>::T_container is list<int>
|
||||
// cp_findContainerType<int,deque<int>,deque<int>>::T_container
|
||||
// is deque<int>
|
||||
|
||||
template<typename T1, typename T2, typename T3=int, typename T4=int,
|
||||
typename T5=int, typename T6=int, typename T7=int, typename T8=int,
|
||||
typename T9=int, typename T10=int, typename T11=int>
|
||||
struct cp_findContainerType {
|
||||
typedef T1 T_container;
|
||||
};
|
||||
|
||||
template<typename T2, typename T3, typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9, typename T10, typename T11>
|
||||
struct cp_findContainerType<int,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> {
|
||||
typedef _bz_typename
|
||||
cp_findContainerType<T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_container
|
||||
T_container;
|
||||
};
|
||||
|
||||
|
||||
// The cp_traits class handles promotion of singleton integers to
|
||||
// containers. It takes two template parameters:
|
||||
// T = argument type
|
||||
// T2 = container type
|
||||
// If T is an integer, then a container of type T2 is created and the
|
||||
// integer is inserted. This container is returned.
|
||||
// Otherwise, T is assumed to be the same type as T2, and the original
|
||||
// container is returned.
|
||||
|
||||
template<typename T, typename T2>
|
||||
struct cp_traits {
|
||||
typedef T T_container;
|
||||
|
||||
static const T_container& make(const T& x)
|
||||
{ return x; }
|
||||
};
|
||||
|
||||
template<typename T2>
|
||||
struct cp_traits<int,T2> {
|
||||
typedef T2 T_container;
|
||||
|
||||
static T2 make(int x)
|
||||
{
|
||||
T2 singleton;
|
||||
singleton.push_back(x);
|
||||
return singleton;
|
||||
}
|
||||
};
|
||||
|
||||
// These versions of indexSet() allow mixtures of integer
|
||||
// and container arguments. At least one integer must be
|
||||
// specified.
|
||||
|
||||
template<typename T1, typename T2>
|
||||
CartesianProduct<TinyVector<int,2>, _bz_typename
|
||||
cp_findContainerType<T1,T2>::T_container,2>
|
||||
indexSet(const T1& c1, const T2& c2)
|
||||
{
|
||||
typedef _bz_typename cp_findContainerType<T1,T2>::T_container
|
||||
T_container;
|
||||
|
||||
return CartesianProduct<TinyVector<int,2>, T_container, 2>(
|
||||
cp_traits<T1,T_container>::make(c1),
|
||||
cp_traits<T2,T_container>::make(c2));
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
CartesianProduct<TinyVector<int,3>, _bz_typename
|
||||
cp_findContainerType<T1,T2,T3>::T_container, 3>
|
||||
indexSet(const T1& c1, const T2& c2, const T3& c3)
|
||||
{
|
||||
typedef _bz_typename cp_findContainerType<T1,T2,T3>::T_container
|
||||
T_container;
|
||||
|
||||
return CartesianProduct<TinyVector<int,3>, T_container, 3>(
|
||||
cp_traits<T1,T_container>::make(c1),
|
||||
cp_traits<T2,T_container>::make(c2),
|
||||
cp_traits<T3,T_container>::make(c3));
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4>
|
||||
CartesianProduct<TinyVector<int,4>, _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4>::T_container, 4>
|
||||
indexSet(const T1& c1, const T2& c2, const T3& c3, const T4& c4)
|
||||
{
|
||||
typedef _bz_typename cp_findContainerType<T1,T2,T3,T4>::T_container
|
||||
T_container;
|
||||
|
||||
return CartesianProduct<TinyVector<int,4>, T_container, 4>(
|
||||
cp_traits<T1,T_container>::make(c1),
|
||||
cp_traits<T2,T_container>::make(c2),
|
||||
cp_traits<T3,T_container>::make(c3),
|
||||
cp_traits<T4,T_container>::make(c4));
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
CartesianProduct<TinyVector<int,5>, _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4,T5>::T_container, 5>
|
||||
indexSet(const T1& c1, const T2& c2, const T3& c3, const T4& c4, const T5& c5)
|
||||
{
|
||||
typedef _bz_typename cp_findContainerType<T1,T2,T3,T4,T5>::T_container
|
||||
T_container;
|
||||
|
||||
return CartesianProduct<TinyVector<int,5>, T_container, 5>(
|
||||
cp_traits<T1,T_container>::make(c1),
|
||||
cp_traits<T2,T_container>::make(c2),
|
||||
cp_traits<T3,T_container>::make(c3),
|
||||
cp_traits<T4,T_container>::make(c4),
|
||||
cp_traits<T5,T_container>::make(c5));
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6>
|
||||
CartesianProduct<TinyVector<int,6>, _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4,T5,T6>::T_container, 6>
|
||||
indexSet(const T1& c1, const T2& c2, const T3& c3, const T4& c4, const T5& c5,
|
||||
const T6& c6)
|
||||
{
|
||||
typedef _bz_typename cp_findContainerType<T1,T2,T3,T4,T5,T6>::T_container
|
||||
T_container;
|
||||
|
||||
return CartesianProduct<TinyVector<int,6>, T_container, 6>(
|
||||
cp_traits<T1,T_container>::make(c1),
|
||||
cp_traits<T2,T_container>::make(c2),
|
||||
cp_traits<T3,T_container>::make(c3),
|
||||
cp_traits<T4,T_container>::make(c4),
|
||||
cp_traits<T5,T_container>::make(c5),
|
||||
cp_traits<T6,T_container>::make(c6));
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7>
|
||||
CartesianProduct<TinyVector<int,7>, _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4,T5,T6,T7>::T_container, 7>
|
||||
indexSet(const T1& c1, const T2& c2, const T3& c3, const T4& c4, const T5& c5,
|
||||
const T6& c6, const T7& c7)
|
||||
{
|
||||
typedef _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4,T5,T6,T7>::T_container
|
||||
T_container;
|
||||
|
||||
return CartesianProduct<TinyVector<int,7>, T_container, 7>(
|
||||
cp_traits<T1,T_container>::make(c1),
|
||||
cp_traits<T2,T_container>::make(c2),
|
||||
cp_traits<T3,T_container>::make(c3),
|
||||
cp_traits<T4,T_container>::make(c4),
|
||||
cp_traits<T5,T_container>::make(c5),
|
||||
cp_traits<T6,T_container>::make(c6),
|
||||
cp_traits<T7,T_container>::make(c7));
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8>
|
||||
CartesianProduct<TinyVector<int,8>, _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4,T5,T6,T7,T8>::T_container, 8>
|
||||
indexSet(const T1& c1, const T2& c2, const T3& c3, const T4& c4, const T5& c5,
|
||||
const T6& c6, const T7& c7, const T8& c8)
|
||||
{
|
||||
typedef _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4,T5,T6,T7,T8>::T_container
|
||||
T_container;
|
||||
|
||||
return CartesianProduct<TinyVector<int,8>, T_container, 8>(
|
||||
cp_traits<T1,T_container>::make(c1),
|
||||
cp_traits<T2,T_container>::make(c2),
|
||||
cp_traits<T3,T_container>::make(c3),
|
||||
cp_traits<T4,T_container>::make(c4),
|
||||
cp_traits<T5,T_container>::make(c5),
|
||||
cp_traits<T6,T_container>::make(c6),
|
||||
cp_traits<T7,T_container>::make(c7),
|
||||
cp_traits<T8,T_container>::make(c8));
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9>
|
||||
CartesianProduct<TinyVector<int,9>, _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4,T5,T6,T7,T8,T9>::T_container, 9>
|
||||
indexSet(const T1& c1, const T2& c2, const T3& c3, const T4& c4, const T5& c5,
|
||||
const T6& c6, const T7& c7, const T8& c8, const T9& c9)
|
||||
{
|
||||
typedef _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4,T5,T6,T7,T8,T9>::T_container
|
||||
T_container;
|
||||
|
||||
return CartesianProduct<TinyVector<int,9>, T_container, 9>(
|
||||
cp_traits<T1,T_container>::make(c1),
|
||||
cp_traits<T2,T_container>::make(c2),
|
||||
cp_traits<T3,T_container>::make(c3),
|
||||
cp_traits<T4,T_container>::make(c4),
|
||||
cp_traits<T5,T_container>::make(c5),
|
||||
cp_traits<T6,T_container>::make(c6),
|
||||
cp_traits<T7,T_container>::make(c7),
|
||||
cp_traits<T8,T_container>::make(c8),
|
||||
cp_traits<T9,T_container>::make(c9));
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10>
|
||||
CartesianProduct<TinyVector<int,10>, _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>::T_container, 10>
|
||||
indexSet(const T1& c1, const T2& c2, const T3& c3, const T4& c4, const T5& c5,
|
||||
const T6& c6, const T7& c7, const T8& c8, const T9& c9, const T10& c10)
|
||||
{
|
||||
typedef _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>::T_container
|
||||
T_container;
|
||||
|
||||
return CartesianProduct<TinyVector<int,10>, T_container, 10>(
|
||||
cp_traits<T1,T_container>::make(c1),
|
||||
cp_traits<T2,T_container>::make(c2),
|
||||
cp_traits<T3,T_container>::make(c3),
|
||||
cp_traits<T4,T_container>::make(c4),
|
||||
cp_traits<T5,T_container>::make(c5),
|
||||
cp_traits<T6,T_container>::make(c6),
|
||||
cp_traits<T7,T_container>::make(c7),
|
||||
cp_traits<T8,T_container>::make(c8),
|
||||
cp_traits<T9,T_container>::make(c9),
|
||||
cp_traits<T10,T_container>::make(c10));
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11>
|
||||
CartesianProduct<TinyVector<int,11>, _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_container, 11>
|
||||
indexSet(const T1& c1, const T2& c2, const T3& c3, const T4& c4, const T5& c5,
|
||||
const T6& c6, const T7& c7, const T8& c8, const T9& c9, const T10& c10,
|
||||
const T11& c11)
|
||||
{
|
||||
typedef _bz_typename
|
||||
cp_findContainerType<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_container
|
||||
T_container;
|
||||
|
||||
return CartesianProduct<TinyVector<int,11>, T_container, 11>(
|
||||
cp_traits<T1,T_container>::make(c1),
|
||||
cp_traits<T2,T_container>::make(c2),
|
||||
cp_traits<T3,T_container>::make(c3),
|
||||
cp_traits<T4,T_container>::make(c4),
|
||||
cp_traits<T5,T_container>::make(c5),
|
||||
cp_traits<T6,T_container>::make(c6),
|
||||
cp_traits<T7,T_container>::make(c7),
|
||||
cp_traits<T8,T_container>::make(c8),
|
||||
cp_traits<T9,T_container>::make(c9),
|
||||
cp_traits<T10,T_container>::make(c10),
|
||||
cp_traits<T11,T_container>::make(c11));
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAY_INDIRECT_H
|
||||
@@ -0,0 +1,550 @@
|
||||
/***************************************************************************
|
||||
* blitz/array/interlace.cc Interlaced array storage.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYINTERLACE_CC
|
||||
#define BZ_ARRAYINTERLACE_CC
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/interlace.cc> must be included via <blitz/array.h>
|
||||
#endif
|
||||
|
||||
#ifndef BZ_ARRAYSHAPE_H
|
||||
#include <blitz/array/shape.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* This header provides two collections of routines:
|
||||
*
|
||||
* interlaceArrays(shape, A1, A2, ...);
|
||||
* allocateArrays(shape, A1, A2, ...);
|
||||
*
|
||||
* interlaceArrays allocates a set of arrays so that their data is
|
||||
* interlaced. For example,
|
||||
*
|
||||
* Array<int,2> A, B;
|
||||
* interlaceArrays(shape(10,10), A, B);
|
||||
*
|
||||
* sets up the array storage so that A(0,0) is followed by B(0,0) in
|
||||
* memory; then A(0,1) and B(0,1), and so on.
|
||||
*
|
||||
* The allocateArrays() routines may or may not interlace the data,
|
||||
* depending on whether interlacing is advantageous for the architecture.
|
||||
* This is controlled by the setting of BZ_INTERLACE_ARRAYS in
|
||||
* <blitz/tuning.h>.
|
||||
*/
|
||||
|
||||
// Warning: Can't instantiate TinyVector<Range,N> because causes
|
||||
// conflict between TinyVector<T,N>::operator=(T) and
|
||||
// TinyVector<T,N>::operator=(Range)
|
||||
|
||||
// NEEDS_WORK -- also shape for up to N=11
|
||||
// NEEDS_WORK -- shape(Range r1, Range r2, ...) (return TinyVector<Range,n>)
|
||||
// maybe use Domain objects
|
||||
// NEEDS_WORK -- doesn't make a lot of sense for user to provide a
|
||||
// GeneralArrayStorage<N_rank+1>
|
||||
|
||||
template<typename T_numtype>
|
||||
void makeInterlacedArray(Array<T_numtype,2>& mainArray,
|
||||
Array<T_numtype,1>& subarray, int slice)
|
||||
{
|
||||
Array<T_numtype,1> tmp = mainArray(Range::all(), slice);
|
||||
subarray.reference(tmp);
|
||||
}
|
||||
|
||||
template<typename T_numtype>
|
||||
void makeInterlacedArray(Array<T_numtype,3>& mainArray,
|
||||
Array<T_numtype,2>& subarray, int slice)
|
||||
{
|
||||
Array<T_numtype,2> tmp = mainArray(Range::all(), Range::all(),
|
||||
slice);
|
||||
subarray.reference(tmp);
|
||||
}
|
||||
|
||||
template<typename T_numtype>
|
||||
void makeInterlacedArray(Array<T_numtype,4>& mainArray,
|
||||
Array<T_numtype,3>& subarray, int slice)
|
||||
{
|
||||
Array<T_numtype,3> tmp = mainArray(Range::all(), Range::all(),
|
||||
Range::all(), slice);
|
||||
subarray.reference(tmp);
|
||||
}
|
||||
|
||||
// These routines always allocate interlaced arrays
|
||||
template<typename T_numtype, int N_rank>
|
||||
void interlaceArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2)
|
||||
{
|
||||
GeneralArrayStorage<N_rank+1> storage(contiguousData);
|
||||
Array<T_numtype, N_rank+1> array(shape, 2, storage);
|
||||
makeInterlacedArray(array, a1, 0);
|
||||
makeInterlacedArray(array, a2, 1);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void interlaceArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3)
|
||||
{
|
||||
GeneralArrayStorage<N_rank+1> storage(contiguousData);
|
||||
Array<T_numtype, N_rank+1> array(shape, 3, storage);
|
||||
makeInterlacedArray(array, a1, 0);
|
||||
makeInterlacedArray(array, a2, 1);
|
||||
makeInterlacedArray(array, a3, 2);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void interlaceArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4)
|
||||
{
|
||||
GeneralArrayStorage<N_rank+1> storage(contiguousData);
|
||||
Array<T_numtype, N_rank+1> array(shape, 4, storage);
|
||||
makeInterlacedArray(array, a1, 0);
|
||||
makeInterlacedArray(array, a2, 1);
|
||||
makeInterlacedArray(array, a3, 2);
|
||||
makeInterlacedArray(array, a4, 3);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void interlaceArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5)
|
||||
{
|
||||
GeneralArrayStorage<N_rank+1> storage(contiguousData);
|
||||
Array<T_numtype, N_rank+1> array(shape, 5, storage);
|
||||
makeInterlacedArray(array, a1, 0);
|
||||
makeInterlacedArray(array, a2, 1);
|
||||
makeInterlacedArray(array, a3, 2);
|
||||
makeInterlacedArray(array, a4, 3);
|
||||
makeInterlacedArray(array, a5, 4);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void interlaceArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6)
|
||||
{
|
||||
GeneralArrayStorage<N_rank+1> storage(contiguousData);
|
||||
Array<T_numtype, N_rank+1> array(shape, 6, storage);
|
||||
makeInterlacedArray(array, a1, 0);
|
||||
makeInterlacedArray(array, a2, 1);
|
||||
makeInterlacedArray(array, a3, 2);
|
||||
makeInterlacedArray(array, a4, 3);
|
||||
makeInterlacedArray(array, a5, 4);
|
||||
makeInterlacedArray(array, a6, 5);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void interlaceArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
|
||||
Array<T_numtype,N_rank>& a7)
|
||||
{
|
||||
GeneralArrayStorage<N_rank+1> storage(contiguousData);
|
||||
Array<T_numtype, N_rank+1> array(shape, 7, storage);
|
||||
makeInterlacedArray(array, a1, 0);
|
||||
makeInterlacedArray(array, a2, 1);
|
||||
makeInterlacedArray(array, a3, 2);
|
||||
makeInterlacedArray(array, a4, 3);
|
||||
makeInterlacedArray(array, a5, 4);
|
||||
makeInterlacedArray(array, a6, 5);
|
||||
makeInterlacedArray(array, a7, 6);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void interlaceArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
|
||||
Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8)
|
||||
{
|
||||
GeneralArrayStorage<N_rank+1> storage(contiguousData);
|
||||
Array<T_numtype, N_rank+1> array(shape, 8, storage);
|
||||
makeInterlacedArray(array, a1, 0);
|
||||
makeInterlacedArray(array, a2, 1);
|
||||
makeInterlacedArray(array, a3, 2);
|
||||
makeInterlacedArray(array, a4, 3);
|
||||
makeInterlacedArray(array, a5, 4);
|
||||
makeInterlacedArray(array, a6, 5);
|
||||
makeInterlacedArray(array, a7, 6);
|
||||
makeInterlacedArray(array, a8, 7);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void interlaceArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
|
||||
Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8,
|
||||
Array<T_numtype,N_rank>& a9)
|
||||
{
|
||||
GeneralArrayStorage<N_rank+1> storage(contiguousData);
|
||||
Array<T_numtype, N_rank+1> array(shape, 9, storage);
|
||||
makeInterlacedArray(array, a1, 0);
|
||||
makeInterlacedArray(array, a2, 1);
|
||||
makeInterlacedArray(array, a3, 2);
|
||||
makeInterlacedArray(array, a4, 3);
|
||||
makeInterlacedArray(array, a5, 4);
|
||||
makeInterlacedArray(array, a6, 5);
|
||||
makeInterlacedArray(array, a7, 6);
|
||||
makeInterlacedArray(array, a8, 7);
|
||||
makeInterlacedArray(array, a9, 8);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void interlaceArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
|
||||
Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8,
|
||||
Array<T_numtype,N_rank>& a9, Array<T_numtype,N_rank>& a10)
|
||||
{
|
||||
GeneralArrayStorage<N_rank+1> storage(contiguousData);
|
||||
Array<T_numtype, N_rank+1> array(shape, 10, storage);
|
||||
makeInterlacedArray(array, a1, 0);
|
||||
makeInterlacedArray(array, a2, 1);
|
||||
makeInterlacedArray(array, a3, 2);
|
||||
makeInterlacedArray(array, a4, 3);
|
||||
makeInterlacedArray(array, a5, 4);
|
||||
makeInterlacedArray(array, a6, 5);
|
||||
makeInterlacedArray(array, a7, 6);
|
||||
makeInterlacedArray(array, a8, 7);
|
||||
makeInterlacedArray(array, a9, 8);
|
||||
makeInterlacedArray(array, a10, 9);
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void interlaceArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
|
||||
Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8,
|
||||
Array<T_numtype,N_rank>& a9, Array<T_numtype,N_rank>& a10,
|
||||
Array<T_numtype,N_rank>& a11)
|
||||
{
|
||||
GeneralArrayStorage<N_rank+1> storage(contiguousData);
|
||||
Array<T_numtype, N_rank+1> array(shape, 11, storage);
|
||||
makeInterlacedArray(array, a1, 0);
|
||||
makeInterlacedArray(array, a2, 1);
|
||||
makeInterlacedArray(array, a3, 2);
|
||||
makeInterlacedArray(array, a4, 3);
|
||||
makeInterlacedArray(array, a5, 4);
|
||||
makeInterlacedArray(array, a6, 5);
|
||||
makeInterlacedArray(array, a7, 6);
|
||||
makeInterlacedArray(array, a8, 7);
|
||||
makeInterlacedArray(array, a9, 8);
|
||||
makeInterlacedArray(array, a10, 9);
|
||||
makeInterlacedArray(array, a11, 10);
|
||||
}
|
||||
|
||||
// NEEDS_WORK -- make `storage' a parameter in these routines
|
||||
// Will be tricky: have to convert GeneralArrayStorage<N_rank> to
|
||||
// GeneralArrayStorage<N_rank+1>
|
||||
|
||||
// These routines may or may not interlace arrays, depending on
|
||||
// whether it is advantageous for this platform.
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void allocateArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2)
|
||||
{
|
||||
#ifdef BZ_INTERLACE_ARRAYS
|
||||
interlaceArrays(shape, a1, a2);
|
||||
#else
|
||||
a1.resize(shape);
|
||||
a2.resize(shape);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void allocateArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3)
|
||||
{
|
||||
#ifdef BZ_INTERLACE_ARRAYS
|
||||
interlaceArrays(shape, a1, a2, a3);
|
||||
#else
|
||||
a1.resize(shape);
|
||||
a2.resize(shape);
|
||||
a3.resize(shape);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void allocateArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4)
|
||||
{
|
||||
#ifdef BZ_INTERLACE_ARRAYS
|
||||
interlaceArrays(shape, a1, a2, a3, a4);
|
||||
#else
|
||||
a1.resize(shape);
|
||||
a2.resize(shape);
|
||||
a3.resize(shape);
|
||||
a4.resize(shape);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void allocateArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5)
|
||||
{
|
||||
#ifdef BZ_INTERLACE_ARRAYS
|
||||
interlaceArrays(shape, a1, a2, a3, a4, a5);
|
||||
#else
|
||||
a1.resize(shape);
|
||||
a2.resize(shape);
|
||||
a3.resize(shape);
|
||||
a4.resize(shape);
|
||||
a5.resize(shape);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void allocateArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6)
|
||||
{
|
||||
#ifdef BZ_INTERLACE_ARRAYS
|
||||
interlaceArrays(shape, a1, a2, a3, a4, a5, a6);
|
||||
#else
|
||||
a1.resize(shape);
|
||||
a2.resize(shape);
|
||||
a3.resize(shape);
|
||||
a4.resize(shape);
|
||||
a5.resize(shape);
|
||||
a6.resize(shape);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void allocateArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
|
||||
Array<T_numtype,N_rank>& a7)
|
||||
{
|
||||
#ifdef BZ_INTERLACE_ARRAYS
|
||||
interlaceArrays(shape, a1, a2, a3, a4, a5, a6, a7);
|
||||
#else
|
||||
a1.resize(shape);
|
||||
a2.resize(shape);
|
||||
a3.resize(shape);
|
||||
a4.resize(shape);
|
||||
a5.resize(shape);
|
||||
a6.resize(shape);
|
||||
a7.resize(shape);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void allocateArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
|
||||
Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8)
|
||||
{
|
||||
#ifdef BZ_INTERLACE_ARRAYS
|
||||
interlaceArrays(shape, a1, a2, a3, a4, a5, a6, a7, a8);
|
||||
#else
|
||||
a1.resize(shape);
|
||||
a2.resize(shape);
|
||||
a3.resize(shape);
|
||||
a4.resize(shape);
|
||||
a5.resize(shape);
|
||||
a6.resize(shape);
|
||||
a7.resize(shape);
|
||||
a8.resize(shape);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void allocateArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
|
||||
Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8,
|
||||
Array<T_numtype,N_rank>& a9)
|
||||
{
|
||||
#ifdef BZ_INTERLACE_ARRAYS
|
||||
interlaceArrays(shape, a1, a2, a3, a4, a5, a6, a7, a8, a9);
|
||||
#else
|
||||
a1.resize(shape);
|
||||
a2.resize(shape);
|
||||
a3.resize(shape);
|
||||
a4.resize(shape);
|
||||
a5.resize(shape);
|
||||
a6.resize(shape);
|
||||
a7.resize(shape);
|
||||
a8.resize(shape);
|
||||
a9.resize(shape);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void allocateArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
|
||||
Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8,
|
||||
Array<T_numtype,N_rank>& a9, Array<T_numtype,N_rank>& a10)
|
||||
{
|
||||
#ifdef BZ_INTERLACE_ARRAYS
|
||||
interlaceArrays(shape, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
|
||||
#else
|
||||
a1.resize(shape);
|
||||
a2.resize(shape);
|
||||
a3.resize(shape);
|
||||
a4.resize(shape);
|
||||
a5.resize(shape);
|
||||
a6.resize(shape);
|
||||
a7.resize(shape);
|
||||
a8.resize(shape);
|
||||
a9.resize(shape);
|
||||
a10.resize(shape);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
void allocateArrays(const TinyVector<int,N_rank>& shape,
|
||||
Array<T_numtype,N_rank>& a1, Array<T_numtype,N_rank>& a2,
|
||||
Array<T_numtype,N_rank>& a3, Array<T_numtype,N_rank>& a4,
|
||||
Array<T_numtype,N_rank>& a5, Array<T_numtype,N_rank>& a6,
|
||||
Array<T_numtype,N_rank>& a7, Array<T_numtype,N_rank>& a8,
|
||||
Array<T_numtype,N_rank>& a9, Array<T_numtype,N_rank>& a10,
|
||||
Array<T_numtype,N_rank>& a11)
|
||||
{
|
||||
#ifdef BZ_INTERLACE_ARRAYS
|
||||
interlaceArrays(shape, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
|
||||
#else
|
||||
a1.resize(shape);
|
||||
a2.resize(shape);
|
||||
a3.resize(shape);
|
||||
a4.resize(shape);
|
||||
a5.resize(shape);
|
||||
a6.resize(shape);
|
||||
a7.resize(shape);
|
||||
a8.resize(shape);
|
||||
a9.resize(shape);
|
||||
a10.resize(shape);
|
||||
a11.resize(shape);
|
||||
#endif
|
||||
}
|
||||
|
||||
// NEEDS_WORK -- allocateArrays for TinyVector<Range,N_rank>
|
||||
|
||||
/** This constructor is used to create interlaced arrays. */
|
||||
template<typename T_numtype, int N_rank>
|
||||
Array<T_numtype,N_rank>::Array(const TinyVector<int,N_rank-1>& shape,
|
||||
int lastExtent, const GeneralArrayStorage<N_rank>& storage)
|
||||
: storage_(storage)
|
||||
{
|
||||
// Create an array with the given shape, plus an extra dimension
|
||||
// for the number of arrays being allocated. This extra dimension
|
||||
// must have minor storage order.
|
||||
|
||||
if (ordering(0) == 0)
|
||||
{
|
||||
// Column major storage order (or something like it)
|
||||
length_[0] = lastExtent;
|
||||
storage_.setBase(0,0);
|
||||
for (int i=1; i < N_rank; ++i)
|
||||
length_[i] = shape[i-1];
|
||||
}
|
||||
else if (ordering(0) == N_rank-1)
|
||||
{
|
||||
// Row major storage order (or something like it)
|
||||
for (int i=0; i < N_rank-1; ++i)
|
||||
length_[i] = shape[i];
|
||||
length_[N_rank-1] = lastExtent;
|
||||
storage_.setBase(N_rank-1, 0);
|
||||
}
|
||||
else {
|
||||
BZPRECHECK(0, "Used allocateArrays() with a peculiar storage format");
|
||||
}
|
||||
|
||||
setupStorage(N_rank-1);
|
||||
}
|
||||
|
||||
// NEEDS_WORK -- see note about TinyVector<Range,N> in <blitz/arrayshape.h>
|
||||
#if 0
|
||||
template<typename T_numtype, int N_rank>
|
||||
Array<T_numtype,N_rank>::Array(const TinyVector<Range,N_rank-1>& shape,
|
||||
int lastExtent, const GeneralArrayStorage<N_rank>& storage)
|
||||
: storage_(storage)
|
||||
{
|
||||
#ifdef BZ_DEBUG
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
BZPRECHECK(shape[i].isAscendingContiguous(),
|
||||
"In call to allocateArrays(), a Range object is not ascending" << endl
|
||||
<< "contiguous: " << shape[i] << endl);
|
||||
#endif
|
||||
|
||||
if (ordering(0) == 0)
|
||||
{
|
||||
// Column major storage order (or something like it)
|
||||
length_[0] = lastExtent;
|
||||
storage_.setBase(0,0);
|
||||
for (int i=1; i < N_rank; ++i)
|
||||
{
|
||||
length_[i] = shape[i-1].length();
|
||||
storage_.setBase(i, shape[i-1].first());
|
||||
}
|
||||
}
|
||||
else if (ordering(0) == N_rank-1)
|
||||
{
|
||||
// Row major storage order (or something like it)
|
||||
for (int i=0; i < N_rank-1; ++i)
|
||||
{
|
||||
length_[i] = shape[i];
|
||||
storage_.setBase(i, shape[i].first());
|
||||
}
|
||||
length_[N_rank-1] = lastExtent;
|
||||
storage_.setBase(N_rank-1, 0);
|
||||
}
|
||||
else {
|
||||
BZPRECHECK(0, "Used allocateArrays() with a peculiar storage format");
|
||||
}
|
||||
|
||||
setupStorage(N_rank-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYINTER_CC
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
/***************************************************************************
|
||||
* blitz/array/io.cc Input/output of arrays.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYIO_CC
|
||||
#define BZ_ARRAYIO_CC
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/io.cc> must be included via <blitz/array.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// NEEDS_WORK???
|
||||
// This version of operator<< is updated on August 2005
|
||||
// by Sergei Mingaleev <mingaleev@gmail.com>.
|
||||
// Also, the corresponding operator>> is updated.
|
||||
|
||||
template<typename T_numtype>
|
||||
ostream& operator<<(ostream& os, const Array<T_numtype,1>& x)
|
||||
{
|
||||
// Write the extent vector: e.g., (-4, 4)
|
||||
|
||||
os << "(" << x.lbound(0) << "," << x.ubound(0) << ")";
|
||||
os << endl << "[ ";
|
||||
|
||||
for (int i1=x.lbound(0); i1<=x.ubound(0); i1++) {
|
||||
os << x(i1) << " ";
|
||||
}
|
||||
os << "]" << endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
ostream& operator<<(ostream& os, const Array<T_numtype,N_rank>& x)
|
||||
{
|
||||
// Write the extent vector: this is separated by 'x's, e.g.
|
||||
// (1, 10) x (-4, 4) x (-5, 5)
|
||||
|
||||
for (int i=0; i < N_rank; ++i) {
|
||||
os << "(";
|
||||
os << x.lbound(i);
|
||||
os << ",";
|
||||
os << x.ubound(i);
|
||||
os << ")";
|
||||
if (i != N_rank-1) os << " x ";
|
||||
}
|
||||
os << endl << "[ ";
|
||||
|
||||
switch (N_rank) {
|
||||
case 2:
|
||||
for (int i1=x.lbound(0); i1<=x.ubound(0); i1++) {
|
||||
for (int i2=x.lbound(1); i2<=x.ubound(1); i2++) {
|
||||
os << x(i1,i2) << " ";
|
||||
}
|
||||
if (i1 != x.ubound(0)) os << endl << " ";
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
for (int i1=x.lbound(0); i1<=x.ubound(0); i1++) {
|
||||
for (int i2=x.lbound(1); i2<=x.ubound(1); i2++) {
|
||||
for (int i3=x.lbound(2); i3<=x.ubound(2); i3++) {
|
||||
os << x(i1,i2,i3) << " ";
|
||||
}
|
||||
if (i1 != x.ubound(0) || i2 != x.ubound(1)) os << endl << " ";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
for (int i1=x.lbound(0); i1<=x.ubound(0); i1++) {
|
||||
for (int i2=x.lbound(1); i2<=x.ubound(1); i2++) {
|
||||
for (int i3=x.lbound(2); i3<=x.ubound(2); i3++) {
|
||||
for (int i4=x.lbound(3); i4<=x.ubound(3); i4++) {
|
||||
os << x(i1,i2,i3,i4) << " ";
|
||||
}
|
||||
if (i1 != x.ubound(0) || i2 != x.ubound(1) || i3 != x.ubound(2))
|
||||
os << endl << " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cout << "Error: operator<< for " << N_rank
|
||||
<< "D Array is not supported!" << endl;
|
||||
BZASSERT("ERROR!");
|
||||
break;
|
||||
};
|
||||
|
||||
os << "]" << endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
/*
|
||||
* Input
|
||||
*/
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
istream& operator>>(istream& is, Array<T_numtype,N_rank>& x)
|
||||
{
|
||||
TinyVector<int,N_rank> lower_bounds, upper_bounds, extent;
|
||||
char sep;
|
||||
|
||||
// Read the extent vector: this is separated by 'x's, e.g.
|
||||
// (1, 10) x (-4, 4) x (-5, 5)
|
||||
|
||||
for (int i=0; i < N_rank; ++i) {
|
||||
is >> sep;
|
||||
BZPRECHECK(!is.bad(), "Premature end of input while scanning Array");
|
||||
BZPRECHECK(sep == '(', "Format error while scanning input \
|
||||
Array \n -- expected '(' opening Array extents");
|
||||
|
||||
is >> lower_bounds(i);
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == ',', "Format error while scanning input \
|
||||
Array \n -- expected ',' between Array extents");
|
||||
is >> upper_bounds(i);
|
||||
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == ')', "Format error while scanning input \
|
||||
Array \n -- expected ',' closing Array extents");
|
||||
|
||||
if (i != N_rank-1) {
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == 'x', "Format error while scanning input \
|
||||
Array \n (expected 'x' between Array extents)");
|
||||
}
|
||||
}
|
||||
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == '[', "Format error while scanning input \
|
||||
Array \n (expected '[' before beginning of Array data)");
|
||||
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
extent(i) = upper_bounds(i) - lower_bounds(i) + 1;
|
||||
x.resize(extent);
|
||||
x.reindexSelf(lower_bounds);
|
||||
|
||||
switch (N_rank) {
|
||||
case 1:
|
||||
for (int i1=x.lbound(0); i1<=x.ubound(0); i1++) {
|
||||
BZPRECHECK(!is.bad(), "Premature end of input while scanning Array");
|
||||
is >> x(i1);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
for (int i1=x.lbound(0); i1<=x.ubound(0); i1++) {
|
||||
for (int i2=x.lbound(1); i2<=x.ubound(1); i2++) {
|
||||
BZPRECHECK(!is.bad(), "Premature end of input while scanning Array");
|
||||
is >> x(i1,i2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
for (int i1=x.lbound(0); i1<=x.ubound(0); i1++) {
|
||||
for (int i2=x.lbound(1); i2<=x.ubound(1); i2++) {
|
||||
for (int i3=x.lbound(2); i3<=x.ubound(2); i3++) {
|
||||
BZPRECHECK(!is.bad(), "Premature end of input while scanning Array");
|
||||
is >> x(i1,i2,i3);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
for (int i1=x.lbound(0); i1<=x.ubound(0); i1++) {
|
||||
for (int i2=x.lbound(1); i2<=x.ubound(1); i2++) {
|
||||
for (int i3=x.lbound(2); i3<=x.ubound(2); i3++) {
|
||||
for (int i4=x.lbound(3); i4<=x.ubound(3); i4++) {
|
||||
BZPRECHECK(!is.bad(), "Premature end of input while scanning Array");
|
||||
is >> x(i1,i2,i3,i4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cout << "Error: read() for " << N_rank
|
||||
<< "D Array is not supported!" << endl;
|
||||
BZASSERT("ERROR!");
|
||||
break;
|
||||
};
|
||||
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == ']', "Format error while scanning input \
|
||||
Array \n (expected ']' after end of Array data)");
|
||||
return is;
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYIO_CC
|
||||
@@ -0,0 +1,324 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/iter.h Basic iterator for arrays.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/iter.h> must be included via <blitz/array.h>
|
||||
#endif
|
||||
|
||||
#ifndef BZ_ARRAY_ITER_H
|
||||
#define BZ_ARRAY_ITER_H
|
||||
|
||||
#ifdef BZ_HAVE_STL
|
||||
#include <iterator>
|
||||
#endif
|
||||
|
||||
#if defined(BZ_DEBUG)
|
||||
#define CheckIteratorValidity(X,Y) \
|
||||
BZPRECHECK(data_!=0, X " invalid iterator (empty array)"); \
|
||||
BZPRECHECK((data_>=beg_+Y && data_<=end_+Y), ((data_<beg_+Y) ? \
|
||||
X " invalid iterator (before beginning of array)" : \
|
||||
X " invalid iterator (past end of array)"));
|
||||
#else
|
||||
#define CheckIteratorValidity(X,Y)
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename T, int N>
|
||||
class ConstArrayIterator {
|
||||
private:
|
||||
// Initialization common to begin,end constructors.
|
||||
//
|
||||
void Init(const Array<T,N>& array) {
|
||||
// Making internal copies of these avoids keeping
|
||||
// a pointer to the array and doing indirection.
|
||||
lbound_ = array.lbound();
|
||||
order_ = array.ordering();
|
||||
|
||||
ubound_(0) = array.ubound(0)+1;
|
||||
dataincr_(order_(0)) = array.stride(order_(0));
|
||||
for (int i=1,r,s=order_(0);i<N;s=r,++i) {
|
||||
r = order_(i);
|
||||
ubound_(i) = array.ubound(i)+1;
|
||||
dataincr_(r) = array.stride(r)-array.extent(s)*array.stride(s);
|
||||
}
|
||||
#if defined(BZ_DEBUG)
|
||||
beg_ = array.data();
|
||||
end_ = end_value(array)-1;
|
||||
if (beg_>end_)
|
||||
std::swap(beg_,end_);
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
ConstArrayIterator() : data_(0) { }
|
||||
|
||||
ConstArrayIterator(const Array<T,N>& array) :
|
||||
data_(const_cast<T*>(array.data())) {
|
||||
Init(array);
|
||||
pos_ = lbound_;
|
||||
}
|
||||
|
||||
ConstArrayIterator(const Array<T,N>& array, const int) :
|
||||
data_(end_value(array)) {
|
||||
Init(array);
|
||||
pos_ = array.ubound();
|
||||
++pos_(order_(0));
|
||||
}
|
||||
|
||||
bool operator==(const ConstArrayIterator<T,N>& x) const
|
||||
{ return data_ == x.data_; }
|
||||
|
||||
bool operator!=(const ConstArrayIterator<T,N>& x) const
|
||||
{ return data_ != x.data_; }
|
||||
|
||||
const T& operator*() const {
|
||||
CheckIteratorValidity("Attempted to dereference",0);
|
||||
return *data_;
|
||||
}
|
||||
|
||||
const T* restrict operator->() const {
|
||||
CheckIteratorValidity("Attempted to dereference",0);
|
||||
return data_;
|
||||
}
|
||||
|
||||
ConstArrayIterator<T,N>& operator++();
|
||||
ConstArrayIterator<T,N>& operator--();
|
||||
|
||||
ConstArrayIterator<T,N> operator++(int) {
|
||||
ConstArrayIterator<T,N> tmp = *this;
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
ConstArrayIterator<T,N> operator--(int) {
|
||||
ConstArrayIterator<T,N> tmp = *this;
|
||||
--(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// get the current position of the Array iterator in index space
|
||||
const TinyVector<int,N>& position() const {
|
||||
CheckIteratorValidity("Array<T,N>::iterator::position() called on",0);
|
||||
return pos_;
|
||||
}
|
||||
|
||||
private:
|
||||
TinyVector<int,N> dataincr_, lbound_, ubound_, order_;
|
||||
|
||||
static T* end_value(const Array<T,N>& array) {
|
||||
T* endval = const_cast<T*>(array.data()) +
|
||||
array.stride(array.ordering(0));
|
||||
for (int i=0;i<N;++i)
|
||||
endval += array.stride(i)*(array.extent(i)-1);
|
||||
return endval;
|
||||
}
|
||||
|
||||
protected:
|
||||
TinyVector<int,N> pos_;
|
||||
T * restrict data_;
|
||||
#if defined(BZ_DEBUG)
|
||||
const T* restrict beg_;
|
||||
const T* restrict end_;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
template<typename T, int N>
|
||||
class ArrayIterator : public ConstArrayIterator<T,N> {
|
||||
private:
|
||||
typedef ConstArrayIterator<T,N> T_base;
|
||||
using T_base::data_;
|
||||
|
||||
#if defined(BZ_DEBUG)
|
||||
using T_base::beg_;
|
||||
using T_base::end_;
|
||||
#endif
|
||||
|
||||
public:
|
||||
ArrayIterator() { }
|
||||
|
||||
ArrayIterator(Array<T,N>& x) : T_base(x) { }
|
||||
|
||||
ArrayIterator(const Array<T,N>& array, const int): T_base(array,0) { }
|
||||
|
||||
T& operator*() const {
|
||||
CheckIteratorValidity("Attempted to dereference",0);
|
||||
return *data_;
|
||||
}
|
||||
|
||||
T* restrict operator->() const {
|
||||
CheckIteratorValidity("Attempted to dereference",0);
|
||||
return data_;
|
||||
}
|
||||
|
||||
ArrayIterator<T,N>& operator++() {
|
||||
T_base::operator++();
|
||||
return *this;
|
||||
}
|
||||
|
||||
ArrayIterator<T,N> operator++(int) {
|
||||
ArrayIterator<T,N> tmp = *this;
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
ArrayIterator<T,N>& operator--() {
|
||||
T_base::operator--();
|
||||
return *this;
|
||||
}
|
||||
|
||||
ArrayIterator<T,N> operator--(int) {
|
||||
ArrayIterator<T,N> tmp = *this;
|
||||
--(*this);
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, int N>
|
||||
ConstArrayIterator<T,N>& ConstArrayIterator<T,N>::operator++() {
|
||||
CheckIteratorValidity("Attempted to increment",0);
|
||||
|
||||
// The first loop iteration is peeled as it increases performance.
|
||||
// The same improvement can be obtained by telling the compiler that
|
||||
// the test is likely to be true, but this has too many portability issues
|
||||
// for now.
|
||||
|
||||
// With a compiler peeling loops correctly (or with an effective BZ_LIKELY
|
||||
// macro, this could be simply written as:
|
||||
//
|
||||
// for (int i=0;i<N;++i) {
|
||||
// const int r = order_(i);
|
||||
// data_ += dataincr_[r];
|
||||
// if (BZ_LIKELY(++pos_(r)!=ubound_(r)))
|
||||
// return *this;
|
||||
// pos_(r) = lbound_(r);
|
||||
// }
|
||||
|
||||
|
||||
const int r0 = order_(0);
|
||||
data_ += dataincr_[r0];
|
||||
if (BZ_LIKELY(++pos_(r0)!=ubound_(r0)))
|
||||
return *this;
|
||||
pos_(r0) = lbound_(r0);
|
||||
|
||||
for (int i=1;i<N;++i) {
|
||||
const int r = order_(i);
|
||||
data_ += dataincr_[r];
|
||||
if (BZ_LIKELY(++pos_(r)!=ubound_(r)))
|
||||
return *this;
|
||||
pos_(r) = lbound_(r);
|
||||
}
|
||||
|
||||
// At this place the value of data_ should match that of the end iterator.
|
||||
// Do the proper correction to achieve that.
|
||||
|
||||
for (int i=1;i<N;++i) {
|
||||
const int r = order_(i);
|
||||
data_ -= dataincr_[r];
|
||||
pos_(r) = ubound_(r)-1;
|
||||
}
|
||||
pos_(r0) = ubound_(r0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T, int N>
|
||||
ConstArrayIterator<T,N>& ConstArrayIterator<T,N>::operator--() {
|
||||
CheckIteratorValidity("Attempted to decrement",1);
|
||||
|
||||
// The first loop iteration is peeled as it increases performance.
|
||||
// The same improvement can be obtained by telling the compiler that
|
||||
// the test is likely to be true, but this has too many portability issues
|
||||
// for now.
|
||||
|
||||
// With a compiler peeling loops correctly (or with an effective BZ_LIKELY
|
||||
// macro, this could be simply written as:
|
||||
//
|
||||
// for (int i=0;i<N;++i) {
|
||||
// const int r = order_(i);
|
||||
// data_ -= dataincr_[r];
|
||||
// if (BZ_LIKELY(pos_(r)--!=lbound_(r)))
|
||||
// return *this;
|
||||
// pos_(r) = ubound_(r)-1;
|
||||
// }
|
||||
|
||||
|
||||
const int r0 = order_(0);
|
||||
data_ -= dataincr_[r0];
|
||||
if (BZ_LIKELY(pos_(r0)--!=lbound_(r0)))
|
||||
return *this;
|
||||
pos_(r0) = ubound_(r0)-1;
|
||||
|
||||
for (int i=1;i<N;++i) {
|
||||
const int r = order_(i);
|
||||
data_ -= dataincr_[r];
|
||||
if (BZ_LIKELY(pos_(r)--!=lbound_(r)))
|
||||
return *this;
|
||||
pos_(r) = ubound_(r)-1;
|
||||
}
|
||||
|
||||
// At this place the value of data_ should match that of the end iterator.
|
||||
// No correction is needed for operator--
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
|
||||
#ifdef BZ_HAVE_STL
|
||||
// support for std::iterator_traits
|
||||
BZ_NAMESPACE(std)
|
||||
|
||||
template <typename T, int N>
|
||||
struct iterator_traits< BZ_BLITZ_SCOPE(ConstArrayIterator)<T,N> > {
|
||||
typedef bidirectional_iterator_tag iterator_category;
|
||||
typedef T value_type;
|
||||
typedef blitz::diffType difference_type;
|
||||
typedef const T* pointer;
|
||||
typedef const T& reference;
|
||||
};
|
||||
|
||||
template <typename T, int N>
|
||||
struct iterator_traits< BZ_BLITZ_SCOPE(ArrayIterator)<T,N> > {
|
||||
typedef bidirectional_iterator_tag iterator_category;
|
||||
typedef T value_type;
|
||||
typedef blitz::diffType difference_type;
|
||||
typedef T* pointer;
|
||||
typedef T& reference;
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_HAVE_STL
|
||||
|
||||
#endif // BZ_ARRAY_ITER_H
|
||||
|
||||
@@ -0,0 +1,774 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/map.h Declaration of the ArrayIndexMapping class
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* ArrayIndexMapping is used to implement tensor array notation. For
|
||||
* example:
|
||||
*
|
||||
* Array<float, 2> A, B;
|
||||
* firstIndex i;
|
||||
* secondIndex j;
|
||||
* thirdIndex k;
|
||||
* Array<float, 3> C = A(i,j) * B(j,k);
|
||||
*
|
||||
* For expression templates purposes, something like B(j,k) is represented
|
||||
* by an instance of class ArrayIndexMapping. This class maps an array onto
|
||||
* the destination array coordinate system, e.g. B(j,k) -> C(i,j,k)
|
||||
*/
|
||||
|
||||
#ifndef BZ_ARRAYMAP_H
|
||||
#define BZ_ARRAYMAP_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/prettyprint.h>
|
||||
#include <blitz/et-forward.h>
|
||||
#include <blitz/tinyvec2.h>
|
||||
#include <blitz/array/domain.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* _bz_doArrayIndexMapping is a helper class that does the index
|
||||
* remapping. It is specialized for ranks 1, 2, 3, ..., 11.
|
||||
*/
|
||||
|
||||
template<int N_rank>
|
||||
struct _bz_doArrayIndexMapping {
|
||||
static const int rank=N_rank;
|
||||
template<typename T_expr, int N_inputRank>
|
||||
static typename T_expr::T_numtype map(const ETBase<T_expr>& expr,
|
||||
const TinyVector<int,N_inputRank>&, int, int, int, int, int, int,
|
||||
int, int, int, int, int)
|
||||
{
|
||||
// If you try to use an array index mapping on an array with
|
||||
// rank greater than 11, then you'll get a precondition failure
|
||||
// here.
|
||||
BZPRECHECK(0,"Index mappings for containers of rank>11 not implemented");
|
||||
return T_expr::T_numtype();
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_doArrayIndexMapping<1> {
|
||||
static const int rank=1;
|
||||
template<typename T_expr, int N_inputRank>
|
||||
static typename T_expr::T_numtype map(const ETBase<T_expr>& expr,
|
||||
const TinyVector<int,N_inputRank>& index, int i0, int, int, int, int,
|
||||
int, int, int, int, int, int)
|
||||
{
|
||||
// this was the case when it took an array. is it necessary?
|
||||
BZPRECHECK(T_expr::rank_==rank,
|
||||
"Rank confusion in _bz_doArrayIndexMapping");
|
||||
return expr.unwrap()(index[i0]);
|
||||
}
|
||||
|
||||
template<int N_inputRank>
|
||||
static TinyVector<int,rank> map_dims(const TinyVector<int,N_inputRank>& index,
|
||||
int i0, int, int, int, int,
|
||||
int, int, int, int, int, int)
|
||||
{
|
||||
// this might be slower but unlike Array, FAI doesn't have 11
|
||||
// overloaded moveTo methods.
|
||||
const TinyVector<int,rank> newindex(index[i0]);
|
||||
return newindex;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
struct _bz_doArrayIndexMapping<2> {
|
||||
static const int rank=2;
|
||||
|
||||
template<typename T_expr, int N_inputRank>
|
||||
static typename T_expr::T_numtype map(const ETBase<T_expr>& expr,
|
||||
const TinyVector<int,N_inputRank>& index, int i0, int i1, int,
|
||||
int, int, int, int, int, int, int, int)
|
||||
{
|
||||
// this was the case when it took an array. is it necessary?
|
||||
BZPRECHECK(T_expr::rank_==rank,
|
||||
"Rank confusion in _bz_doArrayIndexMapping");
|
||||
return expr.unwrap()(index[i0], index[i1]);
|
||||
}
|
||||
|
||||
template<int N_inputRank>
|
||||
static TinyVector<int,rank> map_dims(const TinyVector<int,N_inputRank>& index,
|
||||
int i0, int i1, int, int, int,
|
||||
int, int, int, int, int, int)
|
||||
{
|
||||
return TinyVector<int,rank>(index[i0], index[i1]);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_doArrayIndexMapping<3> {
|
||||
static const int rank=3;
|
||||
|
||||
template<typename T_expr, int N_inputRank>
|
||||
static typename T_expr::T_numtype map(const ETBase<T_expr>& expr,
|
||||
const TinyVector<int,N_inputRank>& index, int i0, int i1, int i2,
|
||||
int, int, int, int, int, int, int, int)
|
||||
{
|
||||
// this was the case when it took an array. is it necessary?
|
||||
BZPRECHECK(T_expr::rank_==rank,
|
||||
"Rank confusion in _bz_doArrayIndexMapping");
|
||||
return expr.unwrap()(index[i0], index[i1], index[i2]);
|
||||
}
|
||||
|
||||
template<int N_inputRank>
|
||||
static TinyVector<int,rank> map_dims(const TinyVector<int,N_inputRank>& index,
|
||||
int i0, int i1, int i2, int, int,
|
||||
int, int, int, int, int, int)
|
||||
{
|
||||
return TinyVector<int,rank>(index[i0], index[i1], index[i2]);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_doArrayIndexMapping<4> {
|
||||
static const int rank=4;
|
||||
|
||||
template<typename T_expr, int N_inputRank>
|
||||
static typename T_expr::T_numtype map(const ETBase<T_expr>& expr,
|
||||
const TinyVector<int,N_inputRank>& index, int i0, int i1, int i2,
|
||||
int i3, int, int, int, int, int, int, int)
|
||||
{
|
||||
// this was the case when it took an array. is it necessary?
|
||||
BZPRECHECK(T_expr::rank_==rank,
|
||||
"Rank confusion in _bz_doArrayIndexMapping");
|
||||
return expr.unwrap()(index[i0], index[i1], index[i2], index[i3]);
|
||||
}
|
||||
|
||||
template<int N_inputRank>
|
||||
static TinyVector<int,rank> map_dims(const TinyVector<int,N_inputRank>& index,
|
||||
int i0, int i1, int i2, int i3, int,
|
||||
int, int, int, int, int, int)
|
||||
{
|
||||
return TinyVector<int,rank>(index[i0], index[i1], index[i2],
|
||||
index[i3]);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_doArrayIndexMapping<5> {
|
||||
static const int rank=5;
|
||||
|
||||
template<typename T_expr, int N_inputRank>
|
||||
static typename T_expr::T_numtype map(const ETBase<T_expr>& expr,
|
||||
const TinyVector<int,N_inputRank>& index, int i0, int i1, int i2,
|
||||
int i3, int i4, int, int, int, int, int, int)
|
||||
{
|
||||
// this was the case when it took an array. is it necessary?
|
||||
BZPRECHECK(T_expr::rank_==rank,
|
||||
"Rank confusion in _bz_doArrayIndexMapping");
|
||||
return expr.unwrap()(index[i0], index[i1], index[i2], index[i3], index[i4]);
|
||||
}
|
||||
|
||||
template<int N_inputRank>
|
||||
static TinyVector<int,rank> map_dims(const TinyVector<int,N_inputRank>& index,
|
||||
int i0, int i1, int i2, int i3, int i4,
|
||||
int, int, int, int, int, int)
|
||||
{
|
||||
return TinyVector<int,rank>(index[i0], index[i1], index[i2],
|
||||
index[i3], index[i4]);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_doArrayIndexMapping<6> {
|
||||
static const int rank=6;
|
||||
|
||||
template<typename T_expr, int N_inputRank>
|
||||
static typename T_expr::T_numtype map(const ETBase<T_expr>& expr,
|
||||
const TinyVector<int,N_inputRank>& index, int i0, int i1, int i2,
|
||||
int i3, int i4, int i5, int, int, int, int, int)
|
||||
{
|
||||
// this was the case when it took an array. is it necessary?
|
||||
BZPRECHECK(T_expr::rank_==rank,
|
||||
"Rank confusion in _bz_doArrayIndexMapping");
|
||||
return expr.unwrap()(index[i0], index[i1], index[i2], index[i3], index[i4],
|
||||
index[i5]);
|
||||
}
|
||||
|
||||
template<int N_inputRank>
|
||||
static TinyVector<int,rank> map_dims(const TinyVector<int,N_inputRank>& index,
|
||||
int i0, int i1, int i2, int i3, int i4,
|
||||
int i5, int, int, int, int, int)
|
||||
{
|
||||
return TinyVector<int,rank>(index[i0], index[i1], index[i2],
|
||||
index[i3], index[i4], index[i5]);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_doArrayIndexMapping<7> {
|
||||
static const int rank=7;
|
||||
|
||||
template<typename T_expr, int N_inputRank>
|
||||
static typename T_expr::T_numtype map(const ETBase<T_expr>& expr,
|
||||
const TinyVector<int,N_inputRank>& index, int i0, int i1, int i2,
|
||||
int i3, int i4, int i5, int i6, int, int, int, int)
|
||||
{
|
||||
// this was the case when it took an array. is it necessary?
|
||||
BZPRECHECK(T_expr::rank_==rank,
|
||||
"Rank confusion in _bz_doArrayIndexMapping");
|
||||
return expr.unwrap()(index[i0], index[i1], index[i2], index[i3],
|
||||
index[i4], index[i5], index[i6]);
|
||||
}
|
||||
|
||||
template<int N_inputRank>
|
||||
static TinyVector<int,rank> map_dims(const TinyVector<int,N_inputRank>& index,
|
||||
int i0, int i1, int i2, int i3, int i4,
|
||||
int i5, int i6, int, int, int, int)
|
||||
{
|
||||
return TinyVector<int,rank>(index[i0], index[i1], index[i2],
|
||||
index[i3], index[i4], index[i5],
|
||||
index[i6]);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_doArrayIndexMapping<8> {
|
||||
static const int rank=8;
|
||||
|
||||
template<typename T_expr, int N_inputRank>
|
||||
static typename T_expr::T_numtype map(const ETBase<T_expr>& expr,
|
||||
const TinyVector<int,N_inputRank>& index, int i0, int i1, int i2,
|
||||
int i3, int i4, int i5, int i6, int i7, int, int, int)
|
||||
{
|
||||
// this was the case when it took an array. is it necessary?
|
||||
BZPRECHECK(T_expr::rank_==rank,
|
||||
"Rank confusion in _bz_doArrayIndexMapping");
|
||||
return expr.unwrap()(index[i0], index[i1], index[i2], index[i3],
|
||||
index[i4], index[i5], index[i6], index[i7]);
|
||||
}
|
||||
|
||||
template<int N_inputRank>
|
||||
static TinyVector<int,rank> map_dims(const TinyVector<int,N_inputRank>& index,
|
||||
int i0, int i1, int i2, int i3, int i4,
|
||||
int i5, int i6, int i7, int, int, int)
|
||||
{
|
||||
return TinyVector<int,rank>(index[i0], index[i1], index[i2],
|
||||
index[i3], index[i4], index[i5],
|
||||
index[i6], index[i7]);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_doArrayIndexMapping<9> {
|
||||
static const int rank=9;
|
||||
|
||||
template<typename T_expr, int N_inputRank>
|
||||
static typename T_expr::T_numtype map(const ETBase<T_expr>& expr,
|
||||
const TinyVector<int,N_inputRank>& index, int i0, int i1, int i2,
|
||||
int i3, int i4, int i5, int i6, int i7, int i8, int, int)
|
||||
{
|
||||
// this was the case when it took an array. is it necessary?
|
||||
BZPRECHECK(T_expr::rank_==rank,
|
||||
"Rank confusion in _bz_doArrayIndexMapping");
|
||||
return expr.unwrap()(index[i0], index[i1], index[i2], index[i3],
|
||||
index[i4], index[i5], index[i6], index[i7],
|
||||
index[i8]);
|
||||
}
|
||||
|
||||
template<int N_inputRank>
|
||||
static TinyVector<int,rank> map_dims(const TinyVector<int,N_inputRank>& index,
|
||||
int i0, int i1, int i2, int i3, int i4,
|
||||
int i5, int i6, int i7, int i8, int, int)
|
||||
{
|
||||
return TinyVector<int,rank>(index[i0], index[i1], index[i2],
|
||||
index[i3], index[i4], index[i5],
|
||||
index[i6], index[i7], index[i8]);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_doArrayIndexMapping<10> {
|
||||
static const int rank=10;
|
||||
|
||||
template<typename T_expr, int N_inputRank>
|
||||
static typename T_expr::T_numtype map(const ETBase<T_expr>& expr,
|
||||
const TinyVector<int,N_inputRank>& index, int i0, int i1, int i2,
|
||||
int i3, int i4, int i5, int i6, int i7, int i8, int i9, int)
|
||||
{
|
||||
// this was the case when it took an array. is it necessary?
|
||||
BZPRECHECK(T_expr::rank_==rank,
|
||||
"Rank confusion in _bz_doArrayIndexMapping");
|
||||
return expr.unwrap()(index[i0], index[i1], index[i2], index[i3],
|
||||
index[i4], index[i5], index[i6], index[i7],
|
||||
index[i8], index[i9]);
|
||||
}
|
||||
|
||||
template<int N_inputRank>
|
||||
static TinyVector<int,rank> map_dims(const TinyVector<int,N_inputRank>& index,
|
||||
int i0, int i1, int i2, int i3, int i4,
|
||||
int i5, int i6, int i7, int i8, int i9, int)
|
||||
{
|
||||
return TinyVector<int,rank>(index[i0], index[i1], index[i2],
|
||||
index[i3], index[i4], index[i5],
|
||||
index[i6], index[i7], index[i8],
|
||||
index[i9]);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_doArrayIndexMapping<11> {
|
||||
static const int rank=11;
|
||||
|
||||
template<typename T_expr, int N_inputRank>
|
||||
static typename T_expr::T_numtype map(const ETBase<T_expr>& expr,
|
||||
const TinyVector<int,N_inputRank>& index, int i0, int i1, int i2,
|
||||
int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10)
|
||||
{
|
||||
// this was the case when it took an array. is it necessary?
|
||||
BZPRECHECK(T_expr::rank_==rank,
|
||||
"Rank confusion in _bz_doArrayIndexMapping");
|
||||
return expr.unwrap()(index[i0], index[i1], index[i2], index[i3],
|
||||
index[i4], index[i5], index[i6], index[i7],
|
||||
index[i8], index[i9], index[i10]);
|
||||
}
|
||||
|
||||
template<int N_inputRank>
|
||||
static TinyVector<int,rank> map_dims(const TinyVector<int,N_inputRank>& index,
|
||||
int i0, int i1, int i2, int i3, int i4,
|
||||
int i5, int i6, int i7, int i8, int i9, int i10)
|
||||
{
|
||||
return TinyVector<int,rank>(index[i0], index[i1], index[i2],
|
||||
index[i3], index[i4], index[i5],
|
||||
index[i6], index[i7], index[i8],
|
||||
index[i9], index[i10]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// default arguments are defined in the fwd header
|
||||
template<typename P_expr, int N_map0, int N_map1, int N_map2,
|
||||
int N_map3, int N_map4, int N_map5, int N_map6, int N_map7,
|
||||
int N_map8, int N_map9, int N_map10>
|
||||
class ArrayIndexMapping {
|
||||
public:
|
||||
typedef P_expr T_expr;
|
||||
typedef typename T_expr::T_numtype T_numtype;
|
||||
|
||||
typedef T_numtype T_optype;
|
||||
typedef typename asET<T_numtype>::T_wrapped T_typeprop;
|
||||
typedef typename unwrapET<T_typeprop>::T_unwrapped T_result;
|
||||
|
||||
typedef T_expr T_ctorArg1;
|
||||
typedef int T_ctorArg2; // dummy
|
||||
typedef ArrayIndexMapping<typename T_expr::T_range_result,N_map0,N_map1,N_map2,N_map3,N_map4,N_map5,N_map6,N_map7,N_map8,N_map9,N_map10> T_range_result;
|
||||
|
||||
/*
|
||||
* This enum block finds the maximum of the N_map0, N_map1, ..., N_map10
|
||||
* parameters and stores it in maxRank10. The rank of the expression is
|
||||
* then maxRank10 + 1, since the IndexPlaceholders start at 0 rather than
|
||||
* 1.
|
||||
*/
|
||||
static const int
|
||||
maxRank1 = (N_map0 > N_map1) ? N_map0 : N_map1,
|
||||
maxRank2 = (N_map2 > maxRank1) ? N_map2 : maxRank1,
|
||||
maxRank3 = (N_map3 > maxRank2) ? N_map3 : maxRank2,
|
||||
maxRank4 = (N_map4 > maxRank3) ? N_map4 : maxRank3,
|
||||
maxRank5 = (N_map5 > maxRank4) ? N_map5 : maxRank4,
|
||||
maxRank6 = (N_map6 > maxRank5) ? N_map6 : maxRank5,
|
||||
maxRank7 = (N_map7 > maxRank6) ? N_map7 : maxRank6,
|
||||
maxRank8 = (N_map8 > maxRank7) ? N_map8 : maxRank7,
|
||||
maxRank9 = (N_map9 > maxRank8) ? N_map9 : maxRank8,
|
||||
maxRank10 = (N_map10 > maxRank9) ? N_map10 : maxRank9;
|
||||
|
||||
static const int
|
||||
numArrayOperands = T_expr::numArrayOperands,
|
||||
numTVOperands = T_expr::numTVOperands,
|
||||
numTMOperands = T_expr::numTMOperands,
|
||||
numIndexPlaceholders = 1,
|
||||
minWidth = simdTypes<T_numtype>::vecWidth,
|
||||
maxWidth = simdTypes<T_numtype>::vecWidth,
|
||||
rank_ = maxRank10 + 1,
|
||||
exprRank = T_expr::rank_;
|
||||
|
||||
template<int N> struct tvresult {
|
||||
typedef FastTV2Iterator<T_numtype, N> Type;
|
||||
};
|
||||
|
||||
/*
|
||||
ArrayIndexMapping(const Array<T_numtype, rank>& array)
|
||||
: iter_(array)
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
ArrayIndexMapping(const ArrayIndexMapping<T_expr,N_map0,
|
||||
N_map1,N_map2,N_map3,N_map4,N_map5,N_map6,N_map7,N_map8,N_map9,
|
||||
N_map10>& z)
|
||||
: iter_(z.iter_)
|
||||
{
|
||||
}
|
||||
|
||||
ArrayIndexMapping(BZ_ETPARM(T_expr) a)
|
||||
: iter_(a)
|
||||
{ }
|
||||
|
||||
// this is ambiguous with the above
|
||||
// ArrayIndexMapping(_bz_typename T_expr::T_ctorArg1 a)
|
||||
// : iter_(a)
|
||||
// { }
|
||||
|
||||
// these bypass the FAI and go directly to the array. That should
|
||||
// prevent any performance impact of using the FAI instead of an
|
||||
// array directly.
|
||||
|
||||
/* Functions for reading. Because they must depend on the result
|
||||
* type, they utilize a helper class.
|
||||
*/
|
||||
|
||||
// For numtypes, apply operator
|
||||
template<typename T> struct readHelper {
|
||||
static T_result first_value(const T_expr& iter) {
|
||||
// is the correct thing to do here to return the index zero value?
|
||||
return indexop(iter, TinyVector<int,1>(0)); }
|
||||
template<int N_rank>
|
||||
#ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
|
||||
static T_result indexop(const T_expr& iter,
|
||||
const TinyVector<int, N_rank> i) {
|
||||
#else
|
||||
static T_result indexop(const T_expr& iter,
|
||||
const TinyVector<int, N_rank>& i) {
|
||||
#endif
|
||||
return _bz_doArrayIndexMapping<exprRank>::map(iter/*.array()*/, i,
|
||||
N_map0, N_map1, N_map2, N_map3, N_map4, N_map5, N_map6,
|
||||
N_map7, N_map8, N_map9, N_map10);
|
||||
};
|
||||
};
|
||||
|
||||
// For ET types, bypass operator and create expression
|
||||
template<typename T> struct readHelper<ETBase<T> > {
|
||||
template<int N_rank>
|
||||
#ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
|
||||
static T_result indexop(const T_expr& iter,
|
||||
const TinyVector<int, N_rank> i) {
|
||||
#else
|
||||
static T_result indexop(const T_expr& iter,
|
||||
const TinyVector<int, N_rank>& i) {
|
||||
#endif
|
||||
return iter(i); }
|
||||
static T_result first_value(const T_expr& iter) {
|
||||
// is the correct thing to do here to return the index zero value?
|
||||
return indexop(iter, TinyVector<int,1>(0)); }
|
||||
};
|
||||
|
||||
template<int N_rank>
|
||||
#ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
|
||||
T_result operator()(const TinyVector<int, N_rank> i) const {
|
||||
#else
|
||||
T_result operator()(const TinyVector<int, N_rank>& i) const {
|
||||
#endif
|
||||
return readHelper<T_typeprop>::indexop(iter_,i); }
|
||||
|
||||
T_result first_value() const {
|
||||
// unclear how to define "first" value for index expressions.
|
||||
BZPRECHECK(0,"Minmax reductions of index expressions not implemented");
|
||||
return readHelper<T_typeprop>::first_value(iter_); }
|
||||
|
||||
// find which dimension in mapped expression that corresponds to
|
||||
// dimension dim. This works such that dimension dim in this
|
||||
// expression corresponds to dimension map_dim(dim) in iter_.
|
||||
int map_dim(const int dim) const
|
||||
{
|
||||
if (N_map0 == dim)
|
||||
return 0;
|
||||
else if ((N_map1 == dim) && (exprRank > 1))
|
||||
return 1;
|
||||
else if ((N_map2 == dim) && (exprRank > 2))
|
||||
return 2;
|
||||
else if ((N_map3 == dim) && (exprRank > 3))
|
||||
return 3;
|
||||
else if ((N_map4 == dim) && (exprRank > 4))
|
||||
return 4;
|
||||
else if ((N_map5 == dim) && (exprRank > 5))
|
||||
return 5;
|
||||
else if ((N_map6 == dim) && (exprRank > 6))
|
||||
return 6;
|
||||
else if ((N_map7 == dim) && (exprRank > 7))
|
||||
return 7;
|
||||
else if ((N_map8 == dim) && (exprRank > 8))
|
||||
return 8;
|
||||
else if ((N_map9 == dim) && (exprRank > 9))
|
||||
return 9;
|
||||
else if ((N_map10 == dim) && (exprRank > 10))
|
||||
return 10;
|
||||
else
|
||||
// means dimension is not in this operand
|
||||
return -1;
|
||||
}
|
||||
|
||||
// remaps the dimensions of an index vector so it can be applied to
|
||||
// iter_, using the _bz_doArrayIndexMapping helper class.
|
||||
template<int N>
|
||||
TinyVector<int, exprRank> map_dims(const TinyVector<int, N>& i) const {
|
||||
return _bz_doArrayIndexMapping<exprRank>::map_dims
|
||||
(i, N_map0, N_map1, N_map2, N_map3, N_map4, N_map5,
|
||||
N_map6, N_map7, N_map8, N_map9, N_map10);
|
||||
}
|
||||
|
||||
int ascending(const int dim) const
|
||||
{
|
||||
const int d=map_dim(dim);
|
||||
const int o = d>=0 ? iter_.ascending(d) : INT_MIN ;
|
||||
return o;
|
||||
}
|
||||
|
||||
int ordering(const int dim) const
|
||||
{
|
||||
// JCC: ignore ordering result from 1d Array
|
||||
if (exprRank == 1)
|
||||
return INT_MIN; // tiny(int());
|
||||
|
||||
const int d=map_dim(dim);
|
||||
const int o = d>=0 ? iter_.ordering(d) : INT_MIN ;
|
||||
return o;
|
||||
}
|
||||
|
||||
int lbound(const int dim) const
|
||||
{
|
||||
const int d=map_dim(dim);
|
||||
const int o = d>=0 ? iter_.lbound(d) : INT_MIN ;
|
||||
return o;
|
||||
}
|
||||
|
||||
int ubound(const int dim) const
|
||||
{
|
||||
const int d=map_dim(dim);
|
||||
const int o = d>=0 ? iter_.ubound(d) : INT_MAX ;
|
||||
return o;
|
||||
}
|
||||
|
||||
// defer calculation to lbound/ubound
|
||||
RectDomain<rank_> domain() const
|
||||
{
|
||||
TinyVector<int, rank_> lb, ub;
|
||||
for(int r=0; r<rank_; ++r) {
|
||||
lb[r]=lbound(r); ub[r]=ubound(r);
|
||||
}
|
||||
return RectDomain<rank_>(lb,ub);
|
||||
}
|
||||
|
||||
// If you have a precondition failure on this routine, it means
|
||||
// you are trying to use stack iteration mode on an expression
|
||||
// which contains an index placeholder. You must use index
|
||||
// iteration mode instead.
|
||||
// (no -- added to support stencils /PJ)
|
||||
T_result operator*() const
|
||||
{
|
||||
return *iter_;
|
||||
}
|
||||
|
||||
// See operator*() note
|
||||
void push(int)
|
||||
{
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
}
|
||||
|
||||
// See operator*() note
|
||||
void pop(int)
|
||||
{
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
}
|
||||
|
||||
// See operator*() note
|
||||
void advance()
|
||||
{
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
}
|
||||
|
||||
// See operator*() note
|
||||
void advance(int)
|
||||
{
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
}
|
||||
|
||||
// See operator*() note
|
||||
void loadStride(int)
|
||||
{
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
}
|
||||
|
||||
bool isUnitStride(int) const
|
||||
{
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isUnitStride() const
|
||||
{
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
return false;
|
||||
}
|
||||
|
||||
void advanceUnitStride()
|
||||
{
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
}
|
||||
|
||||
bool canCollapse(int,int) const
|
||||
{ BZPRECHECK(0,"Can't use stack iteration on an index mapping."); return false; }
|
||||
|
||||
T_result operator[](int)
|
||||
{
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
return T_result();
|
||||
}
|
||||
|
||||
T_result fastRead(int) const
|
||||
{
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
return T_result();
|
||||
}
|
||||
|
||||
template<int N>
|
||||
typename tvresult<N>::Type fastRead_tv(int) const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
return TinyVector<T_numtype, N>();
|
||||
}
|
||||
|
||||
/** Determining whether the resulting expression is aligned is
|
||||
difficult, so to be safe we say no. It shouldn't be attempted
|
||||
anyway, though. */
|
||||
bool isVectorAligned(diffType offset) const {
|
||||
return false; }
|
||||
|
||||
int suggestStride(int) const
|
||||
{
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool isStride(int,int) const
|
||||
{
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
|
||||
template<int N_destrank>
|
||||
void moveTo(const TinyVector<int,N_destrank> i)
|
||||
{
|
||||
iter_.moveTo(map_dims(i));
|
||||
}
|
||||
#else
|
||||
template<int N_destrank>
|
||||
void moveTo(const TinyVector<int,N_destrank>& i)
|
||||
{
|
||||
iter_.moveTo(map_dims(i));
|
||||
}
|
||||
#endif
|
||||
|
||||
T_result shift(int offset, int dim) const {
|
||||
// need to check if dim is mapped into this expression
|
||||
const int d=map_dim(dim);
|
||||
if (d<0)
|
||||
return *iter_;
|
||||
else
|
||||
return iter_.shift(offset, d);
|
||||
}
|
||||
|
||||
T_result shift(int offset1, int dim1,int offset2, int dim2) const {
|
||||
// need to check if dims are mapped into this expression
|
||||
int d1=map_dim(dim1);
|
||||
int d2=map_dim(dim2);
|
||||
if (d1<0) //disable offset
|
||||
{d1=0;offset1=0;}
|
||||
if (d2<0) //disable offset
|
||||
{d2=0;offset2=0;}
|
||||
return iter_.shift(offset1, d1, offset2, d2);
|
||||
}
|
||||
|
||||
void _bz_offsetData(sizeType i) {
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
}
|
||||
|
||||
template<int N>
|
||||
T_range_result operator()(RectDomain<N> d) const
|
||||
{ // need to reorder dimensions here
|
||||
TinyVector<int, exprRank> lb(map_dims(d.lbound())), ub(map_dims(d.ubound()));
|
||||
RectDomain<exprRank> newd(lb,ub);
|
||||
return T_range_result(iter_(newd));
|
||||
}
|
||||
|
||||
void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat&) const
|
||||
{
|
||||
// NEEDS_WORK-- do real formatting for reductions
|
||||
str += "map[NEEDS_WORK]";
|
||||
}
|
||||
|
||||
template<typename T_shape>
|
||||
bool shapeCheck(const T_shape&) const
|
||||
{
|
||||
// NEEDS_WORK-- do a real shape check (tricky)
|
||||
return true;
|
||||
}
|
||||
|
||||
// sliceinfo for expressions
|
||||
template<typename T1, typename T2 = nilArraySection,
|
||||
class T3 = nilArraySection, typename T4 = nilArraySection,
|
||||
class T5 = nilArraySection, typename T6 = nilArraySection,
|
||||
class T7 = nilArraySection, typename T8 = nilArraySection,
|
||||
class T9 = nilArraySection, typename T10 = nilArraySection,
|
||||
class T11 = nilArraySection>
|
||||
class SliceInfo {
|
||||
public:
|
||||
typedef typename T_expr::template SliceInfo<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::T_slice T_slice1;
|
||||
typedef ArrayIndexMapping<T_slice1, N_map0, N_map1, N_map2,
|
||||
N_map3, N_map4, N_map5, N_map6, N_map7,
|
||||
N_map8, N_map9, N_map10> T_slice;
|
||||
};
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9, typename T10, typename T11>
|
||||
typename SliceInfo<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_slice
|
||||
operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6, T7 r7, T8 r8, T9 r9, T10 r10, T11 r11) const
|
||||
{
|
||||
/* Slicing for remapped expressions doesn't work. Because of the
|
||||
potential different types (Range vs int) in the expression,
|
||||
it would be very awkward to implement. As far as I can see,
|
||||
it would require manual coding of the 3^11 calling
|
||||
possibilities. /PJ */
|
||||
BZPRECONDITION(0);
|
||||
}
|
||||
|
||||
private:
|
||||
ArrayIndexMapping() : iter_( Array<T_numtype, exprRank>() ) { }
|
||||
|
||||
T_expr iter_;
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYMAP_H
|
||||
|
||||
@@ -0,0 +1,496 @@
|
||||
/***************************************************************************
|
||||
* blitz/array/methods.cc General array class methods.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYMETHODS_CC
|
||||
#define BZ_ARRAYMETHODS_CC
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/methods.cc> must be included via <blitz/array.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
Array<P_numtype,N_rank>::Array(_bz_ArrayExpr<T_expr> expr)
|
||||
{
|
||||
// Determine extent of the array expression
|
||||
|
||||
TinyVector<int,N_rank> lbound, extent, ordering;
|
||||
TinyVector<bool,N_rank> ascendingFlag;
|
||||
TinyVector<bool,N_rank> in_ordering;
|
||||
in_ordering = false;
|
||||
|
||||
int j = 0;
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
{
|
||||
lbound(i) = expr.lbound(i);
|
||||
int ubound = expr.ubound(i);
|
||||
extent(i) = ubound - lbound(i) + 1;
|
||||
int orderingj = expr.ordering(i);
|
||||
if (orderingj != INT_MIN && orderingj < N_rank &&
|
||||
!in_ordering( orderingj )) { // unique value in ordering array
|
||||
in_ordering( orderingj ) = true;
|
||||
ordering(j++) = orderingj;
|
||||
}
|
||||
int ascending = expr.ascending(i);
|
||||
ascendingFlag(i) = (ascending == 1);
|
||||
|
||||
#ifdef BZ_DEBUG
|
||||
if ((lbound(i) == INT_MIN) || (ubound == INT_MAX)
|
||||
|| (ordering(i) == INT_MIN) || (ascending == INT_MIN))
|
||||
{
|
||||
BZPRECHECK(0,
|
||||
"Attempted to construct an array from an expression " << endl
|
||||
<< "which does not have a shape. To use this constructor, "
|
||||
<< endl
|
||||
<< "the expression must contain at least one array operand.");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// It is possible that ordering is not a permutation of 0,...,N_rank-1.
|
||||
// In that case j will be less than N_rank. We fill in ordering with the
|
||||
// usused values in decreasing order.
|
||||
for (int i = N_rank-1; j < N_rank; ++j) {
|
||||
while (in_ordering(i))
|
||||
--i;
|
||||
ordering(j) = i--;
|
||||
}
|
||||
|
||||
Array<T_numtype,N_rank> A(lbound,extent,
|
||||
GeneralArrayStorage<N_rank>(ordering,ascendingFlag));
|
||||
A = expr;
|
||||
reference(A);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
Array<P_numtype,N_rank>::Array(const TinyVector<int, N_rank>& lbounds,
|
||||
const TinyVector<int, N_rank>& extent,
|
||||
const GeneralArrayStorage<N_rank>& storage)
|
||||
: storage_(storage)
|
||||
{
|
||||
length_ = extent;
|
||||
storage_.setBase(lbounds);
|
||||
setupStorage(N_rank - 1);
|
||||
}
|
||||
|
||||
|
||||
/** This routine takes the storage information for the array
|
||||
(ascendingFlag_[], base_[], and ordering_[]) and the size of the
|
||||
array (length_[]) and computes the stride vector (stride_[]) and
|
||||
the zero offset (see explanation in array.h).
|
||||
*/
|
||||
template<typename P_numtype, int N_rank>
|
||||
_bz_inline2 void Array<P_numtype, N_rank>::computeStrides()
|
||||
{
|
||||
if (N_rank > 1)
|
||||
{
|
||||
diffType stride = 1;
|
||||
|
||||
// This flag simplifies the code in the loop, encouraging
|
||||
// compile-time computation of strides through constant folding.
|
||||
bool allAscending = storage_.allRanksStoredAscending();
|
||||
|
||||
// BZ_OLD_FOR_SCOPING
|
||||
int n;
|
||||
for (n=0; n < N_rank; ++n)
|
||||
{
|
||||
int strideSign = +1;
|
||||
|
||||
// If this rank is stored in descending order, then the stride
|
||||
// will be negative.
|
||||
if (!allAscending)
|
||||
{
|
||||
if (!isRankStoredAscending(ordering(n)))
|
||||
strideSign = -1;
|
||||
}
|
||||
|
||||
// The stride for this rank is the product of the lengths of
|
||||
// the ranks minor to it.
|
||||
stride_[ordering(n)] = stride * strideSign;
|
||||
|
||||
if((storage_.padding()==paddedData)&&(n==0)) {
|
||||
// The lowest rank dimension is padded to vecWidth, so this
|
||||
// needs to be accounted for in the stride
|
||||
stride *= simdTypes<T_numtype>::paddedLength(length_[ordering(0)]);
|
||||
}
|
||||
else
|
||||
stride *= length_[ordering(n)];
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Specialization for N_rank == 1
|
||||
// This simpler calculation makes it easier for the compiler
|
||||
// to propagate stride values.
|
||||
|
||||
if (isRankStoredAscending(0))
|
||||
stride_[0] = 1;
|
||||
else
|
||||
stride_[0] = -1;
|
||||
}
|
||||
|
||||
calculateZeroOffset();
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::calculateZeroOffset()
|
||||
{
|
||||
// Calculate the offset of (0,0,...,0)
|
||||
zeroOffset_ = 0;
|
||||
|
||||
// zeroOffset_ = - sum(where(ascendingFlag_, stride_ * base_,
|
||||
// (length_ - 1 + base_) * stride_))
|
||||
for (int n=0; n < N_rank; ++n)
|
||||
{
|
||||
if (!isRankStoredAscending(n))
|
||||
zeroOffset_ -= (length_[n] - 1 + base(n)) * stride_[n];
|
||||
else
|
||||
zeroOffset_ -= stride_[n] * base(n);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
bool Array<P_numtype, N_rank>::isStorageContiguous() const
|
||||
{
|
||||
// The storage is contiguous if for the set
|
||||
// { | stride[i] * extent[i] | }, i = 0..N_rank-1,
|
||||
// there is only one value which is not in the set
|
||||
// of strides; and if there is one stride which is 1.
|
||||
|
||||
// This algorithm is quadratic in the rank. It is hard
|
||||
// to imagine this being a serious problem.
|
||||
|
||||
int numStridesMissing = 0;
|
||||
bool haveUnitStride = false;
|
||||
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
{
|
||||
diffType stride = BZ_MATHFN_SCOPE(abs)(stride_[i]);
|
||||
if (stride == 1)
|
||||
haveUnitStride = true;
|
||||
|
||||
diffType vi = stride * length_[i];
|
||||
|
||||
int j = 0;
|
||||
for (j=0; j < N_rank; ++j)
|
||||
if (BZ_MATHFN_SCOPE(abs)(stride_[j]) == vi)
|
||||
break;
|
||||
|
||||
if (j == N_rank)
|
||||
{
|
||||
++numStridesMissing;
|
||||
if (numStridesMissing == 2)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return haveUnitStride;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::dumpStructureInformation(ostream& os) const
|
||||
{
|
||||
os << "Dump of Array<" << BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(P_numtype)
|
||||
<< ", " << N_rank << ">:" << endl
|
||||
<< "ordering_ = " << storage_.ordering() << endl
|
||||
<< "ascendingFlag_ = " << storage_.ascendingFlag() << endl
|
||||
<< "base_ = " << storage_.base() << endl
|
||||
<< "length_ = " << length_ << endl
|
||||
<< "stride_ = " << stride_ << endl
|
||||
<< "zeroOffset_ = " << zeroOffset_ << endl
|
||||
<< "numElements() = " << numElements() << endl
|
||||
<< "isStorageContiguous() = " << isStorageContiguous() << endl;
|
||||
}
|
||||
|
||||
/**
|
||||
Make this array a view of another array's data. This overrides the
|
||||
current storage of the array.
|
||||
*/
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::reference(const Array<P_numtype, N_rank>& array)
|
||||
{
|
||||
storage_ = array.storage_;
|
||||
length_ = array.length_;
|
||||
stride_ = array.stride_;
|
||||
zeroOffset_ = array.zeroOffset_;
|
||||
|
||||
T_base::changeBlock(array.noConst());
|
||||
}
|
||||
|
||||
/** This method makes the array reference another, but it does it as a
|
||||
"weak" reference that is not counted. If you can guarantee that
|
||||
the array memory block containing the data is persistent, this
|
||||
will allow reference counting to be bypassed for this array, which
|
||||
if mutex-locking is involved is a significant overhead. */
|
||||
template<typename P_numtype, int N_rank>
|
||||
void
|
||||
Array<P_numtype, N_rank>::weakReference(const Array<P_numtype, N_rank>& array)
|
||||
{
|
||||
storage_ = array.storage_;
|
||||
length_ = array.length_;
|
||||
stride_ = array.stride_;
|
||||
zeroOffset_ = array.zeroOffset_;
|
||||
|
||||
T_base::changeToNullBlock();
|
||||
data_ = array.data_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Modify the Array storage. Array must be unallocated.
|
||||
*/
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::setStorage(GeneralArrayStorage<N_rank> x)
|
||||
{
|
||||
#ifdef BZ_DEBUG
|
||||
if (size() != 0) {
|
||||
BZPRECHECK(0,"Cannot modify storage format of an Array that has already been allocated!" << endl);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
storage_ = x;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
This method is called to allocate memory for a new array. It
|
||||
assumes the storage_ and length_ members are already initialized.
|
||||
*/
|
||||
template<typename P_numtype, int N_rank>
|
||||
_bz_inline2 void Array<P_numtype, N_rank>::setupStorage(int lastRankInitialized)
|
||||
{
|
||||
TAU_TYPE_STRING(p1, "Array<T,N>::setupStorage() [T="
|
||||
+ CT(P_numtype) + ",N=" + CT(N_rank) + "]");
|
||||
TAU_PROFILE(" ", p1, TAU_BLITZ);
|
||||
|
||||
/*
|
||||
* If the length of some of the ranks was unspecified, fill these
|
||||
* in using the last specified value.
|
||||
*
|
||||
* e.g. Array<int,3> A(40) results in a 40x40x40 array.
|
||||
*/
|
||||
for (int i=lastRankInitialized + 1; i < N_rank; ++i)
|
||||
{
|
||||
storage_.setBase(i, storage_.base(lastRankInitialized));
|
||||
length_[i] = length_[lastRankInitialized];
|
||||
}
|
||||
|
||||
// Compute strides
|
||||
computeStrides();
|
||||
|
||||
// Allocate a block of memory.
|
||||
TinyVector<int, N_rank> alloc_length = length();
|
||||
if(storage_.padding()==paddedData) {
|
||||
// The size of the block is NOT equal to numelements, because the
|
||||
// lowest rank dimension is padded to vecWidth
|
||||
alloc_length[ordering(0)] =
|
||||
simdTypes<T_numtype>::paddedLength(alloc_length[ordering(0)]);
|
||||
}
|
||||
sizeType numElem = _bz_returntype<sizeType>::product(alloc_length);
|
||||
if (numElem==0)
|
||||
T_base::changeToNullBlock();
|
||||
else
|
||||
T_base::newBlock(numElem);
|
||||
|
||||
// Adjust the base of the array to account for non-zero base
|
||||
// indices and reversals
|
||||
data_ += zeroOffset_;
|
||||
}
|
||||
|
||||
/** Return a deep copy of an array (as opposed to the reference copy
|
||||
done by the copy constructor. */
|
||||
template<typename P_numtype, int N_rank>
|
||||
Array<P_numtype, N_rank> Array<P_numtype, N_rank>::copy() const
|
||||
{
|
||||
if (numElements())
|
||||
{
|
||||
Array<T_numtype, N_rank> z(length_, storage_);
|
||||
z = *this;
|
||||
return z;
|
||||
}
|
||||
else {
|
||||
// Null array-- don't bother allocating an empty block.
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
/** Make the array have its own memory block by making a copy if the
|
||||
block has a reference count greater than one. */
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::makeUnique()
|
||||
{
|
||||
if (T_base::numReferences() > 1)
|
||||
{
|
||||
T_array tmp = copy();
|
||||
reference(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
Array<P_numtype, N_rank> Array<P_numtype, N_rank>::transpose(int r0, int r1,
|
||||
int r2, int r3, int r4, int r5, int r6, int r7, int r8, int r9, int r10) const
|
||||
{
|
||||
T_array B(*this);
|
||||
B.transposeSelf(r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10);
|
||||
return B;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::transposeSelf(int r0, int r1, int r2, int r3,
|
||||
int r4, int r5, int r6, int r7, int r8, int r9, int r10)
|
||||
{
|
||||
BZPRECHECK(r0+r1+r2+r3+r4+r5+r6+r7+r8+r9+r10 == N_rank * (N_rank-1) / 2,
|
||||
"Invalid array transpose() arguments." << endl
|
||||
<< "Arguments must be a permutation of the numerals (0,...,"
|
||||
<< (N_rank - 1) << ")");
|
||||
|
||||
// Create a temporary reference copy of this array
|
||||
Array<T_numtype, N_rank> x(*this);
|
||||
|
||||
// Now reorder the dimensions using the supplied permutation
|
||||
doTranspose(0, r0, x);
|
||||
doTranspose(1, r1, x);
|
||||
doTranspose(2, r2, x);
|
||||
doTranspose(3, r3, x);
|
||||
doTranspose(4, r4, x);
|
||||
doTranspose(5, r5, x);
|
||||
doTranspose(6, r6, x);
|
||||
doTranspose(7, r7, x);
|
||||
doTranspose(8, r8, x);
|
||||
doTranspose(9, r9, x);
|
||||
doTranspose(10, r10, x);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::doTranspose(int destRank, int sourceRank,
|
||||
Array<T_numtype, N_rank>& array)
|
||||
{
|
||||
// BZ_NEEDS_WORK: precondition check
|
||||
|
||||
if (destRank >= N_rank)
|
||||
return;
|
||||
|
||||
length_[destRank] = array.length_[sourceRank];
|
||||
stride_[destRank] = array.stride_[sourceRank];
|
||||
storage_.setAscendingFlag(destRank,
|
||||
array.isRankStoredAscending(sourceRank));
|
||||
storage_.setBase(destRank, array.base(sourceRank));
|
||||
|
||||
// BZ_NEEDS_WORK: Handling the storage ordering is currently O(N^2)
|
||||
// but it can be done fairly easily in linear time by constructing
|
||||
// the appropriate permutation.
|
||||
|
||||
// Find sourceRank in array.storage_.ordering_
|
||||
int i=0;
|
||||
for (; i < N_rank; ++i)
|
||||
if (array.storage_.ordering(i) == sourceRank)
|
||||
break;
|
||||
|
||||
storage_.setOrdering(i, destRank);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::reverseSelf(int rank)
|
||||
{
|
||||
BZPRECONDITION(rank < N_rank);
|
||||
|
||||
storage_.setAscendingFlag(rank, !isRankStoredAscending(rank));
|
||||
|
||||
diffType adjustment = static_cast<ptrdiff_t>(stride_[rank]) * (lbound(rank) + ubound(rank));
|
||||
zeroOffset_ += adjustment;
|
||||
data_ += adjustment;
|
||||
stride_[rank] *= -1;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
Array<P_numtype, N_rank> Array<P_numtype,N_rank>::reverse(int rank)
|
||||
{
|
||||
T_array B(*this);
|
||||
B.reverseSelf(rank);
|
||||
return B;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename P_numtype2>
|
||||
Array<P_numtype2,N_rank> Array<P_numtype,N_rank>::extractComponent(P_numtype2,
|
||||
int componentNumber, int numComponents) const
|
||||
{
|
||||
BZPRECONDITION((componentNumber >= 0)
|
||||
&& (componentNumber < numComponents));
|
||||
|
||||
// If P_numtype is a multicomponent type, it may have an alignment
|
||||
// setting. For this reason it is not correct to use
|
||||
// numComponents, we must use sizeof(P_numtype)/sizeof(P_numtype2)
|
||||
// instead.
|
||||
BZASSERT(sizeof(P_numtype)%sizeof(P_numtype2)==0);
|
||||
|
||||
TinyVector<diffType, N_rank> stride2;
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
stride2(i) = stride_(i) * sizeof(P_numtype)/sizeof(P_numtype2);
|
||||
const P_numtype2* dataFirst2 =
|
||||
((const P_numtype2*)dataFirst()) + componentNumber;
|
||||
return Array<P_numtype2,N_rank>(const_cast<P_numtype2*>(dataFirst2),
|
||||
length_, stride2, storage_);
|
||||
}
|
||||
|
||||
/*
|
||||
* These routines reindex the current array to use a new base vector.
|
||||
* The first reindexes the array, the second just returns a reindex view
|
||||
* of the current array, leaving the current array unmodified.
|
||||
* (Contributed by Derrick Bass)
|
||||
*/
|
||||
template<typename P_numtype, int N_rank>
|
||||
_bz_inline2 void Array<P_numtype, N_rank>::reindexSelf(const
|
||||
TinyVector<int, N_rank>& newBase)
|
||||
{
|
||||
diffType delta = 0;
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
delta += (base(i) - newBase(i)) * stride_(i);
|
||||
|
||||
data_ += delta;
|
||||
|
||||
// WAS: dot(base() - newBase, stride_);
|
||||
|
||||
storage_.setBase(newBase);
|
||||
calculateZeroOffset();
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
_bz_inline2 Array<P_numtype, N_rank>
|
||||
Array<P_numtype, N_rank>::reindex(const TinyVector<int, N_rank>& newBase)
|
||||
{
|
||||
T_array B(*this);
|
||||
B.reindexSelf(newBase);
|
||||
return B;
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAY_CC
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/***************************************************************************
|
||||
* blitz/array/misc.cc Miscellaneous operators for arrays
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYMISC_CC
|
||||
#define BZ_ARRAYMISC_CC
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/misc.cc> must be included via <blitz/array.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
#define BZ_ARRAY_DECLARE_UOP(fn, fnobj) \
|
||||
template<typename T_numtype, int N_rank> \
|
||||
inline \
|
||||
_bz_ArrayExpr<_bz_ArrayExprUnaryOp<FastArrayIterator<T_numtype,N_rank>, \
|
||||
fnobj<T_numtype> > > \
|
||||
fn(const Array<T_numtype,N_rank>& array) \
|
||||
{ \
|
||||
return _bz_ArrayExprUnaryOp<FastArrayIterator<T_numtype,N_rank>, \
|
||||
fnobj<T_numtype> >(array.beginFast()); \
|
||||
} \
|
||||
\
|
||||
template<typename T_expr> \
|
||||
inline \
|
||||
_bz_ArrayExpr<_bz_ArrayExprUnaryOp<_bz_ArrayExpr<T_expr>, \
|
||||
fnobj<_bz_typename T_expr::T_numtype> > > \
|
||||
fn(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr) \
|
||||
{ \
|
||||
return _bz_ArrayExprUnaryOp<_bz_ArrayExpr<T_expr>, \
|
||||
fnobj<_bz_typename T_expr::T_numtype> >(expr); \
|
||||
}
|
||||
|
||||
BZ_ARRAY_DECLARE_UOP(operator!, LogicalNot)
|
||||
BZ_ARRAY_DECLARE_UOP(operator~, BitwiseNot)
|
||||
BZ_ARRAY_DECLARE_UOP(operator-, Negate)
|
||||
|
||||
/*
|
||||
* cast() functions, for explicit type casting
|
||||
*/
|
||||
|
||||
template<typename T_numtype, int N_rank, typename T_cast>
|
||||
inline
|
||||
_bz_ArrayExpr<_bz_ArrayExprUnaryOp<FastArrayIterator<T_numtype,N_rank>,
|
||||
Cast<T_numtype, T_cast> > >
|
||||
cast(const Array<T_numtype,N_rank>& array, T_cast)
|
||||
{
|
||||
return _bz_ArrayExprUnaryOp<FastArrayIterator<T_numtype,N_rank>,
|
||||
Cast<T_numtype,T_cast> >(array.beginFast());
|
||||
}
|
||||
|
||||
template<typename T_expr, typename T_cast>
|
||||
inline
|
||||
_bz_ArrayExpr<_bz_ArrayExprUnaryOp<_bz_ArrayExpr<T_expr>,
|
||||
Cast<_bz_typename T_expr::T_numtype,T_cast> > >
|
||||
cast(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr, T_cast)
|
||||
{
|
||||
return _bz_ArrayExprUnaryOp<_bz_ArrayExpr<T_expr>,
|
||||
Cast<_bz_typename T_expr::T_numtype,T_cast> >(expr);
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYMISC_CC
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/multi.h Support for multicomponent arrays
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYMULTI_H
|
||||
#define BZ_ARRAYMULTI_H
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/multi.h> must be included via <blitz/array.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* The multicomponent_traits class provides a mapping from multicomponent
|
||||
* tuples to the element type they contain. For example:
|
||||
*
|
||||
* multicomponent_traits<complex<float> >::T_numtype is float,
|
||||
* multicomponent_traits<TinyVector<int,3> >::T_numtype is int.
|
||||
*
|
||||
* This is used to support Array<T,N>::operator[], which extracts components
|
||||
* from a multicomponent array.
|
||||
*/
|
||||
|
||||
// By default, produce a harmless component type, and zero components.
|
||||
template<typename T_component>
|
||||
struct multicomponent_traits {
|
||||
typedef T_component T_element;
|
||||
static const int numComponents = 0;
|
||||
};
|
||||
|
||||
// TinyVector
|
||||
template<typename T_numtype, int N_rank>
|
||||
struct multicomponent_traits<TinyVector<T_numtype,N_rank> > {
|
||||
typedef T_numtype T_element;
|
||||
static const int numComponents = N_rank;
|
||||
};
|
||||
|
||||
// TinyMatrix
|
||||
template<typename T_numtype, int N_rows, int N_cols>
|
||||
struct multicomponent_traits<TinyMatrix<T_numtype,N_rows, N_cols> > {
|
||||
typedef T_numtype T_element;
|
||||
static const int numComponents = N_rows*N_cols;
|
||||
};
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX
|
||||
// complex<T>
|
||||
template<typename T>
|
||||
struct multicomponent_traits<complex<T> > {
|
||||
typedef T T_element;
|
||||
static const int numComponents = 2;
|
||||
};
|
||||
#endif
|
||||
|
||||
// This macro is provided so that users can register their own
|
||||
// multicomponent types.
|
||||
|
||||
#define BZ_DECLARE_MULTICOMPONENT_TYPE(T_tuple,T,N) \
|
||||
BZ_NAMESPACE(blitz) \
|
||||
template<> \
|
||||
struct multicomponent_traits<T_tuple > { \
|
||||
typedef T T_element; \
|
||||
static const int numComponents = N; \
|
||||
}; \
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYMULTI_H
|
||||
@@ -0,0 +1,457 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/newet-macros.h Macros for new e.t. implementation
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_NEWET_MACROS_H
|
||||
#define BZ_NEWET_MACROS_H
|
||||
|
||||
#include <blitz/array/asexpr.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
#ifdef BZ_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS
|
||||
|
||||
/*
|
||||
* Unary functions and operators
|
||||
*/
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_UNARY(name,functor) \
|
||||
\
|
||||
template <typename T1> \
|
||||
_bz_inline_et \
|
||||
typename BZ_BLITZ_SCOPE(BzUnaryExprResult)<functor,T1>::T_result \
|
||||
name(const BZ_BLITZ_SCOPE(ETBase)<T1>& d1) \
|
||||
{ \
|
||||
typedef typename \
|
||||
BZ_BLITZ_SCOPE(BzUnaryExprResult)<functor,T1>::T_result result; \
|
||||
return result(BZ_BLITZ_SCOPE(asExpr)<T1>::getExpr(d1.unwrap())); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Array expression templates: the macro BZ_DECLARE_ARRAY_ET_BINARY(X,Y)
|
||||
* declares a function or operator which takes two operands.
|
||||
* X is the function name (or operator), and Y is the functor object
|
||||
* which implements the operation.
|
||||
*/
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_BINARY(name, applic) \
|
||||
\
|
||||
template <typename T1,typename T2> \
|
||||
_bz_inline_et \
|
||||
typename BZ_BLITZ_SCOPE(BzBinaryExprResult)<applic,T1,T2>::T_result \
|
||||
name(const BZ_BLITZ_SCOPE(ETBase)<T1>& d1, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T2>& d2) \
|
||||
{ \
|
||||
typedef typename \
|
||||
BZ_BLITZ_SCOPE(BzBinaryExprResult)<applic,T1,T2>::T_result result; \
|
||||
return result(BZ_BLITZ_SCOPE(asExpr)<T1>::getExpr(d1.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T2>::getExpr(d2.unwrap())); \
|
||||
}
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(name, applic) \
|
||||
\
|
||||
template <typename T1, typename T2, int N> \
|
||||
_bz_inline_et \
|
||||
typename BZ_BLITZ_SCOPE(BzBinaryExprResult)<applic, \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N>,T1>::T_result \
|
||||
name(const BZ_BLITZ_SCOPE(TinyVector)<T2,N> d1, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T1>& d2) \
|
||||
{ \
|
||||
typedef typename \
|
||||
BZ_BLITZ_SCOPE(BzBinaryExprResult)<applic, \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N>,T1>::T_result result; \
|
||||
return result(BZ_BLITZ_SCOPE(asExpr)< \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N> >::getExpr(d1), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T1>::getExpr(d2.unwrap())); \
|
||||
} \
|
||||
\
|
||||
template <typename T1, typename T2, int N> \
|
||||
_bz_inline_et \
|
||||
typename BZ_BLITZ_SCOPE(BzBinaryExprResult)<applic,T1, \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N> >::T_result \
|
||||
name(const BZ_BLITZ_SCOPE(ETBase)<T1>& d1, \
|
||||
const BZ_BLITZ_SCOPE(TinyVector)<T2,N> d2) \
|
||||
{ \
|
||||
typedef typename \
|
||||
BZ_BLITZ_SCOPE(BzBinaryExprResult)<applic,T1, \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N> >::T_result result; \
|
||||
return result(BZ_BLITZ_SCOPE(asExpr)<T1>::getExpr(d1.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)< \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N> >::getExpr(d2)); \
|
||||
}
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(name, applic, sca) \
|
||||
\
|
||||
template<typename T> \
|
||||
_bz_inline_et \
|
||||
typename BZ_BLITZ_SCOPE(BzBinaryExprResult)<applic,sca,T>::T_result \
|
||||
name(const sca d1, const BZ_BLITZ_SCOPE(ETBase)<T>& d2) \
|
||||
{ \
|
||||
typedef typename \
|
||||
BZ_BLITZ_SCOPE(BzBinaryExprResult)<applic,sca,T>::T_result result; \
|
||||
return result(BZ_BLITZ_SCOPE(asExpr)<sca >::getExpr(d1), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T>::getExpr(d2.unwrap())); \
|
||||
} \
|
||||
\
|
||||
template<typename T> \
|
||||
_bz_inline_et \
|
||||
typename BZ_BLITZ_SCOPE(BzBinaryExprResult)<applic,T,sca >::T_result \
|
||||
name(const BZ_BLITZ_SCOPE(ETBase)<T>& d1, const sca d2) \
|
||||
{ \
|
||||
typedef typename \
|
||||
BZ_BLITZ_SCOPE(BzBinaryExprResult)<applic,T,sca >::T_result result;\
|
||||
return result(BZ_BLITZ_SCOPE(asExpr)<T>::getExpr(d1.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<sca >::getExpr(d2)); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Array expression templates: the macro BZ_DECLARE_ARRAY_ET_TERNARY(X,Y)
|
||||
* declares a function or operator which takes three operands.
|
||||
* X is the function name (or operator), and Y is the functor object
|
||||
* which implements the operation.
|
||||
*/
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_TERNARY(name, applic) \
|
||||
\
|
||||
template <typename T1, typename T2, typename T3> \
|
||||
_bz_inline_et \
|
||||
typename BZ_BLITZ_SCOPE(BzTernaryExprResult)<applic, T1, T2, T3>::T_result \
|
||||
name(const BZ_BLITZ_SCOPE(ETBase)<T1>& d1, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T2>& d2, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T3>& d3) \
|
||||
{ \
|
||||
typedef typename \
|
||||
BZ_BLITZ_SCOPE(BzTernaryExprResult)<applic,T1,T2,T3>::T_result \
|
||||
result; \
|
||||
return result(BZ_BLITZ_SCOPE(asExpr)<T1>::getExpr(d1.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T2>::getExpr(d2.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T3>::getExpr(d3.unwrap())); \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Array expression templates: the macro BZ_DECLARE_ARRAY_ET_QUATERNARY(X,Y)
|
||||
* declares a function or operator which takes four operands.
|
||||
* X is the function name (or operator), and Y is the functor object
|
||||
* which implements the operation.
|
||||
*/
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_QUATERNARY(name, applic) \
|
||||
\
|
||||
template <typename T1, typename T2, typename T3, typename T4> \
|
||||
_bz_inline_et \
|
||||
typename BZ_BLITZ_SCOPE(BzQuaternaryExprResult)<applic, T1, T2, T3, T4>::T_result \
|
||||
name(const BZ_BLITZ_SCOPE(ETBase)<T1>& d1, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T2>& d2, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T3>& d3, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T4>& d4) \
|
||||
{ \
|
||||
typedef typename \
|
||||
BZ_BLITZ_SCOPE(BzQuaternaryExprResult)<applic,T1,T2,T3, T4>::T_result \
|
||||
result; \
|
||||
return result(BZ_BLITZ_SCOPE(asExpr)<T1>::getExpr(d1.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T2>::getExpr(d2.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T3>::getExpr(d3.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T4>::getExpr(d4.unwrap())); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
#else /* !BZ_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS */
|
||||
|
||||
/*
|
||||
* Unary functions and operators
|
||||
*/
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_UNARY(name, functor) \
|
||||
\
|
||||
template<typename T1> \
|
||||
_bz_inline_et \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExpr)<BZ_BLITZ_SCOPE(_bz_ArrayExprUnaryOp)< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr, \
|
||||
functor<_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr::T_numtype> > >\
|
||||
name(const BZ_BLITZ_SCOPE(ETBase)<T1>& d1) \
|
||||
{ \
|
||||
return BZ_BLITZ_SCOPE(_bz_ArrayExpr)< \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExprUnaryOp)< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr, \
|
||||
functor<_bz_typename \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr::T_numtype> > >( \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T1>::getExpr(d1.unwrap())); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Array expression templates: the macro BZ_DECLARE_ARRAY_ET_BINARY(X,Y)
|
||||
* declares a function or operator which takes two operands.
|
||||
* X is the function name (or operator), and Y is the functor object
|
||||
* which implements the operation.
|
||||
*/
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_BINARY(name, applic) \
|
||||
\
|
||||
template<typename T1, typename T2> \
|
||||
_bz_inline_et \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExpr)<BZ_BLITZ_SCOPE(_bz_ArrayExprBinaryOp)< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T2>::T_expr, \
|
||||
applic<_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr::T_numtype, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T2>::T_expr::T_numtype> > > \
|
||||
name(const BZ_BLITZ_SCOPE(ETBase)<T1>& d1, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T2>& d2) \
|
||||
{ \
|
||||
return BZ_BLITZ_SCOPE(_bz_ArrayExpr)< \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExprBinaryOp)< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T2>::T_expr, \
|
||||
applic<_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr::T_numtype, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T2>::T_expr::T_numtype> > >( \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T1>::getExpr(d1.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T2>::getExpr(d2.unwrap())); \
|
||||
}
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(name, applic) \
|
||||
\
|
||||
template <typename T1, typename T2, int N> \
|
||||
_bz_inline_et \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExprBinaryOp)< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)< \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N> >::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr, \
|
||||
applic<BZ_BLITZ_SCOPE(TinyVector)<T2,N>, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr::T_numtype> > \
|
||||
name(const BZ_BLITZ_SCOPE(TinyVector)<T2,N> d1, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T1>& d2) \
|
||||
{ \
|
||||
return BZ_BLITZ_SCOPE(_bz_ArrayExprBinaryOp)< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)< \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N> >::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr, \
|
||||
applic<BZ_BLITZ_SCOPE(TinyVector)<T2,N>, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr::T_numtype> >( \
|
||||
BZ_BLITZ_SCOPE(asExpr)< \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N> >::getExpr(d1), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T1>::getExpr(d2.unwrap())); \
|
||||
} \
|
||||
\
|
||||
template <typename T1, typename T2, int N> \
|
||||
_bz_inline_et \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExprBinaryOp)< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)< \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N> >::T_expr, \
|
||||
applic<_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr::T_numtype, \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N> > > \
|
||||
name(const BZ_BLITZ_SCOPE(ETBase)<T1>& d1, \
|
||||
const BZ_BLITZ_SCOPE(TinyVector)<T2,N> d2) \
|
||||
{ \
|
||||
return BZ_BLITZ_SCOPE(_bz_ArrayExprBinaryOp)< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)< \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N> >::T_expr, \
|
||||
applic<_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr::T_numtype, \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N> > >( \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T1>::getExpr(d1.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)< \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<T2,N> >::getExpr(d2)); \
|
||||
}
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(name, applic, sca) \
|
||||
\
|
||||
template<typename T> \
|
||||
_bz_inline_et \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExprBinaryOp)< \
|
||||
BZ_BLITZ_SCOPE(asExpr)<sca >::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T>::T_expr, \
|
||||
applic<sca,_bz_typename BZ_BLITZ_SCOPE(asExpr)<T>::T_expr::T_numtype> >\
|
||||
name(const sca d1, const BZ_BLITZ_SCOPE(ETBase)<T>& d2) \
|
||||
{ \
|
||||
return BZ_BLITZ_SCOPE(_bz_ArrayExprBinaryOp)< \
|
||||
BZ_BLITZ_SCOPE(asExpr)<sca >::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T>::T_expr, \
|
||||
applic<sca, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T>::T_expr::T_numtype> >( \
|
||||
BZ_BLITZ_SCOPE(asExpr)<sca >::getExpr(d1), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T>::getExpr(d2.unwrap())); \
|
||||
} \
|
||||
\
|
||||
template<typename T> \
|
||||
_bz_inline_et \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExprBinaryOp)< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T>::T_expr, \
|
||||
BZ_BLITZ_SCOPE(asExpr)<sca >::T_expr, \
|
||||
applic<_bz_typename BZ_BLITZ_SCOPE(asExpr)<T>::T_expr::T_numtype, \
|
||||
sca > > \
|
||||
name(const BZ_BLITZ_SCOPE(ETBase)<T>& d1, const sca d2) \
|
||||
{ \
|
||||
return BZ_BLITZ_SCOPE(_bz_ArrayExprBinaryOp)< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T>::T_expr, \
|
||||
BZ_BLITZ_SCOPE(asExpr)<sca >::T_expr, \
|
||||
applic<_bz_typename BZ_BLITZ_SCOPE(asExpr)<T>::T_expr::T_numtype, \
|
||||
sca > >( \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T>::getExpr(d1.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<sca >::getExpr(d2)); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Array expression templates: the macro BZ_DECLARE_ARRAY_ET_TERNARY(X,Y)
|
||||
* declares a function or operator which takes three operands.
|
||||
* X is the function name (or operator), and Y is the functor object
|
||||
* which implements the operation.
|
||||
*/
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_TERNARY(name, applic) \
|
||||
\
|
||||
template<typename T1, typename T2, typename T3> \
|
||||
_bz_inline_et \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExpr)<BZ_BLITZ_SCOPE(_bz_ArrayExprTernaryOp)< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T2>::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T3>::T_expr, \
|
||||
applic<_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr::T_numtype, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T2>::T_expr::T_numtype, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T3>::T_expr::T_numtype> > > \
|
||||
name(const BZ_BLITZ_SCOPE(ETBase)<T1>& d1, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T2>& d2, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T3>& d3) \
|
||||
{ \
|
||||
return BZ_BLITZ_SCOPE(_bz_ArrayExpr)< \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExprTernaryOp)< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T2>::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T3>::T_expr, \
|
||||
applic<_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr::T_numtype, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T2>::T_expr::T_numtype, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T3>::T_expr::T_numtype> > >( \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T1>::getExpr(d1.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T2>::getExpr(d2.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T3>::getExpr(d3.unwrap())); \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Array expression templates: the macro BZ_DECLARE_ARRAY_ET_BINARY(X,Y)
|
||||
* declares a function or operator which takes two operands.
|
||||
* X is the function name (or operator), and Y is the functor object
|
||||
* which implements the operation.
|
||||
*/
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_QUATERNARY(name, functor) \
|
||||
\
|
||||
template<typename T1, typename T2, typename T3,typename T4> \
|
||||
_bz_inline_et \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExpr) \
|
||||
< \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExprQuaternaryOp) \
|
||||
< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T2>::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T3>::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T4>::T_expr, \
|
||||
functor< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr::T_numtype, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T2>::T_expr::T_numtype, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T3>::T_expr::T_numtype, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T4>::T_expr::T_numtype \
|
||||
> > > \
|
||||
\
|
||||
name(const BZ_BLITZ_SCOPE(ETBase)<T1>& d1, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T2>& d2, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T3>& d3, \
|
||||
const BZ_BLITZ_SCOPE(ETBase)<T4>& d4) \
|
||||
{ \
|
||||
return BZ_BLITZ_SCOPE(_bz_ArrayExpr) \
|
||||
< \
|
||||
BZ_BLITZ_SCOPE(_bz_ArrayExprBinaryOp) \
|
||||
< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T2>::T_expr, \
|
||||
functor \
|
||||
< \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T1>::T_expr::T_numtype, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T2>::T_expr::T_numtype, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T3>::T_expr::T_numtype, \
|
||||
_bz_typename BZ_BLITZ_SCOPE(asExpr)<T4>::T_expr::T_numtype \
|
||||
> > > \
|
||||
( \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T1>::getExpr(d1.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T2>::getExpr(d2.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T2>::getExpr(d3.unwrap()), \
|
||||
BZ_BLITZ_SCOPE(asExpr)<T2>::getExpr(d4.unwrap())); \
|
||||
}
|
||||
|
||||
|
||||
#endif /* BZ_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS */
|
||||
|
||||
/*
|
||||
* User-defined expression template routines
|
||||
*/
|
||||
|
||||
#define BZ_DECLARE_FUNCTION(name) \
|
||||
BZ_DEFINE_UNARY_FUNC(name ## _impl,name,true) \
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(name,name ## _impl)
|
||||
|
||||
#define BZ_DECLARE_FUNCTION_RET(name,return_type) \
|
||||
BZ_DEFINE_UNARY_FUNC_RET(name ## _impl,name,return_type) \
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(name,name ## _impl)
|
||||
|
||||
#define BZ_DECLARE_FUNCTION2(name) \
|
||||
BZ_DEFINE_BINARY_FUNC(name ## _impl,name) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(name, name ## _impl)
|
||||
|
||||
#define BZ_DECLARE_FUNCTION2_RET(name,return_type) \
|
||||
BZ_DEFINE_BINARY_FUNC_RET(name ## _impl,name,return_type) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(name, name ## _impl)
|
||||
|
||||
#define BZ_DECLARE_FUNCTION2_SCALAR(name, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(name, name ## _impl, sca)
|
||||
|
||||
#define BZ_DECLARE_FUNCTION3(name) \
|
||||
BZ_DEFINE_TERNARY_FUNC(name ## _impl,name) \
|
||||
BZ_DECLARE_ARRAY_ET_TERNARY(name, name ## _impl)
|
||||
|
||||
#define BZ_DECLARE_FUNCTION3_RET(name,return_type) \
|
||||
BZ_DEFINE_TERNARY_FUNC_RET(name ## _impl,name,return_type) \
|
||||
BZ_DECLARE_ARRAY_ET_TERNARY(name, name ## _impl)
|
||||
|
||||
#define BZ_DECLARE_FUNCTION4(name) \
|
||||
BZ_DEFINE_QUATERNARY_FUNC(name ## _impl,name) \
|
||||
BZ_DECLARE_ARRAY_ET_QUATERNARY(name, name ## _impl)
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/newet.h Gang include of new expression templates implementation
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAY_NEWET_H
|
||||
#define BZ_ARRAY_NEWET_H
|
||||
|
||||
// Gang include of new expression templates implementation.
|
||||
|
||||
#include <blitz/array/ops.h>
|
||||
#include <blitz/array/funcs.h>
|
||||
|
||||
// ET support for functors acting on Arrays
|
||||
|
||||
#include <blitz/array/functorExpr.h>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,416 @@
|
||||
/***************************************************************************
|
||||
* blitz/array/ops.cc Basic operators for arrays.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYOPS_CC
|
||||
#define BZ_ARRAYOPS_CC
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/ops.cc> must be included via <blitz/array.h>
|
||||
#endif
|
||||
|
||||
#include <blitz/update.h>
|
||||
#include <blitz/globeval.cc>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* Constant operands
|
||||
*/
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
_bz_forceinline
|
||||
Array<P_numtype, N_rank>& Array<P_numtype,N_rank>::initialize(T_numtype x)
|
||||
{
|
||||
// we can't use asExpr here, because if we are initializing an array
|
||||
// whose components are also ETBase, it would parse as an array
|
||||
// expression, not as an initialization with a scalar.
|
||||
(*this) = _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef BZ_NEW_EXPRESSION_TEMPLATES
|
||||
|
||||
// need to do operator= separately from the generic templates below so
|
||||
// that operator=(T_numtype) will be the best match for list
|
||||
// initializations.
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
_bz_forceinline
|
||||
Array<P_numtype,N_rank>&
|
||||
Array<P_numtype,N_rank>::operator=(const ETBase<T_expr>& expr)
|
||||
{
|
||||
_bz_evaluate(*this, _bz_typename asExpr<T_expr>::T_expr(expr.unwrap()),
|
||||
_bz_update<T_numtype,
|
||||
_bz_typename asExpr<T_expr>::T_expr::T_result>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
// do NOT remove this operator. it won't work without it, trust me...
|
||||
template<typename P_numtype, int N_rank>
|
||||
_bz_forceinline
|
||||
Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator=(const Array<T_numtype,N_rank>& x)
|
||||
{
|
||||
typedef typename asExpr<Array<T_numtype,N_rank> >::T_expr T_expr;
|
||||
_bz_evaluate(*this, asExpr<Array<T_numtype,N_rank> >::getExpr(x),
|
||||
_bz_update<T_numtype,
|
||||
_bz_typename T_expr::T_result>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
#define BZ_ARRAY_UPDATE(op,name) \
|
||||
template<typename P_numtype, int N_rank> \
|
||||
template<typename T_expr> \
|
||||
_bz_forceinline \
|
||||
Array<P_numtype,N_rank>& \
|
||||
Array<P_numtype,N_rank>::operator op(const ETBase<T_expr>& expr) \
|
||||
{ \
|
||||
_bz_evaluate(*this, _bz_typename asExpr<T_expr>::T_expr(expr.unwrap()), \
|
||||
name<T_numtype, _bz_typename asExpr<T_expr>::T_expr::T_result>()); \
|
||||
return *this; \
|
||||
} \
|
||||
template<typename P_numtype, int N_rank> \
|
||||
_bz_forceinline \
|
||||
Array<P_numtype,N_rank>& \
|
||||
Array<P_numtype,N_rank>::operator op(const Array<T_numtype, N_rank>& x) \
|
||||
{ \
|
||||
typedef typename asExpr<Array<T_numtype,N_rank> >::T_expr T_expr; \
|
||||
_bz_evaluate(*this, asExpr<Array<T_numtype, N_rank> >::getExpr(x), \
|
||||
name<T_numtype, _bz_typename T_expr::T_result>()); \
|
||||
return *this; \
|
||||
} \
|
||||
template<typename P_numtype, int N_rank> \
|
||||
_bz_forceinline \
|
||||
Array<P_numtype,N_rank>& \
|
||||
Array<P_numtype,N_rank>::operator op(const T_numtype& x) \
|
||||
{ \
|
||||
typedef typename asExpr<T_numtype>::T_expr T_expr; \
|
||||
_bz_evaluate(*this, asExpr<T_numtype>::getExpr(x), \
|
||||
name<T_numtype, _bz_typename T_expr::T_result>()); \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
BZ_ARRAY_UPDATE(+=, _bz_plus_update)
|
||||
BZ_ARRAY_UPDATE(-=, _bz_minus_update)
|
||||
BZ_ARRAY_UPDATE(*=, _bz_multiply_update)
|
||||
BZ_ARRAY_UPDATE(/=, _bz_divide_update)
|
||||
BZ_ARRAY_UPDATE(%=, _bz_mod_update)
|
||||
BZ_ARRAY_UPDATE(^=, _bz_xor_update)
|
||||
BZ_ARRAY_UPDATE(&=, _bz_bitand_update)
|
||||
BZ_ARRAY_UPDATE(|=, _bz_bitor_update)
|
||||
BZ_ARRAY_UPDATE(<<=, _bz_shiftl_update)
|
||||
BZ_ARRAY_UPDATE(>>=, _bz_shiftr_update)
|
||||
|
||||
#else
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype,N_rank>::operator+=(T_numtype x)
|
||||
{
|
||||
(*this) += _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype,N_rank>::operator-=(T_numtype x)
|
||||
{
|
||||
(*this) -= _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype,N_rank>::operator*=(T_numtype x)
|
||||
{
|
||||
(*this) *= _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype,N_rank>::operator/=(T_numtype x)
|
||||
{
|
||||
(*this) /= _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype,N_rank>::operator%=(T_numtype x)
|
||||
{
|
||||
(*this) %= _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype,N_rank>::operator^=(T_numtype x)
|
||||
{
|
||||
(*this) ^= _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype,N_rank>::operator&=(T_numtype x)
|
||||
{
|
||||
(*this) &= _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype,N_rank>::operator|=(T_numtype x)
|
||||
{
|
||||
(*this) |= _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype,N_rank>::operator>>=(T_numtype x)
|
||||
{
|
||||
(*this) <<= _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype,N_rank>::operator<<=(T_numtype x)
|
||||
{
|
||||
(*this) <<= _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*
|
||||
* Array operands
|
||||
*/
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator=(const Array<T_numtype,N_rank>& x)
|
||||
{
|
||||
(*this) = _bz_ArrayExpr<FastArrayIterator<T_numtype, N_rank> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename P_numtype2>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator=(const Array<P_numtype2,N_rank>& x)
|
||||
{
|
||||
(*this) = _bz_ArrayExpr<FastArrayIterator<P_numtype2, N_rank> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename P_numtype2>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator+=(const Array<P_numtype2,N_rank>& x)
|
||||
{
|
||||
(*this) += _bz_ArrayExpr<FastArrayIterator<P_numtype2, N_rank> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename P_numtype2>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator-=(const Array<P_numtype2,N_rank>& x)
|
||||
{
|
||||
(*this) -= _bz_ArrayExpr<FastArrayIterator<P_numtype2, N_rank> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename P_numtype2>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator*=(const Array<P_numtype2,N_rank>& x)
|
||||
{
|
||||
(*this) *= _bz_ArrayExpr<FastArrayIterator<P_numtype2, N_rank> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename P_numtype2>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator/=(const Array<P_numtype2,N_rank>& x)
|
||||
{
|
||||
(*this) /= _bz_ArrayExpr<FastArrayIterator<P_numtype2, N_rank> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename P_numtype2>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator%=(const Array<P_numtype2,N_rank>& x)
|
||||
{
|
||||
(*this) %= _bz_ArrayExpr<FastArrayIterator<P_numtype2, N_rank> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename P_numtype2>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator^=(const Array<P_numtype2,N_rank>& x)
|
||||
{
|
||||
(*this) ^= _bz_ArrayExpr<FastArrayIterator<P_numtype2, N_rank> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename P_numtype2>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator&=(const Array<P_numtype2,N_rank>& x)
|
||||
{
|
||||
(*this) &= _bz_ArrayExpr<FastArrayIterator<P_numtype2, N_rank> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename P_numtype2>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator|=(const Array<P_numtype2,N_rank>& x)
|
||||
{
|
||||
(*this) |= _bz_ArrayExpr<FastArrayIterator<P_numtype2, N_rank> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename P_numtype2>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator>>=(const Array<P_numtype2,N_rank>& x)
|
||||
{
|
||||
(*this) >>= _bz_ArrayExpr<FastArrayIterator<P_numtype2, N_rank> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename P_numtype2>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator<<=(const Array<P_numtype2,N_rank>& x)
|
||||
{
|
||||
(*this) <<= _bz_ArrayExpr<FastArrayIterator<P_numtype2, N_rank> >(x.beginFast());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*
|
||||
* Array expression operands
|
||||
*/
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator=(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr)
|
||||
{
|
||||
evaluate(expr, _bz_update<T_numtype, _bz_typename T_expr::T_numtype>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator+=(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr)
|
||||
{
|
||||
evaluate(expr, _bz_plus_update<T_numtype, _bz_typename T_expr::T_numtype>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator-=(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr)
|
||||
{
|
||||
evaluate(expr, _bz_minus_update<T_numtype,
|
||||
_bz_typename T_expr::T_numtype>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator*=(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr)
|
||||
{
|
||||
evaluate(expr, _bz_multiply_update<T_numtype,
|
||||
_bz_typename T_expr::T_numtype>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator/=(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr)
|
||||
{
|
||||
evaluate(expr, _bz_divide_update<T_numtype,
|
||||
_bz_typename T_expr::T_numtype>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator%=(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr)
|
||||
{
|
||||
evaluate(expr, _bz_mod_update<T_numtype,
|
||||
_bz_typename T_expr::T_numtype>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator^=(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr)
|
||||
{
|
||||
evaluate(expr, _bz_xor_update<T_numtype,
|
||||
_bz_typename T_expr::T_numtype>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator&=(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr)
|
||||
{
|
||||
evaluate(expr, _bz_bitand_update<T_numtype,
|
||||
_bz_typename T_expr::T_numtype>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator|=(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr)
|
||||
{
|
||||
evaluate(expr, _bz_bitor_update<T_numtype,
|
||||
_bz_typename T_expr::T_numtype>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator>>=(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr)
|
||||
{
|
||||
evaluate(expr, _bz_shiftr_update<T_numtype,
|
||||
_bz_typename T_expr::T_numtype>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank> template<typename T_expr>
|
||||
inline Array<P_numtype, N_rank>&
|
||||
Array<P_numtype, N_rank>::operator<<=(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr)
|
||||
{
|
||||
evaluate(expr, _bz_shiftl_update<T_numtype,
|
||||
_bz_typename T_expr::T_numtype>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif // BZ_NEW_EXPRESSION_TEMPLATES
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYOPS_CC
|
||||
@@ -0,0 +1,133 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/ops.h Array operators
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAY_OPS_H
|
||||
#define BZ_ARRAY_OPS_H
|
||||
|
||||
#include <blitz/ops.h>
|
||||
#include <blitz/funcs.h>
|
||||
#include <blitz/array/newet-macros.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// unary operators
|
||||
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(operator~, BitwiseNot)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(operator!, LogicalNot)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(operator+, UnaryPlus)
|
||||
BZ_DECLARE_ARRAY_ET_UNARY(operator-, UnaryMinus)
|
||||
|
||||
// binary operators
|
||||
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator+, Add)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator-, Subtract)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator*, Multiply)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator/, Divide)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator%, Modulo)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator^, BitwiseXor)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator&, BitwiseAnd)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator|, BitwiseOr)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator>>, ShiftRight)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator<<, ShiftLeft)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator>, Greater)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator<, Less)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator>=, GreaterOrEqual)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator<=, LessOrEqual)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator==, Equal)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator!=, NotEqual)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator&&, LogicalAnd)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY(operator||, LogicalOr)
|
||||
|
||||
// \todo are these for Arrays of TinyVectors? How do we distinguish these from element-wise operations? they must now be done using the scalar() function
|
||||
/*
|
||||
// Declare binary ops between Array and "scalar-like" TinyVector
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator+, Add)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator-, Subtract)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator*, Multiply)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator/, Divide)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator%, Modulo)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator^, BitwiseXor)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator&, BitwiseAnd)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator|, BitwiseOr)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator>, Greater)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator<, Less)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator>=, GreaterOrEqual)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator<=, LessOrEqual)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator==, Equal)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator!=, NotEqual)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator&&, LogicalAnd)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(operator||, LogicalOr)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC((min), Min)
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC((max), Max)
|
||||
*/
|
||||
|
||||
#define BZ_DECLARE_ARRAY_ET_SCALAR_OPS(sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator+, Add, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator-, Subtract, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator*, Multiply, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator/, Divide, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator%, Modulo, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator^, BitwiseXor, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator&, BitwiseAnd, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator|, BitwiseOr, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator>>, ShiftRight, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator<<, ShiftLeft, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator>, Greater, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator<, Less, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator>=, GreaterOrEqual, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator<=, LessOrEqual, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator==, Equal, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator!=, NotEqual, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator&&, LogicalAnd, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(operator||, LogicalOr, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR((min), Min, sca) \
|
||||
BZ_DECLARE_ARRAY_ET_BINARY_SCALAR((max), Max, sca)
|
||||
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(char)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(unsigned char)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(short)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(unsigned short)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(int)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(unsigned int)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(long)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(unsigned long)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(float)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(double)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(long double)
|
||||
#ifdef BZ_HAVE_COMPLEX
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(complex<float>)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(complex<double>)
|
||||
BZ_DECLARE_ARRAY_ET_SCALAR_OPS(complex<long double>)
|
||||
#endif
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAY_OPS_H
|
||||
@@ -0,0 +1,154 @@
|
||||
/***************************************************************************
|
||||
* blitz/array/reduce.cc Array reductions.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYREDUCE_H
|
||||
#error <blitz/array/reduce.cc> must be included via <blitz/array/reduce.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename T_expr, typename T_reduction>
|
||||
_bz_typename T_reduction::T_resulttype
|
||||
_bz_ArrayExprFullReduce(T_expr expr, T_reduction reduction)
|
||||
{
|
||||
#ifdef BZ_TAU_PROFILING
|
||||
// Tau profiling code. Provide Tau with a pretty-printed version of
|
||||
// the expression.
|
||||
static BZ_STD_SCOPE(string) exprDescription;
|
||||
if (!exprDescription.length()) // faked static initializer
|
||||
{
|
||||
exprDescription = T_reduction::name();
|
||||
exprDescription += "(";
|
||||
prettyPrintFormat format(true); // Terse mode on
|
||||
expr.prettyPrint(exprDescription, format);
|
||||
exprDescription += ")";
|
||||
}
|
||||
TAU_PROFILE(" ", exprDescription, TAU_BLITZ);
|
||||
#endif // BZ_TAU_PROFILING
|
||||
|
||||
return _bz_reduceWithIndexTraversal(expr, reduction);
|
||||
|
||||
#ifdef BZ_NOT_IMPLEMENTED_FLAG
|
||||
if ((T_expr::numIndexPlaceholders > 0) || (T_reduction::needIndex))
|
||||
{
|
||||
// The expression involves index placeholders, so have to
|
||||
// use index traversal rather than stack traversal.
|
||||
return reduceWithIndexTraversal(expr, reduction);
|
||||
}
|
||||
else {
|
||||
// Use a stack traversal
|
||||
return reduceWithStackTraversal(expr, reduction);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T_index> struct _bz_IndexingVariant;
|
||||
|
||||
template <>
|
||||
struct _bz_IndexingVariant<int> {
|
||||
template <int N>
|
||||
static int index(const TinyVector<int,N>& ind,const int i) {
|
||||
return ind[i];
|
||||
}
|
||||
};
|
||||
|
||||
template <int N>
|
||||
struct _bz_IndexingVariant<TinyVector<int,N> > {
|
||||
static const TinyVector<int,N>& index(const TinyVector<int,N>& ind,const int) {
|
||||
return ind;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T_index, typename T_expr, typename T_reduction>
|
||||
_bz_typename T_reduction::T_resulttype
|
||||
_bz_reduceWithIndexTraversalGeneric(T_expr expr, T_reduction reduction)
|
||||
{
|
||||
// This is optimized assuming C-style arrays.
|
||||
|
||||
const int rank = T_expr::rank_;
|
||||
|
||||
TinyVector<int,T_expr::rank_> index, first, last;
|
||||
|
||||
unsigned long count = 1;
|
||||
|
||||
for (int i=0; i < rank; ++i) {
|
||||
first(i) = expr.lbound(i);
|
||||
last(i) = expr.ubound(i) + 1;
|
||||
index(i) = first(i);
|
||||
count *= last(i) - first(i);
|
||||
}
|
||||
|
||||
const int maxRank = rank - 1;
|
||||
const int lastlbound = expr.lbound(maxRank);
|
||||
const int lastubound = expr.ubound(maxRank);
|
||||
|
||||
const int lastIndex = lastubound + 1;
|
||||
|
||||
typedef _bz_IndexingVariant<T_index> adapter;
|
||||
|
||||
_bz_ReduceReset<T_reduction::needIndex,T_reduction::needInit> reset;
|
||||
reset(reduction,first,expr);
|
||||
|
||||
while(true) {
|
||||
for (index[maxRank]=lastlbound;index[maxRank]<lastIndex;++index[maxRank])
|
||||
if (!reduction(expr(index),adapter::index(index,maxRank)))
|
||||
return reduction.result(count);
|
||||
|
||||
int j = rank-2;
|
||||
for (;j>=0;--j) {
|
||||
index(j+1) = first(j+1);
|
||||
++index(j);
|
||||
if (index(j) < last(j))
|
||||
break;
|
||||
}
|
||||
|
||||
if (j<0)
|
||||
return reduction.result(count);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T_expr, typename T_reduction>
|
||||
_bz_typename T_reduction::T_resulttype
|
||||
_bz_reduceWithIndexTraversal(T_expr expr, T_reduction reduction)
|
||||
{
|
||||
return _bz_reduceWithIndexTraversalGeneric<int>(expr,reduction);
|
||||
}
|
||||
|
||||
// This version is for reductions that require a vector of index positions.
|
||||
|
||||
template<typename T_expr, typename T_reduction>
|
||||
_bz_typename T_reduction::T_resulttype
|
||||
_bz_reduceWithIndexVectorTraversal(T_expr expr, T_reduction reduction)
|
||||
{
|
||||
// We are doing minIndex/maxIndex, so initialize with lower bound
|
||||
return _bz_reduceWithIndexTraversalGeneric<TinyVector<int,T_expr::rank_> >(expr,reduction);
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,402 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/reduce.h Reductions of an array (or array expression) in a
|
||||
* single rank: sum, mean, min, minIndex, max, maxIndex,
|
||||
* product, count, any, all
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYREDUCE_H
|
||||
#define BZ_ARRAYREDUCE_H
|
||||
|
||||
#include <blitz/reduce.h>
|
||||
#include <blitz/meta/vecassign.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<bool needIndex,bool needInit> struct _bz_ReduceReset;
|
||||
|
||||
template<>
|
||||
struct _bz_ReduceReset<true,true> {
|
||||
template<typename T_reduction,typename T_index,typename T_expr>
|
||||
void operator()(T_reduction& reduce,const T_index& index,const T_expr& expr) {
|
||||
reduce.reset(index,expr.first_value());
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_ReduceReset<false,true> {
|
||||
template<typename T_reduction,typename T_index,typename T_expr>
|
||||
void operator()(T_reduction& reduce,const T_index&,const T_expr& expr) {
|
||||
reduce.reset(expr.first_value());
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_ReduceReset<true,false> {
|
||||
template<typename T_reduction,typename T_index,typename T_expr>
|
||||
void operator()(T_reduction& reduce,const T_index& index,const T_expr&) {
|
||||
reduce.reset(index);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_ReduceReset<false,false> {
|
||||
template<typename T_reduction,typename T_index,typename T_expr>
|
||||
void operator()(T_reduction& reduce,const T_index&,const T_expr&) {
|
||||
reduce.reset();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Expression template class for reductions. \todo We should be able
|
||||
to do vectorization, at least for complete reduction. */
|
||||
template<typename T_expr, int N_index, typename T_reduction>
|
||||
class _bz_ArrayExprReduce {
|
||||
|
||||
public:
|
||||
typedef _bz_typename T_reduction::T_numtype T_numtype;
|
||||
|
||||
// select return type
|
||||
typedef typename unwrapET<typename T_expr::T_result>::T_unwrapped test;
|
||||
typedef typename selectET<typename T_expr::T_typeprop,
|
||||
T_numtype,
|
||||
_bz_ArrayExprReduce<test, N_index, T_reduction> >::T_selected T_typeprop;
|
||||
typedef typename unwrapET<T_typeprop>::T_unwrapped T_result;
|
||||
typedef T_numtype T_optype;
|
||||
|
||||
typedef T_expr T_ctorArg1;
|
||||
typedef T_reduction T_ctorArg2;
|
||||
typedef int T_range_result; // dummy
|
||||
|
||||
static const int
|
||||
numArrayOperands = T_expr::numArrayOperands,
|
||||
numTVOperands = T_expr::numTVOperands,
|
||||
numTMOperands = T_expr::numTMOperands,
|
||||
numIndexPlaceholders = T_expr::numIndexPlaceholders + 1,
|
||||
minWidth = simdTypes<T_numtype>::vecWidth,
|
||||
maxWidth = simdTypes<T_numtype>::vecWidth,
|
||||
rank_ = T_expr::rank_ - 1;
|
||||
|
||||
/** Vectorization doesn't work for index expressions, so we can use
|
||||
a dummy here. */
|
||||
template<int N> struct tvresult {
|
||||
typedef FastTV2Iterator<T_numtype, N> Type;
|
||||
};
|
||||
|
||||
_bz_ArrayExprReduce(const _bz_ArrayExprReduce& reduce)
|
||||
: reduce_(reduce.reduce_), iter_(reduce.iter_), ordering_(reduce.ordering_) { }
|
||||
|
||||
_bz_ArrayExprReduce(T_expr expr)
|
||||
: iter_(expr)
|
||||
{ computeOrdering(); }
|
||||
|
||||
#if 0
|
||||
_bz_ArrayExprReduce(T_expr expr, T_reduction reduce)
|
||||
: iter_(expr), reduce_(reduce)
|
||||
{ computeOrdering(); }
|
||||
#endif
|
||||
|
||||
int ascending(const int r) const { return iter_.ascending(r); }
|
||||
int ordering(const int r) const { return ordering_[r]; }
|
||||
int lbound(const int r) const { return iter_.lbound(r); }
|
||||
int ubound(const int r) const { return iter_.ubound(r); }
|
||||
RectDomain<rank_> domain() const { return iter_.domain(); }
|
||||
|
||||
template<int N_destRank>
|
||||
T_numtype operator()(const TinyVector<int, N_destRank>& destIndex) const
|
||||
{
|
||||
BZPRECHECK(N_destRank == N_index,
|
||||
"Array reduction performed over rank " << N_index
|
||||
<< " to produce a rank " << N_destRank << " expression." << endl
|
||||
<< "You must reduce over rank " << N_destRank << " instead.");
|
||||
|
||||
TinyVector<int, N_destRank + 1> index;
|
||||
|
||||
// This metaprogram copies elements 0..N-1 of destIndex into index
|
||||
_bz_meta_vecAssign<N_index, 0>::assign(index, destIndex,
|
||||
_bz_update<int,int>());
|
||||
|
||||
int lbound = iter_.lbound(N_index);
|
||||
int ubound = iter_.ubound(N_index);
|
||||
|
||||
BZPRECHECK((lbound != tiny(int())) && (ubound != huge(int())),
|
||||
"Array reduction performed over rank " << N_index
|
||||
<< " is unbounded." << endl
|
||||
<< "There must be an array object in the expression being reduced"
|
||||
<< endl << "which provides a bound in rank " << N_index << ".");
|
||||
|
||||
// If we are doing minIndex/maxIndex, initialize with lower bound
|
||||
|
||||
_bz_ReduceReset<T_reduction::needIndex,T_reduction::needInit> reset;
|
||||
reset(reduce_,lbound,iter_);
|
||||
|
||||
for (index[N_index]=lbound; index[N_index]<=ubound; ++index[N_index]) {
|
||||
if (!reduce_(iter_(index), index[N_index]))
|
||||
break;
|
||||
}
|
||||
|
||||
return reduce_.result(ubound-lbound+1);
|
||||
}
|
||||
|
||||
// If you have a precondition failure on these routines, it means
|
||||
// you are trying to use stack iteration mode on an expression
|
||||
// which contains an index placeholder. You must use index
|
||||
// iteration mode instead.
|
||||
|
||||
int operator*() const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); return 0; }
|
||||
int suggestStride(int) const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); return 0; }
|
||||
|
||||
void push(int) const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); }
|
||||
void pop(int) const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); }
|
||||
void advance() const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); }
|
||||
void advance(int) const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); }
|
||||
void loadStride(int) const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); }
|
||||
void advanceUnitStride() const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); }
|
||||
|
||||
template<int N_rank>
|
||||
void moveTo(const TinyVector<int,N_rank>&) const {
|
||||
BZPRECHECK(0,"Stencils of reductions are not implemented"); }
|
||||
|
||||
bool isUnitStride(int) const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); return false; }
|
||||
bool isUnitStride() const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); return false; }
|
||||
bool canCollapse(int,int) const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); return false; }
|
||||
bool isStride(int,int) const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); return true; }
|
||||
|
||||
T_numtype operator[](int) const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); return T_numtype(); }
|
||||
T_numtype fastRead(int) const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on a reduction."); return T_numtype(); }
|
||||
|
||||
template<int N>
|
||||
typename tvresult<N>::Type fastRead_tv(int) const {
|
||||
BZPRECHECK(0,"Can't use stack iteration on an index mapping.");
|
||||
return TinyVector<T_numtype, N>();
|
||||
}
|
||||
|
||||
/** Determining whether the resulting expression is aligned is
|
||||
difficult, so to be safe we say no. It shouldn't be attempted
|
||||
anyway, though. */
|
||||
bool isVectorAligned(diffType offset) const {
|
||||
return false; }
|
||||
|
||||
// don't know how to define these, so stencil expressions won't work
|
||||
T_result shift(int offset, int dim) const
|
||||
{ BZPRECHECK(0,"Stencils of reductions are not implemented"); return T_numtype(); }
|
||||
T_result shift(int offset1, int dim1,int offset2, int dim2) const
|
||||
{ BZPRECHECK(0,"Stencils of reductions are not implemented"); return T_numtype(); }
|
||||
void _bz_offsetData(sizeType i) { BZPRECONDITION(0); }
|
||||
|
||||
// Unclear how to define this, and stencils don't work anyway
|
||||
T_range_result operator()(RectDomain<rank_> d) const
|
||||
{ BZPRECHECK(0,"Stencils of reductions are not implemented");
|
||||
return T_range_result(); }
|
||||
|
||||
void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format) const
|
||||
{
|
||||
// NEEDS_WORK-- do real formatting for reductions
|
||||
str += "reduce[NEEDS_WORK](";
|
||||
iter_.prettyPrint(str,format);
|
||||
str += ")";
|
||||
}
|
||||
|
||||
/** \todo do a real shape check (tricky) */
|
||||
template<typename T_shape>
|
||||
bool shapeCheck(const T_shape&) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// sliceinfo for expressions
|
||||
template<typename T1, typename T2 = nilArraySection,
|
||||
class T3 = nilArraySection, typename T4 = nilArraySection,
|
||||
class T5 = nilArraySection, typename T6 = nilArraySection,
|
||||
class T7 = nilArraySection, typename T8 = nilArraySection,
|
||||
class T9 = nilArraySection, typename T10 = nilArraySection,
|
||||
class T11 = nilArraySection>
|
||||
class SliceInfo {
|
||||
public:
|
||||
typedef typename T_expr::template SliceInfo<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::T_slice T_slice1;
|
||||
typedef _bz_ArrayExprReduce<T_slice1, N_index, T_reduction> T_slice;
|
||||
};
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9, typename T10, typename T11>
|
||||
typename SliceInfo<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_slice
|
||||
operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6, T7 r7, T8 r8, T9 r9, T10 r10, T11 r11) const
|
||||
{
|
||||
// for slicing reduction results, we would need to set the
|
||||
// dimension reduced over to Range::all(). That's not easy to do
|
||||
// because it requires us to change the type of one of the rn's.
|
||||
BZPRECONDITION(0);
|
||||
}
|
||||
|
||||
private:
|
||||
_bz_ArrayExprReduce() { }
|
||||
|
||||
/** Method for properly initializing the ordering values. \todo If
|
||||
the expression being reduced consist of arrays with different
|
||||
orderings, the call to iter_.ordering() will fail with a
|
||||
"different orderings" error. But just like it can happen that
|
||||
ordering values are missing from the expression, it seems
|
||||
equally valid that ordering is indefinite in cases where the
|
||||
expression has differing values. This doesn't prevent us from
|
||||
assigning the expression to an array, and it shouldn't prevent
|
||||
the expression from being used in a reduction either. (This is
|
||||
bug 2058441.) */
|
||||
void computeOrdering()
|
||||
{
|
||||
TinyVector<bool,rank_> in_ordering;
|
||||
in_ordering = false;
|
||||
|
||||
int j = 0;
|
||||
for (int i=0; i<rank_; ++i) {
|
||||
const int orderingj = iter_.ordering(i);
|
||||
if (orderingj != tiny(int()) && orderingj < rank_ && !in_ordering(orderingj)) {
|
||||
// unique value in ordering array
|
||||
in_ordering(orderingj) = true;
|
||||
ordering_(j++) = orderingj;
|
||||
}
|
||||
}
|
||||
|
||||
// It is possible that ordering is not a permutation of 0,...,rank-1.
|
||||
// In that case j will be less than rank. We fill in ordering with
|
||||
// the unused values in decreasing order.
|
||||
for (int i = rank_; j < rank_; ++j) {
|
||||
while (in_ordering(--i)); // find an unused index
|
||||
ordering_(j) = i;
|
||||
}
|
||||
}
|
||||
|
||||
T_reduction reduce_;
|
||||
T_expr iter_;
|
||||
TinyVector<int,rank_> ordering_;
|
||||
};
|
||||
|
||||
#define BZ_DECL_ARRAY_PARTIAL_REDUCE(fn,reduction) \
|
||||
template<typename T_expr, int N_index> \
|
||||
inline \
|
||||
_bz_ArrayExpr<_bz_ArrayExprReduce<_bz_typename BZ_BLITZ_SCOPE(asExpr)<T_expr>::T_expr, \
|
||||
N_index, \
|
||||
reduction<_bz_typename T_expr::T_numtype> > > \
|
||||
fn(const BZ_BLITZ_SCOPE(ETBase)<T_expr>& expr, \
|
||||
const IndexPlaceholder<N_index>&) \
|
||||
{ \
|
||||
return _bz_ArrayExprReduce<_bz_typename BZ_BLITZ_SCOPE(asExpr)<T_expr>::T_expr, \
|
||||
N_index, \
|
||||
reduction<_bz_typename T_expr::T_numtype> > \
|
||||
(BZ_BLITZ_SCOPE(asExpr)<T_expr>::getExpr(expr.unwrap())); \
|
||||
}
|
||||
|
||||
BZ_DECL_ARRAY_PARTIAL_REDUCE(sum, ReduceSum)
|
||||
BZ_DECL_ARRAY_PARTIAL_REDUCE(mean, ReduceMean)
|
||||
BZ_DECL_ARRAY_PARTIAL_REDUCE((min), ReduceMin)
|
||||
BZ_DECL_ARRAY_PARTIAL_REDUCE(minIndex, ReduceMinIndex)
|
||||
BZ_DECL_ARRAY_PARTIAL_REDUCE((max), ReduceMax)
|
||||
BZ_DECL_ARRAY_PARTIAL_REDUCE(maxIndex, ReduceMaxIndex)
|
||||
BZ_DECL_ARRAY_PARTIAL_REDUCE(product, ReduceProduct)
|
||||
BZ_DECL_ARRAY_PARTIAL_REDUCE(count, ReduceCount)
|
||||
BZ_DECL_ARRAY_PARTIAL_REDUCE(any, ReduceAny)
|
||||
BZ_DECL_ARRAY_PARTIAL_REDUCE(all, ReduceAll)
|
||||
BZ_DECL_ARRAY_PARTIAL_REDUCE(first, ReduceFirst)
|
||||
BZ_DECL_ARRAY_PARTIAL_REDUCE(last, ReduceLast)
|
||||
|
||||
/*
|
||||
* Complete reductions
|
||||
*/
|
||||
|
||||
// Prototype of reduction functions
|
||||
template<typename T_expr, typename T_reduction>
|
||||
_bz_typename T_reduction::T_resulttype
|
||||
_bz_ArrayExprFullReduce(T_expr expr, T_reduction reduction);
|
||||
|
||||
template<typename T_expr, typename T_reduction>
|
||||
_bz_typename T_reduction::T_resulttype
|
||||
_bz_reduceWithIndexTraversal(T_expr expr, T_reduction reduction);
|
||||
|
||||
template<typename T_expr, typename T_reduction>
|
||||
_bz_typename T_reduction::T_resulttype
|
||||
_bz_reduceWithIndexVectorTraversal(T_expr expr, T_reduction reduction);
|
||||
|
||||
#define BZ_DECL_ARRAY_FULL_REDUCE(fn,reduction) \
|
||||
template<typename T_expr> \
|
||||
_bz_inline_et \
|
||||
_bz_typename reduction<_bz_typename T_expr::T_numtype>::T_resulttype \
|
||||
fn(const BZ_BLITZ_SCOPE(ETBase)<T_expr>& expr) \
|
||||
{ \
|
||||
return _bz_ArrayExprFullReduce \
|
||||
(BZ_BLITZ_SCOPE(asExpr)<T_expr>::getExpr(expr.unwrap()), \
|
||||
reduction<_bz_typename T_expr::T_numtype>()); \
|
||||
} \
|
||||
|
||||
BZ_DECL_ARRAY_FULL_REDUCE(sum, ReduceSum)
|
||||
BZ_DECL_ARRAY_FULL_REDUCE(mean, ReduceMean)
|
||||
BZ_DECL_ARRAY_FULL_REDUCE((min), ReduceMin)
|
||||
BZ_DECL_ARRAY_FULL_REDUCE((max), ReduceMax)
|
||||
BZ_DECL_ARRAY_FULL_REDUCE((minmax), ReduceMinMax)
|
||||
BZ_DECL_ARRAY_FULL_REDUCE(product, ReduceProduct)
|
||||
BZ_DECL_ARRAY_FULL_REDUCE(count, ReduceCount)
|
||||
BZ_DECL_ARRAY_FULL_REDUCE(any, ReduceAny)
|
||||
BZ_DECL_ARRAY_FULL_REDUCE(all, ReduceAll)
|
||||
BZ_DECL_ARRAY_FULL_REDUCE(first, ReduceFirst)
|
||||
BZ_DECL_ARRAY_FULL_REDUCE(last, ReduceLast)
|
||||
|
||||
// Special versions of complete reductions: minIndex and
|
||||
// maxIndex
|
||||
|
||||
#define BZ_DECL_ARRAY_FULL_REDUCE_INDEXVECTOR(fn,reduction) \
|
||||
template<typename T_expr> \
|
||||
_bz_inline_et \
|
||||
_bz_typename reduction<_bz_typename T_expr::T_numtype, \
|
||||
T_expr::rank_>::T_resulttype \
|
||||
fn(const BZ_BLITZ_SCOPE(ETBase)<T_expr>& expr) \
|
||||
{ \
|
||||
return _bz_reduceWithIndexVectorTraversal \
|
||||
(BZ_BLITZ_SCOPE(asExpr)<T_expr>::getExpr(expr.unwrap()), \
|
||||
reduction<_bz_typename T_expr::T_numtype, T_expr::rank_>()); \
|
||||
}
|
||||
|
||||
BZ_DECL_ARRAY_FULL_REDUCE_INDEXVECTOR(minIndex, ReduceMinIndexVector)
|
||||
BZ_DECL_ARRAY_FULL_REDUCE_INDEXVECTOR(maxIndex, ReduceMaxIndexVector)
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#include <blitz/array/reduce.cc>
|
||||
|
||||
#endif // BZ_ARRAYREDUCE_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,94 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/shape.h
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYSHAPE_H
|
||||
#define BZ_ARRAYSHAPE_H
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/shape.h> must be included via <blitz/array.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* These routines make it easier to create shape parameters on
|
||||
* the fly: instead of having to write
|
||||
*
|
||||
* A.resize(TinyVector<int,4>(8,8,8,12));
|
||||
*
|
||||
* you can just say
|
||||
*
|
||||
* A.resize(shape(8,8,8,12));
|
||||
*
|
||||
*/
|
||||
inline TinyVector<int,1> shape(int n1)
|
||||
{ return TinyVector<int,1>(n1); }
|
||||
|
||||
inline TinyVector<int,2> shape(int n1, int n2)
|
||||
{ return TinyVector<int,2>(n1,n2); }
|
||||
|
||||
inline TinyVector<int,3> shape(int n1, int n2, int n3)
|
||||
{ return TinyVector<int,3>(n1,n2,n3); }
|
||||
|
||||
inline TinyVector<int,4> shape(int n1, int n2, int n3, int n4)
|
||||
{ return TinyVector<int,4>(n1,n2,n3,n4); }
|
||||
|
||||
inline TinyVector<int,5> shape(int n1, int n2, int n3, int n4,
|
||||
int n5)
|
||||
{ return TinyVector<int,5>(n1,n2,n3,n4,n5); }
|
||||
|
||||
inline TinyVector<int,6> shape(int n1, int n2, int n3, int n4,
|
||||
int n5, int n6)
|
||||
{ return TinyVector<int,6>(n1,n2,n3,n4,n5,n6); }
|
||||
|
||||
inline TinyVector<int,7> shape(int n1, int n2, int n3, int n4,
|
||||
int n5, int n6, int n7)
|
||||
{ return TinyVector<int,7>(n1,n2,n3,n4,n5,n6,n7); }
|
||||
|
||||
inline TinyVector<int,8> shape(int n1, int n2, int n3, int n4,
|
||||
int n5, int n6, int n7, int n8)
|
||||
{ return TinyVector<int,8>(n1,n2,n3,n4,n5,n6,n7,n8); }
|
||||
|
||||
inline TinyVector<int,9> shape(int n1, int n2, int n3, int n4,
|
||||
int n5, int n6, int n7, int n8, int n9)
|
||||
{ return TinyVector<int,9>(n1,n2,n3,n4,n5,n6,n7,n8,n9); }
|
||||
|
||||
inline TinyVector<int,10> shape(int n1, int n2, int n3, int n4,
|
||||
int n5, int n6, int n7, int n8, int n9, int n10)
|
||||
{ return TinyVector<int,10>(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10); }
|
||||
|
||||
inline TinyVector<int,11> shape(int n1, int n2, int n3, int n4,
|
||||
int n5, int n6, int n7, int n8, int n9, int n10, int n11)
|
||||
{ return TinyVector<int,11>(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11); }
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYSHAPE_H
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/slice.h Helper classes for slicing arrays
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYSLICE_H
|
||||
#define BZ_ARRAYSLICE_H
|
||||
|
||||
// #ifndef BZ_ARRAY_H
|
||||
// #error <blitz/array/slice.h> must be included via <blitz/array.h>
|
||||
// #endif
|
||||
|
||||
#include <blitz/range.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// Forward declarations
|
||||
template<typename T, int N>
|
||||
class Array;
|
||||
|
||||
class nilArraySection { };
|
||||
|
||||
template<typename T>
|
||||
class ArraySectionInfo {
|
||||
public:
|
||||
static const int isValidType = 0;
|
||||
static const int rank = 0;
|
||||
static const int isPick = 0;
|
||||
};
|
||||
|
||||
template<>
|
||||
class ArraySectionInfo<Range> {
|
||||
public:
|
||||
static const int isValidType = 1;
|
||||
static const int rank = 1;
|
||||
static const int isPick = 0;
|
||||
};
|
||||
|
||||
template<>
|
||||
class ArraySectionInfo<int> {
|
||||
public:
|
||||
static const int isValidType = 1;
|
||||
static const int rank = 0;
|
||||
static const int isPick = 0;
|
||||
};
|
||||
|
||||
template<>
|
||||
class ArraySectionInfo<nilArraySection> {
|
||||
public:
|
||||
static const int isValidType = 1;
|
||||
static const int rank = 0;
|
||||
static const int isPick = 0;
|
||||
};
|
||||
|
||||
template<typename T_numtype, typename T1, typename T2 = nilArraySection,
|
||||
class T3 = nilArraySection, typename T4 = nilArraySection,
|
||||
class T5 = nilArraySection, typename T6 = nilArraySection,
|
||||
class T7 = nilArraySection, typename T8 = nilArraySection,
|
||||
class T9 = nilArraySection, typename T10 = nilArraySection,
|
||||
class T11 = nilArraySection>
|
||||
class SliceInfo {
|
||||
public:
|
||||
static const int
|
||||
numValidTypes = ArraySectionInfo<T1>::isValidType
|
||||
+ ArraySectionInfo<T2>::isValidType
|
||||
+ ArraySectionInfo<T3>::isValidType
|
||||
+ ArraySectionInfo<T4>::isValidType
|
||||
+ ArraySectionInfo<T5>::isValidType
|
||||
+ ArraySectionInfo<T6>::isValidType
|
||||
+ ArraySectionInfo<T7>::isValidType
|
||||
+ ArraySectionInfo<T8>::isValidType
|
||||
+ ArraySectionInfo<T9>::isValidType
|
||||
+ ArraySectionInfo<T10>::isValidType
|
||||
+ ArraySectionInfo<T11>::isValidType;
|
||||
|
||||
static const int
|
||||
rank = ArraySectionInfo<T1>::rank
|
||||
+ ArraySectionInfo<T2>::rank
|
||||
+ ArraySectionInfo<T3>::rank
|
||||
+ ArraySectionInfo<T4>::rank
|
||||
+ ArraySectionInfo<T5>::rank
|
||||
+ ArraySectionInfo<T6>::rank
|
||||
+ ArraySectionInfo<T7>::rank
|
||||
+ ArraySectionInfo<T8>::rank
|
||||
+ ArraySectionInfo<T9>::rank
|
||||
+ ArraySectionInfo<T10>::rank
|
||||
+ ArraySectionInfo<T11>::rank;
|
||||
|
||||
static const int
|
||||
isPick = ArraySectionInfo<T1>::isPick
|
||||
+ ArraySectionInfo<T2>::isPick
|
||||
+ ArraySectionInfo<T3>::isPick
|
||||
+ ArraySectionInfo<T4>::isPick
|
||||
+ ArraySectionInfo<T5>::isPick
|
||||
+ ArraySectionInfo<T6>::isPick
|
||||
+ ArraySectionInfo<T7>::isPick
|
||||
+ ArraySectionInfo<T8>::isPick
|
||||
+ ArraySectionInfo<T9>::isPick
|
||||
+ ArraySectionInfo<T10>::isPick
|
||||
+ ArraySectionInfo<T11>::isPick;
|
||||
|
||||
typedef Array<T_numtype,numValidTypes> T_array;
|
||||
typedef Array<T_numtype,rank> T_slice;
|
||||
};
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYSLICE_H
|
||||
@@ -0,0 +1,363 @@
|
||||
/***************************************************************************
|
||||
* blitz/array/slicing.cc Slicing of arrays
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYSLICING_CC
|
||||
#define BZ_ARRAYSLICING_CC
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/slicing.cc> must be included via <blitz/array.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* These routines make the array a view of a portion of another array.
|
||||
* They all work by first referencing the other array, and then slicing.
|
||||
*/
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, const RectDomain<N_rank>& subdomain)
|
||||
{
|
||||
reference(array);
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
slice(i, subdomain[i]);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, const StridedDomain<N_rank>& subdomain)
|
||||
{
|
||||
reference(array);
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
slice(i, subdomain[i]);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, Range r0)
|
||||
{
|
||||
reference(array);
|
||||
slice(0, r0);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, Range r0, Range r1)
|
||||
{
|
||||
reference(array);
|
||||
slice(0, r0);
|
||||
slice(1, r1);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2)
|
||||
{
|
||||
reference(array);
|
||||
slice(0, r0);
|
||||
slice(1, r1);
|
||||
slice(2, r2);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3)
|
||||
{
|
||||
reference(array);
|
||||
slice(0, r0);
|
||||
slice(1, r1);
|
||||
slice(2, r2);
|
||||
slice(3, r3);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3,
|
||||
Range r4)
|
||||
{
|
||||
reference(array);
|
||||
slice(0, r0);
|
||||
slice(1, r1);
|
||||
slice(2, r2);
|
||||
slice(3, r3);
|
||||
slice(4, r4);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3,
|
||||
Range r4, Range r5)
|
||||
{
|
||||
reference(array);
|
||||
slice(0, r0);
|
||||
slice(1, r1);
|
||||
slice(2, r2);
|
||||
slice(3, r3);
|
||||
slice(4, r4);
|
||||
slice(5, r5);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3,
|
||||
Range r4, Range r5, Range r6)
|
||||
{
|
||||
reference(array);
|
||||
slice(0, r0);
|
||||
slice(1, r1);
|
||||
slice(2, r2);
|
||||
slice(3, r3);
|
||||
slice(4, r4);
|
||||
slice(5, r5);
|
||||
slice(6, r6);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3,
|
||||
Range r4, Range r5, Range r6, Range r7)
|
||||
{
|
||||
reference(array);
|
||||
slice(0, r0);
|
||||
slice(1, r1);
|
||||
slice(2, r2);
|
||||
slice(3, r3);
|
||||
slice(4, r4);
|
||||
slice(5, r5);
|
||||
slice(6, r6);
|
||||
slice(7, r7);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3,
|
||||
Range r4, Range r5, Range r6, Range r7, Range r8)
|
||||
{
|
||||
reference(array);
|
||||
slice(0, r0);
|
||||
slice(1, r1);
|
||||
slice(2, r2);
|
||||
slice(3, r3);
|
||||
slice(4, r4);
|
||||
slice(5, r5);
|
||||
slice(6, r6);
|
||||
slice(7, r7);
|
||||
slice(8, r8);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3,
|
||||
Range r4, Range r5, Range r6, Range r7, Range r8, Range r9)
|
||||
{
|
||||
reference(array);
|
||||
slice(0, r0);
|
||||
slice(1, r1);
|
||||
slice(2, r2);
|
||||
slice(3, r3);
|
||||
slice(4, r4);
|
||||
slice(5, r5);
|
||||
slice(6, r6);
|
||||
slice(7, r7);
|
||||
slice(8, r8);
|
||||
slice(9, r9);
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::constructSubarray(
|
||||
Array<T_numtype, N_rank>& array, Range r0, Range r1, Range r2, Range r3,
|
||||
Range r4, Range r5, Range r6, Range r7, Range r8, Range r9, Range r10)
|
||||
{
|
||||
reference(array);
|
||||
slice(0, r0);
|
||||
slice(1, r1);
|
||||
slice(2, r2);
|
||||
slice(3, r3);
|
||||
slice(4, r4);
|
||||
slice(5, r5);
|
||||
slice(6, r6);
|
||||
slice(7, r7);
|
||||
slice(8, r8);
|
||||
slice(9, r9);
|
||||
slice(10, r10);
|
||||
}
|
||||
|
||||
/*
|
||||
* This member template is used to implement operator() with any
|
||||
* combination of int and Range parameters. There's room for up
|
||||
* to 11 parameters, but any unused parameters have no effect.
|
||||
*/
|
||||
template<typename P_numtype, int N_rank> template<int N_rank2, typename R0,
|
||||
class R1, typename R2, typename R3, typename R4, typename R5, typename R6, typename R7,
|
||||
class R8, typename R9, typename R10>
|
||||
void Array<P_numtype, N_rank>::constructSlice(Array<T_numtype, N_rank2>& array,
|
||||
R0 r0, R1 r1, R2 r2, R3 r3, R4 r4, R5 r5, R6 r6, R7 r7, R8 r8, R9 r9,
|
||||
R10 r10)
|
||||
{
|
||||
MemoryBlockReference<T_numtype>::changeBlock(array);
|
||||
|
||||
int setRank = 0;
|
||||
|
||||
TinyVector<int, N_rank2> rankMap;
|
||||
|
||||
slice(setRank, r0, array, rankMap, 0);
|
||||
slice(setRank, r1, array, rankMap, 1);
|
||||
slice(setRank, r2, array, rankMap, 2);
|
||||
slice(setRank, r3, array, rankMap, 3);
|
||||
slice(setRank, r4, array, rankMap, 4);
|
||||
slice(setRank, r5, array, rankMap, 5);
|
||||
slice(setRank, r6, array, rankMap, 6);
|
||||
slice(setRank, r7, array, rankMap, 7);
|
||||
slice(setRank, r8, array, rankMap, 8);
|
||||
slice(setRank, r9, array, rankMap, 9);
|
||||
slice(setRank, r10, array, rankMap, 10);
|
||||
|
||||
// Redo the ordering_ array to account for dimensions which
|
||||
// have been sliced away.
|
||||
int j = 0;
|
||||
for (int i=0; i < N_rank2; ++i)
|
||||
{
|
||||
if (rankMap[array.ordering(i)] != -1)
|
||||
storage_.setOrdering(j++, rankMap[array.ordering(i)]);
|
||||
}
|
||||
|
||||
calculateZeroOffset();
|
||||
}
|
||||
|
||||
/*
|
||||
* This member template is also used in the implementation of
|
||||
* operator() with any combination of int and Rank parameters.
|
||||
* It's called by constructSlice(), above. This version handles
|
||||
* Range parameters.
|
||||
*/
|
||||
template<typename P_numtype, int N_rank> template<int N_rank2>
|
||||
void Array<P_numtype, N_rank>::slice(int& setRank, Range r,
|
||||
Array<T_numtype,N_rank2>& array, TinyVector<int,N_rank2>& rankMap,
|
||||
int sourceRank)
|
||||
{
|
||||
// NEEDS WORK: ordering will change completely when some ranks
|
||||
// are deleted.
|
||||
|
||||
#ifdef BZ_DEBUG_SLICE
|
||||
cout << "slice(" << setRank << ", [" << r.first(array.lbound(sourceRank))
|
||||
<< ", " << r.last(array.ubound(sourceRank)) << "], Array<T,"
|
||||
<< N_rank2 << ">, " << sourceRank << ")" << endl;
|
||||
#endif
|
||||
|
||||
rankMap[sourceRank] = setRank;
|
||||
length_[setRank] = array.length(sourceRank);
|
||||
stride_[setRank] = array.stride(sourceRank);
|
||||
storage_.setAscendingFlag(setRank, array.isRankStoredAscending(sourceRank));
|
||||
storage_.setBase(setRank, array.base(sourceRank));
|
||||
slice(setRank, r);
|
||||
++setRank;
|
||||
}
|
||||
|
||||
/*
|
||||
* This member template is also used in the implementation of
|
||||
* operator() with any combination of int and Rank parameters.
|
||||
* It's called by constructSlice(), above. This version handles
|
||||
* int parameters, which reduce the dimensionality by one.
|
||||
*/
|
||||
template<typename P_numtype, int N_rank> template<int N_rank2>
|
||||
void Array<P_numtype, N_rank>::slice(int&, int i,
|
||||
Array<T_numtype,N_rank2>& array, TinyVector<int,N_rank2>& rankMap,
|
||||
int sourceRank)
|
||||
{
|
||||
#ifdef BZ_DEBUG_SLICE
|
||||
cout << "slice(" << i
|
||||
<< ", Array<T," << N_rank2 << ">, " << sourceRank << ")" << endl;
|
||||
cout << "Offset by " << (i * array.stride(sourceRank))
|
||||
<< endl;
|
||||
#endif
|
||||
BZPRECHECK(array.isInRangeForDim(i, sourceRank),
|
||||
"Slice is out of range for array: index=" << i << " rank=" << sourceRank
|
||||
<< endl << "Possible range for index: [" << array.lbound(sourceRank)
|
||||
<< ", " << array.ubound(sourceRank) << "]");
|
||||
|
||||
rankMap[sourceRank] = -1;
|
||||
data_ += i * array.stride(sourceRank);
|
||||
#ifdef BZ_DEBUG_SLICE
|
||||
cout << "data_ = " << data_ << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* After calling slice(int rank, Range r), the array refers only to the
|
||||
* Range r of the original array.
|
||||
* e.g. Array<int,1> x(100);
|
||||
* x.slice(firstRank, Range(25,50));
|
||||
* x = 0; // Sets elements 25..50 of the original array to 0
|
||||
*/
|
||||
template<typename P_numtype, int N_rank>
|
||||
void Array<P_numtype, N_rank>::slice(int rank, Range r)
|
||||
{
|
||||
BZPRECONDITION((rank >= 0) && (rank < N_rank));
|
||||
|
||||
int first = r.first(lbound(rank));
|
||||
int last = r.last(ubound(rank));
|
||||
diffType stride = r.stride();
|
||||
|
||||
#ifdef BZ_DEBUG_SLICE
|
||||
cout << "slice(" << rank << ", Range):" << endl
|
||||
<< "first = " << first << " last = " << last << "stride = " << stride
|
||||
<< endl << "length_[rank] = " << length_[rank] << endl;
|
||||
#endif
|
||||
|
||||
BZPRECHECK((((first <= last) && (stride > 0)) ||
|
||||
((first >= last) && (stride < 0))) &&
|
||||
(first >= base(rank) && (first - base(rank)) < length_[rank]) &&
|
||||
(last >= base(rank) && (last - base(rank)) < length_[rank]),
|
||||
"Bad array slice: Range(" << first << ", " << last << ", "
|
||||
<< stride << "). Array is Range(" << lbound(rank) << ", "
|
||||
<< ubound(rank) << ")");
|
||||
|
||||
// Will the storage be non-contiguous?
|
||||
// (1) Slice in the minor dimension and the range does not span
|
||||
// the entire index interval (NB: non-unit strides are possible)
|
||||
// (2) Slice in a middle dimension and the range is not Range::all()
|
||||
|
||||
length_[rank] = (last - first) / stride + 1;
|
||||
|
||||
// TV 20000312: added second term here, for testsuite/Josef-Wagenhuber
|
||||
diffType offset = (first - base(rank) * stride) * stride_[rank];
|
||||
|
||||
data_ += offset;
|
||||
zeroOffset_ += offset;
|
||||
|
||||
stride_[rank] *= stride;
|
||||
// JCC: adjust ascending flag if slicing with backwards Range
|
||||
if (stride<0)
|
||||
storage_.setAscendingFlag(rank, !isRankStoredAscending(rank));
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYSLICING_CC
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,400 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/stencil-et.h Expression-template-capable stencils
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAY_STENCIL_ET_H
|
||||
#define BZ_ARRAY_STENCIL_ET_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/tinyvec2.h>
|
||||
#include <blitz/prettyprint.h>
|
||||
#include <blitz/array/domain.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/* Stencils as currently implemented rely on being able to give an
|
||||
iterator type to the operator. Some methods have been implemented
|
||||
to make index traversal work so that operands can include index
|
||||
remappings, but it's probably not very efficient. Operands
|
||||
containing reductions or index placeholders don't work. */
|
||||
|
||||
// Utility function for shrinking the domain of the expression the
|
||||
// stencil operates on. The minb and maxb may be defined in fewer
|
||||
// dimensions than the expression, in which the shape is the same in
|
||||
// higher dims.
|
||||
template<int N_rank, int N_rank2>
|
||||
RectDomain<N_rank> _bz_shrinkDomain(const RectDomain<N_rank>& d,
|
||||
const TinyVector<int,N_rank2>& minb,
|
||||
const TinyVector<int,N_rank2>& maxb)
|
||||
{
|
||||
TinyVector<int, N_rank> lb(d.lbound()), ub(d.ubound());
|
||||
// no slicing w tinyvector
|
||||
for(int i=0; i<N_rank2; ++i) {
|
||||
lb[i] = lb[i] - ((minb[i]<0) ? minb[i] : 0);
|
||||
ub[i] = ub[i] - ((maxb[i]>0) ? maxb[i] : 0);
|
||||
}
|
||||
return RectDomain<N_rank>(lb, ub);
|
||||
}
|
||||
|
||||
|
||||
// Helper function that converts slices to unit ranges
|
||||
template<typename T>
|
||||
Range _bz_makeRange(const T& r)
|
||||
{
|
||||
return Range(r);
|
||||
}
|
||||
|
||||
inline nilArraySection _bz_makeRange(const nilArraySection& r)
|
||||
{
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/** necessary because we can't have an #ifdef in the macros
|
||||
\todo convert to _bz_Indexpar. */
|
||||
template<typename T> struct _bz_IndexParameter {
|
||||
#ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
|
||||
typedef T type;
|
||||
#else
|
||||
typedef const T& type;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* There are resolution problems with the functions in this file that
|
||||
generate ET objects and the functions in stencilops.h that define
|
||||
the stencil operators. Because the operators are defined as
|
||||
all-encompassing templates, they will match to arrays with higher
|
||||
priority than the functions here will match to ETBase<..>. This
|
||||
means we must have explicit functions that match Arrays even though
|
||||
the general ETBase function would work. */
|
||||
|
||||
/** ET base class for applying a stencil to an expression. */
|
||||
template<typename P_expr, _bz_typename P_result>
|
||||
class _bz_StencilExpr {
|
||||
public:
|
||||
typedef P_expr T_expr;
|
||||
typedef P_result T_numtype;
|
||||
typedef T_expr T_ctorArg1;
|
||||
typedef int T_ctorArg2; // dummy
|
||||
|
||||
static const int
|
||||
numArrayOperands = T_expr::numArrayOperands,
|
||||
numTVOperands = T_expr::numTVOperands,
|
||||
numTMOperands = T_expr::numTMOperands,
|
||||
numIndexPlaceholders = T_expr::numIndexPlaceholders,
|
||||
/// vectorization of stencils is disabled by setting this to 0.
|
||||
minWidth = 0, //T_expr::minWidth,
|
||||
maxWidth = 0, //T_expr::maxWidth,
|
||||
rank_ = T_expr::rank_;
|
||||
|
||||
_bz_StencilExpr(const _bz_StencilExpr<T_expr, T_numtype>& a)
|
||||
: iter_(a.iter_)
|
||||
{ }
|
||||
|
||||
_bz_StencilExpr(BZ_ETPARM(T_expr) a)
|
||||
: iter_(a)
|
||||
{ }
|
||||
|
||||
_bz_StencilExpr(_bz_typename T_expr::T_ctorArg1 a)
|
||||
: iter_(a)
|
||||
{ }
|
||||
|
||||
#if BZ_TEMPLATE_CTOR_DOESNT_CAUSE_HAVOC
|
||||
template<typename T1>
|
||||
explicit _bz_StencilExpr(BZ_ETPARM(T1) a)
|
||||
: iter_(a)
|
||||
{ }
|
||||
#endif
|
||||
|
||||
int ascending(const int rank) const { return iter_.ascending(rank); }
|
||||
int ordering(const int rank) const { return iter_.ordering(rank); }
|
||||
int lbound(const int rank) const
|
||||
{
|
||||
return iter_.lbound(rank);
|
||||
}
|
||||
int ubound(const int rank) const
|
||||
{
|
||||
return iter_.ubound(rank);
|
||||
}
|
||||
|
||||
// defer calculation to lbound/ubound
|
||||
RectDomain<rank_> domain() const
|
||||
{
|
||||
TinyVector<int, rank_> lb, ub;
|
||||
for(int r=0; r<rank_; ++r) {
|
||||
lb[r]=lbound(r); ub[r]=ubound(r);
|
||||
}
|
||||
return RectDomain<rank_>(lb,ub);
|
||||
}
|
||||
|
||||
//T_numtype first_value() const { return iter_(iter_.lbound()); }
|
||||
|
||||
/** Vectorization doesn't make sense for stencils, so we say so. */
|
||||
bool isVectorAligned(diffType offset) const {
|
||||
return false; }
|
||||
|
||||
void push(int position)
|
||||
{
|
||||
iter_.push(position);
|
||||
}
|
||||
|
||||
void pop(int position)
|
||||
{
|
||||
iter_.pop(position);
|
||||
}
|
||||
|
||||
void advance()
|
||||
{
|
||||
iter_.advance();
|
||||
}
|
||||
|
||||
void advance(int n)
|
||||
{
|
||||
iter_.advance(n);
|
||||
}
|
||||
|
||||
void loadStride(int rank)
|
||||
{
|
||||
iter_.loadStride(rank);
|
||||
}
|
||||
|
||||
bool isUnitStride(int rank) const
|
||||
{ return iter_.isUnitStride(rank); }
|
||||
|
||||
bool isUnitStride() const
|
||||
{ return iter_.isUnitStride(); }
|
||||
|
||||
void advanceUnitStride()
|
||||
{
|
||||
iter_.advanceUnitStride();
|
||||
}
|
||||
|
||||
void moveTo(const TinyVector<int,_bz_StencilExpr::rank_>& i)
|
||||
{
|
||||
iter_.moveTo(i);
|
||||
}
|
||||
|
||||
bool canCollapse(int outerLoopRank, int innerLoopRank) const
|
||||
{
|
||||
// BZ_DEBUG_MESSAGE("_bz_StencilExpr<>::canCollapse");
|
||||
return iter_.canCollapse(outerLoopRank, innerLoopRank);
|
||||
}
|
||||
|
||||
diffType suggestStride(int rank) const
|
||||
{ return iter_.suggestStride(rank); }
|
||||
|
||||
bool isStride(int rank, diffType stride) const
|
||||
{ return iter_.isStride(rank,stride); }
|
||||
|
||||
void _bz_offsetData(sizeType i) { iter_._bz_offsetData(i); }
|
||||
|
||||
void prettyPrint(BZ_STD_SCOPE(string) &str) const
|
||||
{
|
||||
prettyPrintFormat format(true); /* Terse formatting by default */
|
||||
iter_.prettyPrint(str, format);
|
||||
}
|
||||
|
||||
template<typename T_shape>
|
||||
bool shapeCheck(const T_shape& shape) const
|
||||
{ return iter_.shapeCheck(shape); }
|
||||
|
||||
protected:
|
||||
_bz_StencilExpr() { }
|
||||
|
||||
// it needs to be mutable because in the "conceptually const"
|
||||
// methods shift and fastread we offset the iterator but undo it
|
||||
// later
|
||||
mutable P_expr iter_;
|
||||
};
|
||||
|
||||
/** ET base class for applying a stencil to an expression. */
|
||||
template<typename P_expr1, typename P_expr2, _bz_typename P_result>
|
||||
class _bz_StencilExpr2 {
|
||||
public:
|
||||
typedef P_expr1 T_expr1;
|
||||
typedef P_expr2 T_expr2;
|
||||
typedef _bz_typename T_expr1::T_numtype T_numtype1;
|
||||
typedef _bz_typename T_expr2::T_numtype T_numtype2;
|
||||
typedef P_result T_numtype;
|
||||
typedef T_expr1 T_ctorArg1;
|
||||
typedef T_expr2 T_ctorArg2;
|
||||
|
||||
static const int
|
||||
numArrayOperands = T_expr1::numArrayOperands
|
||||
+ T_expr2::numArrayOperands,
|
||||
numTVOperands = T_expr1::numTVOperands + T_expr2::numTVOperands,
|
||||
numTMOperands = T_expr1::numTMOperands + T_expr2::numTMOperands,
|
||||
numIndexPlaceholders = T_expr1::numIndexPlaceholders
|
||||
+ T_expr2::numIndexPlaceholders,
|
||||
/// vectorization of stencils is disabled by setting this to 0.
|
||||
minWidth = 0, //BZ_MIN(T_expr1::minWidth, T_expr2::minWidth),
|
||||
maxWidth = 0, //BZ_MAX(T_expr1::maxWidth, T_expr2::maxWidth),
|
||||
rank_ = BZ_MAX(T_expr1::rank_, T_expr2::rank_);
|
||||
|
||||
_bz_StencilExpr2(const _bz_StencilExpr2<T_expr1, T_expr2, T_numtype>& a)
|
||||
: iter1_(a.iter1_), iter2_(a.iter2_)
|
||||
{ }
|
||||
|
||||
_bz_StencilExpr2(BZ_ETPARM(T_expr1) a, BZ_ETPARM(T_expr2) b)
|
||||
: iter1_(a), iter2_(b)
|
||||
{ }
|
||||
|
||||
/*
|
||||
// what is this for?
|
||||
_bz_StencilExpr2(_bz_typename T_expr1::T_ctorArg1 a)
|
||||
: iter_(a)
|
||||
{ }
|
||||
*/
|
||||
|
||||
#if BZ_TEMPLATE_CTOR_DOESNT_CAUSE_HAVOC
|
||||
template<typename T1, typename T2>
|
||||
explicit _bz_StencilExpr2(BZ_ETPARM(T1) a, BZ_ETPARM(T2) b)
|
||||
: iter1_(a), iter2_(b)
|
||||
{ }
|
||||
#endif
|
||||
|
||||
int ascending(const int rank) const {
|
||||
return bounds::compute_ascending(rank, iter1_.ascending(rank), iter2_.ascending(rank));
|
||||
}
|
||||
|
||||
int ordering(const int rank) const {
|
||||
return bounds::compute_ordering(rank, iter1_.ordering(rank), iter2_.ordering(rank));
|
||||
}
|
||||
|
||||
int lbound(const int rank) const {
|
||||
return bounds::compute_lbound(rank, iter1_.lbound(rank), iter2_.lbound(rank));
|
||||
}
|
||||
|
||||
int ubound(const int rank) const {
|
||||
return bounds::compute_ubound(rank, iter1_.ubound(rank), iter2_.ubound(rank));
|
||||
}
|
||||
|
||||
// defer calculation to lbound/ubound
|
||||
RectDomain<rank_> domain() const
|
||||
{
|
||||
TinyVector<int, rank_> lb, ub;
|
||||
for(int r=0; r<rank_; ++r) {
|
||||
lb[r]=lbound(r); ub[r]=ubound(r);
|
||||
}
|
||||
return RectDomain<rank_>(lb,ub);
|
||||
}
|
||||
|
||||
/** Vectorization doesn't make sense for stencils, so we say so. */
|
||||
bool isVectorAligned(diffType offset) const {
|
||||
return false; }
|
||||
|
||||
void push(int position)
|
||||
{
|
||||
iter1_.push(position);
|
||||
iter2_.push(position);
|
||||
}
|
||||
|
||||
void pop(int position)
|
||||
{
|
||||
iter1_.pop(position);
|
||||
iter2_.pop(position);
|
||||
}
|
||||
|
||||
void advance()
|
||||
{
|
||||
iter1_.advance();
|
||||
iter2_.advance();
|
||||
}
|
||||
|
||||
void advance(int n)
|
||||
{
|
||||
iter1_.advance(n);
|
||||
iter2_.advance(n);
|
||||
}
|
||||
|
||||
void loadStride(int rank)
|
||||
{
|
||||
iter1_.loadStride(rank);
|
||||
iter2_.loadStride(rank);
|
||||
}
|
||||
|
||||
diffType suggestStride(int rank) const
|
||||
{
|
||||
diffType stride1 = iter1_.suggestStride(rank);
|
||||
diffType stride2 = iter2_.suggestStride(rank);
|
||||
return (stride1 > stride2) ? stride1 : stride2;
|
||||
}
|
||||
|
||||
bool isStride(int rank, diffType stride) const
|
||||
{
|
||||
return iter1_.isStride(rank,stride) && iter2_.isStride(rank,stride);
|
||||
}
|
||||
|
||||
bool isUnitStride(int rank) const
|
||||
{ return iter1_.isUnitStride(rank) && iter2_.isUnitStride(rank); }
|
||||
|
||||
bool isUnitStride() const
|
||||
{ return iter1_.isUnitStride() && iter2_.isUnitStride(); }
|
||||
|
||||
void advanceUnitStride()
|
||||
{
|
||||
iter1_.advanceUnitStride();
|
||||
iter2_.advanceUnitStride();
|
||||
}
|
||||
|
||||
bool canCollapse(int outerLoopRank, int innerLoopRank) const
|
||||
{
|
||||
return iter1_.canCollapse(outerLoopRank, innerLoopRank)
|
||||
&& iter2_.canCollapse(outerLoopRank, innerLoopRank);
|
||||
}
|
||||
|
||||
void moveTo(const TinyVector<int,rank_>& i)
|
||||
{
|
||||
iter1_.moveTo(i);
|
||||
iter2_.moveTo(i);
|
||||
}
|
||||
|
||||
void _bz_offsetData(sizeType i)
|
||||
{
|
||||
iter1_._bz_offsetData(i);
|
||||
iter2_._bz_offsetData(i);
|
||||
}
|
||||
|
||||
template<typename T_shape>
|
||||
bool shapeCheck(const T_shape& shape) const
|
||||
{ return iter1_.shapeCheck(shape) && iter2_.shapeCheck(shape); }
|
||||
|
||||
protected:
|
||||
_bz_StencilExpr2() { }
|
||||
|
||||
mutable P_expr1 iter1_;
|
||||
mutable P_expr2 iter2_;
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
// now include the generated file containing all the implementation classes.
|
||||
#include <blitz/array/stencil-classes.cc>
|
||||
|
||||
#endif // BZ_ARRAY_STENCIL_ET_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,614 @@
|
||||
/***************************************************************************
|
||||
* blitz/array/stencils.cc Apply stencils to arrays
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYSTENCILS_CC
|
||||
#define BZ_ARRAYSTENCILS_CC
|
||||
|
||||
#ifndef BZ_ARRAYSTENCILS_H
|
||||
#error <blitz/array/stencil.cc> must be included via <blitz/array/stencils.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// NEEDS_WORK:
|
||||
// o Need to allow scalar arguments as well as arrays
|
||||
// o Unit stride optimization
|
||||
// o Tiling
|
||||
// o Pass coordinate vector to stencil, so that where-like constructs
|
||||
// can depend on location
|
||||
// o Maybe allow expression templates to be passed as
|
||||
// array parameters?
|
||||
|
||||
/*
|
||||
* There are a lot of kludges in this code to work around the fact that
|
||||
* you can't have default template parameters with function templates.
|
||||
* Ideally, one would implement applyStencil(..) as:
|
||||
*
|
||||
* template<typename T_stencil, typename T_numtype1, typename T_array2,
|
||||
* class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
* class T_array7, typename T_array8, typename T_array9, typename T_array10,
|
||||
* class T_array11>
|
||||
* void applyStencil(const T_stencil& stencil, Array<T_numtype1,3>& A,
|
||||
* T_array2& B = _dummyArray, T_array3& C = _dummyArray, ......)
|
||||
*
|
||||
* and allow for up to (say) 11 arrays to be passed. But this doesn't
|
||||
* appear to be legal C++. Instead, 11 versions of applyStencil are
|
||||
* provided, each one with a different number of array parameters,
|
||||
* and these stubs fill in the _dummyArray parameters and invoke
|
||||
* applyStencil_imp().
|
||||
*/
|
||||
|
||||
template<int N_rank, typename T_numtype1, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7, typename T_array8, typename T_array9, typename T_array10,
|
||||
class T_array11>
|
||||
void checkShapes(const Array<T_numtype1,N_rank>& BZ_DEBUG_PARAM(A),
|
||||
const T_array2& BZ_DEBUG_PARAM(B), const T_array3& BZ_DEBUG_PARAM(C),
|
||||
const T_array4& BZ_DEBUG_PARAM(D), const T_array5& BZ_DEBUG_PARAM(E),
|
||||
const T_array6& BZ_DEBUG_PARAM(F), const T_array7& BZ_DEBUG_PARAM(G),
|
||||
const T_array8& BZ_DEBUG_PARAM(H), const T_array9& BZ_DEBUG_PARAM(I),
|
||||
const T_array10& BZ_DEBUG_PARAM(J), const T_array11& BZ_DEBUG_PARAM(K))
|
||||
{
|
||||
BZPRECONDITION(areShapesConformable(A.shape(),B.shape())
|
||||
&& areShapesConformable(A.shape(),C.shape())
|
||||
&& areShapesConformable(A.shape(),D.shape())
|
||||
&& areShapesConformable(A.shape(),E.shape())
|
||||
&& areShapesConformable(A.shape(),F.shape())
|
||||
&& areShapesConformable(A.shape(),G.shape())
|
||||
&& areShapesConformable(A.shape(),H.shape())
|
||||
&& areShapesConformable(A.shape(),I.shape())
|
||||
&& areShapesConformable(A.shape(),J.shape())
|
||||
&& areShapesConformable(A.shape(),K.shape()));
|
||||
}
|
||||
|
||||
template<typename T_extent, int N_rank,
|
||||
class T_stencil, typename T_numtype1, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7, typename T_array8, typename T_array9, typename T_array10,
|
||||
class T_array11>
|
||||
void calcStencilExtent(T_extent& At, const T_stencil& stencil,
|
||||
const Array<T_numtype1,N_rank>&,
|
||||
const T_array2&, const T_array3&, const T_array4&, const T_array5&,
|
||||
const T_array6&, const T_array7&, const T_array8&, const T_array9&,
|
||||
const T_array10&, const T_array11&)
|
||||
{
|
||||
// Interrogate the stencil to find out its extent
|
||||
_bz_typename stencilExtent_traits<T_array2>::T_stencilExtent Bt;
|
||||
_bz_typename stencilExtent_traits<T_array3>::T_stencilExtent Ct;
|
||||
_bz_typename stencilExtent_traits<T_array4>::T_stencilExtent Dt;
|
||||
_bz_typename stencilExtent_traits<T_array5>::T_stencilExtent Et;
|
||||
_bz_typename stencilExtent_traits<T_array6>::T_stencilExtent Ft;
|
||||
_bz_typename stencilExtent_traits<T_array7>::T_stencilExtent Gt;
|
||||
_bz_typename stencilExtent_traits<T_array8>::T_stencilExtent Ht;
|
||||
_bz_typename stencilExtent_traits<T_array9>::T_stencilExtent It;
|
||||
_bz_typename stencilExtent_traits<T_array10>::T_stencilExtent Jt;
|
||||
_bz_typename stencilExtent_traits<T_array11>::T_stencilExtent Kt;
|
||||
|
||||
stencil.apply(At, Bt, Ct, Dt, Et, Ft, Gt, Ht, It, Jt, Kt);
|
||||
At.combine(Bt);
|
||||
At.combine(Ct);
|
||||
At.combine(Dt);
|
||||
At.combine(Et);
|
||||
At.combine(Ft);
|
||||
At.combine(Gt);
|
||||
At.combine(Ht);
|
||||
At.combine(It);
|
||||
At.combine(Jt);
|
||||
At.combine(Kt);
|
||||
}
|
||||
|
||||
template<int N_rank, typename T_stencil, typename T_numtype1, typename T_array2>
|
||||
RectDomain<N_rank> interiorDomain(const T_stencil& stencil,
|
||||
const Array<T_numtype1,N_rank>& A,
|
||||
const T_array2& B)
|
||||
{
|
||||
RectDomain<N_rank> domain = A.domain();
|
||||
|
||||
// Interrogate the stencil to find out its extent
|
||||
stencilExtent<3, T_numtype1> At;
|
||||
calcStencilExtent(At, stencil, A, B, _dummyArray, _dummyArray,
|
||||
_dummyArray, _dummyArray, _dummyArray, _dummyArray, _dummyArray,
|
||||
_dummyArray, _dummyArray);
|
||||
|
||||
// Shrink the domain according to the stencil size
|
||||
TinyVector<int,N_rank> lbound, ubound;
|
||||
lbound = domain.lbound() - (At.min)();
|
||||
ubound = domain.ubound() - (At.max)();
|
||||
return RectDomain<N_rank>(lbound,ubound);
|
||||
}
|
||||
|
||||
template<int hasExtents>
|
||||
struct _getStencilExtent {
|
||||
template<int N_rank,
|
||||
class T_stencil, typename T_numtype1, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7, typename T_array8, typename T_array9, typename T_array10,
|
||||
class T_array11>
|
||||
static void getStencilExtent(TinyVector<int,N_rank>& minb,
|
||||
TinyVector<int,N_rank>& maxb,
|
||||
const T_stencil& stencil, Array<T_numtype1,N_rank>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D, T_array5& E, T_array6& F,
|
||||
T_array7& G, T_array8& H, T_array9& I, T_array10& J, T_array11& K)
|
||||
{
|
||||
// Interrogate the stencil to find out its extent
|
||||
stencilExtent<N_rank, T_numtype1> At;
|
||||
calcStencilExtent(At, stencil, A, B, C, D, E, F, G, H, I, J, K);
|
||||
minb = (At.min)();
|
||||
maxb = (At.max)();
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _getStencilExtent<1> {
|
||||
template<int N_rank,
|
||||
class T_stencil, typename T_numtype1, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7, typename T_array8, typename T_array9, typename T_array10,
|
||||
class T_array11>
|
||||
static inline void getStencilExtent(TinyVector<int,N_rank>& minb,
|
||||
TinyVector<int,N_rank>& maxb,
|
||||
const T_stencil& stencil, Array<T_numtype1,N_rank>&,
|
||||
T_array2&, T_array3&, T_array4&, T_array5&, T_array6&,
|
||||
T_array7&, T_array8&, T_array9&, T_array10&, T_array11&)
|
||||
{
|
||||
stencil.getExtent(minb, maxb);
|
||||
}
|
||||
};
|
||||
|
||||
template<int N_rank,
|
||||
class T_stencil, typename T_numtype1, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7, typename T_array8, typename T_array9, typename T_array10,
|
||||
class T_array11>
|
||||
inline void getStencilExtent(TinyVector<int,N_rank>& minb,
|
||||
TinyVector<int,N_rank>& maxb,
|
||||
const T_stencil& stencil, Array<T_numtype1,N_rank>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D, T_array5& E, T_array6& F,
|
||||
T_array7& G, T_array8& H, T_array9& I, T_array10& J, T_array11& K)
|
||||
{
|
||||
_getStencilExtent<T_stencil::hasExtent>::getStencilExtent(
|
||||
minb, maxb, stencil, A, B, C, D, E, F, G, H, I, J, K);
|
||||
}
|
||||
|
||||
/*
|
||||
* This version applies a stencil to a set of 3D arrays. Up to 11 arrays
|
||||
* may be used. Any unused arrays are turned into dummyArray objects.
|
||||
* Operations on dummyArray objects are translated into no-ops.
|
||||
*/
|
||||
template<typename T_stencil, typename T_numtype1, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7, typename T_array8, typename T_array9, typename T_array10,
|
||||
class T_array11>
|
||||
void applyStencil_imp(const T_stencil& stencil, Array<T_numtype1,3>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D, T_array5& E, T_array6& F,
|
||||
T_array7& G, T_array8& H, T_array9& I, T_array10& J, T_array11& K)
|
||||
{
|
||||
checkShapes(A,B,C,D,E,F,G,H,I,J,K);
|
||||
|
||||
// Determine stencil extent
|
||||
TinyVector<int,3> minb, maxb;
|
||||
getStencilExtent(minb, maxb, stencil, A, B, C, D, E, F, G, H, I, J, K);
|
||||
|
||||
// Now determine the subdomain over which the stencil
|
||||
// can be applied without worrying about overrunning the
|
||||
// boundaries of the array
|
||||
int stencil_lbound0 = minb(0);
|
||||
int stencil_lbound1 = minb(1);
|
||||
int stencil_lbound2 = minb(2);
|
||||
|
||||
int stencil_ubound0 = maxb(0);
|
||||
int stencil_ubound1 = maxb(1);
|
||||
int stencil_ubound2 = maxb(2);
|
||||
|
||||
int lbound0 = (extrema::max)(A.lbound(0), A.lbound(0) - stencil_lbound0);
|
||||
int lbound1 = (extrema::max)(A.lbound(1), A.lbound(1) - stencil_lbound1);
|
||||
int lbound2 = (extrema::max)(A.lbound(2), A.lbound(2) - stencil_lbound2);
|
||||
|
||||
int ubound0 = (extrema::min)(A.ubound(0), A.ubound(0) - stencil_ubound0);
|
||||
int ubound1 = (extrema::min)(A.ubound(1), A.ubound(1) - stencil_ubound1);
|
||||
int ubound2 = (extrema::min)(A.ubound(2), A.ubound(2) - stencil_ubound2);
|
||||
|
||||
#if 0
|
||||
cout << "Stencil bounds are:" << endl
|
||||
<< lbound0 << '\t' << ubound0 << endl
|
||||
<< lbound1 << '\t' << ubound1 << endl
|
||||
<< lbound2 << '\t' << ubound2 << endl;
|
||||
#endif
|
||||
|
||||
// Now do the actual loop
|
||||
FastArrayIterator<T_numtype1,3> Aiter(A);
|
||||
_bz_typename T_array2::T_iterator Biter(B);
|
||||
_bz_typename T_array3::T_iterator Citer(C);
|
||||
_bz_typename T_array4::T_iterator Diter(D);
|
||||
_bz_typename T_array5::T_iterator Eiter(E);
|
||||
_bz_typename T_array6::T_iterator Fiter(F);
|
||||
_bz_typename T_array7::T_iterator Giter(G);
|
||||
_bz_typename T_array8::T_iterator Hiter(H);
|
||||
_bz_typename T_array9::T_iterator Iiter(I);
|
||||
_bz_typename T_array10::T_iterator Jiter(J);
|
||||
_bz_typename T_array11::T_iterator Kiter(K);
|
||||
|
||||
// Load the strides for the innermost loop
|
||||
Aiter.loadStride(2);
|
||||
Biter.loadStride(2);
|
||||
Citer.loadStride(2);
|
||||
Diter.loadStride(2);
|
||||
Eiter.loadStride(2);
|
||||
Fiter.loadStride(2);
|
||||
Giter.loadStride(2);
|
||||
Hiter.loadStride(2);
|
||||
Iiter.loadStride(2);
|
||||
Jiter.loadStride(2);
|
||||
Kiter.loadStride(2);
|
||||
|
||||
for (int i=lbound0; i <= ubound0; ++i)
|
||||
{
|
||||
for (int j=lbound1; j <= ubound1; ++j)
|
||||
{
|
||||
Aiter.moveTo(i,j,lbound2);
|
||||
Biter.moveTo(i,j,lbound2);
|
||||
Citer.moveTo(i,j,lbound2);
|
||||
Diter.moveTo(i,j,lbound2);
|
||||
Eiter.moveTo(i,j,lbound2);
|
||||
Fiter.moveTo(i,j,lbound2);
|
||||
Giter.moveTo(i,j,lbound2);
|
||||
Hiter.moveTo(i,j,lbound2);
|
||||
Iiter.moveTo(i,j,lbound2);
|
||||
Jiter.moveTo(i,j,lbound2);
|
||||
Kiter.moveTo(i,j,lbound2);
|
||||
|
||||
for (int k=lbound2; k <= ubound2; ++k)
|
||||
{
|
||||
stencil.apply(Aiter, Biter, Citer, Diter, Eiter, Fiter, Giter,
|
||||
Hiter, Iiter, Jiter, Kiter);
|
||||
|
||||
Aiter.advance();
|
||||
Biter.advance();
|
||||
Citer.advance();
|
||||
Diter.advance();
|
||||
Eiter.advance();
|
||||
Fiter.advance();
|
||||
Giter.advance();
|
||||
Hiter.advance();
|
||||
Iiter.advance();
|
||||
Jiter.advance();
|
||||
Kiter.advance();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This version applies a stencil to a set of 2D arrays. Up to 11 arrays
|
||||
* may be used. Any unused arrays are turned into dummyArray objects.
|
||||
* Operations on dummyArray objects are translated into no-ops.
|
||||
*/
|
||||
template<typename T_stencil, typename T_numtype1, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7, typename T_array8, typename T_array9, typename T_array10,
|
||||
class T_array11>
|
||||
void applyStencil_imp(const T_stencil& stencil, Array<T_numtype1,2>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D, T_array5& E, T_array6& F,
|
||||
T_array7& G, T_array8& H, T_array9& I, T_array10& J, T_array11& K)
|
||||
{
|
||||
checkShapes(A,B,C,D,E,F,G,H,I,J,K);
|
||||
|
||||
// Determine stencil extent
|
||||
TinyVector<int,2> minb, maxb;
|
||||
getStencilExtent(minb, maxb, stencil, A, B, C, D, E, F, G, H, I, J, K);
|
||||
|
||||
// Now determine the subdomain over which the stencil
|
||||
// can be applied without worrying about overrunning the
|
||||
// boundaries of the array
|
||||
int stencil_lbound0 = minb(0);
|
||||
int stencil_lbound1 = minb(1);
|
||||
|
||||
int stencil_ubound0 = maxb(0);
|
||||
int stencil_ubound1 = maxb(1);
|
||||
|
||||
int lbound0 = (extrema::max)(A.lbound(0), A.lbound(0) - stencil_lbound0);
|
||||
int lbound1 = (extrema::max)(A.lbound(1), A.lbound(1) - stencil_lbound1);
|
||||
|
||||
int ubound0 = (extrema::min)(A.ubound(0), A.ubound(0) - stencil_ubound0);
|
||||
int ubound1 = (extrema::min)(A.ubound(1), A.ubound(1) - stencil_ubound1);
|
||||
|
||||
#if 0
|
||||
cout << "Stencil bounds are:" << endl
|
||||
<< lbound0 << '\t' << ubound0 << endl
|
||||
<< lbound1 << '\t' << ubound1 << endl;
|
||||
#endif
|
||||
|
||||
// Now do the actual loop
|
||||
FastArrayIterator<T_numtype1,2> Aiter(A);
|
||||
_bz_typename T_array2::T_iterator Biter(B);
|
||||
_bz_typename T_array3::T_iterator Citer(C);
|
||||
_bz_typename T_array4::T_iterator Diter(D);
|
||||
_bz_typename T_array5::T_iterator Eiter(E);
|
||||
_bz_typename T_array6::T_iterator Fiter(F);
|
||||
_bz_typename T_array7::T_iterator Giter(G);
|
||||
_bz_typename T_array8::T_iterator Hiter(H);
|
||||
_bz_typename T_array9::T_iterator Iiter(I);
|
||||
_bz_typename T_array10::T_iterator Jiter(J);
|
||||
_bz_typename T_array11::T_iterator Kiter(K);
|
||||
|
||||
// Load the strides for the innermost loop
|
||||
Aiter.loadStride(1);
|
||||
Biter.loadStride(1);
|
||||
Citer.loadStride(1);
|
||||
Diter.loadStride(1);
|
||||
Eiter.loadStride(1);
|
||||
Fiter.loadStride(1);
|
||||
Giter.loadStride(1);
|
||||
Hiter.loadStride(1);
|
||||
Iiter.loadStride(1);
|
||||
Jiter.loadStride(1);
|
||||
Kiter.loadStride(1);
|
||||
|
||||
for (int i=lbound0; i <= ubound0; ++i)
|
||||
{
|
||||
Aiter.moveTo(i,lbound1);
|
||||
Biter.moveTo(i,lbound1);
|
||||
Citer.moveTo(i,lbound1);
|
||||
Diter.moveTo(i,lbound1);
|
||||
Eiter.moveTo(i,lbound1);
|
||||
Fiter.moveTo(i,lbound1);
|
||||
Giter.moveTo(i,lbound1);
|
||||
Hiter.moveTo(i,lbound1);
|
||||
Iiter.moveTo(i,lbound1);
|
||||
Jiter.moveTo(i,lbound1);
|
||||
Kiter.moveTo(i,lbound1);
|
||||
|
||||
for (int k=lbound1; k <= ubound1; ++k)
|
||||
{
|
||||
stencil.apply(Aiter, Biter, Citer, Diter, Eiter, Fiter, Giter,
|
||||
Hiter, Iiter, Jiter, Kiter);
|
||||
|
||||
Aiter.advance();
|
||||
Biter.advance();
|
||||
Citer.advance();
|
||||
Diter.advance();
|
||||
Eiter.advance();
|
||||
Fiter.advance();
|
||||
Giter.advance();
|
||||
Hiter.advance();
|
||||
Iiter.advance();
|
||||
Jiter.advance();
|
||||
Kiter.advance();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This version applies a stencil to a set of 1D arrays. Up to 11 arrays
|
||||
* may be used. Any unused arrays are turned into dummyArray objects.
|
||||
* Operations on dummyArray objects are translated into no-ops.
|
||||
*/
|
||||
template<typename T_stencil, typename T_numtype1, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7, typename T_array8, typename T_array9, typename T_array10,
|
||||
class T_array11>
|
||||
void applyStencil_imp(const T_stencil& stencil, Array<T_numtype1,1>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D, T_array5& E, T_array6& F,
|
||||
T_array7& G, T_array8& H, T_array9& I, T_array10& J, T_array11& K)
|
||||
{
|
||||
checkShapes(A,B,C,D,E,F,G,H,I,J,K);
|
||||
|
||||
// Determine stencil extent
|
||||
TinyVector<int,1> minb, maxb;
|
||||
getStencilExtent(minb, maxb, stencil, A, B, C, D, E, F, G, H, I, J, K);
|
||||
|
||||
// Now determine the subdomain over which the stencil
|
||||
// can be applied without worrying about overrunning the
|
||||
// boundaries of the array
|
||||
int stencil_lbound0 = minb(0);
|
||||
int stencil_ubound0 = maxb(0);
|
||||
|
||||
int lbound0 = (extrema::max)(A.lbound(0), A.lbound(0) - stencil_lbound0);
|
||||
int ubound0 = (extrema::min)(A.ubound(0), A.ubound(0) - stencil_ubound0);
|
||||
|
||||
#if 0
|
||||
cout << "Stencil bounds are:" << endl
|
||||
<< lbound0 << '\t' << ubound0 << endl;
|
||||
#endif
|
||||
|
||||
// Now do the actual loop
|
||||
FastArrayIterator<T_numtype1,1> Aiter(A);
|
||||
_bz_typename T_array2::T_iterator Biter(B);
|
||||
_bz_typename T_array3::T_iterator Citer(C);
|
||||
_bz_typename T_array4::T_iterator Diter(D);
|
||||
_bz_typename T_array5::T_iterator Eiter(E);
|
||||
_bz_typename T_array6::T_iterator Fiter(F);
|
||||
_bz_typename T_array7::T_iterator Giter(G);
|
||||
_bz_typename T_array8::T_iterator Hiter(H);
|
||||
_bz_typename T_array9::T_iterator Iiter(I);
|
||||
_bz_typename T_array10::T_iterator Jiter(J);
|
||||
_bz_typename T_array11::T_iterator Kiter(K);
|
||||
|
||||
// Load the strides for the innermost loop
|
||||
Aiter.loadStride(0);
|
||||
Biter.loadStride(0);
|
||||
Citer.loadStride(0);
|
||||
Diter.loadStride(0);
|
||||
Eiter.loadStride(0);
|
||||
Fiter.loadStride(0);
|
||||
Giter.loadStride(0);
|
||||
Hiter.loadStride(0);
|
||||
Iiter.loadStride(0);
|
||||
Jiter.loadStride(0);
|
||||
Kiter.loadStride(0);
|
||||
|
||||
// Patch from Derrick Bass
|
||||
Aiter.moveTo(lbound0);
|
||||
Biter.moveTo(lbound0);
|
||||
Citer.moveTo(lbound0);
|
||||
Diter.moveTo(lbound0);
|
||||
Eiter.moveTo(lbound0);
|
||||
Fiter.moveTo(lbound0);
|
||||
Giter.moveTo(lbound0);
|
||||
Hiter.moveTo(lbound0);
|
||||
Iiter.moveTo(lbound0);
|
||||
Jiter.moveTo(lbound0);
|
||||
Kiter.moveTo(lbound0);
|
||||
|
||||
for (int i=lbound0; i <= ubound0; ++i)
|
||||
{
|
||||
stencil.apply(Aiter, Biter, Citer, Diter, Eiter, Fiter, Giter,
|
||||
Hiter, Iiter, Jiter, Kiter);
|
||||
|
||||
Aiter.advance();
|
||||
Biter.advance();
|
||||
Citer.advance();
|
||||
Diter.advance();
|
||||
Eiter.advance();
|
||||
Fiter.advance();
|
||||
Giter.advance();
|
||||
Hiter.advance();
|
||||
Iiter.advance();
|
||||
Jiter.advance();
|
||||
Kiter.advance();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* These 11 versions of applyStencil handle from 1 to 11 array parameters.
|
||||
* They pad their argument list with enough dummyArray objects to call
|
||||
* applyStencil_imp with 11 array parameters.
|
||||
*/
|
||||
template<typename T_stencil, typename T_numtype1, int N_rank>
|
||||
inline void applyStencil(const T_stencil& stencil, Array<T_numtype1,N_rank>& A)
|
||||
{
|
||||
applyStencil_imp(stencil, A, _dummyArray, _dummyArray,
|
||||
_dummyArray, _dummyArray, _dummyArray, _dummyArray,
|
||||
_dummyArray, _dummyArray, _dummyArray, _dummyArray);
|
||||
}
|
||||
|
||||
template<typename T_stencil, typename T_numtype1, int N_rank, typename T_array2>
|
||||
inline void applyStencil(const T_stencil& stencil, Array<T_numtype1,N_rank>& A,
|
||||
T_array2& B)
|
||||
{
|
||||
applyStencil_imp(stencil, A, B, _dummyArray, _dummyArray,
|
||||
_dummyArray, _dummyArray, _dummyArray, _dummyArray,
|
||||
_dummyArray, _dummyArray, _dummyArray);
|
||||
}
|
||||
|
||||
template<typename T_stencil, typename T_numtype1, int N_rank, typename T_array2,
|
||||
class T_array3>
|
||||
inline void applyStencil(const T_stencil& stencil, Array<T_numtype1,N_rank>& A,
|
||||
T_array2& B, T_array3& C)
|
||||
{
|
||||
applyStencil_imp(stencil, A, B, C, _dummyArray, _dummyArray,
|
||||
_dummyArray, _dummyArray, _dummyArray, _dummyArray, _dummyArray,
|
||||
_dummyArray);
|
||||
}
|
||||
|
||||
template<typename T_stencil, typename T_numtype1, int N_rank, typename T_array2,
|
||||
class T_array3, typename T_array4>
|
||||
inline void applyStencil(const T_stencil& stencil, Array<T_numtype1,N_rank>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D)
|
||||
{
|
||||
applyStencil_imp(stencil, A, B, C, D, _dummyArray, _dummyArray,
|
||||
_dummyArray, _dummyArray, _dummyArray, _dummyArray, _dummyArray);
|
||||
}
|
||||
|
||||
template<typename T_stencil, typename T_numtype1, int N_rank, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5>
|
||||
inline void applyStencil(const T_stencil& stencil, Array<T_numtype1,N_rank>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D, T_array5& E)
|
||||
{
|
||||
applyStencil_imp(stencil, A, B, C, D, E, _dummyArray,
|
||||
_dummyArray, _dummyArray, _dummyArray, _dummyArray, _dummyArray);
|
||||
}
|
||||
|
||||
template<typename T_stencil, typename T_numtype1, int N_rank, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6>
|
||||
inline void applyStencil(const T_stencil& stencil, Array<T_numtype1,N_rank>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D, T_array5& E, T_array6& F)
|
||||
{
|
||||
applyStencil_imp(stencil, A, B, C, D, E, F,
|
||||
_dummyArray, _dummyArray, _dummyArray, _dummyArray, _dummyArray);
|
||||
}
|
||||
|
||||
template<typename T_stencil, typename T_numtype1, int N_rank, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7>
|
||||
inline void applyStencil(const T_stencil& stencil, Array<T_numtype1,N_rank>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D, T_array5& E, T_array6& F,
|
||||
T_array7& G)
|
||||
{
|
||||
applyStencil_imp(stencil, A, B, C, D, E, F, G,
|
||||
_dummyArray, _dummyArray, _dummyArray, _dummyArray);
|
||||
}
|
||||
|
||||
template<typename T_stencil, typename T_numtype1, int N_rank, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7, typename T_array8>
|
||||
inline void applyStencil(const T_stencil& stencil, Array<T_numtype1,N_rank>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D, T_array5& E, T_array6& F,
|
||||
T_array7& G, T_array8& H)
|
||||
{
|
||||
applyStencil_imp(stencil, A, B, C, D, E, F, G, H,
|
||||
_dummyArray, _dummyArray, _dummyArray);
|
||||
}
|
||||
|
||||
template<typename T_stencil, typename T_numtype1, int N_rank, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7, typename T_array8, typename T_array9>
|
||||
inline void applyStencil(const T_stencil& stencil, Array<T_numtype1,N_rank>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D, T_array5& E, T_array6& F,
|
||||
T_array7& G, T_array8& H, T_array9& I)
|
||||
{
|
||||
applyStencil_imp(stencil, A, B, C, D, E, F, G, H, I,
|
||||
_dummyArray, _dummyArray);
|
||||
}
|
||||
|
||||
template<typename T_stencil, typename T_numtype1, int N_rank, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7, typename T_array8, typename T_array9, typename T_array10>
|
||||
inline void applyStencil(const T_stencil& stencil, Array<T_numtype1,N_rank>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D, T_array5& E, T_array6& F,
|
||||
T_array7& G, T_array8& H, T_array9& I, T_array10& J)
|
||||
{
|
||||
applyStencil_imp(stencil, A, B, C, D, E, F, G, H, I, J,
|
||||
_dummyArray);
|
||||
}
|
||||
|
||||
template<typename T_stencil, typename T_numtype1, int N_rank, typename T_array2,
|
||||
class T_array3, typename T_array4, typename T_array5, typename T_array6,
|
||||
class T_array7, typename T_array8, typename T_array9, typename T_array10,
|
||||
class T_array11>
|
||||
inline void applyStencil(const T_stencil& stencil, Array<T_numtype1,N_rank>& A,
|
||||
T_array2& B, T_array3& C, T_array4& D, T_array5& E, T_array6& F,
|
||||
T_array7& G, T_array8& H, T_array9& I, T_array10& J, T_array11& K)
|
||||
{
|
||||
applyStencil_imp(stencil, A, B, C, D, E, F, G, H, I, J, K);
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYSTENCIL_CC
|
||||
@@ -0,0 +1,348 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/stencils.h Stencils for arrays
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYSTENCILS_H
|
||||
#define BZ_ARRAYSTENCILS_H
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/stencils.h> must be included after <blitz/array.h>
|
||||
#endif
|
||||
|
||||
#include <blitz/array/stencilops.h>
|
||||
|
||||
// NEEDS_WORK: currently stencilExtent returns int(1). What if the
|
||||
// stencil contains calls to math functions, or divisions, etc.?
|
||||
// Should at least return a number of the appropriate type. Probably
|
||||
// return a sequence of quasi-random floating point numbers.
|
||||
|
||||
/*
|
||||
* These macros make it easier for users to declare stencil objects.
|
||||
* The syntax is:
|
||||
*
|
||||
* BZ_DECLARE_STENCILN(stencilname, Array1, Array2, ..., ArrayN)
|
||||
* // stencil operations go here
|
||||
* BZ_END_STENCIL
|
||||
*/
|
||||
|
||||
#define BZ_DECLARE_STENCIL2(name,A,B) \
|
||||
struct name { \
|
||||
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6, \
|
||||
typename T7,typename T8,typename T9,typename T10,typename T11> \
|
||||
static inline void apply(T1& A, T2& B, T3, T4, T5, T6, T7, T8, T9, T10, T11) \
|
||||
{
|
||||
|
||||
#define BZ_END_STENCIL_WITH_SHAPE(MINS,MAXS) } \
|
||||
template<int N> \
|
||||
void getExtent(BZ_BLITZ_SCOPE(TinyVector)<int,N>& minb, \
|
||||
BZ_BLITZ_SCOPE(TinyVector)<int,N>& maxb) const \
|
||||
{ \
|
||||
minb = MINS; \
|
||||
maxb = MAXS; \
|
||||
} \
|
||||
static const bool hasExtent = true; \
|
||||
};
|
||||
|
||||
#define BZ_END_STENCIL } static const bool hasExtent = false; };
|
||||
#define BZ_STENCIL_END BZ_END_STENCIL
|
||||
|
||||
#define BZ_DECLARE_STENCIL3(name,A,B,C) \
|
||||
struct name { \
|
||||
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6, \
|
||||
typename T7,typename T8,typename T9,typename T10,typename T11> \
|
||||
static inline void apply(T1& A, T2& B, T3& C, T4, T5, T6, T7, T8, T9, \
|
||||
T10, T11) \
|
||||
{
|
||||
|
||||
#define BZ_DECLARE_STENCIL4(name,A,B,C,D) \
|
||||
struct name { \
|
||||
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6, \
|
||||
typename T7,typename T8,typename T9,typename T10,typename T11> \
|
||||
static inline void apply(T1& A, T2& B, T3& C, T4& D, T5, T6, T7, \
|
||||
T8, T9, T10, T11) \
|
||||
{
|
||||
|
||||
#define BZ_DECLARE_STENCIL5(name,A,B,C,D,E) \
|
||||
struct name { \
|
||||
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6, \
|
||||
typename T7,typename T8,typename T9,typename T10,typename T11> \
|
||||
static inline void apply(T1& A, T2& B, T3& C, T4& D, T5& E, T6, T7, T8, \
|
||||
T9, T10, T11) \
|
||||
{
|
||||
|
||||
#define BZ_DECLARE_STENCIL6(name,A,B,C,D,E,F) \
|
||||
struct name { \
|
||||
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6, \
|
||||
typename T7,typename T8,typename T9,typename T10,typename T11> \
|
||||
static inline void apply(T1& A, T2& B, T3& C, T4& D, T5& E, T6& F, \
|
||||
T7, T8, T9, T10, T11) \
|
||||
{
|
||||
|
||||
#define BZ_DECLARE_STENCIL7(name,A,B,C,D,E,F,G) \
|
||||
struct name { \
|
||||
template<typename T1,typename T2,typename T3,typename T4, \
|
||||
typename T5,typename T6,typename T7,typename T8,typename T9,typename T10,typename T11> \
|
||||
static inline void apply(T1& A, T2& B, T3& C, T4& D, T5& E, T6& F, T7& G, \
|
||||
T8, T9, T10, T11) \
|
||||
{
|
||||
|
||||
#define BZ_DECLARE_STENCIL8(name,A,B,C,D,E,F,G,H) \
|
||||
struct name { \
|
||||
template<typename T1,typename T2,typename T3,typename T4, \
|
||||
typename T5,typename T6,typename T7,typename T8,typename T9,typename T10,typename T11> \
|
||||
static inline void apply(T1& A, T2& B, T3& C, T4& D, T5& E, T6& F, T7& G, \
|
||||
T8& H, T9, T10, T11) \
|
||||
{
|
||||
|
||||
#define BZ_DECLARE_STENCIL9(name,A,B,C,D,E,F,G,H,I) \
|
||||
struct name { \
|
||||
template<typename T1,typename T2,typename T3,typename T4, \
|
||||
typename T5,typename T6,typename T7,typename T8,typename T9,typename T10, \
|
||||
typename T11> \
|
||||
static inline void apply(T1& A, T2& B, T3& C, T4& D, T5& E, T6& F, T7& G, \
|
||||
T8& H, T9& I, T10, T11) \
|
||||
{
|
||||
|
||||
#define BZ_DECLARE_STENCIL10(name,A,B,C,D,E,F,G,H,I,J) \
|
||||
struct name { \
|
||||
template<typename T1,typename T2,typename T3,typename T4, \
|
||||
typename T5,typename T6,typename T7,typename T8,typename T9,typename T10,typename T11> \
|
||||
static inline void apply(T1& A, T2& B, T3& C, T4& D, T5& E, T6& F, T7& G, \
|
||||
T8& H, T9& I, T10& J, T11) \
|
||||
{
|
||||
|
||||
#define BZ_DECLARE_STENCIL11(name,A,B,C,D,E,F,G,H,I,J,K) \
|
||||
struct name { \
|
||||
template<typename T1,typename T2,typename T3,typename T4, \
|
||||
typename T5,typename T6,typename T7,typename T8,typename T9,typename T10, \
|
||||
typename T11> \
|
||||
static inline void apply(T1& A, T2& B, T3& C, T4& D, T5& E, T6& F, T7& G, \
|
||||
T8& H, T9& I, T10& J, T11& K) \
|
||||
{
|
||||
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
|
||||
/*
|
||||
* dummyArray is used to provide "dummy" padding parameters to applyStencil(),
|
||||
* so that any number of arrays (up to 11) can be given as arguments.
|
||||
*/
|
||||
|
||||
template<typename T> class dummy;
|
||||
|
||||
struct dummyArray {
|
||||
typedef dummy<double> T_iterator;
|
||||
|
||||
const dummyArray& shape() const { return *this; }
|
||||
};
|
||||
|
||||
_bz_global dummyArray _dummyArray;
|
||||
|
||||
/*
|
||||
* This dummy class pretends to be a scalar of type T, or an array iterator
|
||||
* of type T, but really does nothing.
|
||||
*/
|
||||
template<typename T>
|
||||
class dummy {
|
||||
public:
|
||||
dummy() { }
|
||||
|
||||
dummy(T value)
|
||||
: value_(value)
|
||||
{ }
|
||||
|
||||
dummy(const dummyArray&)
|
||||
{ }
|
||||
|
||||
operator T() const { return value_; };
|
||||
|
||||
template<typename T2>
|
||||
void operator=(T2) { }
|
||||
|
||||
_bz_typename multicomponent_traits<T>::T_element operator[](int i) const
|
||||
{ return value_[i]; }
|
||||
|
||||
void loadStride(int) { }
|
||||
void moveTo(int) { }
|
||||
void moveTo(int,int) { }
|
||||
void moveTo(int,int,int) { }
|
||||
void moveTo(int,int,int,int) { }
|
||||
void advance() { }
|
||||
T shift(int,int) { return T(); }
|
||||
|
||||
private:
|
||||
T value_;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* The stencilExtent object is passed to stencil objects to find out
|
||||
* the spatial extent of the stencil. It pretends it's an array,
|
||||
* but really it's just recording the locations of the array reads
|
||||
* via operator().
|
||||
*/
|
||||
|
||||
template<int N_rank,typename P_numtype>
|
||||
class stencilExtent : public ETBase<stencilExtent<N_rank, P_numtype> > {
|
||||
public:
|
||||
typedef P_numtype T_numtype;
|
||||
|
||||
stencilExtent()
|
||||
{
|
||||
min_ = 0;
|
||||
max_ = 0;
|
||||
}
|
||||
|
||||
dummy<T_numtype> operator()(int i) const
|
||||
{
|
||||
update(0, i);
|
||||
return dummy<T_numtype>(1);
|
||||
}
|
||||
|
||||
dummy<T_numtype> operator()(int i, int j) const
|
||||
{
|
||||
update(0, i);
|
||||
update(1, j);
|
||||
return dummy<T_numtype>(1);
|
||||
}
|
||||
|
||||
dummy<T_numtype> operator()(int i, int j, int k) const
|
||||
{
|
||||
update(0, i);
|
||||
update(1, j);
|
||||
update(2, k);
|
||||
return dummy<T_numtype>(1);
|
||||
}
|
||||
|
||||
dummy<T_numtype> shift(int offset, int dim) const
|
||||
{
|
||||
update(dim, offset);
|
||||
return dummy<T_numtype>(1);
|
||||
}
|
||||
|
||||
dummy<T_numtype> shift(int offset1, int dim1, int offset2, int dim2) const
|
||||
{
|
||||
update(dim1, offset1);
|
||||
update(dim2, offset2);
|
||||
return dummy<T_numtype>(1);
|
||||
}
|
||||
|
||||
dummy<_bz_typename multicomponent_traits<T_numtype>::T_element>
|
||||
operator[](int) const
|
||||
{
|
||||
return dummy<_bz_typename multicomponent_traits<T_numtype>::T_element>
|
||||
(1);
|
||||
}
|
||||
|
||||
void update(int rank, int offset) const
|
||||
{
|
||||
if (offset < min_[rank])
|
||||
min_[rank] = offset;
|
||||
if (offset > max_[rank])
|
||||
max_[rank] = offset;
|
||||
}
|
||||
|
||||
template<typename T_numtype2>
|
||||
void combine(const stencilExtent<N_rank,T_numtype2>& x) const
|
||||
{
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
{
|
||||
min_[i] = (extrema::min)(min_[i], (x.min)(i));
|
||||
max_[i] = (extrema::max)(max_[i], (x.max)(i));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T_numtype2>
|
||||
void combine(const dummy<T_numtype2>&) const
|
||||
{ }
|
||||
|
||||
int (min)(int i) const
|
||||
{ return min_[i]; }
|
||||
|
||||
int (max)(int i) const
|
||||
{ return max_[i]; }
|
||||
|
||||
const TinyVector<int,N_rank>& (min)() const
|
||||
{ return min_; }
|
||||
|
||||
const TinyVector<int,N_rank>& (max)() const
|
||||
{ return max_; }
|
||||
|
||||
template<typename T>
|
||||
void operator=(T)
|
||||
{ }
|
||||
|
||||
// NEEDS_WORK: other operators
|
||||
template<typename T> void operator+=(T) { }
|
||||
template<typename T> void operator-=(T) { }
|
||||
template<typename T> void operator*=(T) { }
|
||||
template<typename T> void operator/=(T) { }
|
||||
|
||||
operator T_numtype()
|
||||
{ return T_numtype(1); }
|
||||
|
||||
T_numtype operator*() const
|
||||
{ return T_numtype(1); }
|
||||
|
||||
private:
|
||||
mutable TinyVector<int,N_rank> min_, max_;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* stencilExtent_traits gives a stencilExtent<N,T> object for arrays,
|
||||
* and a dummy object for dummy arrays.
|
||||
*/
|
||||
template<typename T>
|
||||
struct stencilExtent_traits {
|
||||
typedef dummy<double> T_stencilExtent;
|
||||
};
|
||||
|
||||
template<typename T_numtype, int N_rank>
|
||||
struct stencilExtent_traits<Array<T_numtype,N_rank> > {
|
||||
typedef stencilExtent<N_rank,T_numtype> T_stencilExtent;
|
||||
};
|
||||
|
||||
/*
|
||||
* Specialization of areShapesConformable(), originally
|
||||
* defined in <blitz/shapecheck.h>
|
||||
*/
|
||||
|
||||
template<typename T_shape1>
|
||||
inline bool areShapesConformable(const T_shape1&, const dummyArray&) {
|
||||
return true;
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#include <blitz/array/stencils.cc>
|
||||
|
||||
#endif // BZ_ARRAYSTENCILS_H
|
||||
|
||||
@@ -0,0 +1,479 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/storage.h Memory layout of Arrays.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAY_STORAGE_H
|
||||
#define BZ_ARRAY_STORAGE_H
|
||||
|
||||
#ifdef BZ_HAVE_BOOST_SERIALIZATION
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
#endif
|
||||
#ifdef BZ_HAVE_BOOST_MPI
|
||||
#include <boost/mpi/datatype.hpp>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
|
||||
/// Enum for specifying whether padding for alignment should be done.
|
||||
enum paddingPolicy {
|
||||
/// The container should have contiguous data.
|
||||
contiguousData,
|
||||
/** The container data should be padded so minor rank dimensions
|
||||
always are SIMD aligned. */
|
||||
paddedData
|
||||
};
|
||||
|
||||
|
||||
/** The default padding policy, set by the configure script
|
||||
--enable-array-length-padding argument. */
|
||||
const paddingPolicy defaultPadding = BZ_PADDING_DEFAULT;
|
||||
|
||||
|
||||
/**
|
||||
Declaration of class GeneralArrayStorage<N_rank>
|
||||
|
||||
This class describes a storage format for an N-dimensional array.
|
||||
The dimensions can be stored in an arbitrary order (for example, as
|
||||
a C-style row major array or Fortran-style column major array, or
|
||||
something else entirely). Each dimension can be stored in either
|
||||
ascending (the most common) or descending order. Each dimension can
|
||||
have its own base (starting index value: e.g. 0 for C-style arrays,
|
||||
1 for Fortran arrays). The GeneralArrayStorage class also
|
||||
determines the padding policy when SIMD width is set.
|
||||
|
||||
GeneralArrayStorage<N> defaults to C-style arrays. To implement
|
||||
other storage formats, subclass and modify the constructor. The
|
||||
class FortranArray, below, is an example.
|
||||
|
||||
Objects inheriting from GeneralArrayStorage<N> can be passed as
|
||||
an optional constructor argument to Array objects.
|
||||
e.g. Array<int,3> A(16,16,16, FortranArray<3>());
|
||||
will create a 3-dimensional 16x16x16 Fortran-style array.
|
||||
*/
|
||||
|
||||
template<int N_rank>
|
||||
class GeneralArrayStorage {
|
||||
public:
|
||||
class noInitializeFlag { };
|
||||
|
||||
GeneralArrayStorage(noInitializeFlag)
|
||||
{ }
|
||||
|
||||
GeneralArrayStorage(paddingPolicy pp = defaultPadding)
|
||||
{
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
ordering_(i) = N_rank - 1 - i;
|
||||
ascendingFlag_ = true;
|
||||
base_ = 0;
|
||||
paddingPolicy_ = pp;
|
||||
}
|
||||
|
||||
GeneralArrayStorage(const GeneralArrayStorage<N_rank>& x)
|
||||
: paddingPolicy_(x.paddingPolicy_), ascendingFlag_(x.ascendingFlag_),
|
||||
ordering_(x.ordering_), base_(x.base_)
|
||||
{
|
||||
}
|
||||
|
||||
GeneralArrayStorage(TinyVector<int,N_rank> ordering,
|
||||
TinyVector<bool,N_rank> ascendingFlag,
|
||||
paddingPolicy pp = defaultPadding)
|
||||
: paddingPolicy_(pp), ascendingFlag_(ascendingFlag),
|
||||
ordering_(ordering)
|
||||
{
|
||||
base_ = 0;
|
||||
}
|
||||
|
||||
~GeneralArrayStorage()
|
||||
{ }
|
||||
|
||||
GeneralArrayStorage<N_rank>& operator=(
|
||||
const GeneralArrayStorage<N_rank>& rhs)
|
||||
{
|
||||
ordering_ = rhs.ordering();
|
||||
ascendingFlag_ = rhs.ascendingFlag();
|
||||
base_ = rhs.base();
|
||||
paddingPolicy_ = rhs.paddingPolicy_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TinyVector<int, N_rank>& ordering()
|
||||
{ return ordering_; }
|
||||
|
||||
const TinyVector<int, N_rank>& ordering() const
|
||||
{ return ordering_; }
|
||||
|
||||
int ordering(int i) const
|
||||
{ return ordering_[i]; }
|
||||
|
||||
void setOrdering(int i, int order)
|
||||
{ ordering_[i] = order; }
|
||||
|
||||
bool allRanksStoredAscending() const
|
||||
{
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
if (!ascendingFlag_[i]) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isRankStoredAscending(int i) const
|
||||
{ return ascendingFlag_[i]; }
|
||||
|
||||
TinyVector<bool, N_rank>& ascendingFlag()
|
||||
{ return ascendingFlag_; }
|
||||
|
||||
const TinyVector<bool, N_rank>& ascendingFlag() const
|
||||
{ return ascendingFlag_; }
|
||||
|
||||
void setAscendingFlag(int i, bool ascendingFlag)
|
||||
{ ascendingFlag_[i] = ascendingFlag; }
|
||||
|
||||
TinyVector<int, N_rank>& base()
|
||||
{ return base_; }
|
||||
|
||||
const TinyVector<int, N_rank>& base() const
|
||||
{ return base_; }
|
||||
|
||||
int base(int i) const
|
||||
{ return base_[i]; }
|
||||
|
||||
void setBase(int i, int base)
|
||||
{ base_[i] = base; }
|
||||
|
||||
void setBase(const TinyVector<int, N_rank>& base)
|
||||
{ base_ = base; }
|
||||
|
||||
const paddingPolicy& padding() const { return paddingPolicy_; }
|
||||
|
||||
private:
|
||||
#ifdef BZ_HAVE_BOOST_SERIALIZATION
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template<class T_arch>
|
||||
void serialize(T_arch& ar, const unsigned int version) {
|
||||
ar & paddingPolicy_;
|
||||
ar & ascendingFlag_;
|
||||
ar & ordering_;
|
||||
ar & base_;
|
||||
};
|
||||
#endif
|
||||
|
||||
protected:
|
||||
/*
|
||||
* ordering_[] specifies the order in which the array is stored in
|
||||
* memory. For a newly allocated array, ordering_(0) will give the
|
||||
* rank with unit stride, and ordering_(N_rank-1) will be the rank
|
||||
* with largest stride. An order like [2, 1, 0] corresponds to
|
||||
* C-style array storage; an order like [0, 1, 2] corresponds to
|
||||
* Fortran array storage.
|
||||
*
|
||||
* ascendingFlag_[] indicates whether the data in a rank is stored
|
||||
* in ascending or descending order. Most of the time these values
|
||||
* will all be true (indicating ascending order). Some peculiar
|
||||
* formats (e.g. MS-Windows BMP image format) store the data in
|
||||
* descending order.
|
||||
*
|
||||
* base_[] gives the first valid index for each rank. For a C-style
|
||||
* array, all the base_ elements will be zero; for a Fortran-style
|
||||
* array, they will be one. base_[] can be set arbitrarily using
|
||||
* the Array constructor which takes a Range argument, e.g.
|
||||
* Array<float,2> A(Range(30,40),Range(23,33));
|
||||
* will create an array with base_[] = { 30, 23 }.
|
||||
*/
|
||||
|
||||
// declare the tinyvector<bool> first, because it doesn't have alignment
|
||||
paddingPolicy paddingPolicy_;
|
||||
TinyVector<bool, N_rank> ascendingFlag_;
|
||||
TinyVector<int, N_rank> ordering_;
|
||||
TinyVector<int, N_rank> base_;
|
||||
};
|
||||
|
||||
|
||||
/** This tag class can be used to provide a nicer notation for
|
||||
constructing padded arrays: instead of
|
||||
Array<int,2> A(3, 3, GeneralArrayStorage<2>(paddedData));
|
||||
one can simply write:
|
||||
Array<int,2> A(3, 3, paddedArray);
|
||||
where paddedArray is an object of type _bz_paddedTag.
|
||||
*/
|
||||
class _bz_paddedTag {
|
||||
public:
|
||||
operator GeneralArrayStorage<1>()
|
||||
{ return GeneralArrayStorage<1>(paddedData); }
|
||||
|
||||
operator GeneralArrayStorage<2>()
|
||||
{ return GeneralArrayStorage<2>(paddedData); }
|
||||
|
||||
operator GeneralArrayStorage<3>()
|
||||
{ return GeneralArrayStorage<3>(paddedData); }
|
||||
|
||||
operator GeneralArrayStorage<4>()
|
||||
{ return GeneralArrayStorage<4>(paddedData); }
|
||||
|
||||
operator GeneralArrayStorage<5>()
|
||||
{ return GeneralArrayStorage<5>(paddedData); }
|
||||
|
||||
operator GeneralArrayStorage<6>()
|
||||
{ return GeneralArrayStorage<6>(paddedData); }
|
||||
|
||||
operator GeneralArrayStorage<7>()
|
||||
{ return GeneralArrayStorage<7>(paddedData); }
|
||||
|
||||
operator GeneralArrayStorage<8>()
|
||||
{ return GeneralArrayStorage<8>(paddedData); }
|
||||
|
||||
operator GeneralArrayStorage<9>()
|
||||
{ return GeneralArrayStorage<9>(paddedData); }
|
||||
|
||||
operator GeneralArrayStorage<10>()
|
||||
{ return GeneralArrayStorage<10>(paddedData); }
|
||||
|
||||
operator GeneralArrayStorage<11>()
|
||||
{ return GeneralArrayStorage<11>(paddedData); }
|
||||
};
|
||||
|
||||
// A global instance of this class will be placed in
|
||||
// the blitz library (libblitz.a on unix machines).
|
||||
|
||||
_bz_global _bz_paddedTag paddedArray;
|
||||
|
||||
|
||||
/** This tag class can be used to provide a nicer notation for
|
||||
constructing unpadded arrays: instead of
|
||||
Array<int,2> A(3, 3, GeneralArrayStorage<2>(contiguousData));
|
||||
one can simply write:
|
||||
Array<int,2> A(3, 3, contiguousArray);
|
||||
where contiguousArray is an object of type _bz_contiguousTag.
|
||||
*/
|
||||
class _bz_contiguousTag {
|
||||
public:
|
||||
operator GeneralArrayStorage<1>()
|
||||
{ return GeneralArrayStorage<1>(contiguousData); }
|
||||
|
||||
operator GeneralArrayStorage<2>()
|
||||
{ return GeneralArrayStorage<2>(contiguousData); }
|
||||
|
||||
operator GeneralArrayStorage<3>()
|
||||
{ return GeneralArrayStorage<3>(contiguousData); }
|
||||
|
||||
operator GeneralArrayStorage<4>()
|
||||
{ return GeneralArrayStorage<4>(contiguousData); }
|
||||
|
||||
operator GeneralArrayStorage<5>()
|
||||
{ return GeneralArrayStorage<5>(contiguousData); }
|
||||
|
||||
operator GeneralArrayStorage<6>()
|
||||
{ return GeneralArrayStorage<6>(contiguousData); }
|
||||
|
||||
operator GeneralArrayStorage<7>()
|
||||
{ return GeneralArrayStorage<7>(contiguousData); }
|
||||
|
||||
operator GeneralArrayStorage<8>()
|
||||
{ return GeneralArrayStorage<8>(contiguousData); }
|
||||
|
||||
operator GeneralArrayStorage<9>()
|
||||
{ return GeneralArrayStorage<9>(contiguousData); }
|
||||
|
||||
operator GeneralArrayStorage<10>()
|
||||
{ return GeneralArrayStorage<10>(contiguousData); }
|
||||
|
||||
operator GeneralArrayStorage<11>()
|
||||
{ return GeneralArrayStorage<11>(contiguousData); }
|
||||
};
|
||||
|
||||
// A global instance of this class will be placed in
|
||||
// the blitz library (libblitz.a on unix machines).
|
||||
|
||||
_bz_global _bz_contiguousTag contiguousArray;
|
||||
|
||||
|
||||
/**
|
||||
Class FortranArray specializes GeneralArrayStorage to provide
|
||||
Fortran style arrays (column major ordering, base of 1). The
|
||||
noInitializeFlag() passed to the base constructor indicates that
|
||||
the subclass will take care of initializing the ordering_,
|
||||
ascendingFlag_ and base_ members.
|
||||
*/
|
||||
template<int N_rank>
|
||||
class FortranArray : public GeneralArrayStorage<N_rank> {
|
||||
private:
|
||||
typedef GeneralArrayStorage<N_rank> T_base;
|
||||
typedef _bz_typename T_base::noInitializeFlag noInitializeFlag;
|
||||
using T_base::ordering_;
|
||||
using T_base::ascendingFlag_;
|
||||
using T_base::base_;
|
||||
using T_base::paddingPolicy_;
|
||||
public:
|
||||
FortranArray(paddingPolicy pp = defaultPadding)
|
||||
: GeneralArrayStorage<N_rank>(noInitializeFlag())
|
||||
{
|
||||
for (int i=0; i < N_rank; ++i)
|
||||
ordering_(i) = i;
|
||||
ascendingFlag_ = true;
|
||||
base_ = 1;
|
||||
paddingPolicy_ = pp;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// This tag class can be used to provide a nicer notation for
|
||||
// constructing Fortran-style arrays: instead of
|
||||
// Array<int,2> A(3, 3, FortranArray<2>());
|
||||
// one can simply write:
|
||||
// Array<int,2> A(3, 3, fortranArray);
|
||||
// where fortranArray is an object of type _bz_fortranTag.
|
||||
|
||||
class _bz_fortranTag {
|
||||
public:
|
||||
operator GeneralArrayStorage<1>()
|
||||
{ return FortranArray<1>(); }
|
||||
|
||||
operator GeneralArrayStorage<2>()
|
||||
{ return FortranArray<2>(); }
|
||||
|
||||
operator GeneralArrayStorage<3>()
|
||||
{ return FortranArray<3>(); }
|
||||
|
||||
operator GeneralArrayStorage<4>()
|
||||
{ return FortranArray<4>(); }
|
||||
|
||||
operator GeneralArrayStorage<5>()
|
||||
{ return FortranArray<5>(); }
|
||||
|
||||
operator GeneralArrayStorage<6>()
|
||||
{ return FortranArray<6>(); }
|
||||
|
||||
operator GeneralArrayStorage<7>()
|
||||
{ return FortranArray<7>(); }
|
||||
|
||||
operator GeneralArrayStorage<8>()
|
||||
{ return FortranArray<8>(); }
|
||||
|
||||
operator GeneralArrayStorage<9>()
|
||||
{ return FortranArray<9>(); }
|
||||
|
||||
operator GeneralArrayStorage<10>()
|
||||
{ return FortranArray<10>(); }
|
||||
|
||||
operator GeneralArrayStorage<11>()
|
||||
{ return FortranArray<11>(); }
|
||||
};
|
||||
|
||||
// A global instance of this class will be placed in
|
||||
// the blitz library (libblitz.a on unix machines).
|
||||
|
||||
_bz_global _bz_fortranTag fortranArray;
|
||||
|
||||
|
||||
/**
|
||||
Class ColumnMajorArray specializes GeneralArrayStorage to provide
|
||||
column major arrays (column major ordering, base of 0).
|
||||
*/
|
||||
|
||||
template<int N_rank>
|
||||
class ColumnMajorArray : public GeneralArrayStorage<N_rank> {
|
||||
private:
|
||||
typedef GeneralArrayStorage<N_rank> T_base;
|
||||
typedef _bz_typename T_base::noInitializeFlag noInitializeFlag;
|
||||
using T_base::ordering_;
|
||||
using T_base::ascendingFlag_;
|
||||
using T_base::base_;
|
||||
using T_base::paddingPolicy_;
|
||||
public:
|
||||
ColumnMajorArray(paddingPolicy pp = defaultPadding)
|
||||
: GeneralArrayStorage<N_rank>(noInitializeFlag())
|
||||
{
|
||||
ordering_ = tensor::i;//Range(0, N_rank - 1);
|
||||
ascendingFlag_ = true;
|
||||
base_ = 0;
|
||||
paddingPolicy_ = pp;
|
||||
}
|
||||
};
|
||||
|
||||
// This tag class can be used to provide a nicer notation for
|
||||
// constructing column major arrays: instead of
|
||||
// Array<int,2> A(3, 3, ColumnMajorArray<2>());
|
||||
// one can simply write:
|
||||
// Array<int,2> A(3, 3, columnMajorArray);
|
||||
// where columnMajorArray is an object of type _bz_columnMajorTag.
|
||||
|
||||
class _bz_columnMajorTag {
|
||||
|
||||
public:
|
||||
operator GeneralArrayStorage<1>()
|
||||
{ return ColumnMajorArray<1>(); }
|
||||
|
||||
operator GeneralArrayStorage<2>()
|
||||
{ return ColumnMajorArray<2>(); }
|
||||
|
||||
operator GeneralArrayStorage<3>()
|
||||
{ return ColumnMajorArray<3>(); }
|
||||
|
||||
operator GeneralArrayStorage<4>()
|
||||
{ return ColumnMajorArray<4>(); }
|
||||
|
||||
operator GeneralArrayStorage<5>()
|
||||
{ return ColumnMajorArray<5>(); }
|
||||
|
||||
operator GeneralArrayStorage<6>()
|
||||
{ return ColumnMajorArray<6>(); }
|
||||
|
||||
operator GeneralArrayStorage<7>()
|
||||
{ return ColumnMajorArray<7>(); }
|
||||
|
||||
operator GeneralArrayStorage<8>()
|
||||
{ return ColumnMajorArray<8>(); }
|
||||
|
||||
operator GeneralArrayStorage<9>()
|
||||
{ return ColumnMajorArray<9>(); }
|
||||
|
||||
operator GeneralArrayStorage<10>()
|
||||
{ return ColumnMajorArray<10>(); }
|
||||
|
||||
operator GeneralArrayStorage<11>()
|
||||
{ return ColumnMajorArray<11>(); }
|
||||
};
|
||||
|
||||
// A global instance of this class will be placed in
|
||||
// the blitz library (libblitz.a on unix machines).
|
||||
|
||||
_bz_global _bz_columnMajorTag columnMajorArray;
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#ifdef BZ_HAVE_BOOST_MPI
|
||||
namespace boost { namespace mpi {
|
||||
template <int N>
|
||||
struct is_mpi_datatype<blitz::GeneralArrayStorage<N> > : boost::mpl::true_ { };
|
||||
} }
|
||||
#endif
|
||||
|
||||
#endif // BZ_ARRAY_STORAGE_H
|
||||
|
||||
@@ -0,0 +1,438 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/where.h where(X,Y,Z) operator for array expressions
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYWHERE_H
|
||||
#define BZ_ARRAYWHERE_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/promote.h>
|
||||
#include <blitz/prettyprint.h>
|
||||
#include <blitz/bounds.h>
|
||||
#include <blitz/meta/metaprog.h>
|
||||
#include <blitz/tinyvec2.h>
|
||||
#include <blitz/array/domain.h>
|
||||
#include <blitz/array/asexpr.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename P_expr1, typename P_expr2, typename P_expr3>
|
||||
class _bz_ArrayWhere {
|
||||
|
||||
public:
|
||||
typedef P_expr1 T_expr1;
|
||||
typedef P_expr2 T_expr2;
|
||||
typedef P_expr3 T_expr3;
|
||||
typedef _bz_typename T_expr2::T_numtype T_numtype2;
|
||||
typedef _bz_typename T_expr3::T_numtype T_numtype3;
|
||||
typedef BZ_PROMOTE(T_numtype2, T_numtype3) T_numtype;
|
||||
typedef T_expr1 T_ctorArg1;
|
||||
typedef T_expr2 T_ctorArg2;
|
||||
typedef T_expr3 T_ctorArg3;
|
||||
typedef _bz_ArrayWhere<_bz_typename P_expr1::T_range_result,
|
||||
_bz_typename P_expr2::T_range_result,
|
||||
_bz_typename P_expr3::T_range_result> T_range_result;
|
||||
|
||||
// select return type
|
||||
typedef typename unwrapET<typename T_expr1::T_result>::T_unwrapped T_unwrapped1;
|
||||
typedef typename unwrapET<typename T_expr2::T_result>::T_unwrapped T_unwrapped2;
|
||||
typedef typename unwrapET<typename T_expr3::T_result>::T_unwrapped T_unwrapped3;
|
||||
typedef typename selectET2<typename T_expr1::T_typeprop,
|
||||
typename T_expr2::T_typeprop,
|
||||
T_numtype,
|
||||
char>::T_selected T_intermediary;
|
||||
|
||||
typedef typename selectET2<T_intermediary,
|
||||
typename T_expr3::T_typeprop,
|
||||
T_numtype,
|
||||
_bz_ArrayWhere<typename asExpr<T_unwrapped1>::T_expr,
|
||||
typename asExpr<T_unwrapped2>::T_expr,
|
||||
typename asExpr<T_unwrapped3>::T_expr
|
||||
> >::T_selected T_typeprop;
|
||||
typedef typename unwrapET<T_typeprop>::T_unwrapped T_result;
|
||||
typedef T_numtype T_optype;
|
||||
|
||||
static const int
|
||||
numArrayOperands = P_expr1::numArrayOperands
|
||||
+ P_expr2::numArrayOperands
|
||||
+ P_expr3::numArrayOperands,
|
||||
numTVOperands = T_expr1::numTVOperands +
|
||||
T_expr2::numTVOperands +
|
||||
T_expr3::numTVOperands,
|
||||
numTMOperands = T_expr1::numTMOperands +
|
||||
T_expr2::numTMOperands +
|
||||
T_expr3::numTMOperands,
|
||||
numIndexPlaceholders = P_expr1::numIndexPlaceholders
|
||||
+ P_expr2::numIndexPlaceholders
|
||||
+ P_expr3::numIndexPlaceholders,
|
||||
minWidth = BZ_MIN(BZ_MIN(T_expr1::minWidth, T_expr2::minWidth),
|
||||
T_expr3::minWidth),
|
||||
maxWidth = BZ_MAX(BZ_MAX(T_expr1::maxWidth, T_expr2::maxWidth),
|
||||
T_expr3::maxWidth),
|
||||
rank_ = BZ_MAX(BZ_MAX(T_expr1::rank_, T_expr2::rank_),
|
||||
T_expr3::rank_);
|
||||
|
||||
template<int N> struct tvresult {
|
||||
typedef _bz_ArrayWhere<
|
||||
typename T_expr1::template tvresult<N>::Type,
|
||||
typename T_expr2::template tvresult<N>::Type,
|
||||
typename T_expr3::template tvresult<N>::Type> Type;
|
||||
};
|
||||
|
||||
_bz_ArrayWhere(const _bz_ArrayWhere<T_expr1,T_expr2,T_expr3>& a)
|
||||
: iter1_(a.iter1_), iter2_(a.iter2_), iter3_(a.iter3_)
|
||||
{ }
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
_bz_ArrayWhere(BZ_ETPARM(T1) a, BZ_ETPARM(T2) b, BZ_ETPARM(T3) c)
|
||||
: iter1_(a), iter2_(b), iter3_(c)
|
||||
{ }
|
||||
|
||||
T_numtype operator*() const
|
||||
{ return (*iter1_) ? (*iter2_) : (*iter3_); }
|
||||
|
||||
/* Functions for reading. Because they must depend on the result
|
||||
* type, they utilize a helper class.
|
||||
*/
|
||||
|
||||
// For numtypes, apply operator
|
||||
template<typename T> struct readHelper {
|
||||
static T_result fastRead(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3, diffType i) {
|
||||
return iter1.fastRead(i) ? iter2.fastRead(i) : iter3.fastRead(i); }
|
||||
static T_result indexop(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3, int i) {
|
||||
return iter1[i] ? iter2[i] : iter3[i]; }
|
||||
static T_result first_value(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3) {
|
||||
return iter1.first_value() ?
|
||||
iter2.first_value() : iter3.first_value(); }
|
||||
static T_result shift(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3, int offset, int dim) {
|
||||
return iter1.shift(offset, dim) ? iter2.shift(offset, dim) :
|
||||
iter3.shift(offset, dim); }
|
||||
static T_result shift(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3, int offset1, int dim1,
|
||||
int offset2, int dim2) {
|
||||
return iter1.shift(offset1, dim1, offset2, dim2) ?
|
||||
iter2.shift(offset1, dim1, offset2, dim2) :
|
||||
iter3.shift(offset1, dim1, offset2, dim2); }
|
||||
template<int N_rank>
|
||||
#ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
|
||||
static T_result indexop(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3,
|
||||
const TinyVector<int, N_rank> i) {
|
||||
#else
|
||||
static T_result indexop(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3,
|
||||
const TinyVector<int, N_rank>& i) {
|
||||
#endif
|
||||
return iter1(i) ? iter2(i) : iter3(i); }
|
||||
};
|
||||
|
||||
// For ET types, bypass operator and create expression
|
||||
template<typename T> struct readHelper<ETBase<T> > {
|
||||
static T_result fastRead(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3, diffType i) {
|
||||
return T_result(iter1.fastRead(i), iter2.fastRead(i), iter3.fastRead(i)); }
|
||||
static T_result indexop(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3, int i) {
|
||||
return T_result(iter1[i], iter2[i], iter3[i]); };
|
||||
static T_result first_value(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3) {
|
||||
return T_result(iter1.first_value(), iter2.first_value(),
|
||||
iter3.first_value()); }
|
||||
static T_result shift(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3, int offset, int dim) {
|
||||
return T_result(iter1.shift(offset, dim), iter2.shift(offset, dim),
|
||||
iter3.shift(offset, dim)); }
|
||||
static T_result shift(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3, int offset1, int dim1,
|
||||
int offset2, int dim2) {
|
||||
return T_result(iter1.shift(offset1, dim1, offset2, dim2),
|
||||
iter2.shift(offset1, dim1, offset2, dim2),
|
||||
iter3.shift(offset1, dim1, offset2, dim2)); }
|
||||
template<int N_rank>
|
||||
#ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
|
||||
static T_result indexop(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3,
|
||||
const TinyVector<int, N_rank> i) {
|
||||
#else
|
||||
static T_result indexop(const T_expr1& iter1, const T_expr2& iter2,
|
||||
const T_expr3& iter3,
|
||||
const TinyVector<int, N_rank>& i) {
|
||||
#endif
|
||||
return T_result(iter1(i), iter2(i), iter3(i) ); }
|
||||
};
|
||||
|
||||
T_result fastRead(diffType i) const {
|
||||
return readHelper<T_typeprop>::fastRead(iter1_, iter2_, iter3_, i); }
|
||||
|
||||
template<int N>
|
||||
typename tvresult<N>::Type fastRead_tv(diffType i) const
|
||||
{ return typename tvresult<N>::Type(iter1_.template fastRead_tv<N>(i),
|
||||
iter2_.template fastRead_tv<N>(i),
|
||||
iter3_.template fastRead_tv<N>(i)); }
|
||||
|
||||
T_result operator[](int i) const {
|
||||
return readHelper<T_typeprop>::indexop(iter1_, iter2_, iter3_, i); }
|
||||
|
||||
template<int N_rank>
|
||||
#ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
|
||||
T_result operator()(const TinyVector<int, N_rank> i) const {
|
||||
#else
|
||||
T_result operator()(const TinyVector<int, N_rank>& i) const {
|
||||
#endif
|
||||
return readHelper<T_typeprop>::indexop(iter1_, iter2_, iter3_, i); }
|
||||
|
||||
T_result first_value() const {
|
||||
return readHelper<T_typeprop>::first_value(iter1_, iter2_, iter3_); }
|
||||
|
||||
T_result shift(int offset, int dim) const {
|
||||
return readHelper<T_typeprop>::shift(iter1_, iter2_, iter3_,
|
||||
offset, dim); }
|
||||
|
||||
T_result shift(int offset1, int dim1,int offset2, int dim2) const {
|
||||
return readHelper<T_typeprop>::shift(iter1_, iter2_, iter3_,
|
||||
offset1, dim1, offset2, dim2); }
|
||||
|
||||
// ****** end reading
|
||||
|
||||
bool isVectorAligned(diffType offset) const
|
||||
{ return iter1_.isVectorAligned(offset) &&
|
||||
iter2_.isVectorAligned(offset) &&
|
||||
iter3_.isVectorAligned(offset); }
|
||||
|
||||
T_range_result operator()(const RectDomain<rank_>& d) const
|
||||
{ return T_range_result(iter1_(d), iter2_(d), iter3_(d)); }
|
||||
|
||||
int ascending(const int rank) const
|
||||
{
|
||||
return bounds::compute_ascending(rank, bounds::compute_ascending(
|
||||
rank, iter1_.ascending(rank), iter2_.ascending(rank)),
|
||||
iter3_.ascending(rank));
|
||||
}
|
||||
|
||||
int ordering(const int rank) const
|
||||
{
|
||||
return bounds::compute_ordering(rank, bounds::compute_ordering(
|
||||
rank, iter1_.ordering(rank), iter2_.ordering(rank)),
|
||||
iter3_.ordering(rank));
|
||||
}
|
||||
|
||||
int lbound(const int rank) const
|
||||
{
|
||||
return bounds::compute_lbound(rank, bounds::compute_lbound(
|
||||
rank, iter1_.lbound(rank), iter2_.lbound(rank)),
|
||||
iter3_.lbound(rank));
|
||||
}
|
||||
|
||||
int ubound(const int rank) const
|
||||
{
|
||||
return bounds::compute_ubound(rank, bounds::compute_ubound(
|
||||
rank, iter1_.ubound(rank), iter2_.ubound(rank)),
|
||||
iter3_.ubound(rank));
|
||||
}
|
||||
|
||||
// defer calculation to lbound/ubound
|
||||
RectDomain<rank_> domain() const
|
||||
{
|
||||
TinyVector<int, rank_> lb, ub;
|
||||
for(int r=0; r<rank_; ++r) {
|
||||
lb[r]=lbound(r); ub[r]=ubound(r);
|
||||
}
|
||||
return RectDomain<rank_>(lb,ub);
|
||||
}
|
||||
|
||||
void push(int position)
|
||||
{
|
||||
iter1_.push(position);
|
||||
iter2_.push(position);
|
||||
iter3_.push(position);
|
||||
}
|
||||
|
||||
void pop(int position)
|
||||
{
|
||||
iter1_.pop(position);
|
||||
iter2_.pop(position);
|
||||
iter3_.pop(position);
|
||||
}
|
||||
|
||||
void advance()
|
||||
{
|
||||
iter1_.advance();
|
||||
iter2_.advance();
|
||||
iter3_.advance();
|
||||
}
|
||||
|
||||
void advance(int n)
|
||||
{
|
||||
iter1_.advance(n);
|
||||
iter2_.advance(n);
|
||||
iter3_.advance(n);
|
||||
}
|
||||
|
||||
void loadStride(int rank)
|
||||
{
|
||||
iter1_.loadStride(rank);
|
||||
iter2_.loadStride(rank);
|
||||
iter3_.loadStride(rank);
|
||||
}
|
||||
|
||||
bool isUnitStride(int rank) const
|
||||
{
|
||||
return iter1_.isUnitStride(rank)
|
||||
&& iter2_.isUnitStride(rank)
|
||||
&& iter3_.isUnitStride(rank);
|
||||
}
|
||||
|
||||
bool isUnitStride() const
|
||||
{
|
||||
return iter1_.isUnitStride()
|
||||
&& iter2_.isUnitStride()
|
||||
&& iter3_.isUnitStride();
|
||||
}
|
||||
|
||||
void advanceUnitStride()
|
||||
{
|
||||
iter1_.advanceUnitStride();
|
||||
iter2_.advanceUnitStride();
|
||||
iter3_.advanceUnitStride();
|
||||
}
|
||||
|
||||
bool canCollapse(int outerLoopRank, int innerLoopRank) const
|
||||
{
|
||||
return iter1_.canCollapse(outerLoopRank, innerLoopRank)
|
||||
&& iter2_.canCollapse(outerLoopRank, innerLoopRank)
|
||||
&& iter3_.canCollapse(outerLoopRank, innerLoopRank);
|
||||
}
|
||||
|
||||
template<int N_rank>
|
||||
void moveTo(const TinyVector<int,N_rank>& i)
|
||||
{
|
||||
iter1_.moveTo(i);
|
||||
iter2_.moveTo(i);
|
||||
iter3_.moveTo(i);
|
||||
}
|
||||
|
||||
// this is needed for the stencil expression fastRead to work
|
||||
void _bz_offsetData(sizeType i)
|
||||
{
|
||||
iter1_._bz_offsetData(i);
|
||||
iter2_._bz_offsetData(i);
|
||||
iter3_._bz_offsetData(i);
|
||||
}
|
||||
|
||||
diffType suggestStride(int rank) const
|
||||
{
|
||||
diffType stride1 = iter1_.suggestStride(rank);
|
||||
diffType stride2 = iter2_.suggestStride(rank);
|
||||
diffType stride3 = iter3_.suggestStride(rank);
|
||||
return stride1>(stride2=(stride2>stride3?stride2:stride3))?stride1:stride2;
|
||||
}
|
||||
|
||||
bool isStride(int rank, diffType stride) const
|
||||
{
|
||||
return iter1_.isStride(rank,stride)
|
||||
&& iter2_.isStride(rank,stride)
|
||||
&& iter3_.isStride(rank,stride);
|
||||
}
|
||||
|
||||
void prettyPrint(BZ_STD_SCOPE(string) &str,
|
||||
prettyPrintFormat& format) const
|
||||
{
|
||||
str += "where(";
|
||||
iter1_.prettyPrint(str,format);
|
||||
str += ",";
|
||||
iter2_.prettyPrint(str,format);
|
||||
str += ",";
|
||||
iter3_.prettyPrint(str,format);
|
||||
str += ")";
|
||||
}
|
||||
|
||||
template<typename T_shape>
|
||||
bool shapeCheck(const T_shape& shape) const
|
||||
{
|
||||
int t1 = iter1_.shapeCheck(shape);
|
||||
int t2 = iter2_.shapeCheck(shape);
|
||||
int t3 = iter3_.shapeCheck(shape);
|
||||
|
||||
return t1 && t2 && t3;
|
||||
}
|
||||
|
||||
|
||||
// sliceinfo for expressions
|
||||
template<typename T1, typename T2 = nilArraySection,
|
||||
class T3 = nilArraySection, typename T4 = nilArraySection,
|
||||
class T5 = nilArraySection, typename T6 = nilArraySection,
|
||||
class T7 = nilArraySection, typename T8 = nilArraySection,
|
||||
class T9 = nilArraySection, typename T10 = nilArraySection,
|
||||
class T11 = nilArraySection>
|
||||
class SliceInfo {
|
||||
public:
|
||||
typedef typename T_expr1::template SliceInfo<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::T_slice T_slice1;
|
||||
typedef typename T_expr2::template SliceInfo<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::T_slice T_slice2;
|
||||
typedef typename T_expr3::template SliceInfo<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::T_slice T_slice3;
|
||||
typedef _bz_ArrayWhere<T_slice1, T_slice2, T_slice3> T_slice;
|
||||
};
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9, typename T10, typename T11>
|
||||
typename SliceInfo<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_slice
|
||||
operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6, T7 r7, T8 r8, T9 r9, T10 r10, T11 r11) const
|
||||
{
|
||||
return typename SliceInfo<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_slice
|
||||
(iter1_(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11),
|
||||
iter2_(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11),
|
||||
iter3_(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11));
|
||||
}
|
||||
|
||||
private:
|
||||
_bz_ArrayWhere() { }
|
||||
|
||||
T_expr1 iter1_;
|
||||
T_expr2 iter2_;
|
||||
T_expr3 iter3_;
|
||||
};
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
inline
|
||||
_bz_ArrayExpr<_bz_ArrayWhere<_bz_typename asExpr<T1>::T_expr,
|
||||
_bz_typename asExpr<T2>::T_expr, _bz_typename asExpr<T3>::T_expr> >
|
||||
where(const T1& a, const T2& b, const T3& c)
|
||||
{
|
||||
return _bz_ArrayExpr<_bz_ArrayWhere<_bz_typename asExpr<T1>::T_expr,
|
||||
_bz_typename asExpr<T2>::T_expr,
|
||||
_bz_typename asExpr<T3>::T_expr> >(a,b,c);
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYWHERE_H
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/array/zip.h "zip" scalar arrays into a multicomponent array expr
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
|
||||
*
|
||||
* This file is a part of Blitz.
|
||||
*
|
||||
* Blitz is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* Blitz is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Suggestions: blitz-devel@lists.sourceforge.net
|
||||
* Bugs: blitz-support@lists.sourceforge.net
|
||||
*
|
||||
* For more information, please see the Blitz++ Home Page:
|
||||
* https://sourceforge.net/projects/blitz/
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef BZ_ARRAYZIP_H
|
||||
#define BZ_ARRAYZIP_H
|
||||
|
||||
#ifndef BZ_ARRAY_H
|
||||
#error <blitz/array/zip.h> must be included via <blitz/array.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename P_component, typename T1, typename T2>
|
||||
struct Zip2 {
|
||||
typedef P_component T_numtype;
|
||||
|
||||
static inline T_numtype apply(T1 a, T2 b)
|
||||
{ return T_numtype(a,b); }
|
||||
|
||||
template<typename T_left, typename T_right>
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str,
|
||||
prettyPrintFormat& format, const T_left& t1,
|
||||
const T_right& t2)
|
||||
{
|
||||
str += "zip(";
|
||||
t1.prettyPrint(str, format);
|
||||
str += ",";
|
||||
t2.prettyPrint(str, format);
|
||||
str += ")";
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T_component, typename T1, typename T2>
|
||||
inline _bz_ArrayExpr<_bz_ArrayExprBinaryOp<
|
||||
_bz_typename asExpr<T1>::T_expr,
|
||||
_bz_typename asExpr<T2>::T_expr,
|
||||
Zip2<T_component,
|
||||
_bz_typename asExpr<T1>::T_expr::T_numtype,
|
||||
_bz_typename asExpr<T2>::T_expr::T_numtype> > >
|
||||
zip(const T1& a, const T2& b, T_component)
|
||||
{
|
||||
return _bz_ArrayExpr<_bz_ArrayExprBinaryOp<
|
||||
_bz_typename asExpr<T1>::T_expr,
|
||||
_bz_typename asExpr<T2>::T_expr,
|
||||
Zip2<T_component,
|
||||
_bz_typename asExpr<T1>::T_expr::T_numtype,
|
||||
_bz_typename asExpr<T2>::T_expr::T_numtype> > >(a,b);
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAYZIP_H
|
||||
|
||||
Reference in New Issue
Block a user