Removed *.o, include, lib.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,27 +0,0 @@
|
||||
|
||||
#ifndef BZ_ARRAY_CC
|
||||
#define BZ_ARRAY_CC
|
||||
|
||||
// not-quite-declarations-of-array files
|
||||
|
||||
#include <blitz/array/iter.h> // Array iterators
|
||||
#include <blitz/array/fastiter.h> // Fast Array iterators (for et)
|
||||
#include <blitz/array/asexpr.cc> // ET type functions
|
||||
#include <blitz/array/expr.cc> // Array expression objects
|
||||
#include <blitz/range.cc> // range objects
|
||||
#include <blitz/array/methods.cc> // Member functions
|
||||
#include <blitz/array/ops.cc> // Assignment operators
|
||||
#include <blitz/array/io.cc> // Output formatting
|
||||
#include <blitz/array/interlace.cc> // Allocation of interlaced arrays
|
||||
#include <blitz/array/resize.cc> // Array resize, resizeAndPreserve
|
||||
#include <blitz/array/slicing.cc> // Slicing and subarrays
|
||||
#include <blitz/array/cycle.cc> // Cycling arrays
|
||||
#include <blitz/array/complex.cc> // Special support for complex arrays
|
||||
#include <blitz/array/et.h> // Expression templates
|
||||
#include <blitz/array/reduce.h> // Array reduction expression templates
|
||||
#include <blitz/array/zip.h> // Zipping multicomponent types
|
||||
#include <blitz/array/where.h> // where(X,Y,Z)
|
||||
#include <blitz/array/indirect.h> // Indirection
|
||||
#include <blitz/array/stencils.h> // Stencil objects
|
||||
#include <blitz/tinymat2.cc> // TinyMatrix implementations
|
||||
#endif
|
||||
@@ -1,40 +0,0 @@
|
||||
/***************************************************************************
|
||||
* blitz/array.h Minimal include version of Array<T,N>
|
||||
*
|
||||
* $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_ONLY_H
|
||||
#define BZ_ARRAY_ONLY_H
|
||||
|
||||
// See comments in <blitz/array-old.h> for an explanation of the new
|
||||
// headers arrangement.
|
||||
|
||||
#include <blitz/array-impl.h>
|
||||
|
||||
#endif // BZ_ARRAY_ONLY_H
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,304 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,347 +0,0 @@
|
||||
// -*- 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
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,61 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,83 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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
|
||||
@@ -1,173 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,42 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,18 +0,0 @@
|
||||
#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
@@ -1,489 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,313 +0,0 @@
|
||||
// -*- 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
@@ -1,112 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,613 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,550 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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
|
||||
@@ -1,324 +0,0 @@
|
||||
// -*- 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
|
||||
|
||||
@@ -1,774 +0,0 @@
|
||||
// -*- 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
|
||||
|
||||
@@ -1,496 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,457 +0,0 @@
|
||||
// -*- 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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,416 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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
|
||||
@@ -1,133 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,154 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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
|
||||
|
||||
@@ -1,402 +0,0 @@
|
||||
// -*- 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
@@ -1,94 +0,0 @@
|
||||
// -*- 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
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,363 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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
@@ -1,400 +0,0 @@
|
||||
// -*- 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
@@ -1,614 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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
|
||||
@@ -1,348 +0,0 @@
|
||||
// -*- 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
|
||||
|
||||
@@ -1,479 +0,0 @@
|
||||
// -*- 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
|
||||
|
||||
@@ -1,438 +0,0 @@
|
||||
// -*- 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
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
// -*- 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
|
||||
|
||||
@@ -1,259 +0,0 @@
|
||||
/***************************************************************************
|
||||
* blitz/bench.cc Benchmarking 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_BENCH_CC
|
||||
#define BZ_BENCH_CC
|
||||
|
||||
#ifndef BZ_BENCH_H
|
||||
#error <blitz/bench.cc> must be included via <blitz/bench.h>
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_STD
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#else
|
||||
#include <fstream.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename P_parameter>
|
||||
Benchmark<P_parameter>::Benchmark(unsigned numImplementations)
|
||||
{
|
||||
state_ = uninitialized;
|
||||
numImplementations_ = numImplementations;
|
||||
numStoredImplementations_ = 0;
|
||||
implementations_ = new BenchmarkImplementation<P_parameter>* [numImplementations_];
|
||||
rates_.resize(numImplementations, numParameterSettings());
|
||||
Mflops_.resize(numImplementations, numParameterSettings());
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
Benchmark<P_parameter>::~Benchmark()
|
||||
{
|
||||
delete [] implementations_;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void Benchmark<P_parameter>::addImplementation(
|
||||
BenchmarkImplementation<P_parameter> * implementation)
|
||||
{
|
||||
BZPRECONDITION(state_ == uninitialized);
|
||||
BZPRECONDITION(numStoredImplementations_ < numImplementations_);
|
||||
|
||||
implementations_[numStoredImplementations_++] = implementation;
|
||||
|
||||
if (numStoredImplementations_ == numImplementations_)
|
||||
state_ = initialized;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void Benchmark<P_parameter>::run(ostream& log)
|
||||
{
|
||||
BZPRECONDITION(state_ == initialized);
|
||||
state_ = running;
|
||||
|
||||
Timer t;
|
||||
|
||||
for (unsigned j=0; j < numImplementations_; ++j)
|
||||
{
|
||||
for (unsigned i=0; i < numParameterSettings(); ++i)
|
||||
{
|
||||
log << setw(20) << implementations_[j]->implementationName()
|
||||
<< " " << setw(8) << getParameterSetting(i) << " ";
|
||||
log.flush();
|
||||
|
||||
implementations_[j]->initialize(getParameterSetting(i));
|
||||
implementations_[j]->tickle();
|
||||
|
||||
unsigned long iterations = getIterationSetting(i);
|
||||
|
||||
t.start();
|
||||
implementations_[j]->run(iterations);
|
||||
t.stop();
|
||||
double tm = t.elapsedSeconds();
|
||||
|
||||
t.start();
|
||||
implementations_[j]->runOverhead(iterations);
|
||||
t.stop();
|
||||
double tmOverhead = t.elapsedSeconds();
|
||||
|
||||
rates_(j,i) = iterations / (tm - tmOverhead);
|
||||
Mflops_(j,i) = rates_(j,i)
|
||||
* implementations_[j]->flopsPerIteration() / 1.0e+6;
|
||||
|
||||
log << setw(10) << (rates_(j,i)/1.0e+6) << " Mops/s ";
|
||||
|
||||
if (implementations_[j]->flopsPerIteration() != 0)
|
||||
{
|
||||
log << "[" << setw(7) << Mflops_(j,i) << " Mflops]";
|
||||
}
|
||||
|
||||
log << endl;
|
||||
log.flush();
|
||||
|
||||
implementations_[j]->done();
|
||||
}
|
||||
}
|
||||
|
||||
state_ = done;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
double Benchmark<P_parameter>::getMflops(unsigned implementation,
|
||||
unsigned setting) const
|
||||
{
|
||||
BZPRECONDITION(state_ == done);
|
||||
BZPRECONDITION(implementation < numImplementations_);
|
||||
BZPRECONDITION(setting < numParameterSettings());
|
||||
|
||||
return Mflops_(implementation, setting);
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
double Benchmark<P_parameter>::getRate(unsigned implementation,
|
||||
unsigned setting) const
|
||||
{
|
||||
BZPRECONDITION(state_ == done);
|
||||
BZPRECONDITION(implementation < numImplementations_);
|
||||
BZPRECONDITION(setting < numParameterSettings());
|
||||
|
||||
return rates_(implementation, setting);
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void Benchmark<P_parameter>::saveMatlabGraph(const char* filename) const
|
||||
{
|
||||
BZPRECONDITION(state_ == done);
|
||||
|
||||
{
|
||||
//ugly but saveMatlabGraph is coded into all benchmarks
|
||||
std::string pyfn(filename);
|
||||
pyfn=pyfn.replace(pyfn.find(".m"),2,std::string(".py"),0,3);
|
||||
savePylabGraph(pyfn.c_str());
|
||||
}
|
||||
|
||||
ofstream ofs(filename);
|
||||
|
||||
assert(ofs.good());
|
||||
|
||||
ofs << "% This matlab file generated automatically by class Benchmark"
|
||||
<< endl << "% of the Blitz++ class library." << endl << endl;
|
||||
|
||||
ofs.setf(ios::scientific);
|
||||
|
||||
ofs << "parm = [ ";
|
||||
int i;
|
||||
for (i=0; i < numParameterSettings(); ++i)
|
||||
ofs << setprecision(12) << double(getParameterSetting(i)) << " ";
|
||||
ofs << "]; " << endl << endl;
|
||||
|
||||
ofs << "Mf = [ ";
|
||||
for (i=0; i < numParameterSettings(); ++i)
|
||||
{
|
||||
for (int j=0; j < numImplementations_; ++j)
|
||||
{
|
||||
ofs << setprecision(12) << getMflops(j,i) << " ";
|
||||
}
|
||||
if (i != numParameterSettings()-1)
|
||||
ofs << ";" << endl;
|
||||
}
|
||||
ofs << "] ;" << endl << endl;
|
||||
|
||||
ofs << "semilogx(parm,Mf), title('" << description() << "'), " << endl
|
||||
<< " xlabel('" << parameterDescription() << "'), "
|
||||
<< "ylabel('Mflops')" << endl
|
||||
<< "legend(";
|
||||
|
||||
for (int j=0; j < numImplementations_; ++j)
|
||||
{
|
||||
ofs << "'" << implementations_[j]->implementationName()
|
||||
<< "'";
|
||||
if (j != numImplementations_ - 1)
|
||||
ofs << ", ";
|
||||
}
|
||||
|
||||
ofs << ")" << endl;
|
||||
}
|
||||
|
||||
|
||||
template<typename P_parameter>
|
||||
void Benchmark<P_parameter>::savePylabGraph(const char* filename) const
|
||||
{
|
||||
BZPRECONDITION(state_ == done);
|
||||
|
||||
ofstream ofs(filename);
|
||||
|
||||
assert(ofs.good());
|
||||
|
||||
ofs << "# This python file generated automatically by class Benchmark\n"
|
||||
<< "# of the Blitz++ class library.\n"
|
||||
<< "from pylab import *\nfrom numpy import *\n"
|
||||
<< "clf()\n";
|
||||
|
||||
ofs.setf(ios::scientific);
|
||||
|
||||
ofs << "parm = array([ ";
|
||||
int i;
|
||||
for (i=0; i < numParameterSettings(); ++i)
|
||||
ofs << setprecision(12) << double(getParameterSetting(i)) << ", ";
|
||||
ofs << "])\n\n";
|
||||
|
||||
ofs << "Mf = array([[ ";
|
||||
for (i=0; i < numParameterSettings(); ++i)
|
||||
{
|
||||
if(i>0) ofs << ", [ ";
|
||||
for (int j=0; j < numImplementations_; ++j)
|
||||
{
|
||||
ofs << setprecision(12) << getMflops(j,i) << ", ";
|
||||
}
|
||||
ofs << "]";
|
||||
}
|
||||
ofs << "])" << endl << endl;
|
||||
|
||||
ofs << "semilogx(parm,Mf)\ntitle('" << description() << "')\n"
|
||||
<< "xlabel('" << parameterDescription() << "')\n"
|
||||
<< "ylabel('Mflops')\n";
|
||||
<< "legend([";
|
||||
|
||||
for (int j=0; j < numImplementations_; ++j)
|
||||
{
|
||||
ofs << "'" << implementations_[j]->implementationName()
|
||||
<< "'";
|
||||
if (j != numImplementations_ - 1)
|
||||
ofs << ", ";
|
||||
}
|
||||
|
||||
ofs << "])\n";
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_BENCH_CC
|
||||
@@ -1,143 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/bench.h Benchmark classes
|
||||
*
|
||||
* $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_BENCH_H
|
||||
#define BZ_BENCH_H
|
||||
|
||||
#include <blitz/matrix.h>
|
||||
#include <blitz/timer.h>
|
||||
|
||||
#if defined(BZ_HAVE_STD)
|
||||
#include <cmath>
|
||||
#else
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// Forward declaration
|
||||
template<typename P_parameter = unsigned>
|
||||
class BenchmarkImplementation;
|
||||
|
||||
|
||||
// Declaration of class Benchmark<T>
|
||||
// The template parameter T is the parameter type which is varied in
|
||||
// the benchmark. Typically T will be an unsigned, and will represent
|
||||
// the length of a vector, size of an array, etc.
|
||||
|
||||
template<typename P_parameter = unsigned>
|
||||
class Benchmark {
|
||||
|
||||
public:
|
||||
typedef P_parameter T_parameter;
|
||||
|
||||
Benchmark(unsigned numImplementations);
|
||||
|
||||
~Benchmark();
|
||||
|
||||
void addImplementation(BenchmarkImplementation<T_parameter>*
|
||||
implementation);
|
||||
|
||||
void run(ostream& log = cout);
|
||||
|
||||
double getMflops(unsigned implementation, unsigned setting) const;
|
||||
|
||||
double getRate(unsigned implementation, unsigned setting) const;
|
||||
|
||||
void saveMatlabGraph(const char* filename) const;
|
||||
void savePylabGraph(const char* filename) const;
|
||||
|
||||
public:
|
||||
// Virtual functions
|
||||
|
||||
virtual const char* description() const
|
||||
{ return ""; }
|
||||
|
||||
virtual const char* parameterDescription() const
|
||||
{ return "Vector length"; }
|
||||
|
||||
virtual unsigned numParameterSettings() const
|
||||
{ return 19; }
|
||||
|
||||
virtual T_parameter getParameterSetting(unsigned i) const
|
||||
{ return BZ_MATHFN_SCOPE(pow)(10.0, (i+1)/4.0); }
|
||||
|
||||
virtual long getIterationSetting(unsigned i) const
|
||||
{ return 1000000L / getParameterSetting(i); }
|
||||
|
||||
private:
|
||||
Benchmark(const Benchmark<P_parameter>&) { }
|
||||
void operator=(const Benchmark<P_parameter>&) { }
|
||||
|
||||
enum { uninitialized, initialized, running, done } state_;
|
||||
|
||||
unsigned numImplementations_;
|
||||
unsigned numStoredImplementations_;
|
||||
|
||||
BenchmarkImplementation<T_parameter>** implementations_;
|
||||
|
||||
Matrix<double,RowMajor> rates_; // Iterations per second array
|
||||
Matrix<double,RowMajor> Mflops_;
|
||||
};
|
||||
|
||||
template<typename P_parameter>
|
||||
class BenchmarkImplementation {
|
||||
|
||||
public:
|
||||
typedef P_parameter T_parameter;
|
||||
|
||||
virtual void initialize(P_parameter parameter) { }
|
||||
|
||||
virtual void done() { }
|
||||
|
||||
virtual const char* implementationName() const
|
||||
{ return ""; }
|
||||
|
||||
virtual void run(long iterations) = 0;
|
||||
|
||||
virtual void runOverhead(long iterations)
|
||||
{
|
||||
for (long i=0; i < iterations; ++i)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
virtual void tickle() { }
|
||||
|
||||
virtual long flopsPerIteration() const
|
||||
{ return 0; }
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#include <blitz/bench.cc>
|
||||
|
||||
#endif // BZ_BENCH_H
|
||||
@@ -1,467 +0,0 @@
|
||||
/***************************************************************************
|
||||
* blitz/benchext.cc Methods for Benchmarking class with external control.
|
||||
*
|
||||
* $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_BENCHEXT_CC
|
||||
#define BZ_BENCHEXT_CC
|
||||
|
||||
#ifndef BZ_BENCHEXT_H
|
||||
#error <blitz/benchext.cc> must be included via <blitz/benchext.h>
|
||||
#endif
|
||||
|
||||
//#include <blitz/vector-et.h>
|
||||
|
||||
#ifdef BZ_HAVE_STD
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#else
|
||||
#include <fstream.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename P_parameter>
|
||||
BenchmarkExt<P_parameter>::BenchmarkExt(const char* name,
|
||||
int numImplementations)
|
||||
{
|
||||
BZPRECONDITION(numImplementations > 0);
|
||||
|
||||
description_ = name;
|
||||
numImplementations_ = numImplementations;
|
||||
|
||||
implementationDescriptions_.resize(numImplementations);
|
||||
parameterDescription_ = "Vector length";
|
||||
|
||||
// we don't really know this is the default, do we...
|
||||
setDependentVariable("flops");
|
||||
|
||||
/*
|
||||
// Set up default parameters and iterations
|
||||
setNumParameters(19);
|
||||
|
||||
// NEEDS_WORK: once pow(X,Y) is supported, can just say
|
||||
// parameters_ = pow(10.0, Range(1,20)/4.0);
|
||||
|
||||
for (unsigned i=0; i < numParameters_; ++i)
|
||||
parameters_(i) = static_cast<P_parameter>(BZ_MATHFN_SCOPE(pow)(10.0, (i+1)/4.0));
|
||||
|
||||
iterations_ = 5.0e+5 / parameters_;
|
||||
flopsPerIteration_ = parameters_;
|
||||
*/
|
||||
// Set up initial state
|
||||
state_ = initializing;
|
||||
implementationNumber_ = 0;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
BenchmarkExt<P_parameter>::~BenchmarkExt()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void BenchmarkExt<P_parameter>::setNumParameters(int numParameters)
|
||||
{
|
||||
//BZPRECONDITION(state_ == initializing);
|
||||
|
||||
numParameters_ = numParameters;
|
||||
|
||||
parameters_.resize(numParameters_);
|
||||
iterations_.resize(numParameters_);
|
||||
flopsPerIteration_.resize(numParameters_);
|
||||
|
||||
// Set up timer and Mflops array
|
||||
times_.resize(numImplementations_, numParameters_);
|
||||
instr_.resize(numImplementations_, numParameters_);
|
||||
flops_.resize(numImplementations_, numParameters_);
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void BenchmarkExt<P_parameter>::setParameterVector(Array<P_parameter,1> parms)
|
||||
{
|
||||
BZPRECONDITION(state_ == initializing);
|
||||
BZPRECONDITION(parms.size() == parameters_.size());
|
||||
|
||||
parameters_ = parms;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void BenchmarkExt<P_parameter>::setParameterDescription(const char* string)
|
||||
{
|
||||
parameterDescription_ = string;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void BenchmarkExt<P_parameter>::setIterations(Array<long,1> iters)
|
||||
{
|
||||
BZPRECONDITION(state_ == initializing);
|
||||
|
||||
iterations_ = iters;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void BenchmarkExt<P_parameter>::setOpsPerIteration(Array<double,1>
|
||||
flopsPerIteration)
|
||||
{
|
||||
BZPRECONDITION(flopsPerIteration_.size() == flopsPerIteration.size());
|
||||
|
||||
flopsPerIteration_ = flopsPerIteration;
|
||||
}
|
||||
|
||||
/** Set the dependent variable of the measurements. If the independent
|
||||
variable is seconds, we output "G<dvar>/s", if it is cycles, we
|
||||
output "<dvar/c". */
|
||||
template<typename P_parameter>
|
||||
void BenchmarkExt<P_parameter>::setDependentVariable(const char* dvar)
|
||||
{
|
||||
BZPRECONDITION(Timer::indep_var()!="");
|
||||
|
||||
if(timer_.indep_var()=="s") {
|
||||
depvar_ = string("G")+dvar+"/s";
|
||||
timerconversion_ = 1./1e9;
|
||||
}
|
||||
else if(timer_.indep_var()=="c") {
|
||||
depvar_ = string(dvar)+"/c";
|
||||
timerconversion_ = 1.;
|
||||
}
|
||||
else {
|
||||
depvar_ = std::string(dvar)+"/"+timer_.indep_var();
|
||||
timerconversion_ = 1;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void BenchmarkExt<P_parameter>::beginBenchmarking()
|
||||
{
|
||||
BZPRECONDITION(state_ == initializing);
|
||||
state_ = benchmarking;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void BenchmarkExt<P_parameter>::beginImplementation(const char* description)
|
||||
{
|
||||
// it would really be better if it worked for as many as we give it
|
||||
BZPRECONDITION(implementationNumber_ < numImplementations_);
|
||||
BZPRECONDITION(state_ == benchmarking);
|
||||
|
||||
implementationDescriptions_[implementationNumber_] = description;
|
||||
|
||||
state_ = benchmarkingImplementation;
|
||||
parameterNumber_ = 0;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
bool BenchmarkExt<P_parameter>::doneImplementationBenchmark() const
|
||||
{
|
||||
BZPRECONDITION(state_ == benchmarkingImplementation);
|
||||
return parameterNumber_ == numParameters_;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
const string& BenchmarkExt<P_parameter>::currentImplementation() const
|
||||
{
|
||||
BZPRECONDITION(implementationNumber_ < numImplementations_);
|
||||
return implementationDescriptions_[implementationNumber_];
|
||||
}
|
||||
|
||||
|
||||
template<typename P_parameter>
|
||||
P_parameter BenchmarkExt<P_parameter>::getParameter() const
|
||||
{
|
||||
BZPRECONDITION(state_ == benchmarkingImplementation);
|
||||
BZPRECONDITION(parameterNumber_ < numParameters_);
|
||||
|
||||
return parameters_(parameterNumber_);
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
long BenchmarkExt<P_parameter>::getIterations() const
|
||||
{
|
||||
BZPRECONDITION(state_ == benchmarkingImplementation);
|
||||
BZPRECONDITION(parameterNumber_ < numParameters_);
|
||||
|
||||
return iterations_(parameterNumber_);
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
inline void BenchmarkExt<P_parameter>::start()
|
||||
{
|
||||
BZPRECONDITION(state_ == benchmarkingImplementation);
|
||||
BZPRECONDITION(parameterNumber_ < numParameters_);
|
||||
state_ = running;
|
||||
timer_.start();
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
inline void BenchmarkExt<P_parameter>::stop()
|
||||
{
|
||||
timer_.stop();
|
||||
BZPRECONDITION(state_ == running);
|
||||
state_ = benchmarkingImplementation;
|
||||
|
||||
times_(int(implementationNumber_), int(parameterNumber_)) = timer_.elapsed();
|
||||
instr_(int(implementationNumber_), int(parameterNumber_)) = timer_.instr();
|
||||
flops_(int(implementationNumber_), int(parameterNumber_)) = timer_.flops();
|
||||
++parameterNumber_;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
inline void BenchmarkExt<P_parameter>::startOverhead()
|
||||
{
|
||||
BZPRECONDITION(state_ == benchmarkingImplementation);
|
||||
BZPRECONDITION(parameterNumber_ > 0);
|
||||
BZPRECONDITION(parameterNumber_ <= numParameters_);
|
||||
state_ = runningOverhead;
|
||||
timer_.start();
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
inline void BenchmarkExt<P_parameter>::stopOverhead()
|
||||
{
|
||||
BZPRECONDITION(state_ == runningOverhead);
|
||||
timer_.stop();
|
||||
|
||||
cout << "\ttimer overhead: " <<
|
||||
1.0*timer_.elapsed()/times_(int(implementationNumber_), int(parameterNumber_-1)) << endl;
|
||||
|
||||
times_(int(implementationNumber_), int(parameterNumber_-1)) -=
|
||||
timer_.elapsed();
|
||||
instr_(int(implementationNumber_), int(parameterNumber_-1)) -=
|
||||
timer_.instr();
|
||||
flops_(int(implementationNumber_), int(parameterNumber_-1)) -=
|
||||
timer_.flops();
|
||||
|
||||
if(times_(int(implementationNumber_), int(parameterNumber_-1))<0) {
|
||||
cerr << "\tError: Timer underflow in benchmark " << implementationDescriptions_[implementationNumber_] << " " << parameters_(parameterNumber_-1) << endl;
|
||||
times_(int(implementationNumber_), int(parameterNumber_-1)) = blitz::huge(times_(0,0));
|
||||
}
|
||||
state_ = benchmarkingImplementation;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
inline void BenchmarkExt<P_parameter>::skip()
|
||||
{
|
||||
BZPRECONDITION(state_ == benchmarkingImplementation);
|
||||
BZPRECONDITION(parameterNumber_ < numParameters_);
|
||||
times_(int(implementationNumber_), int(parameterNumber_)) = blitz::quiet_NaN(double());
|
||||
++parameterNumber_;
|
||||
state_ = benchmarkingImplementation;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void BenchmarkExt<P_parameter>::endImplementation()
|
||||
{
|
||||
BZPRECONDITION(state_ == benchmarkingImplementation);
|
||||
BZPRECONDITION(parameterNumber_ == numParameters_);
|
||||
|
||||
++implementationNumber_;
|
||||
|
||||
state_ = benchmarking;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void BenchmarkExt<P_parameter>::endBenchmarking()
|
||||
{
|
||||
BZPRECONDITION(state_ == benchmarking);
|
||||
BZPRECONDITION(implementationNumber_ == numImplementations_);
|
||||
|
||||
state_ = done;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
double BenchmarkExt<P_parameter>::getMflops(unsigned implementation,
|
||||
unsigned parameterNum) const
|
||||
{
|
||||
BZPRECONDITION(state_ == done);
|
||||
BZPRECONDITION(implementation < numImplementations_);
|
||||
BZPRECONDITION(parameterNum < numParameters_);
|
||||
return 1.0*iterations_(parameterNum) * flopsPerIteration_(parameterNum)
|
||||
/ times_(int(implementation), int(parameterNum)) * timerconversion_;
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
double BenchmarkExt<P_parameter>::getinstrperc(int implementation,
|
||||
int parameterNum) const
|
||||
{
|
||||
BZPRECONDITION(state_ == done);
|
||||
BZPRECONDITION(implementation < numImplementations_);
|
||||
BZPRECONDITION(parameterNum < numParameters_);
|
||||
return 1.0*instr_(implementation,parameterNum)/
|
||||
times_(int(implementation), int(parameterNum));
|
||||
}
|
||||
template<typename P_parameter>
|
||||
double BenchmarkExt<P_parameter>::getflopsperc(int implementation,
|
||||
int parameterNum) const
|
||||
{
|
||||
BZPRECONDITION(state_ == done);
|
||||
BZPRECONDITION(implementation < numImplementations_);
|
||||
BZPRECONDITION(parameterNum < numParameters_);
|
||||
return 1.0*flops_(implementation,parameterNum)/
|
||||
times_(int(implementation), int(parameterNum));
|
||||
}
|
||||
|
||||
template<typename P_parameter>
|
||||
void BenchmarkExt<P_parameter>::saveMatlabGraph(const char* filename, const char* graphType) const
|
||||
{
|
||||
BZPRECONDITION(state_ == done);
|
||||
|
||||
{
|
||||
//ugly but saveMatlabGraph is coded into all benchmarks
|
||||
std::string pyfn(filename);
|
||||
pyfn=pyfn.replace(pyfn.find(".m"),2,std::string(".py"),0,3);
|
||||
savePylabGraph(pyfn.c_str());
|
||||
}
|
||||
|
||||
ofstream ofs(filename);
|
||||
|
||||
assert(ofs.good());
|
||||
|
||||
ofs << "% This matlab file generated automatically by class Benchmark"
|
||||
<< endl << "% of the Blitz++ class library." << endl << endl;
|
||||
|
||||
ofs.setf(ios::scientific);
|
||||
|
||||
// This will be a lot simpler once Matlab-style output formatting
|
||||
// of vectors & matrices is finished.
|
||||
|
||||
// ofs << "parm = " << parameters_ << ";" << endl << endl;
|
||||
|
||||
ofs << "parm = [ ";
|
||||
unsigned i;
|
||||
for (i=0; i < numParameters_; ++i)
|
||||
ofs << setprecision(12) << double(parameters_(i)) << " ";
|
||||
ofs << "]; " << endl << endl;
|
||||
|
||||
ofs << "Mf = [ ";
|
||||
for (i=0; i < numParameters_; ++i)
|
||||
{
|
||||
for (unsigned j=0; j < numImplementations_; ++j)
|
||||
{
|
||||
ofs << setprecision(12) << getMflops(j,i) << " ";
|
||||
}
|
||||
if (i != numParameters_ - 1)
|
||||
ofs << ";" << endl;
|
||||
}
|
||||
ofs << "] ;" << endl << endl;
|
||||
|
||||
ofs << graphType << "(parm,Mf), title('" << description_ << "'), " << endl
|
||||
<< " xlabel('" << parameterDescription_ << "'), "
|
||||
<< "ylabel('" << depvar_ << "')\n"
|
||||
<< "legend(";
|
||||
|
||||
for (unsigned j=0; j < numImplementations_; ++j)
|
||||
{
|
||||
ofs << "'" << implementationDescriptions_[j] << "'";
|
||||
if (j != numImplementations_ - 1)
|
||||
ofs << ", ";
|
||||
}
|
||||
|
||||
ofs << ")" << endl;
|
||||
}
|
||||
|
||||
|
||||
template<typename P_parameter>
|
||||
void BenchmarkExt<P_parameter>::savePylabGraph(const char* filename, const char* graphType) const
|
||||
{
|
||||
BZPRECONDITION(state_ == done);
|
||||
|
||||
ofstream ofs(filename);
|
||||
|
||||
assert(ofs.good());
|
||||
|
||||
ofs << "# This python file generated automatically by class Benchmark\n"
|
||||
<< "# of the Blitz++ class library.\n"
|
||||
<< "from pylab import *\nfrom numpy import *\n"
|
||||
<< "clf()\n";
|
||||
|
||||
ofs.setf(ios::scientific);
|
||||
|
||||
ofs << "legnames=[";
|
||||
for (unsigned j=0; j < numImplementations_; ++j)
|
||||
{
|
||||
ofs << "'" << implementationDescriptions_[j] << "'";
|
||||
if (j != numImplementations_ - 1)
|
||||
ofs << ", ";
|
||||
}
|
||||
|
||||
ofs << "]\n\nparm = array([ ";
|
||||
unsigned i;
|
||||
for (i=0; i < numParameters_; ++i)
|
||||
ofs << setprecision(12) << double(parameters_(i)) << ", ";
|
||||
ofs << "])\n\n";
|
||||
|
||||
ofs << "Mf = array([[ ";
|
||||
for (i=0; i < numParameters_; ++i)
|
||||
{
|
||||
if(i>0) ofs << ", [ ";
|
||||
for (unsigned j=0; j < numImplementations_; ++j)
|
||||
{
|
||||
ofs << setprecision(12) << getMflops(j,i);
|
||||
if(j<numImplementations_-1) ofs << ", ";
|
||||
}
|
||||
ofs << "]";
|
||||
}
|
||||
ofs << "])" << endl << endl;
|
||||
#ifdef BZ_HAVE_LIBPAPI
|
||||
// add i/c and flops counters
|
||||
ofs << "ic = array([[ ";
|
||||
for (i=0; i < numParameters_; ++i)
|
||||
{
|
||||
if(i>0) ofs << ", [ ";
|
||||
for (unsigned j=0; j < numImplementations_; ++j)
|
||||
{
|
||||
ofs << setprecision(12) << getinstrperc(j,i);
|
||||
if(j<numImplementations_-1) ofs << ", ";
|
||||
}
|
||||
ofs << "]";
|
||||
}
|
||||
ofs << "])" << endl << endl;
|
||||
ofs << "fc = array([[ ";
|
||||
for (i=0; i < numParameters_; ++i)
|
||||
{
|
||||
if(i>0) ofs << ", [ ";
|
||||
for (unsigned j=0; j < numImplementations_; ++j)
|
||||
{
|
||||
ofs << setprecision(12) << getflopsperc(j,i);
|
||||
if(j<numImplementations_-1) ofs << ", ";
|
||||
}
|
||||
ofs << "]";
|
||||
}
|
||||
ofs << "])" << endl << endl;
|
||||
#endif
|
||||
|
||||
ofs << graphType << "(parm,Mf)\ntitle('" << description_ << "')\n"
|
||||
<< "xlabel('" << parameterDescription_ << "')\n"
|
||||
<< "ylabel('" << depvar_ << "')\n";
|
||||
|
||||
ofs << "legend(legnames)\n";
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_BENCHEXT_CC
|
||||
@@ -1,137 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/benchext.h BenchmarkExt classes (Benchmarks with external
|
||||
* control)
|
||||
*
|
||||
* $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_BENCHEXT_H
|
||||
#define BZ_BENCHEXT_H
|
||||
|
||||
//#ifndef BZ_MATRIX_H
|
||||
#include <blitz/array.h>
|
||||
//#endif
|
||||
#include <vector>
|
||||
|
||||
#ifndef BZ_TIMER_H
|
||||
#include <blitz/timer.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <string>
|
||||
|
||||
// NEEDS_WORK: replace use of const char* with <string>, once standard
|
||||
// library is widely supported.
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// Declaration of class BenchmarkExt<T>
|
||||
// The template parameter T is the parameter type which is varied in
|
||||
// the benchmark. Typically T will be an unsigned, and will represent
|
||||
// the length of a vector, size of an array, etc.
|
||||
|
||||
template<typename P_parameter = unsigned>
|
||||
class BenchmarkExt {
|
||||
|
||||
public:
|
||||
typedef P_parameter T_parameter;
|
||||
|
||||
BenchmarkExt(const char* description, int numImplementations);
|
||||
|
||||
~BenchmarkExt();
|
||||
|
||||
void setNumParameters(int numParameters);
|
||||
void setParameterVector(Array<T_parameter,1> parms);
|
||||
void setParameterDescription(const char* string);
|
||||
void setIterations(Array<long,1> iters);
|
||||
void setOpsPerIteration(Array<double,1> flopsPerIteration);
|
||||
void setDependentVariable(const char* string);
|
||||
|
||||
void beginBenchmarking();
|
||||
|
||||
void beginImplementation(const char* description);
|
||||
bool doneImplementationBenchmark() const;
|
||||
const string& currentImplementation() const;
|
||||
|
||||
T_parameter getParameter() const;
|
||||
long getIterations() const;
|
||||
|
||||
inline void start();
|
||||
inline void stop();
|
||||
|
||||
void startOverhead();
|
||||
void stopOverhead();
|
||||
void skip();
|
||||
|
||||
|
||||
void endImplementation();
|
||||
|
||||
void endBenchmarking();
|
||||
double getMflops(unsigned implementation, unsigned parameterNum) const;
|
||||
double getinstrperc(int implementation, int parameterNum) const;
|
||||
double getflopsperc(int implementation, int parameterNum) const;
|
||||
|
||||
void saveMatlabGraph(const char* filename, const char* graphType="semilogx") const;
|
||||
void savePylabGraph(const char* filename, const char* graphType="semilogx") const;
|
||||
|
||||
protected:
|
||||
BenchmarkExt(const BenchmarkExt<P_parameter>&) { }
|
||||
void operator=(const BenchmarkExt<P_parameter>&) { }
|
||||
|
||||
enum { initializing, benchmarking, benchmarkingImplementation,
|
||||
running, runningOverhead, done } state_;
|
||||
|
||||
unsigned numImplementations_;
|
||||
unsigned implementationNumber_;
|
||||
|
||||
std::string description_;
|
||||
std::vector<std::string> implementationDescriptions_;
|
||||
|
||||
Array<double,2> times_; // Elapsed time
|
||||
Array<long long,2> instr_; // instructions according to timer
|
||||
Array<long long,2> flops_; // flops according to timer
|
||||
|
||||
Array<T_parameter,1> parameters_;
|
||||
Array<long,1> iterations_;
|
||||
Array<double,1> flopsPerIteration_;
|
||||
|
||||
Timer timer_;
|
||||
|
||||
std::string parameterDescription_;
|
||||
std::string depvar_;
|
||||
double timerconversion_;
|
||||
|
||||
unsigned numParameters_;
|
||||
unsigned parameterNumber_;
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#include <blitz/benchext.cc>
|
||||
|
||||
#endif // BZ_BENCHEXT_H
|
||||
@@ -1,198 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/blitz.h Includes all the important header files
|
||||
*
|
||||
* $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_BLITZ_H
|
||||
#define BZ_BLITZ_H
|
||||
|
||||
/*
|
||||
* These symbols allow use of the IEEE and System V math libraries
|
||||
* (libm.a and libmsaa.a) on some platforms.
|
||||
*/
|
||||
|
||||
#ifdef BZ_ENABLE_XOPEN_SOURCE
|
||||
#ifndef _ALL_SOURCE
|
||||
#define _ALL_SOURCE
|
||||
#endif
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE
|
||||
#endif
|
||||
#ifndef _XOPEN_SOURCE_EXTENDED
|
||||
#define _XOPEN_SOURCE_EXTENDED 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <blitz/bzconfig.h>
|
||||
#include <blitz/compiler.h> // Compiler-specific directives
|
||||
#include <blitz/tuning.h> // Performance tuning
|
||||
#include <blitz/tau.h> // Profiling
|
||||
|
||||
#ifdef BZ_HAVE_STL
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_STD
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstdio> // sprintf, etc.
|
||||
#include <cmath>
|
||||
#else
|
||||
#include <iostream.h>
|
||||
#include <iomanip.h>
|
||||
#include <stdio.h> // sprintf, etc.
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX
|
||||
#include <complex>
|
||||
#endif
|
||||
|
||||
#define BZ_THROW // Needed in <blitz/numinquire.h>
|
||||
|
||||
// This macro is needed to pass template types to macros, since macros
|
||||
// don't recognize <> as parentheses.
|
||||
#define bzCC(...) __VA_ARGS__
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
#ifdef BZ_HAVE_STD
|
||||
BZ_USING_NAMESPACE(std)
|
||||
#endif
|
||||
|
||||
#ifdef BZ_GENERATE_GLOBAL_INSTANCES
|
||||
#define _bz_global
|
||||
#define BZ_GLOBAL_INIT(X) =X
|
||||
#else
|
||||
#define _bz_global extern
|
||||
#define BZ_GLOBAL_INIT(X)
|
||||
#endif
|
||||
|
||||
/* Define types for indexing, depending on whether 64- or 32-bit
|
||||
indices are desired. There are separate typedefs for sizeType and
|
||||
indexType, because it might be useful to have possibility of arrays
|
||||
with 64-bit numbers of elements without paying the size overhead of
|
||||
making all dimensional indexes 64-bit.
|
||||
*/
|
||||
// Used for dimensional indexes (not implemented yet).
|
||||
#ifdef BZ_FULLY64BIT
|
||||
#warning 64-bit array dimensions not yet implemented
|
||||
typedef ptrdiff_t indexType;
|
||||
#else
|
||||
typedef int indexType;
|
||||
#endif
|
||||
typedef size_t sizeType; // Used for memory indexing
|
||||
typedef ptrdiff_t diffType; // Used for memory index differences, ie strides
|
||||
|
||||
// set the default padding policy
|
||||
#ifdef BZ_PAD_ARRAYS
|
||||
#define BZ_PADDING_DEFAULT paddedData
|
||||
#else
|
||||
#define BZ_PADDING_DEFAULT contiguousData
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
/*
|
||||
* Thread safety issues. Compiling with -pthread under gcc, or -mt
|
||||
* under solaris, should automatically define _REENTRANT. Also have
|
||||
* support for OpenMP (which defines _OPENMP) or Windows thread
|
||||
* implementation. The --enable-threadsafe configure option now
|
||||
* defines BZ_THREADSAFE. If this is defined but no thread support is
|
||||
* detected when compiling, we call #error below.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Which mutex implementation should be used for synchronizing
|
||||
* reference counts. Options are Thread Building Block Atomics (which
|
||||
* is preferred over the others), pthreads, OpenMP, or Windows
|
||||
* threads. If we use TBB, the mutex macros are empty since it
|
||||
* requires no locking.
|
||||
*/
|
||||
#ifdef BZ_THREADSAFE
|
||||
#ifdef BZ_THREADSAFE_USE_TBB
|
||||
#include "tbb/atomic.h"
|
||||
#define BZ_THREADSAFE_USE_ATOMIC
|
||||
#define BZ_REFCOUNT_DECLARE(name) tbb::atomic<int> name;
|
||||
#else
|
||||
#define BZ_REFCOUNT_DECLARE(name) volatile int name;
|
||||
#if defined(_REENTRANT)
|
||||
#define BZ_THREADSAFE_USE_PTHREADS
|
||||
#elif defined (_OPENMP)
|
||||
#define BZ_THREADSAFE_USE_OPENMP
|
||||
#elif defined(_WIN32)
|
||||
#define BZ_THREADSAFE_USE_WINDOWS
|
||||
#else
|
||||
#error Blitz is configured with --enable-threadsafe, but no compiler thread support is found. Did you forget, e.g., "--pthread"?
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define BZ_REFCOUNT_DECLARE(name) int name;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BZ_THREADSAFE_USE_PTHREADS
|
||||
#include <pthread.h>
|
||||
|
||||
#define BZ_MUTEX_DECLARE(name) mutable pthread_mutex_t name;
|
||||
#define BZ_MUTEX_INIT(name) pthread_mutex_init(&name,NULL); mutexLocking_ = true;
|
||||
|
||||
#define BZ_MUTEX_LOCK(name) if (mutexLocking_) pthread_mutex_lock(&name);
|
||||
#define BZ_MUTEX_UNLOCK(name) if (mutexLocking_) pthread_mutex_unlock(&name);
|
||||
#define BZ_MUTEX_DESTROY(name) pthread_mutex_destroy(&name);
|
||||
#elif defined (BZ_THREADSAFE_USE_WINDOWS)
|
||||
// Include Windows.h header in case user has not already done so.
|
||||
// Disable Windows min/max macro definitions
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
|
||||
#define BZ_MUTEX_DECLARE(name) mutable CRITICAL_SECTION name;
|
||||
#define BZ_MUTEX_INIT(name) ::InitializeCriticalSection(&name); mutexLocking_ = true;
|
||||
#define BZ_MUTEX_LOCK(name) if (mutexLocking_) ::EnterCriticalSection(&name);
|
||||
#define BZ_MUTEX_UNLOCK(name) if (mutexLocking_) ::LeaveCriticalSection(&name);
|
||||
#define BZ_MUTEX_DESTROY(name) ::DeleteCriticalSection(&name);
|
||||
#elif defined (BZ_THREADSAFE_USE_OPENMP)
|
||||
#include <omp.h>
|
||||
|
||||
#define BZ_MUTEX_DECLARE(name) mutable omp_lock_t name;
|
||||
#define BZ_MUTEX_INIT(name) omp_init_lock(&name); mutexLocking_ = true;
|
||||
#define BZ_MUTEX_LOCK(name) if (mutexLocking_) omp_set_lock(&name);
|
||||
#define BZ_MUTEX_UNLOCK(name) if (mutexLocking_) omp_unset_lock(&name);
|
||||
#define BZ_MUTEX_DESTROY(name) omp_destroy_lock(&name);
|
||||
#else
|
||||
#define BZ_MUTEX_DECLARE(name)
|
||||
#define BZ_MUTEX_INIT(name)
|
||||
#define BZ_MUTEX_LOCK(name)
|
||||
#define BZ_MUTEX_UNLOCK(name)
|
||||
#define BZ_MUTEX_DESTROY(name)
|
||||
#endif
|
||||
|
||||
#include <blitz/bzdebug.h> // Debugging macros
|
||||
|
||||
#endif // BZ_BLITZ_H
|
||||
@@ -1,101 +0,0 @@
|
||||
#ifndef BZ_BOUNDS_H
|
||||
#define BZ_BOUNDS_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
struct bounds {
|
||||
static int compute_ascending(const int BZ_DEBUG_PARAM(rank),
|
||||
const int ascending1, const int ascending2)
|
||||
{
|
||||
// The value INT_MIN indicates that there are no arrays
|
||||
// in a subtree of the expression. This logic returns
|
||||
// whichever ascending is available. If there are two
|
||||
// conflicting ascending values, this is an error.
|
||||
|
||||
if (ascending1 == ascending2)
|
||||
return ascending1;
|
||||
else if (ascending1 == INT_MIN)
|
||||
return ascending2;
|
||||
else if (ascending2 == INT_MIN)
|
||||
return ascending1;
|
||||
|
||||
BZ_DEBUG_MESSAGE("Two array operands have different"
|
||||
<< endl << "ascending flags: for rank " << rank
|
||||
<< ", the flags are " << ascending1 << " and "
|
||||
<< ascending2 << endl);
|
||||
BZ_PRE_FAIL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int compute_ordering(const int BZ_DEBUG_PARAM(rank),
|
||||
const int order1, const int order2)
|
||||
{
|
||||
// The value INT_MIN indicates that there are no arrays
|
||||
// in a subtree of the expression. This logic returns
|
||||
// whichever ordering is available. If there are two
|
||||
// conflicting ordering values, this is an error.
|
||||
|
||||
if (order1 == order2)
|
||||
return order1;
|
||||
else if (order1 == INT_MIN)
|
||||
return order2;
|
||||
else if (order2 == INT_MIN)
|
||||
return order1;
|
||||
|
||||
BZ_DEBUG_MESSAGE("Two array operands have different"
|
||||
<< endl << "orders: for rank " << rank << ", the orders are "
|
||||
<< order1 << " and " << order2 << endl);
|
||||
BZ_PRE_FAIL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int compute_lbound(const int BZ_DEBUG_PARAM(rank),
|
||||
const int lbound1, const int lbound2)
|
||||
{
|
||||
// The value INT_MIN indicates that there are no arrays
|
||||
// in a subtree of the expression. This logic returns
|
||||
// whichever lbound is available. If there are two
|
||||
// conflicting lbound values, this is an error.
|
||||
|
||||
if (lbound1 == lbound2)
|
||||
return lbound1;
|
||||
else if (lbound1 == INT_MIN)
|
||||
return lbound2;
|
||||
else if (lbound2 == INT_MIN)
|
||||
return lbound1;
|
||||
|
||||
BZ_DEBUG_MESSAGE("Two array operands have different"
|
||||
<< endl << "lower bounds: in rank " << rank << ", the bounds are "
|
||||
<< lbound1 << " and " << lbound2 << endl);
|
||||
BZ_PRE_FAIL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int compute_ubound(const int BZ_DEBUG_PARAM(rank),
|
||||
const int ubound1, const int ubound2)
|
||||
{
|
||||
// The value INT_MAX indicates that there are no arrays
|
||||
// in a subtree of the expression. This logic returns
|
||||
// whichever ubound is available. If there are two
|
||||
// conflicting ubound values, this is an error.
|
||||
|
||||
if (ubound1 == ubound2)
|
||||
return ubound1;
|
||||
else if (ubound1 == INT_MAX)
|
||||
return ubound2;
|
||||
else if (ubound2 == INT_MAX)
|
||||
return ubound1;
|
||||
|
||||
BZ_DEBUG_MESSAGE("Two array operands have different"
|
||||
<< endl << "upper bounds: in rank " << rank << ", the bounds are "
|
||||
<< ubound1 << " and " << ubound2 << endl);
|
||||
BZ_PRE_FAIL;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,99 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/bzconfig.h Select compiler-specific config file
|
||||
*
|
||||
* $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/
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/* Select the compiler-specific config.h header file */
|
||||
#ifndef BZCONFIG_H
|
||||
#define BZCONFIG_H
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#if defined(__GNUC__)
|
||||
/* GNU gcc compiler for newer Mac OS X Darwin */
|
||||
#include <blitz/gnu/bzconfig.h>
|
||||
#else
|
||||
/* IBM xlc compiler for Darwin */
|
||||
#include <blitz/apple/bzconfig.h>
|
||||
#endif
|
||||
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
/* Intel icc compiler */
|
||||
#include <blitz/intel/bzconfig.h>
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
/* Microsoft VS.NET compiler */
|
||||
#include <blitz/ms/bzconfig.h>
|
||||
|
||||
#elif defined(__xlC__)
|
||||
/* IBM xlC compiler */
|
||||
#include <blitz/ibm/bzconfig.h>
|
||||
|
||||
#elif defined(__DECCXX)
|
||||
/* Compaq cxx compiler */
|
||||
#include <blitz/compaq/bzconfig.h>
|
||||
|
||||
#elif defined(__HP_aCC)
|
||||
/* HP aCC compiler */
|
||||
#include <blitz/hp/bzconfig.h>
|
||||
|
||||
#elif defined(_SGI_COMPILER_VERSION)
|
||||
/* SGI CC compiler */
|
||||
#include <blitz/sgi/bzconfig.h>
|
||||
|
||||
#elif defined(__SUNPRO_CC)
|
||||
/* SunPRO CC compiler */
|
||||
#include <blitz/sun/bzconfig.h>
|
||||
|
||||
#elif defined(__PATHCC__)
|
||||
/* Pathscale pathCC compiler */
|
||||
#include <blitz/pathscale/bzconfig.h>
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
/* GNU gcc compiler */
|
||||
#include <blitz/gnu/bzconfig.h>
|
||||
|
||||
#elif defined(__PGI)
|
||||
/* PGI pgCC compiler */
|
||||
#include <blitz/pgi/bzconfig.h>
|
||||
|
||||
#elif defined(__KCC)
|
||||
/* KAI KCC compiler */
|
||||
#include <blitz/kai/bzconfig.h>
|
||||
|
||||
#elif defined(__FUJITSU)
|
||||
/* Fujitsu FCC compiler */
|
||||
#include <blitz/fujitsu/bzconfig.h>
|
||||
|
||||
/* Add other compilers here */
|
||||
|
||||
#else
|
||||
#error Unknown compiler
|
||||
#endif
|
||||
|
||||
#endif /* BZCONFIG_H */
|
||||
@@ -1,240 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/bzdebug.h Debugging macros
|
||||
*
|
||||
* $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_DEBUG_H
|
||||
#define BZ_DEBUG_H
|
||||
|
||||
#ifdef BZ_HAVE_STD
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_RTTI
|
||||
#include <typeinfo>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* These globals are used by the Blitz++ testsuite. The _bz_global
|
||||
* modifier ensures that they will reside in libblitz.a, but appear
|
||||
* "extern" elsewhere.
|
||||
*/
|
||||
|
||||
_bz_global bool assertFailMode BZ_GLOBAL_INIT(false);
|
||||
_bz_global int assertFailCount BZ_GLOBAL_INIT(0);
|
||||
_bz_global int assertSuccessCount BZ_GLOBAL_INIT(0);
|
||||
|
||||
|
||||
#if defined(BZ_TESTSUITE)
|
||||
/*
|
||||
* In testsuite mode, these routines allow a test suite to check
|
||||
* that precondition checking is being done properly. A typical
|
||||
* use looks like this:
|
||||
*
|
||||
* beginCheckAssert();
|
||||
* // Some operation which should cause an assert to fail
|
||||
* endCheckAssert();
|
||||
*
|
||||
* The routine beginCheckAssert() sets a flag which results in
|
||||
* failed asserts being silently tallied. If no asserts have
|
||||
* failed by the time endCheckAssert() is invoked, the program
|
||||
* halts and issues an error code.
|
||||
*
|
||||
* In normal operation (i.e. when beginCheckAssert() has not
|
||||
* been called), failed preconditions will cause the program
|
||||
* to halt and issue an error code. -- TV 980226
|
||||
*/
|
||||
|
||||
inline void checkAssert(bool condition, const char* where=0,
|
||||
int line=0)
|
||||
{
|
||||
if (assertFailMode == true)
|
||||
{
|
||||
if (condition == true)
|
||||
++assertSuccessCount;
|
||||
else
|
||||
++assertFailCount;
|
||||
}
|
||||
else {
|
||||
if (!condition)
|
||||
{
|
||||
BZ_STD_SCOPE(cerr) << "Unexpected assert failure!" << BZ_STD_SCOPE(endl);
|
||||
if (where)
|
||||
BZ_STD_SCOPE(cerr) << where << ":" << line << BZ_STD_SCOPE(endl);
|
||||
BZ_STD_SCOPE(cerr).flush();
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void beginCheckAssert()
|
||||
{
|
||||
assertFailMode = true;
|
||||
assertSuccessCount = 0;
|
||||
assertFailCount = 0;
|
||||
}
|
||||
|
||||
inline void endCheckAssert()
|
||||
{
|
||||
assert(assertFailMode == true);
|
||||
assertFailMode = false;
|
||||
if (assertFailCount == 0)
|
||||
{
|
||||
BZ_STD_SCOPE(cerr) << "Assert check failed!" << BZ_STD_SCOPE(endl);
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
#define BZASSERT(X) blitz::checkAssert(X, __FILE__, __LINE__)
|
||||
#define BZPRECONDITION(X) blitz::checkAssert(X, __FILE__, __LINE__)
|
||||
#define BZPOSTCONDITION(X) blitz::checkAssert(X, __FILE__, __LINE__)
|
||||
#define BZSTATECHECK(X,Y) blitz::checkAssert(X == Y, __FILE__, __LINE__)
|
||||
#define BZPRECHECK(X,Y) \
|
||||
{ \
|
||||
if ((assertFailMode == false) && (!(X))) \
|
||||
BZ_STD_SCOPE(cerr) << Y << BZ_STD_SCOPE(endl); \
|
||||
blitz::checkAssert(X, __FILE__, __LINE__); \
|
||||
}
|
||||
|
||||
#define BZ_DEBUG_MESSAGE(X) \
|
||||
{ \
|
||||
if (assertFailMode == false) \
|
||||
{ \
|
||||
BZ_STD_SCOPE(cout) << __FILE__ << ":" << __LINE__ << " " \
|
||||
<< X << BZ_STD_SCOPE(endl); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define BZ_DEBUG_PARAM(X) X
|
||||
#define BZ_PRE_FAIL blitz::checkAssert(0)
|
||||
#define BZ_ASM_DEBUG_MARKER
|
||||
|
||||
#elif defined(BZ_DEBUG)
|
||||
|
||||
#define BZASSERT(X) assert(X)
|
||||
#define BZPRECONDITION(X) assert(X)
|
||||
#define BZPOSTCONDITION(X) assert(X)
|
||||
#define BZSTATECHECK(X,Y) assert(X == Y)
|
||||
#define BZPRECHECK(X,Y) \
|
||||
{ if (!(X)) \
|
||||
{ BZ_STD_SCOPE(cerr) << "[Blitz++] Precondition failure: Module " \
|
||||
<< __FILE__ \
|
||||
<< " line " << __LINE__ << BZ_STD_SCOPE(endl) \
|
||||
<< Y << BZ_STD_SCOPE(endl); \
|
||||
BZ_STD_SCOPE(cerr).flush(); \
|
||||
assert(0); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define BZ_DEBUG_MESSAGE(X) \
|
||||
{ BZ_STD_SCOPE(cout) << __FILE__ << ":" << __LINE__ << " " \
|
||||
<< X << BZ_STD_SCOPE(endl); }
|
||||
|
||||
#define BZ_DEBUG_PARAM(X) X
|
||||
#define BZ_PRE_FAIL assert(0)
|
||||
|
||||
// This routine doesn't exist anywhere; it's used to mark a
|
||||
// position of interest in assembler (.s) files
|
||||
void _bz_debug_marker();
|
||||
#define BZ_ASM_DEBUG_MARKER _bz_debug_marker();
|
||||
|
||||
#else // !BZ_TESTSUITE && !BZ_DEBUG
|
||||
|
||||
#define BZASSERT(X)
|
||||
#define BZPRECONDITION(X)
|
||||
#define BZPOSTCONDITION(X)
|
||||
#define BZSTATECHECK(X,Y)
|
||||
#define BZPRECHECK(X,Y)
|
||||
#define BZ_DEBUG_MESSAGE(X)
|
||||
#define BZ_DEBUG_PARAM(X)
|
||||
#define BZ_PRE_FAIL
|
||||
#define BZ_ASM_DEBUG_MARKER
|
||||
|
||||
#endif // !BZ_TESTSUITE && !BZ_DEBUG
|
||||
|
||||
#define BZ_NOT_IMPLEMENTED() \
|
||||
{ BZ_STD_SCOPE(cerr) << "[Blitz++] Not implemented: module " \
|
||||
<< __FILE__ << " line " << __LINE__ << BZ_STD_SCOPE(endl); \
|
||||
BZ_STD_SCOPE(exit)(1); }
|
||||
|
||||
#ifdef BZ_HAVE_RTTI
|
||||
#define BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(X) typeid(X).name()
|
||||
#else
|
||||
|
||||
template<typename T>
|
||||
class _bz_stringLiteralForNumericType {
|
||||
public:
|
||||
static const char* string()
|
||||
{ return "unknown"; }
|
||||
};
|
||||
|
||||
#define BZ_DECL_SLFNT(X,Y) \
|
||||
template<> \
|
||||
class _bz_stringLiteralForNumericType< X > { \
|
||||
public: \
|
||||
static const char* string() \
|
||||
{ return Y; } \
|
||||
}
|
||||
|
||||
#ifdef BZ_HAVE_BOOL
|
||||
BZ_DECL_SLFNT(bool, "bool");
|
||||
#endif
|
||||
|
||||
BZ_DECL_SLFNT(char, "char");
|
||||
BZ_DECL_SLFNT(unsigned char, "unsigned char");
|
||||
BZ_DECL_SLFNT(short int, "short int");
|
||||
BZ_DECL_SLFNT(short unsigned int, "short unsigned int");
|
||||
BZ_DECL_SLFNT(int, "int");
|
||||
BZ_DECL_SLFNT(unsigned int, "unsigned int");
|
||||
BZ_DECL_SLFNT(long, "long");
|
||||
BZ_DECL_SLFNT(unsigned long, "unsigned long");
|
||||
BZ_DECL_SLFNT(float, "float");
|
||||
BZ_DECL_SLFNT(double, "double");
|
||||
BZ_DECL_SLFNT(long double, "long double");
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX
|
||||
BZ_DECL_SLFNT(complex<float>, "complex<float>");
|
||||
BZ_DECL_SLFNT(complex<double>, "complex<double>");
|
||||
BZ_DECL_SLFNT(complex<long double>, "complex<long double>");
|
||||
#endif
|
||||
|
||||
#define BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(X) \
|
||||
_bz_stringLiteralForNumericType<X>::string()
|
||||
|
||||
#endif // !BZ_HAVE_RTTI
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_DEBUG_H
|
||||
@@ -1,179 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/compiler.h Compiler specific directives and kludges
|
||||
*
|
||||
* 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_COMPILER_H
|
||||
#define BZ_COMPILER_H
|
||||
|
||||
// The file <blitz/bzconfig.h> is used to select a compiler-specific
|
||||
// config.h file that is generated automatically by configure.
|
||||
|
||||
#include <blitz/bzconfig.h>
|
||||
|
||||
/*
|
||||
* Define some kludges.
|
||||
*/
|
||||
|
||||
#ifndef BZ_HAVE_TEMPLATES
|
||||
#error In <blitz/config.h>: A working template implementation is required by Blitz++ (you may need to rerun the compiler/bzconfig script)
|
||||
#endif
|
||||
|
||||
#ifndef BZ_HAVE_MEMBER_TEMPLATES
|
||||
#error In <blitz/config.h>: Your compiler does not support member templates. (you may need to rerun the compiler/bzconfig script)
|
||||
#endif
|
||||
|
||||
#ifndef BZ_HAVE_FULL_SPECIALIZATION_SYNTAX
|
||||
#error In <blitz/config.h>: Your compiler does not support template<> full specialization syntax. You may need to rerun the compiler/bzconfig script.
|
||||
#endif
|
||||
|
||||
#ifndef BZ_HAVE_PARTIAL_ORDERING
|
||||
#error In <blitz/config.h>: Your compiler does not support partial ordering (you may need to rerun the compiler/bzconfig script)
|
||||
#endif
|
||||
|
||||
#ifndef BZ_HAVE_PARTIAL_SPECIALIZATION
|
||||
#error In <blitz/config.h>: Your compiler does not support partial specialization (you may need to rerun the compiler/bzconfig script)
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_NAMESPACES
|
||||
#define BZ_NAMESPACE(X) namespace X {
|
||||
#define BZ_NAMESPACE_END }
|
||||
#define BZ_USING_NAMESPACE(X) using namespace X;
|
||||
#else
|
||||
#define BZ_NAMESPACE(X)
|
||||
#define BZ_NAMESPACE_END
|
||||
#define BZ_USING_NAMESPACE(X)
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_TEMPLATE_QUALIFIED_RETURN_TYPE
|
||||
#define BZ_USE_NUMTRAIT
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_DEFAULT_TEMPLATE_PARAMETERS
|
||||
#define BZ_TEMPLATE_DEFAULT(X) = X
|
||||
#else
|
||||
#define BZ_TEMPLATE_DEFAULT(X)
|
||||
#endif
|
||||
|
||||
#ifndef BZ_HAVE_EXPLICIT
|
||||
#define explicit
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_TYPENAME
|
||||
#define _bz_typename typename
|
||||
#else
|
||||
#define _bz_typename
|
||||
#endif
|
||||
|
||||
#ifndef BZ_HAVE_MUTABLE
|
||||
#define mutable
|
||||
#endif
|
||||
|
||||
#ifdef BZ_DISABLE_RESTRICT
|
||||
#undef BZ_HAVE_NCEG_RESTRICT
|
||||
#endif
|
||||
|
||||
#ifndef BZ_HAVE_NCEG_RESTRICT
|
||||
#if defined(BZ_HAVE_NCEG_RESTRICT_EGCS)
|
||||
#define restrict __restrict__
|
||||
#else
|
||||
#define restrict
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(BZ_HAVE_BOOL) && !defined(BZ_NO_BOOL_KLUDGE)
|
||||
#define bool int
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_ENUM_COMPUTATIONS_WITH_CAST
|
||||
#define BZ_ENUM_CAST(X) (int)X
|
||||
#elif defined(BZ_HAVE_ENUM_COMPUTATIONS)
|
||||
#define BZ_ENUM_CAST(X) X
|
||||
#else
|
||||
#error In <blitz/config.h>: Your compiler does not support enum computations. You may have to rerun compiler/bzconfig.
|
||||
#endif
|
||||
|
||||
#if defined(BZ_MATH_FN_IN_NAMESPACE_STD)
|
||||
#define BZ_MATHFN_SCOPE(x) std::x
|
||||
#elif defined(BZ_HAVE_NAMESPACES)
|
||||
#define BZ_MATHFN_SCOPE(x) ::x
|
||||
#else
|
||||
#define BZ_MATHFN_SCOPE(x) x
|
||||
#endif
|
||||
|
||||
#if defined(BZ_MATH_ABSINT_IN_NAMESPACE_STD)
|
||||
#include <cstdlib>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if defined(BZ_MATH_ABSINT_IN_NAMESPACE_STD)
|
||||
#define BZ_MATHABSINT_SCOPE(x) std::x
|
||||
#elif defined(BZ_HAVE_NAMESPACES)
|
||||
#define BZ_MATHABSINT_SCOPE(x) ::x
|
||||
#else
|
||||
#define BZ_MATHABSINT_SCOPE(x) x
|
||||
#endif
|
||||
|
||||
#if defined(BZ_HAVE_COMPLEX_MATH_IN_NAMESPACE_STD)
|
||||
#define BZ_CMATHFN_SCOPE(x) std::x
|
||||
#elif defined(BZ_HAVE_NAMESPACES)
|
||||
#define BZ_CMATHFN_SCOPE(x) ::x
|
||||
#else
|
||||
#define BZ_CMATHFN_SCOPE(x) x
|
||||
#endif
|
||||
|
||||
#if defined(BZ_HAVE_NAMESPACES)
|
||||
#define BZ_IEEEMATHFN_SCOPE(x) ::x
|
||||
#else
|
||||
#define BZ_IEEEMATHFN_SCOPE(x) x
|
||||
#endif
|
||||
|
||||
#if defined(BZ_HAVE_NAMESPACES)
|
||||
#define BZ_BLITZ_SCOPE(x) blitz::x
|
||||
#else
|
||||
#define BZ_BLITZ_SCOPE(x) ::x
|
||||
#endif
|
||||
|
||||
#if defined(BZ_HAVE_NAMESPACES) && defined(BZ_HAVE_STD)
|
||||
#define BZ_STD_SCOPE(x) std::x
|
||||
#else
|
||||
#define BZ_STD_SCOPE(x) ::x
|
||||
#endif
|
||||
|
||||
// These macros are just markers to document the code in the places
|
||||
// where playing with the processor branch prediction scheme might
|
||||
// help. For now these are just nops.
|
||||
|
||||
#define BZ_LIKELY(x) (x)
|
||||
#define BZ_UNLIKELY(x) (x)
|
||||
|
||||
#endif // BZ_COMPILER_H
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef BZ_POINTERSTACK_H
|
||||
#define BZ_POINTERSTACK_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// helper class ConstPointerStack
|
||||
template<typename P_numtype, int N_rank>
|
||||
class ConstPointerStack {
|
||||
public:
|
||||
typedef P_numtype T_numtype;
|
||||
|
||||
void operator=(const ConstPointerStack<P_numtype,N_rank>& rhs)
|
||||
{
|
||||
for (int i=0; i<N_rank; ++i)
|
||||
stack_[i] = rhs.stack_[i];
|
||||
}
|
||||
|
||||
const T_numtype*& operator[](int position)
|
||||
{
|
||||
return stack_[position];
|
||||
}
|
||||
|
||||
private:
|
||||
const T_numtype * stack_[N_rank];
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,71 +0,0 @@
|
||||
#ifndef BZ_ET_FORWARD_H
|
||||
#define BZ_ET_FORWARD_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
|
||||
// forward declarations of ET classes
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename T> class ETBase;
|
||||
|
||||
// the actual array/vector classes
|
||||
template<typename P_numtype, int N_rank> class Array;
|
||||
template<typename P_numtype, int N_length> class TinyVector;
|
||||
template<typename P_numtype, int N_rows, int N_columns> class TinyMatrix;
|
||||
|
||||
// and their fast iterators
|
||||
template<typename P_numtype, int N_rank> class FastArrayIterator;
|
||||
template<typename P_numtype, int N_rank> class FastArrayCopyIterator;
|
||||
template<typename P_numtype, int N_length> class FastTV2Iterator;
|
||||
template<typename P_numtype, int N_length> class FastTV2CopyIterator;
|
||||
template<typename P_numtype, int N_rows,
|
||||
int N_columns> class FastTM2Iterator;
|
||||
template<typename P_numtype, int N_rows,
|
||||
int N_columns> class FastTM2CopyIterator;
|
||||
|
||||
// expression container classes
|
||||
template<typename P_expr> class _bz_ArrayExpr;
|
||||
template<typename P_expr, typename P_op> class _bz_ArrayExprUnaryOp;
|
||||
template<typename P_expr1, typename P_expr2,
|
||||
typename P_op> class _bz_ArrayExprBinaryOp;
|
||||
template<typename P_expr1, typename P_expr2,
|
||||
typename P_expr3, typename P_op> class _bz_ArrayExprTernaryOp;
|
||||
template<typename P_expr1, typename P_expr2, typename P_expr3,
|
||||
typename P_expr4, typename P_op> class _bz_ArrayExprQuaternaryOp;
|
||||
template<typename P_numtype> class _bz_ArrayExprConstant;
|
||||
|
||||
// more specialized expression types
|
||||
template<typename P_expr, int N_map0, int N_map1=0, int N_map2=0,
|
||||
int N_map3=0, int N_map4=0, int N_map5=0, int N_map6=0, int N_map7=0,
|
||||
int N_map8=0, int N_map9=0, int N_map10=0> class ArrayIndexMapping;
|
||||
|
||||
template<typename T_expr, int N_index,
|
||||
typename T_reduction> class _bz_ArrayExprReduce;
|
||||
|
||||
template<typename P_expr, _bz_typename P_result> class _bz_StencilExpr;
|
||||
|
||||
template<int N> class IndexPlaceholder;
|
||||
|
||||
template<typename P_expr1, typename P_expr2,
|
||||
typename P_expr3> class _bz_ArrayWhere;
|
||||
|
||||
// functors
|
||||
template<typename P_functor, typename P_expr,
|
||||
typename P_result> class _bz_FunctorExpr;
|
||||
|
||||
template<typename P_functor, typename P_expr1,
|
||||
typename P_expr2, typename P_result> class _bz_FunctorExpr2;
|
||||
|
||||
template<typename P_functor, typename P_expr1,
|
||||
typename P_expr2, typename P_expr3,
|
||||
class P_result> class _bz_FunctorExpr3;
|
||||
|
||||
class LeviCivita;
|
||||
|
||||
class Range;
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,60 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/etbase.h Declaration of the ETBase<T> 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_ETBASE_H
|
||||
#define BZ_ETBASE_H
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename T>
|
||||
class ETBase {
|
||||
public:
|
||||
typedef T T_unwrapped;
|
||||
|
||||
ETBase()
|
||||
{ }
|
||||
|
||||
ETBase(const ETBase<T>&)
|
||||
{ }
|
||||
|
||||
T& unwrap() { return static_cast<T&>(*this); }
|
||||
|
||||
const T& unwrap() const { return static_cast<const T&>(*this); }
|
||||
|
||||
ETBase<T>& wrap() { return static_cast<ETBase<T>&>(*this); }
|
||||
|
||||
const ETBase<T>& wrap() const { return static_cast<const ETBase<T>&>(*this); }
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ETBASE_H
|
||||
|
||||
@@ -1,657 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/funcs.h Function objects for math 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_FUNCS_H
|
||||
#define BZ_FUNCS_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/promote.h>
|
||||
#include <blitz/prettyprint.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/* Helper functions. We use SFINAE to make these apply only for
|
||||
non-blitz numerical types (POD and complex), because otherwise they
|
||||
match against Array, etc, better than the ET versions that take
|
||||
ETBase parameters. */
|
||||
|
||||
template<typename T, bool b> struct _bz_isnot_blitz {};
|
||||
template<typename T> struct _bz_isnot_blitz<T, true> {typedef T Type;};
|
||||
template<typename T, bool b> struct _bz_isnot_blitz<std::complex<T>, b> {typedef std::complex<T> Type;};
|
||||
|
||||
template <typename T>
|
||||
inline typename _bz_isnot_blitz<T, std::numeric_limits<T>::is_specialized>::Type
|
||||
pow2(const T x)
|
||||
{ return x*x; }
|
||||
|
||||
template <typename T>
|
||||
inline typename _bz_isnot_blitz<T, std::numeric_limits<T>::is_specialized>::Type
|
||||
pow3(const T x)
|
||||
{ return x*x*x; }
|
||||
|
||||
template <typename T>
|
||||
inline typename _bz_isnot_blitz<T, std::numeric_limits<T>::is_specialized>::Type
|
||||
pow4(const T x)
|
||||
{ return x*x*x*x; }
|
||||
|
||||
template <typename T>
|
||||
inline typename _bz_isnot_blitz<T, std::numeric_limits<T>::is_specialized>::Type
|
||||
pow5(const T x)
|
||||
{ return x*x*x*x*x; }
|
||||
|
||||
template <typename T>
|
||||
inline typename _bz_isnot_blitz<T, std::numeric_limits<T>::is_specialized>::Type
|
||||
pow6(const T x)
|
||||
{ return x*x*x*x*x*x; }
|
||||
|
||||
template <typename T>
|
||||
inline typename _bz_isnot_blitz<T, std::numeric_limits<T>::is_specialized>::Type
|
||||
pow7(const T x)
|
||||
{ return x*x*x*x*x*x*x; }
|
||||
|
||||
template <typename T>
|
||||
inline typename _bz_isnot_blitz<T, std::numeric_limits<T>::is_specialized>::Type
|
||||
pow8(const T x)
|
||||
{ return x*x*x*x*x*x*x*x; }
|
||||
|
||||
/** This class can be used to select between two types based on a bool. */
|
||||
template<bool b, typename T1, typename T2> struct ifthenelse {
|
||||
typedef T1 Type;
|
||||
};
|
||||
template<typename T1, typename T2> struct ifthenelse<false,T1,T2> {
|
||||
typedef T2 Type;
|
||||
};
|
||||
|
||||
|
||||
/* Unary functions whose return type is the same as the argument (if
|
||||
coerce_int is false) or (if coerce_int is true) returns a double
|
||||
for int arguments. (This is how gcc defines its math functions, so
|
||||
we should do the same.) Coerce_int is true except for the functions
|
||||
that can also meaningfully operate on ints. */
|
||||
|
||||
#define BZ_DEFINE_UNARY_FUNC(name,fun,coerce_int) \
|
||||
template<typename T_numtype1> \
|
||||
struct name { \
|
||||
typedef typename BZ_BLITZ_SCOPE(ifthenelse)<coerce_int,typename BZ_BLITZ_SCOPE(ifthenelse)<BZ_STD_SCOPE(numeric_limits)<T_numtype1>::is_integer,double,T_numtype1>::Type,T_numtype1>::Type T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(const T_numtype1 a) \
|
||||
{ return fun(a); } \
|
||||
\
|
||||
template<typename T1> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, const T1& t1) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_abs,BZ_MATHFN_SCOPE(abs),false)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_acos,BZ_MATHFN_SCOPE(acos),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_asin,BZ_MATHFN_SCOPE(asin),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_atan,BZ_MATHFN_SCOPE(atan),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_ceil,BZ_MATHFN_SCOPE(ceil),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_cos,BZ_MATHFN_SCOPE(cos),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_cosh,BZ_MATHFN_SCOPE(cosh),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_exp,BZ_MATHFN_SCOPE(exp),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_fabs,BZ_MATHFN_SCOPE(fabs),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_floor,BZ_MATHFN_SCOPE(floor),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_log,BZ_MATHFN_SCOPE(log),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_log10,BZ_MATHFN_SCOPE(log10),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_sin,BZ_MATHFN_SCOPE(sin),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_sinh,BZ_MATHFN_SCOPE(sinh),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_sqrt,BZ_MATHFN_SCOPE(sqrt),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_tan,BZ_MATHFN_SCOPE(tan),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_tanh,BZ_MATHFN_SCOPE(tanh),true)
|
||||
|
||||
#ifdef BZ_HAVE_IEEE_MATH
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_acosh,BZ_IEEEMATHFN_SCOPE(acosh),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_asinh,BZ_IEEEMATHFN_SCOPE(asinh),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_atanh,BZ_IEEEMATHFN_SCOPE(atanh),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_cbrt,BZ_IEEEMATHFN_SCOPE(cbrt),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_erf,BZ_IEEEMATHFN_SCOPE(erf),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_erfc,BZ_IEEEMATHFN_SCOPE(erfc),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_expm1,BZ_IEEEMATHFN_SCOPE(expm1),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_j0,BZ_IEEEMATHFN_SCOPE(j0),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_j1,BZ_IEEEMATHFN_SCOPE(j1),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_lgamma,BZ_IEEEMATHFN_SCOPE(lgamma),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_logb,BZ_IEEEMATHFN_SCOPE(logb),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_log1p,BZ_IEEEMATHFN_SCOPE(log1p),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_rint,BZ_IEEEMATHFN_SCOPE(rint),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_y0,BZ_IEEEMATHFN_SCOPE(y0),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_y1,BZ_IEEEMATHFN_SCOPE(y1),true)
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_SYSTEM_V_MATH
|
||||
BZ_DEFINE_UNARY_FUNC(Fn__class,BZ_IEEEMATHFN_SCOPE(_class),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_nearest,BZ_IEEEMATHFN_SCOPE(nearest),true)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_rsqrt,BZ_IEEEMATHFN_SCOPE(rsqrt),true)
|
||||
#endif
|
||||
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_sqr,BZ_BLITZ_SCOPE(pow2),false)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_cube,BZ_BLITZ_SCOPE(pow3),false)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_pow4,BZ_BLITZ_SCOPE(pow4),false)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_pow5,BZ_BLITZ_SCOPE(pow5),false)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_pow6,BZ_BLITZ_SCOPE(pow6),false)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_pow7,BZ_BLITZ_SCOPE(pow7),false)
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_pow8,BZ_BLITZ_SCOPE(pow8),false)
|
||||
|
||||
/* Unary functions that return a specified type */
|
||||
|
||||
#define BZ_DEFINE_UNARY_FUNC_RET(name,fun,ret) \
|
||||
template<typename T_numtype1> \
|
||||
struct name { \
|
||||
typedef ret T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(const T_numtype1 a) \
|
||||
{ return fun(a); } \
|
||||
\
|
||||
template<typename T1> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, const T1& t1) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
#ifdef BZ_HAVE_IEEE_MATH
|
||||
BZ_DEFINE_UNARY_FUNC_RET(Fn_ilogb,BZ_IEEEMATHFN_SCOPE(ilogb),int)
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_SYSTEM_V_MATH
|
||||
BZ_DEFINE_UNARY_FUNC_RET(Fn_itrunc,BZ_IEEEMATHFN_SCOPE(itrunc),int)
|
||||
BZ_DEFINE_UNARY_FUNC_RET(Fn_uitrunc,BZ_IEEEMATHFN_SCOPE(uitrunc),unsigned int)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX
|
||||
/* Specialization of unary functor for complex type */
|
||||
|
||||
#define BZ_DEFINE_UNARY_CFUNC(name,fun) \
|
||||
template<typename T> \
|
||||
struct name< BZ_STD_SCOPE(complex)<T> > { \
|
||||
typedef BZ_STD_SCOPE(complex)<T> T_numtype1; \
|
||||
typedef BZ_STD_SCOPE(complex)<T> T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(const T_numtype1 a) \
|
||||
{ return fun(a); } \
|
||||
\
|
||||
template<typename T1> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, const T1& t1) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX_FCNS
|
||||
BZ_DEFINE_UNARY_FUNC(Fn_conj,BZ_CMATHFN_SCOPE(conj),false)
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX_MATH1
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_cos,BZ_CMATHFN_SCOPE(cos))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_cosh,BZ_CMATHFN_SCOPE(cosh))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_exp,BZ_CMATHFN_SCOPE(exp))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_log,BZ_CMATHFN_SCOPE(log))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_log10,BZ_CMATHFN_SCOPE(log10))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_sin,BZ_CMATHFN_SCOPE(sin))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_sinh,BZ_CMATHFN_SCOPE(sinh))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_sqrt,BZ_CMATHFN_SCOPE(sqrt))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_tan,BZ_CMATHFN_SCOPE(tan))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_tanh,BZ_CMATHFN_SCOPE(tanh))
|
||||
#endif // BZ_HAVE_COMPLEX_MATH1
|
||||
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_sqr,BZ_BLITZ_SCOPE(pow2))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_cube,BZ_BLITZ_SCOPE(pow3))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_pow4,BZ_BLITZ_SCOPE(pow4))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_pow5,BZ_BLITZ_SCOPE(pow5))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_pow6,BZ_BLITZ_SCOPE(pow6))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_pow7,BZ_BLITZ_SCOPE(pow7))
|
||||
BZ_DEFINE_UNARY_CFUNC(Fn_pow8,BZ_BLITZ_SCOPE(pow8))
|
||||
|
||||
/* Unary functions that apply only to complex<T> and return T */
|
||||
|
||||
#define BZ_DEFINE_UNARY_CFUNC2(name,fun) \
|
||||
template<typename T_numtype1> \
|
||||
struct name; \
|
||||
\
|
||||
template<typename T> \
|
||||
struct name< BZ_STD_SCOPE(complex)<T> > { \
|
||||
typedef BZ_STD_SCOPE(complex)<T> T_numtype1; \
|
||||
typedef T T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(const T_numtype1 a) \
|
||||
{ return fun(a); } \
|
||||
\
|
||||
template<typename T1> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, const T1& t1) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX_FCNS
|
||||
BZ_DEFINE_UNARY_CFUNC2(Fn_abs,BZ_CMATHFN_SCOPE(abs))
|
||||
BZ_DEFINE_UNARY_CFUNC2(Fn_arg,BZ_CMATHFN_SCOPE(arg))
|
||||
BZ_DEFINE_UNARY_CFUNC2(Fn_imag,BZ_CMATHFN_SCOPE(imag))
|
||||
BZ_DEFINE_UNARY_CFUNC2(Fn_norm,BZ_CMATHFN_SCOPE(norm))
|
||||
BZ_DEFINE_UNARY_CFUNC2(Fn_real,BZ_CMATHFN_SCOPE(real))
|
||||
#endif // BZ_HAVE_COMPLEX_FCNS
|
||||
|
||||
#endif // BZ_HAVE_COMPLEX
|
||||
|
||||
/* Binary functions that return type based on type promotion */
|
||||
|
||||
#define BZ_DEFINE_BINARY_FUNC(name,fun) \
|
||||
template<typename T_numtype1, typename T_numtype2> \
|
||||
struct name { \
|
||||
typedef BZ_PROMOTE(T_numtype1, T_numtype2) T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a, T_numtype2 b) \
|
||||
{ return fun(a,b); } \
|
||||
\
|
||||
template<typename T1, typename T2> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, const T1& t1, \
|
||||
const T2& t2) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += ","; \
|
||||
t2.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
BZ_DEFINE_BINARY_FUNC(Fn_atan2,BZ_MATHFN_SCOPE(atan2))
|
||||
BZ_DEFINE_BINARY_FUNC(Fn_fmod,BZ_MATHFN_SCOPE(fmod))
|
||||
BZ_DEFINE_BINARY_FUNC(Fn_pow,BZ_MATHFN_SCOPE(pow))
|
||||
|
||||
#ifdef BZ_HAVE_SYSTEM_V_MATH
|
||||
BZ_DEFINE_BINARY_FUNC(Fn_copysign,BZ_IEEEMATHFN_SCOPE(copysign))
|
||||
BZ_DEFINE_BINARY_FUNC(Fn_drem,BZ_IEEEMATHFN_SCOPE(drem))
|
||||
BZ_DEFINE_BINARY_FUNC(Fn_hypot,BZ_IEEEMATHFN_SCOPE(hypot))
|
||||
BZ_DEFINE_BINARY_FUNC(Fn_nextafter,BZ_IEEEMATHFN_SCOPE(nextafter))
|
||||
BZ_DEFINE_BINARY_FUNC(Fn_remainder,BZ_IEEEMATHFN_SCOPE(remainder))
|
||||
BZ_DEFINE_BINARY_FUNC(Fn_scalb,BZ_IEEEMATHFN_SCOPE(scalb))
|
||||
#endif
|
||||
|
||||
/* Binary functions that return a specified type */
|
||||
|
||||
#define BZ_DEFINE_BINARY_FUNC_RET(name,fun,ret) \
|
||||
template<typename T_numtype1, typename T_numtype2> \
|
||||
struct name { \
|
||||
typedef ret T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a, T_numtype2 b) \
|
||||
{ return fun(a,b); } \
|
||||
\
|
||||
template<typename T1, typename T2> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, const T1& t1, \
|
||||
const T2& t2) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += ","; \
|
||||
t2.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
#ifdef BZ_HAVE_SYSTEM_V_MATH
|
||||
BZ_DEFINE_BINARY_FUNC_RET(Fn_unordered,BZ_IEEEMATHFN_SCOPE(unordered),int)
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX
|
||||
/* Specialization of binary functor for complex type */
|
||||
|
||||
#define BZ_DEFINE_BINARY_CFUNC(name,fun) \
|
||||
template<typename T> \
|
||||
struct name< BZ_STD_SCOPE(complex)<T>, BZ_STD_SCOPE(complex)<T> > { \
|
||||
typedef BZ_STD_SCOPE(complex)<T> T_numtype1; \
|
||||
typedef BZ_STD_SCOPE(complex)<T> T_numtype2; \
|
||||
typedef BZ_STD_SCOPE(complex)<T> T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a, T_numtype2 b) \
|
||||
{ return fun(a,b); } \
|
||||
\
|
||||
template<typename T1, typename T2> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, const T1& t1, \
|
||||
const T2& t2) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += ","; \
|
||||
t2.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
template<typename T> \
|
||||
struct name< BZ_STD_SCOPE(complex)<T>, T > { \
|
||||
typedef BZ_STD_SCOPE(complex)<T> T_numtype1; \
|
||||
typedef T T_numtype2; \
|
||||
typedef BZ_STD_SCOPE(complex)<T> T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a, T_numtype2 b) \
|
||||
{ return fun(a,b); } \
|
||||
\
|
||||
template<typename T1, typename T2> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, const T1& t1, \
|
||||
const T2& t2) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += ","; \
|
||||
t2.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
template<typename T> \
|
||||
struct name< T, BZ_STD_SCOPE(complex)<T> > { \
|
||||
typedef T T_numtype1; \
|
||||
typedef BZ_STD_SCOPE(complex)<T> T_numtype2; \
|
||||
typedef BZ_STD_SCOPE(complex)<T> T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a, T_numtype2 b) \
|
||||
{ return fun(a,b); } \
|
||||
\
|
||||
template<typename T1, typename T2> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, const T1& t1, \
|
||||
const T2& t2) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += ","; \
|
||||
t2.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX_MATH1
|
||||
BZ_DEFINE_BINARY_CFUNC(Fn_pow,BZ_CMATHFN_SCOPE(pow))
|
||||
#endif
|
||||
|
||||
/* Binary functions that apply only to T and return complex<T> */
|
||||
|
||||
#define BZ_DEFINE_BINARY_FUNC_CRET(name,fun) \
|
||||
template<typename T_numtype1, typename T_numtype2> \
|
||||
struct name; \
|
||||
\
|
||||
template<typename T> \
|
||||
struct name<T, T> { \
|
||||
typedef T T_numtype1; \
|
||||
typedef T T_numtype2; \
|
||||
typedef BZ_STD_SCOPE(complex)<T> T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a, T_numtype2 b) \
|
||||
{ return fun(a,b); } \
|
||||
\
|
||||
template<typename T1, typename T2> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, const T1& t1, \
|
||||
const T2& t2) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += ","; \
|
||||
t2.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX_FCNS
|
||||
BZ_DEFINE_BINARY_FUNC_CRET(Fn_polar,BZ_CMATHFN_SCOPE(polar))
|
||||
#endif
|
||||
|
||||
#endif // BZ_HAVE_COMPLEX
|
||||
|
||||
/* Ternary functions that return type based on type promotion */
|
||||
|
||||
#define BZ_DEFINE_TERNARY_FUNC(name,fun) \
|
||||
template <typename P_numtype1, typename P_numtype2, \
|
||||
typename P_numtype3> \
|
||||
struct name { \
|
||||
typedef BZ_PROMOTE(P_numtype1, \
|
||||
BZ_PROMOTE(P_numtype2,P_numtype3)) T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(P_numtype1 x, P_numtype2 y, P_numtype3 z) \
|
||||
{ return fun(x,y,z); } \
|
||||
\
|
||||
template <typename T1, typename T2, typename T3> \
|
||||
static void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, \
|
||||
const T1& a,const T2& b, const T3& c) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
a.prettyPrint(str,format); \
|
||||
str += ","; \
|
||||
b.prettyPrint(str,format); \
|
||||
str += ","; \
|
||||
c.prettyPrint(str,format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
/* Ternary functions that return a specified type */
|
||||
|
||||
#define BZ_DEFINE_TERNARY_FUNC_RET(name,fun,ret) \
|
||||
template <typename P_numtype1, typename P_numtype2, \
|
||||
typename P_numtype3> \
|
||||
struct name { \
|
||||
typedef ret T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(P_numtype1 x, P_numtype2 y, P_numtype3 z) \
|
||||
{ return fun(x,y,z); } \
|
||||
\
|
||||
template <typename T1, typename T2, typename T3> \
|
||||
static void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, \
|
||||
const T1& a,const T2& b, const T3& c) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
a.prettyPrint(str,format); \
|
||||
str += ","; \
|
||||
b.prettyPrint(str,format); \
|
||||
str += ","; \
|
||||
c.prettyPrint(str,format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
/* Quaternary functions that return type based on type promotion */
|
||||
|
||||
#define BZ_DEFINE_QUATERNARY_FUNC(name,fun) \
|
||||
template<typename T_numtype1, typename T_numtype2, \
|
||||
typename T_numtype3, typename T_numtype4> \
|
||||
struct name { \
|
||||
typedef BZ_PROMOTE(BZ_PROMOTE(T_numtype1, T_numtype2), \
|
||||
BZ_PROMOTE(T_numtype3, T_numtype4)) T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(const T_numtype1 a, const T_numtype2 b, \
|
||||
const T_numtype3 c, const T_numtype4 d) \
|
||||
{ return fun(a,b,c,d); } \
|
||||
\
|
||||
template<typename T1, typename T2, \
|
||||
typename T3, typename T4> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
BZ_BLITZ_SCOPE(prettyPrintFormat) &format, \
|
||||
const T1& t1,const T2& t2, const T3& t3, const T4& t4) \
|
||||
{ \
|
||||
str += #fun; \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += ","; \
|
||||
t2.prettyPrint(str, format); \
|
||||
str += ","; \
|
||||
t3.prettyPrint(str, format); \
|
||||
str += ","; \
|
||||
t4.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
|
||||
/* These functions don't quite fit the usual patterns */
|
||||
|
||||
#ifdef BZ_HAVE_IEEE_MATH
|
||||
// isnan() Nonzero if NaNS or NaNQ
|
||||
template<typename T_numtype1>
|
||||
struct Fn_isnan {
|
||||
typedef int T_numtype;
|
||||
|
||||
static inline T_numtype
|
||||
apply(T_numtype1 a)
|
||||
{
|
||||
#ifdef BZ_ISNAN_IN_NAMESPACE_STD
|
||||
return BZ_STD_SCOPE(isnan)(a);
|
||||
#else
|
||||
return BZ_IEEEMATHFN_SCOPE(isnan)(a);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T1>
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str,
|
||||
prettyPrintFormat& format, const T1& t1)
|
||||
{
|
||||
str += "isnan";
|
||||
str += "(";
|
||||
t1.prettyPrint(str, format);
|
||||
str += ")";
|
||||
}
|
||||
};
|
||||
#endif // BZ_HAVE_IEEE_MATH
|
||||
|
||||
|
||||
// Blitz cast() function
|
||||
template<typename T_numtype1, typename T_cast>
|
||||
struct Cast {
|
||||
typedef T_cast T_numtype;
|
||||
|
||||
static inline T_numtype
|
||||
apply(T_numtype1 a)
|
||||
{ return T_numtype(a); }
|
||||
|
||||
template<typename T1>
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str,
|
||||
prettyPrintFormat& format, const T1& t1)
|
||||
{
|
||||
str += BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(T_cast);
|
||||
str += "(";
|
||||
t1.prettyPrint(str, format);
|
||||
str += ")";
|
||||
}
|
||||
};
|
||||
|
||||
// Blitz min/max functions
|
||||
template<typename T_numtype1, typename T_numtype2>
|
||||
struct Min {
|
||||
typedef BZ_PROMOTE(T_numtype1, T_numtype2) T_numtype;
|
||||
|
||||
static inline T_numtype
|
||||
apply(T_numtype1 a, T_numtype2 b)
|
||||
{ return (a < b ? a : b); }
|
||||
|
||||
template<typename T1, typename T2>
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str,
|
||||
prettyPrintFormat& format, const T1& t1, const T2& t2)
|
||||
{
|
||||
str += "min(";
|
||||
t1.prettyPrint(str, format);
|
||||
str += ",";
|
||||
t2.prettyPrint(str, format);
|
||||
str += ")";
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T_numtype1, typename T_numtype2>
|
||||
struct Max {
|
||||
typedef BZ_PROMOTE(T_numtype1, T_numtype2) T_numtype;
|
||||
|
||||
static inline T_numtype
|
||||
apply(T_numtype1 a, T_numtype2 b)
|
||||
{ return (a > b ? a : b); }
|
||||
|
||||
template<typename T1, typename T2>
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str,
|
||||
prettyPrintFormat& format, const T1& t1, const T2& t2)
|
||||
{
|
||||
str += "max(";
|
||||
t1.prettyPrint(str, format);
|
||||
str += ",";
|
||||
t2.prettyPrint(str, format);
|
||||
str += ")";
|
||||
}
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_FUNCS_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,436 +0,0 @@
|
||||
#ifndef _BLITZ_GNU_BZCONFIG_H
|
||||
#define _BLITZ_GNU_BZCONFIG_H 1
|
||||
|
||||
/* blitz/gnu/bzconfig.h. Generated automatically at end of configure. */
|
||||
/* blitz/config.h. Generated from config.h.in by configure. */
|
||||
/* blitz/config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* config.h Compiler language support flags
|
||||
*
|
||||
* This file was generated automatically when running the configure script.
|
||||
* You should rerun configure each time you switch compilers, install new
|
||||
* standard libraries, or change compiler versions.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* Macro for declaring aligned variables */
|
||||
#ifndef BZ_ALIGN_VARIABLE
|
||||
#define BZ_ALIGN_VARIABLE(vartype,varname,alignment) vartype varname;
|
||||
#endif
|
||||
|
||||
/* Enable dimensions with > 2^31 elements (NOT IMPLEMENTED) */
|
||||
/* #undef BZ_FULLY64BIT */
|
||||
|
||||
/* define if bool is a built-in type */
|
||||
#ifndef BZ_HAVE_BOOL
|
||||
#define BZ_HAVE_BOOL /**/
|
||||
#endif
|
||||
|
||||
/* define if the Boost library is available */
|
||||
/* #undef BZ_HAVE_BOOST */
|
||||
|
||||
/* Define to 1 if you have the <boost/mpi.hpp> header file. */
|
||||
/* #undef BZ_HAVE_BOOST_MPI_HPP */
|
||||
|
||||
/* define if the Boost::Serialization library is available */
|
||||
/* #undef BZ_HAVE_BOOST_SERIALIZATION */
|
||||
|
||||
/* define if the compiler has <climits> header */
|
||||
#ifndef BZ_HAVE_CLIMITS
|
||||
#define BZ_HAVE_CLIMITS /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler has complex<T> */
|
||||
#ifndef BZ_HAVE_COMPLEX
|
||||
#define BZ_HAVE_COMPLEX /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler has standard complex<T> functions */
|
||||
#ifndef BZ_HAVE_COMPLEX_FCNS
|
||||
#define BZ_HAVE_COMPLEX_FCNS /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler has complex math functions */
|
||||
#ifndef BZ_HAVE_COMPLEX_MATH1
|
||||
#define BZ_HAVE_COMPLEX_MATH1 /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler has more complex math functions */
|
||||
/* #undef BZ_HAVE_COMPLEX_MATH2 */
|
||||
|
||||
/* define if complex math functions are in namespace std */
|
||||
#ifndef BZ_HAVE_COMPLEX_MATH_IN_NAMESPACE_STD
|
||||
#define BZ_HAVE_COMPLEX_MATH_IN_NAMESPACE_STD /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports const_cast<> */
|
||||
#ifndef BZ_HAVE_CONST_CAST
|
||||
#define BZ_HAVE_CONST_CAST /**/
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <cstring> header file. */
|
||||
#ifndef BZ_HAVE_CSTRING
|
||||
#define BZ_HAVE_CSTRING 1
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports default template parameters */
|
||||
#ifndef BZ_HAVE_DEFAULT_TEMPLATE_PARAMETERS
|
||||
#define BZ_HAVE_DEFAULT_TEMPLATE_PARAMETERS /**/
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#ifndef BZ_HAVE_DLFCN_H
|
||||
#define BZ_HAVE_DLFCN_H 1
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports dynamic_cast<> */
|
||||
#ifndef BZ_HAVE_DYNAMIC_CAST
|
||||
#define BZ_HAVE_DYNAMIC_CAST /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler handle computations inside an enum */
|
||||
#ifndef BZ_HAVE_ENUM_COMPUTATIONS
|
||||
#define BZ_HAVE_ENUM_COMPUTATIONS /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler handles (int) casts in enum computations */
|
||||
#ifndef BZ_HAVE_ENUM_COMPUTATIONS_WITH_CAST
|
||||
#define BZ_HAVE_ENUM_COMPUTATIONS_WITH_CAST /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports exceptions */
|
||||
#ifndef BZ_HAVE_EXCEPTIONS
|
||||
#define BZ_HAVE_EXCEPTIONS /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports the explicit keyword */
|
||||
#ifndef BZ_HAVE_EXPLICIT
|
||||
#define BZ_HAVE_EXPLICIT /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports explicit template function qualification */
|
||||
#ifndef BZ_HAVE_EXPLICIT_TEMPLATE_FUNCTION_QUALIFICATION
|
||||
#define BZ_HAVE_EXPLICIT_TEMPLATE_FUNCTION_QUALIFICATION /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler recognizes the full specialization syntax */
|
||||
#ifndef BZ_HAVE_FULL_SPECIALIZATION_SYNTAX
|
||||
#define BZ_HAVE_FULL_SPECIALIZATION_SYNTAX /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports function templates with non-type parameters
|
||||
*/
|
||||
#ifndef BZ_HAVE_FUNCTION_NONTYPE_PARAMETERS
|
||||
#define BZ_HAVE_FUNCTION_NONTYPE_PARAMETERS /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports IEEE math library */
|
||||
#ifndef BZ_HAVE_IEEE_MATH
|
||||
#define BZ_HAVE_IEEE_MATH /**/
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#ifndef BZ_HAVE_INTTYPES_H
|
||||
#define BZ_HAVE_INTTYPES_H 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the `m' library (-lm). */
|
||||
/* #undef BZ_HAVE_LIBM */
|
||||
|
||||
/* Define to 1 if you have the `papi' library (-lpapi). */
|
||||
/* #undef BZ_HAVE_LIBPAPI */
|
||||
|
||||
/* define if the compiler supports member constants */
|
||||
#ifndef BZ_HAVE_MEMBER_CONSTANTS
|
||||
#define BZ_HAVE_MEMBER_CONSTANTS /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports member templates */
|
||||
#ifndef BZ_HAVE_MEMBER_TEMPLATES
|
||||
#define BZ_HAVE_MEMBER_TEMPLATES /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports member templates outside the class
|
||||
declaration */
|
||||
#ifndef BZ_HAVE_MEMBER_TEMPLATES_OUTSIDE_CLASS
|
||||
#define BZ_HAVE_MEMBER_TEMPLATES_OUTSIDE_CLASS /**/
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#ifndef BZ_HAVE_MEMORY_H
|
||||
#define BZ_HAVE_MEMORY_H 1
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports the mutable keyword */
|
||||
#ifndef BZ_HAVE_MUTABLE
|
||||
#define BZ_HAVE_MUTABLE /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler implements namespaces */
|
||||
#ifndef BZ_HAVE_NAMESPACES
|
||||
#define BZ_HAVE_NAMESPACES /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports the Numerical C Extensions Group restrict
|
||||
keyword */
|
||||
/* #undef BZ_HAVE_NCEG_RESTRICT */
|
||||
|
||||
/* define if the compiler supports the __restrict__ keyword */
|
||||
#ifndef BZ_HAVE_NCEG_RESTRICT_EGCS
|
||||
#define BZ_HAVE_NCEG_RESTRICT_EGCS /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler has numeric_limits<T> */
|
||||
#ifndef BZ_HAVE_NUMERIC_LIMITS
|
||||
#define BZ_HAVE_NUMERIC_LIMITS /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler accepts the old for scoping rules */
|
||||
/* #undef BZ_HAVE_OLD_FOR_SCOPING */
|
||||
|
||||
/* define if the compiler supports partial ordering */
|
||||
#ifndef BZ_HAVE_PARTIAL_ORDERING
|
||||
#define BZ_HAVE_PARTIAL_ORDERING /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports partial specialization */
|
||||
#ifndef BZ_HAVE_PARTIAL_SPECIALIZATION
|
||||
#define BZ_HAVE_PARTIAL_SPECIALIZATION /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports reinterpret_cast<> */
|
||||
#ifndef BZ_HAVE_REINTERPRET_CAST
|
||||
#define BZ_HAVE_REINTERPRET_CAST /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports Run-Time Type Identification */
|
||||
#ifndef BZ_HAVE_RTTI
|
||||
#define BZ_HAVE_RTTI /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler has getrusage() function */
|
||||
#ifndef BZ_HAVE_RUSAGE
|
||||
#define BZ_HAVE_RUSAGE /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports static_cast<> */
|
||||
#ifndef BZ_HAVE_STATIC_CAST
|
||||
#define BZ_HAVE_STATIC_CAST /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports ISO C++ standard library */
|
||||
#ifndef BZ_HAVE_STD
|
||||
#define BZ_HAVE_STD /**/
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#ifndef BZ_HAVE_STDINT_H
|
||||
#define BZ_HAVE_STDINT_H 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#ifndef BZ_HAVE_STDLIB_H
|
||||
#define BZ_HAVE_STDLIB_H 1
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports Standard Template Library */
|
||||
#ifndef BZ_HAVE_STL
|
||||
#define BZ_HAVE_STL /**/
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#ifndef BZ_HAVE_STRINGS_H
|
||||
#define BZ_HAVE_STRINGS_H 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#ifndef BZ_HAVE_STRING_H
|
||||
#define BZ_HAVE_STRING_H 1
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports System V math library */
|
||||
/* #undef BZ_HAVE_SYSTEM_V_MATH */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#ifndef BZ_HAVE_SYS_STAT_H
|
||||
#define BZ_HAVE_SYS_STAT_H 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#ifndef BZ_HAVE_SYS_TYPES_H
|
||||
#define BZ_HAVE_SYS_TYPES_H 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <tbb/atomic.h> header file. */
|
||||
/* #undef BZ_HAVE_TBB_ATOMIC_H */
|
||||
|
||||
/* define if the compiler supports basic templates */
|
||||
#ifndef BZ_HAVE_TEMPLATES
|
||||
#define BZ_HAVE_TEMPLATES /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports templates as template arguments */
|
||||
#ifndef BZ_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS
|
||||
#define BZ_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports use of the template keyword as a qualifier
|
||||
*/
|
||||
#ifndef BZ_HAVE_TEMPLATE_KEYWORD_QUALIFIER
|
||||
#define BZ_HAVE_TEMPLATE_KEYWORD_QUALIFIER /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports template-qualified base class specifiers */
|
||||
#ifndef BZ_HAVE_TEMPLATE_QUALIFIED_BASE_CLASS
|
||||
#define BZ_HAVE_TEMPLATE_QUALIFIED_BASE_CLASS /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports template-qualified return types */
|
||||
#ifndef BZ_HAVE_TEMPLATE_QUALIFIED_RETURN_TYPE
|
||||
#define BZ_HAVE_TEMPLATE_QUALIFIED_RETURN_TYPE /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports function matching with argument types which
|
||||
are template scope-qualified */
|
||||
#ifndef BZ_HAVE_TEMPLATE_SCOPED_ARGUMENT_MATCHING
|
||||
#define BZ_HAVE_TEMPLATE_SCOPED_ARGUMENT_MATCHING /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler recognizes typename */
|
||||
#ifndef BZ_HAVE_TYPENAME
|
||||
#define BZ_HAVE_TYPENAME /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports the vector type promotion mechanism */
|
||||
#ifndef BZ_HAVE_TYPE_PROMOTION
|
||||
#define BZ_HAVE_TYPE_PROMOTION /**/
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#ifndef BZ_HAVE_UNISTD_H
|
||||
#define BZ_HAVE_UNISTD_H 1
|
||||
#endif
|
||||
|
||||
/* define if the compiler supports numeric traits promotions */
|
||||
#ifndef BZ_HAVE_USE_NUMTRAIT
|
||||
#define BZ_HAVE_USE_NUMTRAIT /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler has valarray<T> */
|
||||
#ifndef BZ_HAVE_VALARRAY
|
||||
#define BZ_HAVE_VALARRAY /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler has isnan function in namespace std */
|
||||
#ifndef BZ_ISNAN_IN_NAMESPACE_STD
|
||||
#define BZ_ISNAN_IN_NAMESPACE_STD /**/
|
||||
#endif
|
||||
|
||||
/* Define to the sub-directory where libtool stores uninstalled libraries. */
|
||||
#ifndef BZ_LT_OBJDIR
|
||||
#define BZ_LT_OBJDIR ".libs/"
|
||||
#endif
|
||||
|
||||
/* define if the compiler has C math abs(integer types) in namespace std */
|
||||
#ifndef BZ_MATH_ABSINT_IN_NAMESPACE_STD
|
||||
#define BZ_MATH_ABSINT_IN_NAMESPACE_STD /**/
|
||||
#endif
|
||||
|
||||
/* define if the compiler has C math functions in namespace std */
|
||||
#ifndef BZ_MATH_FN_IN_NAMESPACE_STD
|
||||
#define BZ_MATH_FN_IN_NAMESPACE_STD /**/
|
||||
#endif
|
||||
|
||||
/* Name of package */
|
||||
#ifndef BZ_PACKAGE
|
||||
#define BZ_PACKAGE "blitz"
|
||||
#endif
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#ifndef BZ_PACKAGE_BUGREPORT
|
||||
#define BZ_PACKAGE_BUGREPORT "blitz-support@lists.sourceforge.net"
|
||||
#endif
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#ifndef BZ_PACKAGE_NAME
|
||||
#define BZ_PACKAGE_NAME "blitz"
|
||||
#endif
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#ifndef BZ_PACKAGE_STRING
|
||||
#define BZ_PACKAGE_STRING "blitz 0.10"
|
||||
#endif
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#ifndef BZ_PACKAGE_TARNAME
|
||||
#define BZ_PACKAGE_TARNAME "blitz"
|
||||
#endif
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#ifndef BZ_PACKAGE_URL
|
||||
#define BZ_PACKAGE_URL ""
|
||||
#endif
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#ifndef BZ_PACKAGE_VERSION
|
||||
#define BZ_PACKAGE_VERSION "0.10"
|
||||
#endif
|
||||
|
||||
/* Pad array lengths to SIMD width. */
|
||||
/* #undef BZ_PAD_ARRAYS */
|
||||
|
||||
/* Set SIMD instruction width in bytes */
|
||||
#ifndef BZ_SIMD_WIDTH
|
||||
#define BZ_SIMD_WIDTH 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#ifndef BZ_STDC_HEADERS
|
||||
#define BZ_STDC_HEADERS 1
|
||||
#endif
|
||||
|
||||
/* Enable Blitz thread-safety features */
|
||||
/* #undef BZ_THREADSAFE */
|
||||
|
||||
/* Use TBB atomic types */
|
||||
/* #undef BZ_THREADSAFE_USE_TBB */
|
||||
|
||||
/* Specifies whether compiler alignment pragmas should be used */
|
||||
/* #undef BZ_USE_ALIGNMENT_PRAGMAS */
|
||||
|
||||
/* Version number of package */
|
||||
#ifndef BZ_VERSION
|
||||
#define BZ_VERSION "0.10"
|
||||
#endif
|
||||
|
||||
/* CXX */
|
||||
#ifndef BZ__compiler_name
|
||||
#define BZ__compiler_name "c++"
|
||||
#endif
|
||||
|
||||
/* CXXFLAGS */
|
||||
#ifndef BZ__compiler_options
|
||||
#define BZ__compiler_options ""
|
||||
#endif
|
||||
|
||||
/* date */
|
||||
#ifndef BZ__config_date
|
||||
#define BZ__config_date "Thu Sep 13 14:05:09 CEST 2018"
|
||||
#endif
|
||||
|
||||
/* uname -a */
|
||||
#ifndef BZ__os_name
|
||||
#define BZ__os_name "Darwin Christians-MacBook-Pro-5.local 17.5.0 Darwin Kernel Version 17.5.0: Fri Apr 13 19:32:32 PDT 2018; root:xnu-4570.51.2~1/RELEASE_X86_64 x86_64"
|
||||
#endif
|
||||
|
||||
/* target */
|
||||
#ifndef BZ__platform
|
||||
#define BZ__platform "x86_64-apple-darwin17.5.0"
|
||||
#endif
|
||||
|
||||
/* once: _BLITZ_GNU_BZCONFIG_H */
|
||||
#endif
|
||||
@@ -1,275 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/indexexpr.h Declaration of the IndexPlaceholder<N> 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_INDEXEXPR_H
|
||||
#define BZ_INDEXEXPR_H
|
||||
|
||||
#include <blitz/tinyvec2.h>
|
||||
#include <blitz/prettyprint.h>
|
||||
#include <blitz/etbase.h>
|
||||
#include <blitz/array/domain.h>
|
||||
#include <blitz/array/slice.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<int N>
|
||||
class IndexPlaceholder
|
||||
#ifdef BZ_NEW_EXPRESSION_TEMPLATES
|
||||
: public ETBase<IndexPlaceholder<N> >
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
IndexPlaceholder()
|
||||
{ }
|
||||
|
||||
#ifdef BZ_NEW_EXPRESSION_TEMPLATES
|
||||
IndexPlaceholder(const IndexPlaceholder<N>& x)
|
||||
: ETBase< IndexPlaceholder<N> >(x)
|
||||
{ }
|
||||
#else
|
||||
IndexPlaceholder(const IndexPlaceholder<N>&)
|
||||
{ }
|
||||
#endif
|
||||
|
||||
~IndexPlaceholder()
|
||||
{ }
|
||||
|
||||
void operator=(const IndexPlaceholder<N>&)
|
||||
{ }
|
||||
|
||||
typedef int T_numtype;
|
||||
typedef int T_ctorArg1; // Dummy; not used
|
||||
typedef int T_ctorArg2; // Ditto
|
||||
typedef int T_range_result; // dummy
|
||||
|
||||
typedef typename opType<T_numtype>::T_optype T_optype;
|
||||
typedef typename asET<T_numtype>::T_wrapped T_typeprop;
|
||||
typedef typename unwrapET<T_typeprop>::T_unwrapped T_result;
|
||||
|
||||
static const int
|
||||
numArrayOperands = 0,
|
||||
numTVOperands = 0,
|
||||
numTMOperands = 0,
|
||||
numIndexPlaceholders = 1,
|
||||
minWidth = simdTypes<T_numtype>::vecWidth,
|
||||
maxWidth = simdTypes<T_numtype>::vecWidth,
|
||||
rank_ = N+1;
|
||||
|
||||
/** The vectorized return type for an IndexPlaceholder should be
|
||||
some form of range, but that's not useful since a vectorized
|
||||
TinyVector assignment can not contain index placeholders. In
|
||||
fact, since vectorization doesn't work for index expressions
|
||||
anyway, we can just set this to a dummy. */
|
||||
template<int M> struct tvresult {
|
||||
typedef FastTV2Iterator<T_numtype, M> Type;
|
||||
};
|
||||
|
||||
// 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.
|
||||
int operator*() const {
|
||||
BZPRECONDITION(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
|
||||
template<int N_rank>
|
||||
T_result operator()(TinyVector<int, N_rank> i) const { return i[N]; }
|
||||
#else
|
||||
template<int N_rank>
|
||||
T_result operator()(const TinyVector<int, N_rank>& i) const { return i[N]; }
|
||||
#endif
|
||||
|
||||
int ascending(int) const { return INT_MIN; }
|
||||
int ordering(int) const { return INT_MIN; }
|
||||
int lbound(int) const { return INT_MIN; } // tiny(int());
|
||||
int ubound(int) const { return INT_MAX; } // huge(int());
|
||||
|
||||
RectDomain<rank_> domain() const
|
||||
{
|
||||
const TinyVector<int, rank_> lb(lbound(0)), ub(ubound(0));
|
||||
return RectDomain<rank_>(lb,ub);
|
||||
}
|
||||
|
||||
// See operator*() note
|
||||
|
||||
void push(int) { BZPRECONDITION(0); }
|
||||
void pop(int) { BZPRECONDITION(0); }
|
||||
void advance() { BZPRECONDITION(0); }
|
||||
void advance(int) { BZPRECONDITION(0); }
|
||||
void loadStride(int) { BZPRECONDITION(0); }
|
||||
template<int N_rank>
|
||||
void moveTo(const TinyVector<int,N_rank>& i) { BZPRECONDITION(0); }
|
||||
|
||||
bool isUnitStride(int) const {
|
||||
BZPRECONDITION(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isUnitStride() const {
|
||||
BZPRECONDITION(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
void advanceUnitStride() { BZPRECONDITION(0); }
|
||||
|
||||
bool canCollapse(int,int) const {
|
||||
BZPRECONDITION(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
T_result operator[](int) const {
|
||||
BZPRECONDITION(0);
|
||||
return T_numtype();
|
||||
}
|
||||
|
||||
T_result fastRead(diffType) const {
|
||||
BZPRECONDITION(0);
|
||||
return T_numtype();
|
||||
}
|
||||
|
||||
template<int M>
|
||||
typename tvresult<M>::Type fastRead_tv(diffType) const {
|
||||
BZPRECONDITION(0);
|
||||
return TinyVector<T_numtype, M>();
|
||||
}
|
||||
|
||||
/** There are no alignment issues here, so just return true. */
|
||||
bool isVectorAligned(diffType offset) const {
|
||||
return true; }
|
||||
|
||||
diffType suggestStride(int) const {
|
||||
BZPRECONDITION(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool isStride(int,diffType) const {
|
||||
BZPRECONDITION(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
// don't know how to define shift, as it relies on having an
|
||||
// implicit position. thus stencils won't work
|
||||
T_result shift(int offset, int dim) const
|
||||
{ BZPRECHECK(0,"Stencils of index expressions are not implemented");
|
||||
return T_numtype(); }
|
||||
T_result shift(int offset1, int dim1,int offset2, int dim2) const {
|
||||
BZPRECHECK(0,"Stencils of index expressions 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 index expressions are not implemented");
|
||||
return T_range_result(); }
|
||||
|
||||
void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat&) const {
|
||||
// NEEDS_WORK-- do real formatting for reductions
|
||||
str += "index-expr[NEEDS_WORK]";
|
||||
}
|
||||
|
||||
template<typename T_shape>
|
||||
bool shapeCheck(const T_shape&) const { return true; }
|
||||
|
||||
// sliceinfo for index placeholder does nothing
|
||||
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:
|
||||
static const int new_rank =
|
||||
((N>0) ? ArraySectionInfo<T1>::rank : 0)
|
||||
+ ((N>1) ? ArraySectionInfo<T2>::rank : 0)
|
||||
+ ((N>2) ? ArraySectionInfo<T3>::rank : 0)
|
||||
+ ((N>3) ? ArraySectionInfo<T4>::rank : 0)
|
||||
+ ((N>4) ? ArraySectionInfo<T5>::rank : 0)
|
||||
+ ((N>5) ? ArraySectionInfo<T6>::rank : 0)
|
||||
+ ((N>6) ? ArraySectionInfo<T7>::rank : 0)
|
||||
+ ((N>7) ? ArraySectionInfo<T8>::rank : 0)
|
||||
+ ((N>8) ? ArraySectionInfo<T9>::rank : 0)
|
||||
+ ((N>9) ? ArraySectionInfo<T10>::rank : 0)
|
||||
+ ((N>10) ? ArraySectionInfo<T11>::rank : 0);
|
||||
typedef IndexPlaceholder<new_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
|
||||
{
|
||||
// slicing of index placeholders is not implemented. there are
|
||||
// two problems: First, if you slice the dimension of the index
|
||||
// placeholder, it should be replaced with a constant. Second,
|
||||
// if you restrict the range of that dimension, the index
|
||||
// placeholder should start from a nonzero value.
|
||||
BZPRECONDITION(0);
|
||||
}
|
||||
};
|
||||
|
||||
typedef IndexPlaceholder<0> firstIndex;
|
||||
typedef IndexPlaceholder<1> secondIndex;
|
||||
typedef IndexPlaceholder<2> thirdIndex;
|
||||
typedef IndexPlaceholder<3> fourthIndex;
|
||||
typedef IndexPlaceholder<4> fifthIndex;
|
||||
typedef IndexPlaceholder<5> sixthIndex;
|
||||
typedef IndexPlaceholder<6> seventhIndex;
|
||||
typedef IndexPlaceholder<7> eighthIndex;
|
||||
typedef IndexPlaceholder<8> ninthIndex;
|
||||
typedef IndexPlaceholder<9> tenthIndex;
|
||||
typedef IndexPlaceholder<10> eleventhIndex;
|
||||
|
||||
#ifndef BZ_NO_TENSOR_INDEX_OBJECTS
|
||||
|
||||
BZ_NAMESPACE(tensor)
|
||||
_bz_global blitz::IndexPlaceholder<0> i;
|
||||
_bz_global blitz::IndexPlaceholder<1> j;
|
||||
_bz_global blitz::IndexPlaceholder<2> k;
|
||||
_bz_global blitz::IndexPlaceholder<3> l;
|
||||
_bz_global blitz::IndexPlaceholder<4> m;
|
||||
_bz_global blitz::IndexPlaceholder<5> n;
|
||||
_bz_global blitz::IndexPlaceholder<6> o;
|
||||
_bz_global blitz::IndexPlaceholder<7> p;
|
||||
_bz_global blitz::IndexPlaceholder<8> q;
|
||||
_bz_global blitz::IndexPlaceholder<9> r;
|
||||
_bz_global blitz::IndexPlaceholder<10> s;
|
||||
_bz_global blitz::IndexPlaceholder<11> t;
|
||||
BZ_NAMESPACE_END // tensor
|
||||
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_INDEXEXPR_H
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#ifndef BZ_INDEXMAP_FWD
|
||||
#define BZ_INDEXMAP_FWD
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,163 +0,0 @@
|
||||
#ifndef BZ_LEVICIVITA_H
|
||||
#define BZ_LEVICIVITA_H
|
||||
|
||||
#include <blitz/prettyprint.h>
|
||||
#include <blitz/shapecheck.h>
|
||||
#include <blitz/numinquire.h>
|
||||
#include <blitz/array/domain.h>
|
||||
#include <blitz/etbase.h>
|
||||
#include <blitz/tinyvec2io.cc>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/* Defines an object which represents the 3-dimensional
|
||||
levi-civita symbol used for cross products. That way the cross
|
||||
product can be represented as an expression. */
|
||||
class LeviCivita : public ETBase<LeviCivita> {
|
||||
public:
|
||||
typedef char T_numtype;
|
||||
|
||||
typedef opType<T_numtype>::T_optype T_optype;
|
||||
typedef asET<T_numtype>::T_wrapped T_typeprop;
|
||||
typedef unwrapET<T_typeprop>::T_unwrapped T_result;
|
||||
|
||||
typedef void T_ctorArg1;
|
||||
typedef char T_ctorArg2; // dummy
|
||||
typedef TinyVector<int, 3> T_index;
|
||||
typedef LeviCivita T_range_result;
|
||||
static const int
|
||||
numArrayOperands = 0,
|
||||
numTVOperands = 0,
|
||||
numTMOperands = 0,
|
||||
numIndexPlaceholders = 3,
|
||||
minWidth = simdTypes<T_numtype>::vecWidth,
|
||||
maxWidth = simdTypes<T_numtype>::vecWidth,
|
||||
rank_ = 3;
|
||||
|
||||
// copy constructor and default constructors are implicit
|
||||
|
||||
int ascending(const int) const { return true; }
|
||||
int ordering(const int) const { return INT_MIN; }
|
||||
int lbound(const int) const { return 0; }
|
||||
int ubound(const int) const { return 2; }
|
||||
|
||||
RectDomain<rank_> domain() const
|
||||
{
|
||||
return RectDomain<rank_>(TinyVector<int,3>(0),
|
||||
TinyVector<int,3>(2));
|
||||
}
|
||||
|
||||
T_numtype operator*() const { BZPRECONDITION(0); return 0; }
|
||||
T_numtype first_value() const { BZPRECONDITION(0); return 0; }
|
||||
|
||||
bool assertInRange(const T_index& BZ_DEBUG_PARAM(index)) const {
|
||||
BZPRECHECK((index[0]<3) && (index[0]>=0) &&
|
||||
(index[1]<3) && (index[1]>=0) &&
|
||||
(index[2]<3) && (index[2]>=0),
|
||||
"LeviCivita index out of range: " << index
|
||||
<< endl << "Lower bounds: 0" << endl
|
||||
<< "Length: 3" << endl);
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
|
||||
template<int N_rank>
|
||||
T_numtype operator()(const TinyVector<int,N_rank> i) const
|
||||
{ assertInRange(i); return (i[1]-i[0])*(i[2]-i[0])*(i[2]-i[1])/2; }
|
||||
#else
|
||||
template<int N_rank>
|
||||
T_numtype operator()(const TinyVector<int,N_rank>& i) const
|
||||
{ assertInRange(i); return (i[1]-i[0])*(i[2]-i[0])*(i[2]-i[1])/2; }
|
||||
#endif
|
||||
|
||||
// can't set domain
|
||||
template<int N_rank>
|
||||
const LeviCivita operator()(const RectDomain<N_rank>& d) const
|
||||
{
|
||||
BZPRECONDITION(0); return *this;
|
||||
}
|
||||
|
||||
void push(int) { }
|
||||
void pop(int) { }
|
||||
void advance() { }
|
||||
void advance(int) { }
|
||||
void loadStride(int) { }
|
||||
|
||||
bool isUnitStride(int) const
|
||||
{ return true; }
|
||||
|
||||
void advanceUnitStride()
|
||||
{ }
|
||||
|
||||
bool canCollapse(int,int) const
|
||||
{ return true; }
|
||||
|
||||
T_numtype operator[](int) const
|
||||
{ BZPRECONDITION(0); return 0; }
|
||||
|
||||
T_numtype fastRead(diffType) const
|
||||
{ BZPRECONDITION(0); return 0; }
|
||||
|
||||
T_numtype fastRead_tv(diffType) const
|
||||
{ BZPRECONDITION(0); return 0; }
|
||||
|
||||
// this is needed for the stencil expression fastRead to work
|
||||
void _bz_offsetData(sizeType i) const{BZPRECONDITION(0);};
|
||||
|
||||
// and these are needed for stencil expression shift to work
|
||||
void _bz_offsetData(sizeType offset, int dim) const {BZPRECONDITION(0);};
|
||||
|
||||
void _bz_offsetData(sizeType offset1, int dim1, sizeType offset2, int dim2) const {BZPRECONDITION(0);};
|
||||
|
||||
diffType suggestStride(int) const
|
||||
{ return 1; }
|
||||
|
||||
bool isStride(int,diffType) const
|
||||
{ return true; }
|
||||
|
||||
void moveTo(int) const { BZPRECONDITION(0); }
|
||||
|
||||
T_numtype shift(int offset, int dim) const {
|
||||
BZPRECONDITION(0); return T_numtype(); }
|
||||
|
||||
T_numtype shift(int offset1, int dim1,int offset2, int dim2) const
|
||||
{ BZPRECONDITION(0); return T_numtype();}
|
||||
|
||||
template<int N_rank>
|
||||
void moveTo(const TinyVector<int,N_rank>&) const { BZPRECONDITION(0); }
|
||||
|
||||
void prettyPrint(BZ_STD_SCOPE(string) &str,
|
||||
prettyPrintFormat& format) const
|
||||
{
|
||||
str += "epsilon_ijk";
|
||||
}
|
||||
|
||||
template<typename T_shape>
|
||||
bool shapeCheck(const T_shape& shape) const
|
||||
{ return areShapesConformable(shape, TinyVector<int,3>(3,3,3)); }
|
||||
|
||||
|
||||
// we can't reduce the rank of this object, so we can't slice it
|
||||
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 void 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 *this;
|
||||
}
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,399 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
// $Id$
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997
|
||||
* Silicon Graphics Computer Systems, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Silicon Graphics makes no
|
||||
* representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied warranty.
|
||||
*/
|
||||
|
||||
/* NOTE: This is not portable code. Parts of numeric_limits<> are
|
||||
* inherently machine-dependent, and this file is written for the MIPS
|
||||
* architecture and the SGI MIPSpro C++ compiler. Parts of it (in
|
||||
* particular, some of the characteristics of floating-point types)
|
||||
* are almost certainly incorrect for any other platform.
|
||||
*/
|
||||
|
||||
#include <blitz/wrap-climits.h>
|
||||
#include <float.h>
|
||||
|
||||
BZ_NAMESPACE(std)
|
||||
|
||||
enum float_round_style {
|
||||
round_indeterminate = -1,
|
||||
round_toward_zero = 0,
|
||||
round_to_nearest = 1,
|
||||
round_toward_infinity = 2,
|
||||
round_toward_neg_infinity = 3
|
||||
};
|
||||
|
||||
enum float_denorm_style {
|
||||
denorm_indeterminate = -1,
|
||||
denorm_absent = 0,
|
||||
denorm_present = 1
|
||||
};
|
||||
|
||||
// Base class for all specializations of numeric_limits.
|
||||
|
||||
template <typename __number>
|
||||
class _Numeric_limits_base {
|
||||
public:
|
||||
static const bool is_specialized = false;
|
||||
|
||||
static __number (min)() { return __number(); }
|
||||
static __number (max)() { return __number(); }
|
||||
|
||||
static const int digits = 0;
|
||||
static const int digits10 = 0;
|
||||
|
||||
static const bool is_signed = false;
|
||||
static const bool is_integer = false;
|
||||
static const bool is_exact = false;
|
||||
|
||||
static const int radix = 0;
|
||||
|
||||
static __number epsilon() { return __number(); }
|
||||
static __number round_error() { return __number(); }
|
||||
|
||||
static const int min_exponent = 0;
|
||||
static const int min_exponent10 = 0;
|
||||
static const int max_exponent = 0;
|
||||
static const int max_exponent10 = 0;
|
||||
|
||||
static const bool has_infinity = false;
|
||||
static const bool has_quiet_NaN = false;
|
||||
static const bool has_signaling_NaN = false;
|
||||
static const float_denorm_style has_denorm = denorm_absent;
|
||||
static const bool has_denorm_loss = false;
|
||||
|
||||
static __number infinity() { return __number(); }
|
||||
static __number quiet_NaN() { return __number(); }
|
||||
static __number signaling_NaN() { return __number(); }
|
||||
static __number denorm_min() { return __number(); }
|
||||
|
||||
static const bool is_iec559 = false;
|
||||
static const bool is_bounded = false;
|
||||
static const bool is_modulo = false;
|
||||
|
||||
static const bool traps = false;
|
||||
static const bool tinyness_before = false;
|
||||
static const float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
#define __declare_numeric_base_member(__type, __mem) \
|
||||
template <typename __number> \
|
||||
const __type _Numeric_limits_base<__number>:: __mem
|
||||
|
||||
__declare_numeric_base_member(bool, is_specialized);
|
||||
__declare_numeric_base_member(int, digits);
|
||||
__declare_numeric_base_member(int, digits10);
|
||||
__declare_numeric_base_member(bool, is_signed);
|
||||
__declare_numeric_base_member(bool, is_integer);
|
||||
__declare_numeric_base_member(bool, is_exact);
|
||||
__declare_numeric_base_member(int, radix);
|
||||
__declare_numeric_base_member(int, min_exponent);
|
||||
__declare_numeric_base_member(int, max_exponent);
|
||||
__declare_numeric_base_member(int, min_exponent10);
|
||||
__declare_numeric_base_member(int, max_exponent10);
|
||||
__declare_numeric_base_member(bool, has_infinity);
|
||||
__declare_numeric_base_member(bool, has_quiet_NaN);
|
||||
__declare_numeric_base_member(bool, has_signaling_NaN);
|
||||
__declare_numeric_base_member(float_denorm_style, has_denorm);
|
||||
__declare_numeric_base_member(bool, has_denorm_loss);
|
||||
__declare_numeric_base_member(bool, is_iec559);
|
||||
__declare_numeric_base_member(bool, is_bounded);
|
||||
__declare_numeric_base_member(bool, is_modulo);
|
||||
__declare_numeric_base_member(bool, traps);
|
||||
__declare_numeric_base_member(bool, tinyness_before);
|
||||
__declare_numeric_base_member(float_round_style, round_style);
|
||||
|
||||
#undef __declare_numeric_base_member
|
||||
|
||||
// Base class for integers.
|
||||
|
||||
template <typename _Int,
|
||||
_Int __imin,
|
||||
_Int __imax,
|
||||
int __idigits = -1>
|
||||
class _Integer_limits : public _Numeric_limits_base<_Int> {
|
||||
public:
|
||||
static const bool is_specialized = true;
|
||||
|
||||
static _Int (min)() { return __imin; }
|
||||
static _Int (max)() { return __imax; }
|
||||
|
||||
static const int digits =
|
||||
(__idigits < 0) ? sizeof(_Int) * CHAR_BIT - (__imin == 0 ? 0 : 1)
|
||||
: __idigits;
|
||||
static const int digits10 = (digits * 301) / 1000;
|
||||
// log 2 = 0.301029995664...
|
||||
|
||||
static const bool is_signed = __imin != 0;
|
||||
static const bool is_integer = true;
|
||||
static const bool is_exact = true;
|
||||
static const int radix = 2;
|
||||
|
||||
|
||||
static const bool is_bounded = true;
|
||||
static const bool is_modulo = true;
|
||||
};
|
||||
|
||||
#define __declare_integer_limits_member(__type, __mem) \
|
||||
template <typename _Int, _Int __imin, _Int __imax, int __idigits> \
|
||||
const __type _Integer_limits<_Int, __imin, __imax, __idigits>:: __mem
|
||||
|
||||
__declare_integer_limits_member(bool, is_specialized);
|
||||
__declare_integer_limits_member(int, digits);
|
||||
__declare_integer_limits_member(int, digits10);
|
||||
__declare_integer_limits_member(bool, is_signed);
|
||||
__declare_integer_limits_member(bool, is_integer);
|
||||
__declare_integer_limits_member(bool, is_exact);
|
||||
__declare_integer_limits_member(int, radix);
|
||||
__declare_integer_limits_member(bool, is_bounded);
|
||||
__declare_integer_limits_member(bool, is_modulo);
|
||||
|
||||
#undef __declare_integer_limits_member
|
||||
|
||||
// Base class for floating-point numbers.
|
||||
template <typename __number,
|
||||
int __Digits, int __Digits10,
|
||||
int __MinExp, int __MaxExp,
|
||||
int __MinExp10, int __MaxExp10,
|
||||
unsigned int __InfinityWord,
|
||||
unsigned int __QNaNWord, unsigned int __SNaNWord,
|
||||
bool __IsIEC559,
|
||||
float_round_style __RoundStyle>
|
||||
class _Floating_limits : public _Numeric_limits_base<__number>
|
||||
{
|
||||
public:
|
||||
static const bool is_specialized = true;
|
||||
|
||||
static const int digits = __Digits;
|
||||
static const int digits10 = __Digits10;
|
||||
|
||||
static const bool is_signed = true;
|
||||
|
||||
static const int radix = 2;
|
||||
|
||||
static const int min_exponent = __MinExp;
|
||||
static const int max_exponent = __MaxExp;
|
||||
static const int min_exponent10 = __MinExp10;
|
||||
static const int max_exponent10 = __MaxExp10;
|
||||
|
||||
static const bool has_infinity = true;
|
||||
static const bool has_quiet_NaN = true;
|
||||
static const bool has_signaling_NaN = true;
|
||||
static const float_denorm_style has_denorm = denorm_indeterminate;
|
||||
static const bool has_denorm_loss = false;
|
||||
|
||||
static __number infinity() {
|
||||
static unsigned int _S_inf[sizeof(__number) / sizeof(int)] =
|
||||
{ __InfinityWord };
|
||||
return *reinterpret_cast<__number*>(&_S_inf);
|
||||
}
|
||||
static __number quiet_NaN() {
|
||||
static unsigned int _S_nan[sizeof(__number) / sizeof(int)] =
|
||||
{ __QNaNWord };
|
||||
return *reinterpret_cast<__number*>(&_S_nan);
|
||||
}
|
||||
static __number signaling_NaN() {
|
||||
static unsigned int _S_nan[sizeof(__number) / sizeof(int)] =
|
||||
{ __SNaNWord };
|
||||
return *reinterpret_cast<__number*>(&_S_nan);
|
||||
}
|
||||
|
||||
static const bool is_iec559 = __IsIEC559;
|
||||
static const bool is_bounded = true;
|
||||
static const bool traps = true;
|
||||
static const bool tinyness_before = false;
|
||||
|
||||
static const float_round_style round_style = __RoundStyle;
|
||||
};
|
||||
|
||||
#define __declare_float_limits_member(__type, __mem) \
|
||||
template <typename __Num, int __Dig, int __Dig10, \
|
||||
int __MnX, int __MxX, int __MnX10, int __MxX10, \
|
||||
unsigned int __Inf, unsigned int __QNaN, unsigned int __SNaN, \
|
||||
bool __IsIEEE, float_round_style __Sty> \
|
||||
const __type _Floating_limits<__Num, __Dig, __Dig10, \
|
||||
__MnX, __MxX, __MnX10, __MxX10, \
|
||||
__Inf, __QNaN, __SNaN,__IsIEEE, __Sty>:: __mem
|
||||
|
||||
__declare_float_limits_member(bool, is_specialized);
|
||||
__declare_float_limits_member(int, digits);
|
||||
__declare_float_limits_member(int, digits10);
|
||||
__declare_float_limits_member(bool, is_signed);
|
||||
__declare_float_limits_member(int, radix);
|
||||
__declare_float_limits_member(int, min_exponent);
|
||||
__declare_float_limits_member(int, max_exponent);
|
||||
__declare_float_limits_member(int, min_exponent10);
|
||||
__declare_float_limits_member(int, max_exponent10);
|
||||
__declare_float_limits_member(bool, has_infinity);
|
||||
__declare_float_limits_member(bool, has_quiet_NaN);
|
||||
__declare_float_limits_member(bool, has_signaling_NaN);
|
||||
__declare_float_limits_member(float_denorm_style, has_denorm);
|
||||
__declare_float_limits_member(bool, has_denorm_loss);
|
||||
__declare_float_limits_member(bool, is_iec559);
|
||||
__declare_float_limits_member(bool, is_bounded);
|
||||
__declare_float_limits_member(bool, traps);
|
||||
__declare_float_limits_member(bool, tinyness_before);
|
||||
__declare_float_limits_member(float_round_style, round_style);
|
||||
|
||||
#undef __declare_float_limits_member
|
||||
|
||||
// Class numeric_limits
|
||||
|
||||
// The unspecialized class.
|
||||
|
||||
template<typename T>
|
||||
class numeric_limits : public _Numeric_limits_base<T> {};
|
||||
|
||||
// Specializations for all built-in integral types.
|
||||
|
||||
#ifndef __STL_NO_BOOL
|
||||
|
||||
template<>
|
||||
class numeric_limits<bool>
|
||||
: public _Integer_limits<bool, false, true, 0> {};
|
||||
|
||||
#endif /* __STL_NO_BOOL */
|
||||
|
||||
template<>
|
||||
class numeric_limits<char>
|
||||
: public _Integer_limits<char, CHAR_MIN, CHAR_MAX> {};
|
||||
|
||||
template<>
|
||||
class numeric_limits<signed char>
|
||||
: public _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX> {};
|
||||
|
||||
template<>
|
||||
class numeric_limits<unsigned char>
|
||||
: public _Integer_limits<unsigned char, 0, UCHAR_MAX> {};
|
||||
|
||||
#ifdef __STL_HAS_WCHAR_T
|
||||
|
||||
template<>
|
||||
class numeric_limits<wchar_t>
|
||||
: public _Integer_limits<wchar_t, INT_MIN, INT_MAX> {};
|
||||
|
||||
#endif
|
||||
|
||||
template<>
|
||||
class numeric_limits<short>
|
||||
: public _Integer_limits<short, SHRT_MIN, SHRT_MAX> {};
|
||||
|
||||
template<>
|
||||
class numeric_limits<unsigned short>
|
||||
: public _Integer_limits<unsigned short, 0, USHRT_MAX> {};
|
||||
|
||||
template<>
|
||||
class numeric_limits<int>
|
||||
: public _Integer_limits<int, INT_MIN, INT_MAX> {};
|
||||
|
||||
template<>
|
||||
class numeric_limits<unsigned int>
|
||||
: public _Integer_limits<unsigned int, 0, UINT_MAX> {};
|
||||
|
||||
template<>
|
||||
class numeric_limits<long>
|
||||
: public _Integer_limits<long, LONG_MIN, LONG_MAX> {};
|
||||
|
||||
template<>
|
||||
class numeric_limits<unsigned long>
|
||||
: public _Integer_limits<unsigned long, 0, ULONG_MAX> {};
|
||||
|
||||
#ifdef __STL_LONG_LONG
|
||||
#ifdef LONG_LONG_MIN
|
||||
|
||||
// CYGNUS LOCAL 9/4/1998
|
||||
// fixed LONGLONG to be LONG_LONG
|
||||
template<>
|
||||
class numeric_limits<long long>
|
||||
: public _Integer_limits<long long, LONG_LONG_MIN, LONG_LONG_MAX> {};
|
||||
|
||||
// CYGNUS LOCAL 9/4/1998
|
||||
// fixed LONGLONG to be LONG_LONG
|
||||
template<>
|
||||
class numeric_limits<unsigned long long>
|
||||
: public _Integer_limits<unsigned long long, 0, ULONG_LONG_MAX> {};
|
||||
|
||||
#endif
|
||||
#endif /* __STL_LONG_LONG */
|
||||
|
||||
// Specializations for all built-in floating-point type.
|
||||
|
||||
template<> class numeric_limits<float>
|
||||
: public _Floating_limits<float,
|
||||
FLT_MANT_DIG, // Binary digits of precision
|
||||
FLT_DIG, // Decimal digits of precision
|
||||
FLT_MIN_EXP, // Minimum exponent
|
||||
FLT_MAX_EXP, // Maximum exponent
|
||||
FLT_MIN_10_EXP, // Minimum base 10 exponent
|
||||
FLT_MAX_10_EXP, // Maximum base 10 exponent
|
||||
0x7f800000u, // First word of +infinity
|
||||
0x7f810000u, // First word of quiet NaN
|
||||
0x7fc10000u, // First word of signaling NaN
|
||||
true, // conforms to iec559
|
||||
round_to_nearest>
|
||||
{
|
||||
public:
|
||||
static float (min)() { return FLT_MIN; }
|
||||
static float denorm_min() { return FLT_MIN; }
|
||||
static float (max)() { return FLT_MAX; }
|
||||
static float epsilon() { return FLT_EPSILON; }
|
||||
static float round_error() { return 0.5f; } // Units: ulps.
|
||||
};
|
||||
|
||||
template<> class numeric_limits<double>
|
||||
: public _Floating_limits<double,
|
||||
DBL_MANT_DIG, // Binary digits of precision
|
||||
DBL_DIG, // Decimal digits of precision
|
||||
DBL_MIN_EXP, // Minimum exponent
|
||||
DBL_MAX_EXP, // Maximum exponent
|
||||
DBL_MIN_10_EXP, // Minimum base 10 exponent
|
||||
DBL_MAX_10_EXP, // Maximum base 10 exponent
|
||||
0x7ff00000u, // First word of +infinity
|
||||
0x7ff10000u, // First word of quiet NaN
|
||||
0x7ff90000u, // First word of signaling NaN
|
||||
true, // conforms to iec559
|
||||
round_to_nearest>
|
||||
{
|
||||
public:
|
||||
static double (min)() { return DBL_MIN; }
|
||||
static double denorm_min() { return DBL_MIN; }
|
||||
static double (max)() { return DBL_MAX; }
|
||||
static double epsilon() { return DBL_EPSILON; }
|
||||
static double round_error() { return 0.5; } // Units: ulps.
|
||||
};
|
||||
|
||||
template<> class numeric_limits<long double>
|
||||
: public _Floating_limits<long double,
|
||||
LDBL_MANT_DIG, // Binary digits of precision
|
||||
LDBL_DIG, // Decimal digits of precision
|
||||
LDBL_MIN_EXP, // Minimum exponent
|
||||
LDBL_MAX_EXP, // Maximum exponent
|
||||
LDBL_MIN_10_EXP,// Minimum base 10 exponent
|
||||
LDBL_MAX_10_EXP,// Maximum base 10 exponent
|
||||
0x7ff00000u, // First word of +infinity
|
||||
0x7ff10000u, // First word of quiet NaN
|
||||
0x7ff90000u, // First word of signaling NaN
|
||||
false, // Doesn't conform to iec559
|
||||
round_to_nearest>
|
||||
{
|
||||
public:
|
||||
static long double (min)() { return LDBL_MIN; }
|
||||
static long double denorm_min() { return LDBL_MIN; }
|
||||
static long double (max)() { return LDBL_MAX; }
|
||||
static long double epsilon() { return LDBL_EPSILON; }
|
||||
static long double round_error() { return 4; } // Units: ulps.
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/listinit.h Classes for initialization lists
|
||||
*
|
||||
* $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/
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
* Initialization lists provide a convenient way to set the elements
|
||||
* of an array. For example,
|
||||
*
|
||||
* Array<int,2> A(3,3);
|
||||
* A = 1, 0, 0,
|
||||
* 0, 1, 0,
|
||||
* 0, 0, 1;
|
||||
*/
|
||||
|
||||
#ifndef BZ_LISTINIT_H
|
||||
#define BZ_LISTINIT_H
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename T_numtype, typename T_iterator>
|
||||
class ListInitializer {
|
||||
|
||||
public:
|
||||
ListInitializer(T_iterator iter)
|
||||
: iter_(iter)
|
||||
{
|
||||
}
|
||||
|
||||
ListInitializer<T_numtype, T_iterator> operator,(T_numtype x)
|
||||
{
|
||||
*iter_ = x;
|
||||
++iter_;
|
||||
return ListInitializer<T_numtype, T_iterator>(iter_);
|
||||
}
|
||||
|
||||
private:
|
||||
ListInitializer();
|
||||
|
||||
protected:
|
||||
T_iterator iter_;
|
||||
};
|
||||
|
||||
template<typename T_array, typename T_iterator = _bz_typename T_array::T_numtype*>
|
||||
class ListInitializationSwitch {
|
||||
|
||||
public:
|
||||
typedef _bz_typename T_array::T_numtype T_numtype;
|
||||
|
||||
ListInitializationSwitch(const ListInitializationSwitch<T_array>& lis)
|
||||
: array_(lis.array_), value_(lis.value_),
|
||||
wipeOnDestruct_(true)
|
||||
{
|
||||
lis.disable();
|
||||
}
|
||||
|
||||
ListInitializationSwitch(T_array& array, T_numtype value)
|
||||
: array_(array), value_(value), wipeOnDestruct_(true)
|
||||
{ }
|
||||
|
||||
~ListInitializationSwitch()
|
||||
{
|
||||
if (wipeOnDestruct_)
|
||||
array_.initialize(value_);
|
||||
}
|
||||
|
||||
ListInitializer<T_numtype, T_iterator> operator,(T_numtype x)
|
||||
{
|
||||
wipeOnDestruct_ = false;
|
||||
T_iterator iter = array_.getInitializationIterator();
|
||||
*iter = value_;
|
||||
++iter;
|
||||
//T_iterator iter2 = iter + 1;
|
||||
*iter = x;
|
||||
++iter;
|
||||
return ListInitializer<T_numtype, T_iterator>(iter);
|
||||
}
|
||||
|
||||
void disable() const
|
||||
{
|
||||
wipeOnDestruct_ = false;
|
||||
}
|
||||
|
||||
private:
|
||||
ListInitializationSwitch();
|
||||
|
||||
protected:
|
||||
T_array& array_;
|
||||
T_numtype value_;
|
||||
mutable bool wipeOnDestruct_;
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_LISTINIT_H
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
/***************************************************************************
|
||||
* blitz/memblock.cc MemoryBlock<T> and MemoryBlockReference<T> 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_MEMBLOCK_CC
|
||||
#define BZ_MEMBLOCK_CC
|
||||
|
||||
#include <blitz/numtrait.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename P_type>
|
||||
void MemoryBlock<P_type>::deallocate()
|
||||
{
|
||||
const sizeType byteWidth= simdTypes<P_type>::byteWidth;
|
||||
const int cacheLineSize = BZ_L1_CACHE_LINE_SIZE;
|
||||
|
||||
#ifdef BZ_ALIGN_BLOCKS_ON_CACHELINE_BOUNDARY
|
||||
const sizeType minLengthToAlign =
|
||||
BZ_CACHE_LINES_TO_ALIGN*cacheLineSize;
|
||||
#else
|
||||
const sizeType minLengthToAlign = blitz::huge(size_t());
|
||||
#endif
|
||||
|
||||
const sizeType numBytes = length_ * sizeof(T_type);
|
||||
|
||||
// depending on the situation, the block was allocated as any of
|
||||
// three different types, so we need to take care to get it right
|
||||
// when freeing
|
||||
|
||||
if (!allocatedByUs_)
|
||||
// the block was allocated by someone else, so it should just be freed
|
||||
delete [] dataBlockAddress_;
|
||||
|
||||
else {
|
||||
// we allocated the block, so it may have been shifted
|
||||
if ((numBytes < minLengthToAlign) || (cacheLineSize%byteWidth !=0)) {
|
||||
// block was not cache line shifted
|
||||
delete [] dBA_tv_;
|
||||
}
|
||||
else {
|
||||
// block was cache line shifted, manually call destructors
|
||||
if (!NumericTypeTraits<T_type>::hasTrivialCtor)
|
||||
for (sizeType i=0; i < length_; ++i)
|
||||
data_[i].~T_type();
|
||||
delete [] dBA_char_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Allocate a memory block. If we're allocating a large array it may
|
||||
be desireable for performance reasons to force the array to start
|
||||
on a cache line boundary. We do this by allocating a little more
|
||||
memory than necessary, then shifting the pointer to the next cache
|
||||
line boundary. Note that this only works if the SIMD byte width of
|
||||
P_type fits evenly into the cache line size, otherwise we may have
|
||||
to allocate a lot more memory to be sure to get to a common
|
||||
multiple of both the cache line size and the size of the
|
||||
object. This can easily be the case for multicomponent containers,
|
||||
and in this case, nothing is done.x */
|
||||
template<typename P_type>
|
||||
inline void MemoryBlock<P_type>::allocate(sizeType length)
|
||||
{
|
||||
TAU_TYPE_STRING(p1, "MemoryBlock<T>::allocate() [T="
|
||||
+ CT(P_type) + "]");
|
||||
TAU_PROFILE(p1, "void ()", TAU_BLITZ);
|
||||
|
||||
const sizeType vecWidth= simdTypes<P_type>::vecWidth;
|
||||
const sizeType byteWidth= simdTypes<P_type>::byteWidth;
|
||||
const int cacheLineSize = BZ_L1_CACHE_LINE_SIZE;
|
||||
|
||||
BZASSERT(length%vecWidth==0);
|
||||
|
||||
#ifdef BZ_ALIGN_BLOCKS_ON_CACHELINE_BOUNDARY
|
||||
const sizeType minLengthToAlign =
|
||||
BZ_CACHE_LINES_TO_ALIGN*cacheLineSize;
|
||||
#else
|
||||
const sizeType minLengthToAlign = blitz::huge(size_t());
|
||||
#endif
|
||||
|
||||
const sizeType numBytes = length * sizeof(T_type);
|
||||
|
||||
//cout << "Size: " << sizeof(P_type) << ", alignment " << __alignof__(P_type) << endl;
|
||||
|
||||
if ((numBytes < minLengthToAlign) || (cacheLineSize%byteWidth !=0)) {
|
||||
// no shifting to cache line
|
||||
dBA_tv_ =
|
||||
new typename simdTypes<P_type>::vecType[length/vecWidth];
|
||||
data_= dataBlockAddress_;
|
||||
}
|
||||
else {
|
||||
// shift to cache line
|
||||
|
||||
dBA_char_ = new char[numBytes + cacheLineSize + 1];
|
||||
|
||||
// Shift to the next cache line boundary.
|
||||
diffType offsetToCacheLine =
|
||||
diffType(dBA_char_) % cacheLineSize;
|
||||
diffType shift = (offsetToCacheLine == 0) ? 0 :
|
||||
(cacheLineSize - offsetToCacheLine);
|
||||
data_char_ = dBA_char_ + shift;
|
||||
|
||||
// Use placement new to construct types with nontrival ctors
|
||||
if (!NumericTypeTraits<T_type>::hasTrivialCtor) {
|
||||
for (sizeType i=0; i < length; ++i)
|
||||
new(&data_[i]) T_type;
|
||||
}
|
||||
}
|
||||
|
||||
allocatedByUs_ = true;
|
||||
|
||||
#ifdef BZ_DEBUG_LOG_ALLOCATIONS
|
||||
cout << "MemoryBlock: allocated " << setw(8) << length
|
||||
<< " at " << ((void *)dataBlockAddress_) << endl;
|
||||
#endif
|
||||
|
||||
BZASSERT(isVectorAligned(data_));
|
||||
}
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_MEMBLOCK_CC
|
||||
@@ -1,546 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/memblock.h MemoryBlock<T> and MemoryBlockReference<T>
|
||||
*
|
||||
* $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_MEMBLOCK_H
|
||||
#define BZ_MEMBLOCK_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/simdtypes.h>
|
||||
#ifdef BZ_HAVE_BOOST_SERIALIZATION
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
#include <boost/serialization/base_object.hpp>
|
||||
#include <boost/serialization/split_member.hpp>
|
||||
#include <boost/serialization/array.hpp>
|
||||
#include <boost/serialization/collection_size_type.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#endif
|
||||
#include <stddef.h> // diffType
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
enum preexistingMemoryPolicy {
|
||||
duplicateData,
|
||||
deleteDataWhenDone,
|
||||
neverDeleteData
|
||||
};
|
||||
|
||||
// This function makes it possible for users to make sure threadsafety
|
||||
// is enabled.
|
||||
inline bool isThreadsafe() {
|
||||
#ifdef BZ_THREADSAFE
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
// Forward declaration of MemoryBlockReference
|
||||
template<typename T_type> class MemoryBlockReference;
|
||||
|
||||
// Class MemoryBlock provides a reference-counted block of memory. This block
|
||||
// may be referred to by multiple vector, matrix and array objects. The memory
|
||||
// is automatically deallocated when the last referring object is destructed.
|
||||
// MemoryBlock may be subclassed to provide special allocators.
|
||||
template<typename P_type>
|
||||
class MemoryBlock {
|
||||
|
||||
friend class MemoryBlockReference<P_type>;
|
||||
|
||||
public:
|
||||
typedef P_type T_type;
|
||||
|
||||
protected:
|
||||
explicit MemoryBlock(sizeType items)
|
||||
{
|
||||
// pad the length to vecWidth, if not already done
|
||||
const int w = simdTypes<T_type>::vecWidth;
|
||||
const int mod = items%w;
|
||||
if (mod>0)
|
||||
items += simdTypes<T_type>::vecWidth-mod;
|
||||
BZASSERT(items%w==0);
|
||||
|
||||
length_ = items;
|
||||
allocate(length_);
|
||||
|
||||
BZASSERT(dataBlockAddress_ != 0);
|
||||
|
||||
references_ = 1;
|
||||
BZ_MUTEX_INIT(mutex)
|
||||
}
|
||||
|
||||
/** Constructor for a preallocated block that should be deleted when
|
||||
we are done? */
|
||||
MemoryBlock(sizeType length, T_type* data)
|
||||
{
|
||||
length_ = length;
|
||||
data_ = data;
|
||||
dataBlockAddress_ = data;
|
||||
references_ = 1;
|
||||
BZ_MUTEX_INIT(mutex);
|
||||
allocatedByUs_ = false;
|
||||
}
|
||||
|
||||
virtual ~MemoryBlock()
|
||||
{
|
||||
if (dataBlockAddress_)
|
||||
{
|
||||
#ifdef BZ_DEBUG_LOG_ALLOCATIONS
|
||||
cout << "MemoryBlock: freed " << setw(8) << length_
|
||||
<< " at " << ((void *)dataBlockAddress_) << endl;
|
||||
#endif
|
||||
|
||||
deallocate();
|
||||
}
|
||||
|
||||
BZ_MUTEX_DESTROY(mutex)
|
||||
}
|
||||
|
||||
// set mutex locking policy and return true if successful
|
||||
bool doLock(bool lockingPolicy)
|
||||
{
|
||||
#if defined(BZ_THREADSAFE) && !defined(BZ_THREADSAFE_USE_ATOMIC)
|
||||
if (mutexLocking_ == lockingPolicy) { // already set
|
||||
return true;
|
||||
}
|
||||
else if (references_ <= 1) { // no multiple references, safe to change
|
||||
mutexLocking_ = lockingPolicy;
|
||||
return true;
|
||||
}
|
||||
return false; // unsafe to change
|
||||
#elif defined(BZ_THREADSAFE_USE_ATOMIC)
|
||||
// with locking we consider the request successful
|
||||
return true;
|
||||
#else
|
||||
// without threadsafety we return false if user wants to enable locking
|
||||
return !lockingPolicy;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Note that the the MemoryBlock will be created with reference
|
||||
count 1, so there is no need to call addReference immediately
|
||||
upon creating it. (The creator obviously does have to call
|
||||
removeReference, though.) This avoids the initial mutex lock. */
|
||||
void addReference()
|
||||
{
|
||||
#ifdef BZ_DEBUG_LOG_REFERENCES
|
||||
BZ_MUTEX_LOCK(mutex)
|
||||
const int refcount = ++references_;
|
||||
BZ_MUTEX_UNLOCK(mutex)
|
||||
|
||||
cout << "MemoryBlock: reffed " << setw(8) << length_
|
||||
<< " at " << ((void *)dataBlockAddress_) << " (r="
|
||||
<< refcount << ")" << endl;
|
||||
#else
|
||||
BZ_MUTEX_LOCK(mutex)
|
||||
++references_;
|
||||
BZ_MUTEX_UNLOCK(mutex)
|
||||
#endif
|
||||
}
|
||||
|
||||
T_type* restrict data()
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
|
||||
const T_type* restrict data() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
|
||||
T_type*& dataBlockAddress()
|
||||
{
|
||||
return dataBlockAddress_;
|
||||
}
|
||||
|
||||
sizeType length() const
|
||||
{
|
||||
return length_;
|
||||
}
|
||||
|
||||
int removeReference()
|
||||
{
|
||||
|
||||
BZ_MUTEX_LOCK(mutex)
|
||||
const int refcount = --references_;
|
||||
BZ_MUTEX_UNLOCK(mutex)
|
||||
|
||||
#ifdef BZ_DEBUG_LOG_REFERENCES
|
||||
cout << "MemoryBlock: dereffed " << setw(8) << length_
|
||||
<< " at " << ((void *)dataBlockAddress_) << " (r=" << refcount
|
||||
<< ")" << endl;
|
||||
#endif
|
||||
return refcount;
|
||||
}
|
||||
|
||||
int references() const
|
||||
{
|
||||
BZ_MUTEX_LOCK(mutex)
|
||||
const int refcount = references_;
|
||||
BZ_MUTEX_UNLOCK(mutex)
|
||||
|
||||
return refcount;
|
||||
}
|
||||
|
||||
protected:
|
||||
inline void allocate(sizeType length);
|
||||
void deallocate();
|
||||
|
||||
private: // Disabled member functions
|
||||
MemoryBlock(const MemoryBlock<T_type>&) { };
|
||||
|
||||
void operator=(const MemoryBlock<T_type>&) {};
|
||||
|
||||
/** The default constructor is needed for serialization. */
|
||||
MemoryBlock() {};
|
||||
#ifdef BZ_HAVE_BOOST_SERIALIZATION
|
||||
friend class boost::serialization::access;
|
||||
|
||||
|
||||
/** Implementation of boost::serialization. It doesn't make sense to
|
||||
save the mutex, the reference count, or the allocation flags,
|
||||
since upon restoring, we must necessarily reallocate. */
|
||||
template<class T_arch>
|
||||
void save(T_arch& ar, const unsigned int version) const {
|
||||
#if defined(BZ_THREADSAFE) && !defined(BZ_THREADSAFE_USE_ATOMIC)
|
||||
ar << mutexLocking_;
|
||||
#endif
|
||||
const boost::serialization::collection_size_type count(length_);
|
||||
ar << BOOST_SERIALIZATION_NVP(count);
|
||||
#ifdef BZ_DEBUG_LOG_ALLOCATIONS
|
||||
cout << "MemoryBlock: serializing " << length_ << " data for MemoryBlock at "
|
||||
<< ((void*)this) << endl;
|
||||
#endif
|
||||
if(length_>0)
|
||||
ar << boost::serialization::make_array(data_, length_);
|
||||
};
|
||||
|
||||
template<class T_arch>
|
||||
void load(T_arch& ar, const unsigned int version) {
|
||||
#if defined(BZ_THREADSAFE) && !defined(BZ_THREADSAFE_USE_ATOMIC)
|
||||
ar >> mutexLocking_;
|
||||
#endif
|
||||
boost::serialization::collection_size_type count(length_);
|
||||
ar >> BOOST_SERIALIZATION_NVP(count);
|
||||
length_=count;
|
||||
allocate(length_);
|
||||
|
||||
#ifdef BZ_DEBUG_LOG_ALLOCATIONS
|
||||
cout << "MemoryBlock: unserializing " << length_ << " data for MemoryBlock at "
|
||||
<< ((void*)this) << endl;
|
||||
#endif
|
||||
|
||||
if(length_>0)
|
||||
ar >> boost::serialization::make_array(data_, length_);
|
||||
|
||||
// initialize the members that are not restored. Note that we
|
||||
// must initialize references_ to 0 here because the
|
||||
// unserialization always adds a reference since the creation of
|
||||
// the MemoryBlock object happens by the boost::serialization
|
||||
// magic.
|
||||
references_ = 0;
|
||||
BZ_MUTEX_INIT(mutex);
|
||||
};
|
||||
|
||||
BOOST_SERIALIZATION_SPLIT_MEMBER()
|
||||
#endif
|
||||
|
||||
|
||||
private: // Data members
|
||||
#if defined(BZ_THREADSAFE) && !defined(BZ_THREADSAFE_USE_ATOMIC)
|
||||
// with atomic reference counts, there is no locking
|
||||
bool mutexLocking_;
|
||||
#endif
|
||||
/** Keeps track of whether the block was preallocated or not. This
|
||||
affects potential alignment so must be taken into account when
|
||||
we delete. */
|
||||
bool allocatedByUs_;
|
||||
|
||||
union {
|
||||
T_type * restrict data_;
|
||||
typename simdTypes<T_type>::vecType * restrict data_tv_;
|
||||
char * restrict data_char_;
|
||||
};
|
||||
union {
|
||||
T_type * dataBlockAddress_;
|
||||
typename simdTypes<T_type>::vecType * restrict dBA_tv_;
|
||||
char * dBA_char_;
|
||||
};
|
||||
sizeType length_;
|
||||
|
||||
BZ_REFCOUNT_DECLARE(references_)
|
||||
BZ_MUTEX_DECLARE(mutex)
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename P_type>
|
||||
class MemoryBlockReference {
|
||||
|
||||
public:
|
||||
typedef P_type T_type;
|
||||
|
||||
protected:
|
||||
T_type * restrict data_;
|
||||
|
||||
private:
|
||||
MemoryBlock<T_type>* block_;
|
||||
|
||||
#ifdef BZ_HAVE_BOOST_SERIALIZATION
|
||||
friend class boost::serialization::access;
|
||||
|
||||
/** Serialization operator. This is a bit hacky, because we need to
|
||||
restore the data pointer as part of the skeleton, not
|
||||
content. For this reason, we serialize the offset as a
|
||||
collection_size_item even though it's a signed type. This makes
|
||||
the serialization code treat it as part of the skeleton and not
|
||||
content, which is what we want.
|
||||
*/
|
||||
template<class T_arch>
|
||||
void save(T_arch& ar, const unsigned int version) const {
|
||||
#ifdef BZ_DEBUG_LOG_ALLOCATIONS
|
||||
cout << "MemoryBlockReference: serializing object at " << ((void*)this) << ", MemoryBlock at "
|
||||
<< ((void*)block_) <<endl;
|
||||
#endif
|
||||
ar << block_;
|
||||
ptrdiff_t ptroffset=0;
|
||||
if(block_)
|
||||
ptroffset = data_ - block_->data();
|
||||
boost::serialization::collection_size_type
|
||||
offset(*reinterpret_cast<size_t*>(&ptroffset));
|
||||
ar << BOOST_SERIALIZATION_NVP(offset);
|
||||
};
|
||||
|
||||
/** Unserialization operator. See comment for the save method for
|
||||
the reinterpret_cast hack.
|
||||
*/
|
||||
template<class T_arch>
|
||||
void load(T_arch& ar, const unsigned int version) {
|
||||
#ifdef BZ_DEBUG_LOG_ALLOCATIONS
|
||||
cout << "MemoryBlockReference: unserializing at " << ((void*)this) << endl;
|
||||
#endif
|
||||
ar >> block_;
|
||||
addReference();
|
||||
boost::serialization::collection_size_type offset;
|
||||
ar >> BOOST_SERIALIZATION_NVP(offset);
|
||||
ptrdiff_t ptroffset = *reinterpret_cast<ptrdiff_t*>(&offset);
|
||||
if(block_)
|
||||
data_ = block_->data() + ptroffset;
|
||||
else
|
||||
data_ = 0;
|
||||
};
|
||||
|
||||
BOOST_SERIALIZATION_SPLIT_MEMBER()
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
MemoryBlockReference()
|
||||
{
|
||||
block_ = 0;
|
||||
// no block, so nothing to add reference to
|
||||
data_ = 0;
|
||||
}
|
||||
|
||||
MemoryBlockReference(MemoryBlockReference<T_type>& ref, sizeType offset=0)
|
||||
{
|
||||
block_ = ref.block_;
|
||||
addReference();
|
||||
data_ = ref.data_ + offset;
|
||||
}
|
||||
|
||||
MemoryBlockReference(sizeType length, T_type* data,
|
||||
preexistingMemoryPolicy deletionPolicy)
|
||||
{
|
||||
// Create a memory block using already allocated memory.
|
||||
|
||||
// Note: if the deletionPolicy is duplicateData, this must
|
||||
// be handled by the leaf class. In MemoryBlockReference,
|
||||
// this is treated as neverDeleteData; the leaf class (e.g. Array)
|
||||
// must duplicate the data.
|
||||
|
||||
if ((deletionPolicy == neverDeleteData)
|
||||
|| (deletionPolicy == duplicateData)) {
|
||||
// in this case, we do not need a MemoryBlock to ref-count the data
|
||||
block_ = 0;
|
||||
}
|
||||
else if (deletionPolicy == deleteDataWhenDone) {
|
||||
block_ = new MemoryBlock<T_type>(length, data);
|
||||
|
||||
#ifdef BZ_DEBUG_LOG_ALLOCATIONS
|
||||
cout << "MemoryBlockReference: created MemoryBlock at "
|
||||
<< ((void*)block_) << endl;
|
||||
#endif
|
||||
}
|
||||
// creating a MemoryBlock automatically sets it to one
|
||||
// reference, so we do no longer need to add a reference in
|
||||
// the constructor.
|
||||
|
||||
data_ = data;
|
||||
}
|
||||
|
||||
explicit MemoryBlockReference(sizeType items)
|
||||
{
|
||||
block_ = new MemoryBlock<T_type>(items);
|
||||
// creating a MemoryBlock automatically sets it to one
|
||||
// reference, so we do no longer need to add a reference in
|
||||
// the constructor.
|
||||
data_ = block_->data();
|
||||
|
||||
#ifdef BZ_DEBUG_LOG_ALLOCATIONS
|
||||
cout << "MemoryBlockReference: created MemoryBlock at "
|
||||
<< ((void*)block_) << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
~MemoryBlockReference()
|
||||
{
|
||||
blockRemoveReference();
|
||||
}
|
||||
|
||||
/** Returns true if the offset from data_ is vector aligned. */
|
||||
bool isVectorAligned(size_t offset) const
|
||||
{ return simdTypes<T_type>::isVectorAligned(data_ + offset); }
|
||||
|
||||
/** Returns the allocated length of the memory block. */
|
||||
sizeType blockLength() const { return block_->length(); };
|
||||
|
||||
protected:
|
||||
#ifdef BZ_TESTSUITE
|
||||
public:
|
||||
#endif
|
||||
int numReferences() const
|
||||
{
|
||||
if (block_)
|
||||
return block_->references();
|
||||
#ifdef BZ_DEBUG_LOG_REFERENCES
|
||||
cout << "Invalid reference count for data at "<< data_ << endl;
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool lockReferenceCount(bool lockingPolicy) const
|
||||
{
|
||||
if (block_)
|
||||
return block_->doLock(lockingPolicy);
|
||||
// if we have no block, consider request successful
|
||||
#ifdef BZ_DEBUG_LOG_REFERENCES
|
||||
cout << "No reference count locking for data at "<< data_ << endl;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void changeToNullBlock()
|
||||
{
|
||||
blockRemoveReference();
|
||||
block_ = 0;
|
||||
// no block, so nothing to add reference to
|
||||
data_ = 0;
|
||||
}
|
||||
|
||||
void changeBlock(MemoryBlockReference<T_type>& ref, sizeType offset=0)
|
||||
{
|
||||
blockRemoveReference();
|
||||
block_ = ref.block_;
|
||||
addReference();
|
||||
data_ = ref.data_ + offset;
|
||||
}
|
||||
|
||||
void newBlock(sizeType items)
|
||||
{
|
||||
blockRemoveReference();
|
||||
block_ = new MemoryBlock<T_type>(items);
|
||||
// creating a memory block automatically sets it to one reference
|
||||
data_ = block_->data();
|
||||
|
||||
#ifdef BZ_DEBUG_LOG_ALLOCATIONS
|
||||
cout << "MemoryBlockReference: created MemoryBlock at "
|
||||
<< ((void*)block_) << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
void blockRemoveReference()
|
||||
{
|
||||
const int refcount = removeReference();
|
||||
if (refcount == 0)
|
||||
{
|
||||
#ifdef BZ_DEBUG_LOG_ALLOCATIONS
|
||||
cout << "MemoryBlockReference: no more refs, delete MemoryBlock object at "
|
||||
<< ((void*)block_) << endl;
|
||||
#endif
|
||||
|
||||
delete block_;
|
||||
}
|
||||
}
|
||||
|
||||
void addReference() const
|
||||
{
|
||||
if (block_) {
|
||||
#ifdef BZ_DEBUG_LOG_REFERENCES
|
||||
cout << "MemoryBlockReference: reffing block at " << ((void*)block_)
|
||||
<< endl;
|
||||
#endif
|
||||
block_->addReference();
|
||||
}
|
||||
else {
|
||||
#ifdef BZ_DEBUG_LOG_REFERENCES
|
||||
cout << "MemoryBlockReference:: Skipping reference count for data at "<< data_ << endl;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
int removeReference() const
|
||||
{
|
||||
if (block_) {
|
||||
#ifdef BZ_DEBUG_LOG_REFERENCES
|
||||
cout << "MemoryBlockReference: dereffing block at " << ((void*)block_)
|
||||
<< endl;
|
||||
#endif
|
||||
return block_->removeReference();
|
||||
}
|
||||
#ifdef BZ_DEBUG_LOG_REFERENCES
|
||||
cout << "Skipping reference count for data at "<< data_ << endl;
|
||||
#endif
|
||||
return -1;
|
||||
};
|
||||
|
||||
void operator=(const MemoryBlockReference<T_type>&)
|
||||
{ }
|
||||
};
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#include <blitz/memblock.cc>
|
||||
|
||||
#endif // BZ_MEMBLOCK_H
|
||||
@@ -1,170 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/meta/dot.h Tiny vector dot product metaprogram
|
||||
*
|
||||
* $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_META_DOT_H
|
||||
#define BZ_META_DOT_H
|
||||
|
||||
#ifndef BZ_PROMOTE_H
|
||||
#include <blitz/promote.h>
|
||||
#endif
|
||||
|
||||
#ifndef BZ_METAPROG_H
|
||||
#include <blitz/meta/metaprog.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<int N, int I>
|
||||
class _bz_meta_vectorDot {
|
||||
public:
|
||||
static const int loopFlag = (I < N-1) ? 1 : 0;
|
||||
|
||||
template<typename T_expr1, typename T_expr2>
|
||||
static inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype,
|
||||
_bz_typename T_expr2::T_numtype)
|
||||
f(const T_expr1& a, const T_expr2& b)
|
||||
{
|
||||
return a[I] * b[I]
|
||||
+ _bz_meta_vectorDot<loopFlag * N, loopFlag * (I+1)>::f(a,b);
|
||||
}
|
||||
|
||||
template<typename T_expr1, typename T_expr2>
|
||||
static inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype,
|
||||
_bz_typename T_expr2::T_numtype)
|
||||
f_value_ref(T_expr1 a, const T_expr2& b)
|
||||
{
|
||||
return a[I] * b[I]
|
||||
+ _bz_meta_vectorDot<loopFlag * N, loopFlag * (I+1)>::f(a,b);
|
||||
}
|
||||
|
||||
template<typename T_expr1, typename T_expr2>
|
||||
static inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype,
|
||||
_bz_typename T_expr2::T_numtype)
|
||||
f_ref_value(const T_expr1& a, T_expr2 b)
|
||||
{
|
||||
return a[I] * b[I]
|
||||
+ _bz_meta_vectorDot<loopFlag * N, loopFlag * (I+1)>::f(a,b);
|
||||
}
|
||||
|
||||
template<typename T_expr1, typename P_numtype2>
|
||||
static inline BZ_PROMOTE(_bz_typename T_expr1::T_numtype,
|
||||
P_numtype2)
|
||||
dotWithArgs(const T_expr1& a, P_numtype2 i1, P_numtype2 i2=0,
|
||||
P_numtype2 i3=0, P_numtype2 i4=0, P_numtype2 i5=0, P_numtype2 i6=0,
|
||||
P_numtype2 i7=0, P_numtype2 i8=0, P_numtype2 i9=0, P_numtype2 i10=0)
|
||||
{
|
||||
return a[I] * i1
|
||||
+ _bz_meta_vectorDot<loopFlag * N, loopFlag * (I+1)>::dotWithArgs
|
||||
(a, i2, i3, i4, i5, i6, i7, i8, i9);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
class _bz_meta_vectorDot<0,0> {
|
||||
public:
|
||||
template<typename T_expr1, typename T_expr2>
|
||||
static inline _bz_meta_nullOperand f(const T_expr1&, const T_expr2&)
|
||||
{ return _bz_meta_nullOperand(); }
|
||||
|
||||
template<typename T_expr1, typename P_numtype2>
|
||||
static inline _bz_meta_nullOperand
|
||||
dotWithArgs(const T_expr1& a, P_numtype2 i1, P_numtype2 i2=0,
|
||||
P_numtype2 i3=0, P_numtype2 i4=0, P_numtype2 i5=0, P_numtype2 i6=0,
|
||||
P_numtype2 i7=0, P_numtype2 i8=0, P_numtype2 i9=0, P_numtype2 i10=0)
|
||||
{
|
||||
return _bz_meta_nullOperand();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
template<int N, int I, typename T_ret>
|
||||
class _bz_meta_vectorDotRet {
|
||||
public:
|
||||
static const int loopFlag = (I < N-1) ? 1 : 0;
|
||||
|
||||
template<typename T_expr1, typename T_expr2>
|
||||
static inline T_ret
|
||||
f(const T_expr1& a, const T_expr2& b)
|
||||
{
|
||||
return static_cast<T_ret>(a[I]) * static_cast<T_ret>(b[I])
|
||||
+ _bz_meta_vectorDotRet<loopFlag * N, loopFlag * (I+1), T_ret>::f(a,b);
|
||||
}
|
||||
|
||||
template<typename T_expr1, typename T_expr2>
|
||||
static inline T_ret
|
||||
f_value_ref(T_expr1 a, const T_expr2& b)
|
||||
{
|
||||
return static_cast<T_ret>(a[I]) * static_cast<T_ret>(b[I])
|
||||
+ _bz_meta_vectorDotRet<loopFlag * N, loopFlag * (I+1), T_ret>::f(a,b);
|
||||
}
|
||||
|
||||
template<typename T_expr1, typename T_expr2>
|
||||
static inline T_ret
|
||||
f_ref_value(const T_expr1& a, T_expr2 b)
|
||||
{
|
||||
return static_cast<T_ret>(a[I]) * static_cast<T_ret>(b[I])
|
||||
+ _bz_meta_vectorDotRet<loopFlag * N, loopFlag * (I+1), T_ret>::f(a,b);
|
||||
}
|
||||
|
||||
template<typename T_expr1, typename P_numtype2>
|
||||
static inline T_ret
|
||||
dotWithArgs(const T_expr1& a, P_numtype2 i1, P_numtype2 i2=0,
|
||||
P_numtype2 i3=0, P_numtype2 i4=0, P_numtype2 i5=0, P_numtype2 i6=0,
|
||||
P_numtype2 i7=0, P_numtype2 i8=0, P_numtype2 i9=0, P_numtype2 i10=0)
|
||||
{
|
||||
return static_cast<T_ret>(a[I]) * static_cast<T_ret>(i1)
|
||||
+ _bz_meta_vectorDotRet<loopFlag * N, loopFlag * (I+1), T_ret>::dotWithArgs
|
||||
(a, i2, i3, i4, i5, i6, i7, i8, i9);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T_ret>
|
||||
class _bz_meta_vectorDotRet<0,0, T_ret> {
|
||||
public:
|
||||
template<typename T_expr1, typename T_expr2>
|
||||
static inline _bz_meta_nullOperand f(const T_expr1&, const T_expr2&)
|
||||
{ return _bz_meta_nullOperand(); }
|
||||
|
||||
template<typename T_expr1, typename P_numtype2>
|
||||
static inline _bz_meta_nullOperand
|
||||
dotWithArgs(const T_expr1& a, P_numtype2 i1, P_numtype2 i2=0,
|
||||
P_numtype2 i3=0, P_numtype2 i4=0, P_numtype2 i5=0, P_numtype2 i6=0,
|
||||
P_numtype2 i7=0, P_numtype2 i8=0, P_numtype2 i9=0, P_numtype2 i10=0)
|
||||
{
|
||||
return _bz_meta_nullOperand();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_META_DOT_H
|
||||
@@ -1,85 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/meta/matassign.h TinyMatrix assignment metaprogram
|
||||
*
|
||||
* $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_META_MATASSIGN_H
|
||||
#define BZ_META_MATASSIGN_H
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<int N_rows, int N_columns, int I, int J>
|
||||
class _bz_meta_matAssign2 {
|
||||
public:
|
||||
static const int go = (J < N_columns - 1) ? 1 : 0;
|
||||
|
||||
template<typename T_matrix, typename T_expr, typename T_updater>
|
||||
static inline void f(T_matrix& mat, T_expr expr, T_updater u)
|
||||
{
|
||||
u.update(mat(I,J), expr(I,J));
|
||||
_bz_meta_matAssign2<N_rows * go, N_columns * go, I * go, (J+1) * go>
|
||||
::f(mat, expr, u);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
class _bz_meta_matAssign2<0,0,0,0> {
|
||||
public:
|
||||
template<typename T_matrix, typename T_expr, typename T_updater>
|
||||
static inline void f(T_matrix&, T_expr, T_updater)
|
||||
{ }
|
||||
};
|
||||
|
||||
template<int N_rows, int N_columns, int I>
|
||||
class _bz_meta_matAssign {
|
||||
public:
|
||||
static const int go = (I < N_rows-1) ? 1 : 0;
|
||||
|
||||
template<typename T_matrix, typename T_expr, typename T_updater>
|
||||
static inline void f(T_matrix& mat, T_expr expr, T_updater u)
|
||||
{
|
||||
_bz_meta_matAssign2<N_rows, N_columns, I, 0>::f(mat, expr, u);
|
||||
_bz_meta_matAssign<N_rows * go, N_columns * go, (I+1) * go>
|
||||
::f(mat, expr, u);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
class _bz_meta_matAssign<0,0,0> {
|
||||
public:
|
||||
template<typename T_matrix, typename T_expr, typename T_updater>
|
||||
static inline void f(T_matrix&, T_expr, T_updater)
|
||||
{ }
|
||||
};
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_META_ASSIGN_H
|
||||
@@ -1,128 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/meta/matmat.h TinyMatrix matrix-matrix product metaprogram
|
||||
*
|
||||
* $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_META_MATMAT_H
|
||||
#define BZ_META_MATMAT_H
|
||||
|
||||
#ifndef BZ_TINYMAT_H
|
||||
#error <blitz/meta/matmat.h> must be included via <blitz/tinymat.h>
|
||||
#endif
|
||||
|
||||
#include <blitz/meta/metaprog.h>
|
||||
#include <blitz/tinymatexpr.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// Template metaprogram for matrix-matrix multiplication
|
||||
template<int N_rows1, int N_columns, int N_columns2, int N_rowStride1,
|
||||
int N_colStride1, int N_rowStride2, int N_colStride2, int K>
|
||||
class _bz_meta_matrixMatrixProduct {
|
||||
public:
|
||||
static const int go = (K != N_columns - 1) ? 1 : 0;
|
||||
|
||||
template<typename T_numtype1, typename T_numtype2>
|
||||
static inline BZ_PROMOTE(T_numtype1, T_numtype2)
|
||||
f(const T_numtype1* matrix1, const T_numtype2* matrix2, int i, int j)
|
||||
{
|
||||
return matrix1[i * N_rowStride1 + K * N_colStride1]
|
||||
* matrix2[K * N_rowStride2 + j * N_colStride2]
|
||||
+ _bz_meta_matrixMatrixProduct<N_rows1 * go, N_columns * go,
|
||||
N_columns2 * go, N_rowStride1 * go, N_colStride1 * go,
|
||||
N_rowStride2 * go, N_colStride2 * go, (K+1) * go>
|
||||
::f(matrix1, matrix2, i, j);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
class _bz_meta_matrixMatrixProduct<0,0,0,0,0,0,0,0> {
|
||||
public:
|
||||
static inline _bz_meta_nullOperand f(const void*, const void*, int, int)
|
||||
{ return _bz_meta_nullOperand(); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename T_numtype1, typename T_numtype2, int N_rows1, int N_columns,
|
||||
int N_columns2, int N_rowStride1, int N_colStride1,
|
||||
int N_rowStride2, int N_colStride2>
|
||||
class _bz_tinyMatrixMatrixProduct {
|
||||
public:
|
||||
typedef BZ_PROMOTE(T_numtype1, T_numtype2) T_numtype;
|
||||
|
||||
static const int rows = N_rows1, columns = N_columns2;
|
||||
|
||||
_bz_tinyMatrixMatrixProduct(const T_numtype1* matrix1,
|
||||
const T_numtype2* matrix2)
|
||||
: matrix1_(matrix1), matrix2_(matrix2)
|
||||
{ }
|
||||
|
||||
_bz_tinyMatrixMatrixProduct(const _bz_tinyMatrixMatrixProduct<T_numtype1,
|
||||
T_numtype2, N_rows1, N_columns, N_columns2, N_rowStride1, N_colStride1,
|
||||
N_rowStride2, N_colStride2>& x)
|
||||
: matrix1_(x.matrix1_), matrix2_(x.matrix2_)
|
||||
{ }
|
||||
|
||||
const T_numtype1* matrix1() const
|
||||
{ return matrix1_; }
|
||||
|
||||
const T_numtype2* matrix2() const
|
||||
{ return matrix2_; }
|
||||
|
||||
T_numtype operator()(int i, int j) const
|
||||
{
|
||||
return _bz_meta_matrixMatrixProduct<N_rows1, N_columns,
|
||||
N_columns2, N_rowStride1, N_colStride1, N_rowStride2,
|
||||
N_colStride2, 0>::f(matrix1_, matrix2_, i, j);
|
||||
}
|
||||
|
||||
protected:
|
||||
const T_numtype1* matrix1_;
|
||||
const T_numtype2* matrix2_;
|
||||
};
|
||||
|
||||
template<typename T_numtype1, typename T_numtype2, int N_rows1, int N_columns1,
|
||||
int N_columns2>
|
||||
inline
|
||||
_bz_tinyMatExpr<_bz_tinyMatrixMatrixProduct<T_numtype1, T_numtype2, N_rows1,
|
||||
N_columns1, N_columns2, N_columns1, 1, N_columns2, 1> >
|
||||
product(const TinyMatrix<T_numtype1, N_rows1, N_columns1>& a,
|
||||
const TinyMatrix<T_numtype2, N_columns1, N_columns2>& b)
|
||||
{
|
||||
typedef _bz_tinyMatrixMatrixProduct<T_numtype1, T_numtype2,
|
||||
N_rows1, N_columns1, N_columns2, N_columns1, 1, N_columns2, 1> T_expr;
|
||||
return _bz_tinyMatExpr<T_expr>(T_expr(a.data(), b.data()));
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_META_MATMAT_H
|
||||
|
||||
@@ -1,193 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/tiny/matvec.h TinyMatrix/TinyVector product metaprogram
|
||||
*
|
||||
* $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_META_MATVEC_H
|
||||
#define BZ_META_MATVEC_H
|
||||
|
||||
#ifndef BZ_BLITZ_H
|
||||
#include <blitz/blitz.h>
|
||||
#endif
|
||||
|
||||
#ifndef BZ_VECEXPRWRAP_H
|
||||
#include <blitz/vecexprwrap.h>
|
||||
#endif
|
||||
|
||||
#ifndef BZ_METAPROG_H
|
||||
#include <blitz/meta/metaprog.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// Forward declarations
|
||||
template<int N_rows, int N_columns, int N_rowStride, int N_colStride,
|
||||
int N_vecStride, int J>
|
||||
class _bz_meta_matrixVectorProduct2;
|
||||
|
||||
|
||||
template<typename T_numtype1, typename T_numtype2, int N_rows, int N_columns,
|
||||
int N_rowStride, int N_colStride, int N_vecStride>
|
||||
class _bz_tinyMatrixVectorProduct {
|
||||
public:
|
||||
typedef BZ_PROMOTE(T_numtype1, T_numtype2) T_numtype;
|
||||
|
||||
_bz_tinyMatrixVectorProduct(const _bz_tinyMatrixVectorProduct<T_numtype1,
|
||||
T_numtype2, N_rows, N_columns, N_rowStride, N_colStride,
|
||||
N_vecStride>& z)
|
||||
: matrix_(z.matrix_), vector_(z.vector_)
|
||||
{ }
|
||||
|
||||
_bz_tinyMatrixVectorProduct(const T_numtype1* matrix,
|
||||
const T_numtype2* vector)
|
||||
: matrix_(matrix), vector_(vector)
|
||||
{ }
|
||||
|
||||
T_numtype operator[](unsigned i) const
|
||||
{
|
||||
return _bz_meta_matrixVectorProduct2<N_rows, N_columns, N_rowStride,
|
||||
N_colStride, N_vecStride, 0>::f(matrix_, vector_, i);
|
||||
}
|
||||
|
||||
T_numtype operator()(unsigned i) const
|
||||
{
|
||||
return _bz_meta_matrixVectorProduct2<N_rows, N_columns, N_rowStride,
|
||||
N_colStride, N_vecStride, 0>::f(matrix_, vector_, i);
|
||||
}
|
||||
|
||||
static const int
|
||||
_bz_staticLengthCount = 1,
|
||||
_bz_dynamicLengthCount = 0,
|
||||
_bz_staticLength = N_rows;
|
||||
|
||||
#ifdef BZ_HAVE_COSTS
|
||||
static const int
|
||||
_bz_costPerEval = 2 * N_columns * costs::memoryAccess
|
||||
+ (N_columns-1) * costs::add;
|
||||
#endif
|
||||
|
||||
unsigned _bz_suggestLength() const
|
||||
{
|
||||
return N_rows;
|
||||
}
|
||||
|
||||
bool _bz_hasFastAccess() const
|
||||
{ return true; }
|
||||
|
||||
T_numtype _bz_fastAccess(unsigned i) const
|
||||
{
|
||||
return _bz_meta_matrixVectorProduct2<N_rows, N_columns, N_rowStride,
|
||||
N_colStride, N_vecStride, 0>::f(matrix_, vector_, i);
|
||||
}
|
||||
|
||||
unsigned length(unsigned recommendedLength) const
|
||||
{ return N_rows; }
|
||||
|
||||
const T_numtype1* matrix() const
|
||||
{ return matrix_; }
|
||||
|
||||
const T_numtype2* vector() const
|
||||
{ return vector_; }
|
||||
|
||||
protected:
|
||||
const T_numtype1* matrix_;
|
||||
const T_numtype2* vector_;
|
||||
};
|
||||
|
||||
template<typename T_numtype1, typename T_numtype2, int N_rows, int N_columns>
|
||||
inline _bz_VecExpr<_bz_tinyMatrixVectorProduct<T_numtype1, T_numtype2,
|
||||
N_rows, N_columns, N_columns, 1, 1> >
|
||||
product(const TinyMatrix<T_numtype1, N_rows, N_columns>& matrix,
|
||||
const TinyVector<T_numtype2, N_columns>& vector)
|
||||
{
|
||||
typedef _bz_tinyMatrixVectorProduct<T_numtype1, T_numtype2, N_rows,
|
||||
N_columns, N_columns, 1, 1> T_expr;
|
||||
return _bz_VecExpr<T_expr>(T_expr(matrix.data(), vector.data()));
|
||||
}
|
||||
|
||||
// Template metaprogram for matrix-vector multiplication
|
||||
|
||||
template<int N_rows, int N_columns, int N_rowStride, int N_colStride,
|
||||
int N_vecStride, int J>
|
||||
class _bz_meta_matrixVectorProduct2 {
|
||||
|
||||
public:
|
||||
static const int go = J < (N_columns-1) ? 1 : 0;
|
||||
|
||||
template<typename T_numtype1, typename T_numtype2>
|
||||
static inline BZ_PROMOTE(T_numtype1, T_numtype2)
|
||||
f(const T_numtype1* matrix, const T_numtype2* vector, int i)
|
||||
{
|
||||
return matrix[i * N_rowStride + J * N_colStride]
|
||||
* vector[J * N_vecStride]
|
||||
|
||||
+ _bz_meta_matrixVectorProduct2<N_rows * go, N_columns * go,
|
||||
N_rowStride * go, N_colStride * go, N_vecStride * go, (J+1)*go>
|
||||
::f(matrix, vector, i);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<>
|
||||
class _bz_meta_matrixVectorProduct2<0,0,0,0,0,0> {
|
||||
public:
|
||||
static inline _bz_meta_nullOperand f(const void*, const void*, int)
|
||||
{ return _bz_meta_nullOperand(); }
|
||||
};
|
||||
|
||||
template<int N_rows, int N_columns, int N_rowStride, int N_colStride,
|
||||
int N_vecStride, int I>
|
||||
class _bz_meta_matrixVectorProduct {
|
||||
public:
|
||||
static const int go = I < (N_rows - 1) ? 1 : 0;
|
||||
|
||||
template<typename T_numtype1, typename T_numtype2, typename T_numtype3>
|
||||
static inline void f(TinyVector<T_numtype3, N_rows>& result,
|
||||
const T_numtype1* matrix, const T_numtype2* vector)
|
||||
{
|
||||
result[I] = _bz_meta_matrixVectorProduct2<N_rows, N_columns,
|
||||
N_rowStride, N_colStride, N_vecStride, 0>::f(matrix,vector, I);
|
||||
|
||||
_bz_meta_matrixVectorProduct<N_rows * go, N_columns * go,
|
||||
N_rowStride * go, N_colStride * go, N_vecStride * go, (I+1)*go>
|
||||
::f(result, matrix, vector);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
class _bz_meta_matrixVectorProduct<0,0,0,0,0,0> {
|
||||
public:
|
||||
static inline void f(const _bz_tinyBase&, const void*, const void*)
|
||||
{ }
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_META_MATVEC_H
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/meta/metaprog.h Useful metaprogram declarations
|
||||
*
|
||||
* $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_META_METAPROG_H
|
||||
#define BZ_META_METAPROG_H
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// Null Operand
|
||||
|
||||
class _bz_meta_nullOperand {
|
||||
public:
|
||||
_bz_meta_nullOperand() { }
|
||||
};
|
||||
|
||||
template<typename T> inline T operator+(const T& a, _bz_meta_nullOperand)
|
||||
{ return a; }
|
||||
template<typename T> inline T operator*(const T& a, _bz_meta_nullOperand)
|
||||
{ return a; }
|
||||
|
||||
// MetaMax
|
||||
|
||||
template<int N1, int N2>
|
||||
class _bz_meta_max {
|
||||
public:
|
||||
static const int max = (N1 > N2) ? N1 : N2;
|
||||
};
|
||||
|
||||
// MetaMin
|
||||
|
||||
template<int N1, int N2>
|
||||
class _bz_meta_min {
|
||||
public:
|
||||
static const int min = (N1 < N2) ? N1 : N2;
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_META_METAPROG_H
|
||||
@@ -1,91 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/meta/product.h TinyVector product metaprogram
|
||||
*
|
||||
* $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_META_PRODUCT_H
|
||||
#define BZ_META_PRODUCT_H
|
||||
|
||||
#ifndef BZ_PROMOTE_H
|
||||
#include <blitz/promote.h>
|
||||
#endif
|
||||
|
||||
#ifndef BZ_METAPROG_H
|
||||
#include <blitz/meta/metaprog.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<int N, int I>
|
||||
class _bz_meta_vectorProduct {
|
||||
public:
|
||||
static const int loopFlag = (I < N-1) ? 1 : 0;
|
||||
|
||||
template<typename T_expr1>
|
||||
static inline BZ_SUMTYPE(_bz_typename T_expr1::T_numtype)
|
||||
f(const T_expr1& a)
|
||||
{
|
||||
return a[I] * _bz_meta_vectorProduct<loopFlag * N,
|
||||
loopFlag * (I+1)>::f(a);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
class _bz_meta_vectorProduct<0,0> {
|
||||
public:
|
||||
template<typename T_expr1>
|
||||
static inline _bz_meta_nullOperand f(const T_expr1&)
|
||||
{ return _bz_meta_nullOperand(); }
|
||||
};
|
||||
|
||||
template<int N, int I, typename T_ret>
|
||||
class _bz_meta_vectorProductRet {
|
||||
public:
|
||||
static const int loopFlag = (I < N-1) ? 1 : 0;
|
||||
|
||||
template<typename T_expr1>
|
||||
static inline T_ret
|
||||
f(const T_expr1& a)
|
||||
{
|
||||
return static_cast<T_ret>(a[I]) * _bz_meta_vectorProductRet<loopFlag * N,
|
||||
loopFlag * (I+1), T_ret>::f(a);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T_ret>
|
||||
class _bz_meta_vectorProductRet<0,0, T_ret> {
|
||||
public:
|
||||
template<typename T_expr1>
|
||||
static inline _bz_meta_nullOperand f(const T_expr1&)
|
||||
{ return _bz_meta_nullOperand(); }
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_META_PRODUCT_H
|
||||
@@ -1,89 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/meta/sum.h TinyVector sum metaprogram
|
||||
*
|
||||
* $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_META_SUM_H
|
||||
#define BZ_META_SUM_H
|
||||
|
||||
#ifndef BZ_METAPROG_H
|
||||
#include <blitz/meta/metaprog.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<int N, int I>
|
||||
class _bz_meta_vectorSum {
|
||||
public:
|
||||
static const int loopFlag = (I < N-1) ? 1 : 0;
|
||||
|
||||
template<typename T_expr1>
|
||||
static inline BZ_SUMTYPE(_bz_typename T_expr1::T_numtype)
|
||||
f(const T_expr1& a)
|
||||
{
|
||||
return a[I] +
|
||||
_bz_meta_vectorSum<loopFlag * N, loopFlag * (I+1)>::f(a);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
class _bz_meta_vectorSum<0,0> {
|
||||
public:
|
||||
template<typename T_expr1>
|
||||
static inline _bz_meta_nullOperand f(const T_expr1&)
|
||||
{ return _bz_meta_nullOperand(); }
|
||||
|
||||
};
|
||||
|
||||
template<int N, int I, typename T_ret>
|
||||
class _bz_meta_vectorSumRet {
|
||||
public:
|
||||
static const int loopFlag = (I < N-1) ? 1 : 0;
|
||||
|
||||
template<typename T_expr1>
|
||||
static inline T_ret
|
||||
f(const T_expr1& a)
|
||||
{
|
||||
return static_cast<T_ret>(a[I]) +
|
||||
_bz_meta_vectorSumRet<loopFlag * N, loopFlag * (I+1), T_ret>::f(a);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T_ret>
|
||||
class _bz_meta_vectorSumRet<0,0, T_ret> {
|
||||
public:
|
||||
template<typename T_expr1>
|
||||
static inline _bz_meta_nullOperand f(const T_expr1&)
|
||||
{ return _bz_meta_nullOperand(); }
|
||||
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_META_SUM_H
|
||||
@@ -1,97 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/meta/vecassign.h TinyVector assignment metaprogram
|
||||
*
|
||||
* $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_META_VECASSIGN_H
|
||||
#define BZ_META_VECASSIGN_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<int N, int I>
|
||||
class _bz_meta_vecAssign {
|
||||
public:
|
||||
static const int loopFlag = (I < N-1) ? 1 : 0;
|
||||
|
||||
template<typename T_data, typename T_expr, typename T_updater>
|
||||
static inline void fastAssign(T_data* data, T_expr expr, T_updater u)
|
||||
{
|
||||
u.update(data[I], expr.fastRead(I));
|
||||
_bz_meta_vecAssign<N * loopFlag, (I+1) * loopFlag>
|
||||
::fastAssign(data,expr,u);
|
||||
}
|
||||
|
||||
template<typename T_vector, typename T_expr, typename T_updater>
|
||||
static inline void assign(T_vector& vec, T_expr expr, T_updater u)
|
||||
{
|
||||
u.update(vec[I], expr[I]);
|
||||
_bz_meta_vecAssign<N * loopFlag, (I+1) * loopFlag>
|
||||
::assign(vec,expr,u);
|
||||
}
|
||||
|
||||
template<typename T_vector, typename T_numtype, typename T_updater>
|
||||
static inline void assignWithArgs(T_vector& vec, T_updater u,
|
||||
T_numtype x0, T_numtype x1=0, T_numtype x2=0, T_numtype x3=0,
|
||||
T_numtype x4=0, T_numtype x5=0, T_numtype x6=0, T_numtype x7=0,
|
||||
T_numtype x8=0, T_numtype x9=0)
|
||||
{
|
||||
u.update(vec[I], x0);
|
||||
_bz_meta_vecAssign<N * loopFlag, (I+1) * loopFlag>
|
||||
::assignWithArgs(vec, u, x1, x2, x3, x4, x5, x6, x7, x8, x9);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<>
|
||||
class _bz_meta_vecAssign<0,0> {
|
||||
public:
|
||||
template<typename T_vector, typename T_expr, typename T_updater>
|
||||
static inline void fastAssign(T_vector&, T_expr, T_updater)
|
||||
{ }
|
||||
|
||||
template<typename T_vector, typename T_expr, typename T_updater>
|
||||
static inline void assign(T_vector&, T_expr, T_updater)
|
||||
{ }
|
||||
|
||||
template<typename T_vector, typename T_numtype, typename T_updater>
|
||||
static inline void assignWithArgs(T_vector&, T_updater,
|
||||
T_numtype, T_numtype =0, T_numtype =0, T_numtype =0,
|
||||
T_numtype =0, T_numtype =0, T_numtype =0, T_numtype =0,
|
||||
T_numtype =0, T_numtype =0)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_META_ASSIGN_H
|
||||
@@ -1,72 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/minmax.h Declaration of min and max 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_MINMAX_H
|
||||
#define BZ_MINMAX_H
|
||||
|
||||
#include <blitz/promote.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* These functions are in their own namespace (blitz::minmax) to avoid
|
||||
* conflicts with the array reduction operations min and max.
|
||||
*/
|
||||
|
||||
BZ_NAMESPACE(extrema)
|
||||
|
||||
template<typename T1, typename T2>
|
||||
BZ_PROMOTE(T1,T2) (min)(const T1& a, const T2& b)
|
||||
{
|
||||
typedef BZ_PROMOTE(T1,T2) T_promote;
|
||||
|
||||
if (a <= b)
|
||||
return T_promote(a);
|
||||
else
|
||||
return T_promote(b);
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
BZ_PROMOTE(T1,T2) (max)(const T1& a, const T2& b)
|
||||
{
|
||||
typedef BZ_PROMOTE(T1,T2) T_promote;
|
||||
|
||||
if (a >= b)
|
||||
return T_promote(a);
|
||||
else
|
||||
return T_promote(b);
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,312 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/numinquire.h Numeric inquiry 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/
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
* These numeric inquiry functions are provided as an alternative
|
||||
* to the somewhat klunky numeric_limits<T>::yadda_yadda syntax.
|
||||
* Where a similar Fortran 90 function exists, the same name has
|
||||
* been used.
|
||||
*
|
||||
* The argument in all cases is a dummy of the appropriate type
|
||||
* (double, int, etc.)
|
||||
*
|
||||
* These functions assume that numeric_limits<T> has been specialized
|
||||
* for the appropriate case. If not, the results are not useful.
|
||||
*/
|
||||
|
||||
#ifndef BZ_NUMINQUIRE_H
|
||||
#define BZ_NUMINQUIRE_H
|
||||
|
||||
#ifndef BZ_BLITZ_H
|
||||
#include <blitz/blitz.h>
|
||||
#endif
|
||||
|
||||
#ifndef BZ_HAVE_NUMERIC_LIMITS
|
||||
#include <blitz/limits-hack.h>
|
||||
#else
|
||||
#include <limits>
|
||||
#endif
|
||||
|
||||
#ifndef BZ_RANGE_H
|
||||
#include <blitz/range.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* This traits class provides zero and one values for numeric
|
||||
* types. This was previously a template function with specializations,
|
||||
* but the specializations were causing multiply-defined symbols
|
||||
* at link time. TV 980226
|
||||
*/
|
||||
|
||||
template<typename T_numtype>
|
||||
struct _bz_OneZeroTraits {
|
||||
static inline T_numtype zero() { return 0; }
|
||||
static inline T_numtype one() { return 1; }
|
||||
};
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX
|
||||
|
||||
template<>
|
||||
struct _bz_OneZeroTraits<complex<float> > {
|
||||
static inline complex<float> zero() { return complex<float>(0.0f,0.0f); }
|
||||
static inline complex<float> one() { return complex<float>(1.0f,0.0f); }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_OneZeroTraits<complex<double> > {
|
||||
static inline complex<double> zero() { return complex<double>(0.0,0.0); }
|
||||
static inline complex<double> one() { return complex<double>(1.0,0.0); }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct _bz_OneZeroTraits<complex<long double> > {
|
||||
static inline complex<long double> zero()
|
||||
{ return complex<long double>(0.0,0.0); }
|
||||
|
||||
static inline complex<long double> one()
|
||||
{ return complex<long double>(1.0,0.0); }
|
||||
};
|
||||
|
||||
#endif // BZ_HAVE_COMPLEX
|
||||
|
||||
template<typename T>
|
||||
inline T zero(T)
|
||||
{
|
||||
return _bz_OneZeroTraits<T>::zero();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T one(T)
|
||||
{
|
||||
return _bz_OneZeroTraits<T>::one();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline int digits(T)
|
||||
{
|
||||
return numeric_limits<T>::digits;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline int digits10(T)
|
||||
{
|
||||
return numeric_limits<T>::digits10;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T epsilon(T) BZ_THROW
|
||||
{
|
||||
return numeric_limits<T>::epsilon();
|
||||
}
|
||||
|
||||
// neghuge() by Theodore Papadopoulo, to fix a problem with
|
||||
// max() reductions.
|
||||
template<typename T>
|
||||
inline T neghuge(T) BZ_THROW
|
||||
{
|
||||
return numeric_limits<T>::is_integer ? (numeric_limits<T>::min)()
|
||||
: - (numeric_limits<T>::max)();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T huge(T) BZ_THROW
|
||||
{
|
||||
return (numeric_limits<T>::max)();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T tiny(T) BZ_THROW
|
||||
{
|
||||
return (numeric_limits<T>::min)();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline int max_exponent(T)
|
||||
{
|
||||
return numeric_limits<T>::max_exponent;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline int min_exponent(T)
|
||||
{
|
||||
return numeric_limits<T>::min_exponent;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline int min_exponent10(T)
|
||||
{
|
||||
return numeric_limits<T>::min_exponent10;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline int max_exponent10(T)
|
||||
{
|
||||
return numeric_limits<T>::max_exponent10;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline int precision(T)
|
||||
{
|
||||
return numeric_limits<T>::digits10;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline int radix(T)
|
||||
{
|
||||
return numeric_limits<T>::radix;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline Range range(T)
|
||||
{
|
||||
return Range(numeric_limits<T>::min_exponent10,
|
||||
numeric_limits<T>::max_exponent10);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool is_signed(T) {
|
||||
return numeric_limits<T>::is_signed;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool is_integer(T) {
|
||||
return numeric_limits<T>::is_integer;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool is_exact(T) {
|
||||
return numeric_limits<T>::is_exact;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T round_error(T) BZ_THROW
|
||||
{
|
||||
return numeric_limits<T>::round_error();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool has_infinity(T) {
|
||||
return numeric_limits<T>::has_infinity;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool has_quiet_NaN(T) {
|
||||
return numeric_limits<T>::has_quiet_NaN;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool has_signaling_NaN(T) {
|
||||
return numeric_limits<T>::has_signaling_NaN;
|
||||
}
|
||||
|
||||
// Provided for non-US english users
|
||||
template<typename T>
|
||||
inline bool has_signalling_NaN(T) {
|
||||
return numeric_limits<T>::has_signaling_NaN;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool has_denorm(T) {
|
||||
return numeric_limits<T>::has_denorm;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool has_denorm_loss(T) {
|
||||
return numeric_limits<T>::has_denorm_loss;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T infinity(T) BZ_THROW
|
||||
{
|
||||
return numeric_limits<T>::infinity();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T quiet_NaN(T) BZ_THROW
|
||||
{
|
||||
return numeric_limits<T>::quiet_NaN();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T signaling_NaN(T) BZ_THROW
|
||||
{
|
||||
return numeric_limits<T>::signaling_NaN();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T signalling_NaN(T) BZ_THROW
|
||||
{
|
||||
return numeric_limits<T>::signaling_NaN();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T denorm_min(T) BZ_THROW
|
||||
{
|
||||
return numeric_limits<T>::denorm_min();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool is_iec559(T) {
|
||||
return numeric_limits<T>::is_iec559;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool is_bounded(T) {
|
||||
return numeric_limits<T>::is_bounded;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool is_modulo(T) {
|
||||
return numeric_limits<T>::is_modulo;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool traps(T) {
|
||||
return numeric_limits<T>::traps;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool tinyness_before(T) {
|
||||
return numeric_limits<T>::tinyness_before;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline BZ_STD_SCOPE(float_round_style) round_style(T)
|
||||
{
|
||||
return numeric_limits<T>::round_style;
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_NUMINQUIRE_H
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/numtrait.h Declaration of the NumericTypeTraits 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_NUMTRAIT_H
|
||||
#define BZ_NUMTRAIT_H
|
||||
|
||||
#ifndef BZ_BLITZ_H
|
||||
#include <blitz/blitz.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
#ifndef BZ_USE_NUMTRAIT
|
||||
#define BZ_SUMTYPE(X) X
|
||||
#define BZ_DIFFTYPE(X) X
|
||||
#define BZ_FLOATTYPE(X) X
|
||||
#define BZ_SIGNEDTYPE(X) X
|
||||
#else
|
||||
|
||||
#define BZ_SUMTYPE(X) _bz_typename NumericTypeTraits<X>::T_sumtype
|
||||
#define BZ_DIFFTYPE(X) _bz_typename NumericTypeTraits<X>::T_difftype
|
||||
#define BZ_FLOATTYPE(X) _bz_typename NumericTypeTraits<X>::T_floattype
|
||||
#define BZ_SIGNEDTYPE(X) _bz_typename NumericTypeTraits<X>::T_signedtype
|
||||
|
||||
template<typename P_numtype>
|
||||
class NumericTypeTraits {
|
||||
public:
|
||||
typedef P_numtype T_sumtype; // Type to be used for summing
|
||||
typedef P_numtype T_difftype; // Type to be used for difference
|
||||
typedef P_numtype T_floattype; // Type to be used for floating-point
|
||||
// calculations
|
||||
typedef P_numtype T_signedtype; // Type to be used for signed calculations
|
||||
enum { hasTrivialCtor = 0 }; // Assume the worst
|
||||
};
|
||||
|
||||
#define BZDECLNUMTRAIT(X,Y,Z,W,U) \
|
||||
template<> \
|
||||
class NumericTypeTraits<X> { \
|
||||
public: \
|
||||
typedef Y T_sumtype; \
|
||||
typedef Z T_difftype; \
|
||||
typedef W T_floattype; \
|
||||
typedef U T_signedtype; \
|
||||
enum { hasTrivialCtor = 1 }; \
|
||||
}
|
||||
|
||||
#ifdef BZ_HAVE_BOOL
|
||||
BZDECLNUMTRAIT(bool,unsigned,int,float,int);
|
||||
#endif
|
||||
|
||||
BZDECLNUMTRAIT(char,int,int,float,char);
|
||||
BZDECLNUMTRAIT(unsigned char, unsigned, int, float,int);
|
||||
BZDECLNUMTRAIT(short int, int, int, float, short int);
|
||||
BZDECLNUMTRAIT(short unsigned int, unsigned int, int, float, int);
|
||||
BZDECLNUMTRAIT(int, long, int, float, int);
|
||||
BZDECLNUMTRAIT(unsigned int, unsigned long, int, float, long);
|
||||
BZDECLNUMTRAIT(long, long, long, double, long);
|
||||
BZDECLNUMTRAIT(unsigned long, unsigned long, long, double, long);
|
||||
BZDECLNUMTRAIT(float, double, float, float, float);
|
||||
BZDECLNUMTRAIT(double, double, double, double, double);
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX
|
||||
// BZDECLNUMTRAIT(complex<float>, complex<double>, complex<float>, complex<float>);
|
||||
// BZDECLNUMTRAIT(complex<double>, complex<long double>, complex<double>, complex<double>);
|
||||
#endif // BZ_HAVE_COMPLEX
|
||||
|
||||
#endif // BZ_USE_NUMTRAIT
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_NUMTRAIT_H
|
||||
@@ -1,218 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/ops.h Function objects for math 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_OPS_H
|
||||
#define BZ_OPS_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/promote.h>
|
||||
#include <blitz/prettyprint.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* Originally these function objects had no template arguments, e.g.
|
||||
*
|
||||
* struct Add {
|
||||
* template<typename T_numtype1, typename T_numtype2>
|
||||
* static inline BZ_PROMOTE(T_numtype1, T_numtype2)
|
||||
* apply(T_numtype1 a, T_numtype2 b)
|
||||
* { return a + b; }
|
||||
* };
|
||||
*
|
||||
* This made for neater expression templates syntax. However, there are
|
||||
* some situations in which users may want to override type promotion
|
||||
* for certain operations. For example, in theoretical physics, there
|
||||
* are U1 objects which when multiplied yield U1 objects, but when added
|
||||
* yield a different type. To allow for this kind of behaviour, function
|
||||
* objects have been changed to take template parameters:
|
||||
*
|
||||
* template<typename T_numtype1, typename T_numtype2>
|
||||
* struct Add {
|
||||
* typedef BZ_PROMOTE(T_numtype1, T_numtype2) T_numtype;
|
||||
*
|
||||
* static inline T_numtype apply(T_numtype1 a, T_numtype2 b)
|
||||
* { return a + b; }
|
||||
* };
|
||||
*
|
||||
* Type promotion is performed inside the function object. The expression
|
||||
* templates code always looks inside the function object to determine
|
||||
* the type promotion, e.g. Add<int,float>::T_numtype
|
||||
*
|
||||
* Users are free to specialize these function objects for their own types.
|
||||
*/
|
||||
|
||||
/* Unary operators that return same type as argument */
|
||||
|
||||
#define BZ_DEFINE_UNARY_OP(name,op) \
|
||||
template<typename T_numtype1> \
|
||||
struct name { \
|
||||
typedef T_numtype1 T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a) \
|
||||
{ return op a; } \
|
||||
\
|
||||
template<typename T1> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
prettyPrintFormat& format, const T1& t1) \
|
||||
{ \
|
||||
str += #op; \
|
||||
t1.prettyPrint(str, format); \
|
||||
} \
|
||||
};
|
||||
|
||||
BZ_DEFINE_UNARY_OP(BitwiseNot,~)
|
||||
BZ_DEFINE_UNARY_OP(UnaryPlus,+)
|
||||
BZ_DEFINE_UNARY_OP(UnaryMinus,-)
|
||||
|
||||
|
||||
/* Unary operators that return a specified type */
|
||||
|
||||
#define BZ_DEFINE_UNARY_OP_RET(name,op,ret) \
|
||||
template<typename T_numtype1> \
|
||||
struct name { \
|
||||
typedef ret T_numtype; \
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a) \
|
||||
{ return op a; } \
|
||||
\
|
||||
template<typename T1> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
prettyPrintFormat& format, const T1& t1) \
|
||||
{ \
|
||||
str += #op; \
|
||||
t1.prettyPrint(str, format); \
|
||||
} \
|
||||
};
|
||||
|
||||
BZ_DEFINE_UNARY_OP_RET(LogicalNot,!,bool)
|
||||
|
||||
|
||||
/* Binary operators that return type based on type promotion */
|
||||
|
||||
#define BZ_DEFINE_BINARY_OP(name,op) \
|
||||
template<typename T_numtype1, typename T_numtype2> \
|
||||
struct name { \
|
||||
typedef BZ_PROMOTE(T_numtype1, T_numtype2) T_numtype; \
|
||||
\
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a, T_numtype2 b) \
|
||||
{ return a op b; } \
|
||||
\
|
||||
template<typename T1, typename T2> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
prettyPrintFormat& format, const T1& t1, \
|
||||
const T2& t2) \
|
||||
{ \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += #op; \
|
||||
t2.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
BZ_DEFINE_BINARY_OP(Add,+)
|
||||
BZ_DEFINE_BINARY_OP(Subtract,-)
|
||||
BZ_DEFINE_BINARY_OP(Multiply,*)
|
||||
BZ_DEFINE_BINARY_OP(Divide,/)
|
||||
BZ_DEFINE_BINARY_OP(Modulo,%)
|
||||
BZ_DEFINE_BINARY_OP(BitwiseXor,^)
|
||||
BZ_DEFINE_BINARY_OP(BitwiseAnd,&)
|
||||
BZ_DEFINE_BINARY_OP(BitwiseOr,|)
|
||||
BZ_DEFINE_BINARY_OP(ShiftRight,>>)
|
||||
BZ_DEFINE_BINARY_OP(ShiftLeft,<<)
|
||||
|
||||
|
||||
/* Binary operators that return a specified type */
|
||||
|
||||
#define BZ_DEFINE_BINARY_OP_RET(name,op,ret) \
|
||||
template<typename T_numtype1, typename T_numtype2> \
|
||||
struct name { \
|
||||
typedef ret T_numtype; \
|
||||
static inline T_numtype \
|
||||
apply(T_numtype1 a, T_numtype2 b) \
|
||||
{ return a op b; } \
|
||||
\
|
||||
template<typename T1, typename T2> \
|
||||
static inline void prettyPrint(BZ_STD_SCOPE(string) &str, \
|
||||
prettyPrintFormat& format, const T1& t1, \
|
||||
const T2& t2) \
|
||||
{ \
|
||||
str += "("; \
|
||||
t1.prettyPrint(str, format); \
|
||||
str += #op; \
|
||||
t2.prettyPrint(str, format); \
|
||||
str += ")"; \
|
||||
} \
|
||||
};
|
||||
|
||||
BZ_DEFINE_BINARY_OP_RET(Greater,>,bool)
|
||||
BZ_DEFINE_BINARY_OP_RET(Less,<,bool)
|
||||
BZ_DEFINE_BINARY_OP_RET(GreaterOrEqual,>=,bool)
|
||||
BZ_DEFINE_BINARY_OP_RET(LessOrEqual,<=,bool)
|
||||
BZ_DEFINE_BINARY_OP_RET(Equal,==,bool)
|
||||
BZ_DEFINE_BINARY_OP_RET(NotEqual,!=,bool)
|
||||
BZ_DEFINE_BINARY_OP_RET(LogicalAnd,&&,bool)
|
||||
BZ_DEFINE_BINARY_OP_RET(LogicalOr,||,bool)
|
||||
|
||||
/* already defined in funcs
|
||||
// We define these explicitly since they don't fit a pattern
|
||||
template<typename P_numtype1, typename P_numtype2>
|
||||
struct Min {
|
||||
public:
|
||||
typedef P_numtype1 T_numtype1;
|
||||
typedef P_numtype2 T_numtype2;
|
||||
typedef bool T_numtype;
|
||||
|
||||
static inline T_numtype apply(T_numtype1 x, T_numtype2 y)
|
||||
{ return (x < y ? x : y); }
|
||||
};
|
||||
|
||||
template<typename P_numtype1, typename P_numtype2>
|
||||
class Max {
|
||||
public:
|
||||
typedef P_numtype1 T_numtype1;
|
||||
typedef P_numtype2 T_numtype2;
|
||||
typedef bool T_numtype;
|
||||
|
||||
static inline T_numtype apply(T_numtype1 x, T_numtype2 y)
|
||||
{ return (x > y ? x : y); }
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_OPS_H
|
||||
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/prettyprint.h Format object for pretty-printing of
|
||||
* 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_PRETTYPRINT_H
|
||||
#define BZ_PRETTYPRINT_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
class prettyPrintFormat {
|
||||
|
||||
public:
|
||||
prettyPrintFormat(const bool terse = false)
|
||||
: tersePrintingSelected_(terse)
|
||||
{
|
||||
arrayOperandCounter_ = 0;
|
||||
scalarOperandCounter_ = 0;
|
||||
dumpArrayShapes_ = false;
|
||||
}
|
||||
|
||||
void setDumpArrayShapesMode() { dumpArrayShapes_ = true; }
|
||||
char nextArrayOperandSymbol()
|
||||
{
|
||||
return static_cast<char>('A' + ((arrayOperandCounter_++) % 26));
|
||||
}
|
||||
char nextScalarOperandSymbol()
|
||||
{
|
||||
return static_cast<char>('s' + ((scalarOperandCounter_++) % 26));
|
||||
}
|
||||
|
||||
bool tersePrintingSelected() const { return tersePrintingSelected_; }
|
||||
bool dumpArrayShapesMode() const { return dumpArrayShapes_; }
|
||||
|
||||
private:
|
||||
bool tersePrintingSelected_;
|
||||
bool dumpArrayShapes_;
|
||||
int arrayOperandCounter_;
|
||||
int scalarOperandCounter_;
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_PRETTYPRINT_H
|
||||
@@ -1,172 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***********************************************************************
|
||||
* promote.h Arithmetic type promotion trait 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_PROMOTE_H
|
||||
#define BZ_PROMOTE_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
#ifdef BZ_HAVE_TEMPLATE_QUALIFIED_RETURN_TYPE
|
||||
#define BZ_PROMOTE(A,B) _bz_typename BZ_BLITZ_SCOPE(promote_trait)<A,B>::T_promote
|
||||
#else
|
||||
#define BZ_PROMOTE(A,B) A
|
||||
#endif
|
||||
|
||||
#if defined(BZ_HAVE_PARTIAL_SPECIALIZATION) && !defined(BZ_DISABLE_NEW_PROMOTE)
|
||||
|
||||
/*
|
||||
* This compiler supports partial specialization, so type promotion
|
||||
* can be done the elegant way. This implementation is after ideas
|
||||
* by Jean-Louis Leroy.
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
struct precision_trait {
|
||||
static const int precisionRank = 0;
|
||||
static const bool knowPrecisionRank = false;
|
||||
};
|
||||
|
||||
#define BZ_DECLARE_PRECISION(T,rank) \
|
||||
template<> \
|
||||
struct precision_trait< T > { \
|
||||
static const int precisionRank = rank; \
|
||||
static const bool knowPrecisionRank = true; \
|
||||
};
|
||||
|
||||
BZ_DECLARE_PRECISION(int,100)
|
||||
BZ_DECLARE_PRECISION(unsigned int,200)
|
||||
BZ_DECLARE_PRECISION(long,300)
|
||||
BZ_DECLARE_PRECISION(unsigned long,400)
|
||||
BZ_DECLARE_PRECISION(float,500)
|
||||
BZ_DECLARE_PRECISION(double,600)
|
||||
BZ_DECLARE_PRECISION(long double,700)
|
||||
|
||||
#ifdef BZ_HAVE_COMPLEX
|
||||
BZ_DECLARE_PRECISION(complex<float>,800)
|
||||
BZ_DECLARE_PRECISION(complex<double>,900)
|
||||
BZ_DECLARE_PRECISION(complex<long double>,1000)
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
struct autopromote_trait {
|
||||
typedef T T_numtype;
|
||||
};
|
||||
|
||||
#define BZ_DECLARE_AUTOPROMOTE(T1,T2) \
|
||||
template<> \
|
||||
struct autopromote_trait<T1> { \
|
||||
typedef T2 T_numtype; \
|
||||
};
|
||||
|
||||
// These are the odd cases where small integer types
|
||||
// are automatically promoted to int or unsigned int for
|
||||
// arithmetic.
|
||||
BZ_DECLARE_AUTOPROMOTE(bool, int)
|
||||
BZ_DECLARE_AUTOPROMOTE(char, int)
|
||||
BZ_DECLARE_AUTOPROMOTE(unsigned char, int)
|
||||
BZ_DECLARE_AUTOPROMOTE(short int, int)
|
||||
BZ_DECLARE_AUTOPROMOTE(short unsigned int, unsigned int)
|
||||
|
||||
template<typename T1, typename T2, bool promoteToT1>
|
||||
struct _bz_promote2 {
|
||||
typedef T1 T_promote;
|
||||
};
|
||||
|
||||
template<typename T1, typename T2>
|
||||
struct _bz_promote2<T1,T2,false> {
|
||||
typedef T2 T_promote;
|
||||
};
|
||||
|
||||
template<typename T1_orig, typename T2_orig>
|
||||
struct promote_trait {
|
||||
// Handle promotion of small integers to int/unsigned int
|
||||
typedef _bz_typename autopromote_trait<T1_orig>::T_numtype T1;
|
||||
typedef _bz_typename autopromote_trait<T2_orig>::T_numtype T2;
|
||||
|
||||
// True if T1 is higher ranked
|
||||
static const bool
|
||||
T1IsBetter =
|
||||
precision_trait<T1>::precisionRank >
|
||||
precision_trait<T2>::precisionRank;
|
||||
|
||||
// True if we know ranks for both T1 and T2
|
||||
static const bool
|
||||
knowBothRanks =
|
||||
precision_trait<T1>::knowPrecisionRank &&
|
||||
precision_trait<T2>::knowPrecisionRank;
|
||||
|
||||
// True if we know T1 but not T2
|
||||
static const bool
|
||||
knowT1butNotT2 =
|
||||
precision_trait<T1>::knowPrecisionRank &&
|
||||
!precision_trait<T2>::knowPrecisionRank;
|
||||
|
||||
// True if we know T2 but not T1
|
||||
static const bool
|
||||
knowT2butNotT1 =
|
||||
precision_trait<T2>::knowPrecisionRank &&
|
||||
!precision_trait<T1>::knowPrecisionRank;
|
||||
|
||||
// True if T1 is bigger than T2
|
||||
static const bool
|
||||
T1IsLarger = sizeof(T1) >= sizeof(T2);
|
||||
|
||||
// We know T1 but not T2: false
|
||||
// We know T2 but not T1: true
|
||||
// Otherwise, if T1 is bigger than T2: true
|
||||
// static const bool
|
||||
// defaultPromotion = knowT1butNotT2 ? false :
|
||||
// (knowT2butNotT1 ? true : T1IsLarger);
|
||||
|
||||
// If we have both ranks, then use them.
|
||||
// If we have only one rank, then use the unknown type.
|
||||
// If we have neither rank, then promote to the larger type.
|
||||
static const bool
|
||||
promoteToT1 = knowBothRanks ? T1IsBetter : (knowT1butNotT2 ? false :
|
||||
(knowT2butNotT1 ? true : T1IsLarger));
|
||||
// static const bool
|
||||
// promoteToT1 = knowBothRanks ? T1IsBetter : defaultPromotion;
|
||||
|
||||
typedef _bz_typename _bz_promote2<T1,T2,promoteToT1>::T_promote T_promote;
|
||||
};
|
||||
|
||||
#else // !BZ_HAVE_PARTIAL_SPECIALIZATION
|
||||
|
||||
// No partial specialization -- have to do it the ugly way.
|
||||
#include <blitz/promote-old.h>
|
||||
|
||||
#endif // !BZ_HAVE_PARTIAL_SPECIALIZATION
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_PROMOTE_H
|
||||
@@ -1,33 +0,0 @@
|
||||
#ifndef BZ_RANGE_CC
|
||||
#define BZ_RANGE_CC
|
||||
|
||||
|
||||
#include <blitz/range.h>
|
||||
#include <blitz/array/ops.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
|
||||
inline Range::T_numtype Range::operator[](int i) const
|
||||
{
|
||||
return first_ + i * stride_;
|
||||
}
|
||||
|
||||
inline RectDomain<Range::rank_> Range::domain() const
|
||||
{
|
||||
return RectDomain<rank_>(TinyVector<int,1>(0),
|
||||
TinyVector<int,1>(ubound(0)));
|
||||
}
|
||||
|
||||
inline bool Range::assertInRange(const T_index& BZ_DEBUG_PARAM(index)) const
|
||||
{
|
||||
BZPRECHECK((index[0]<=ubound(0)) && (index[0]>=0),
|
||||
"Range index out of range: " << index[0]
|
||||
<< endl << "Lower bounds: 0" << endl
|
||||
<< "Length: " << length() << endl);
|
||||
return true;
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,326 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/range.h Declaration of the Range 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_RANGE_H
|
||||
#define BZ_RANGE_H
|
||||
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/etbase.h>
|
||||
#include <blitz/array/asexpr.h>
|
||||
#include <blitz/prettyprint.h>
|
||||
#include <blitz/tinyvec2.h>
|
||||
#include <climits> // for INT_MIN, INT_MAX
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// A Range object is an ET that generates the specified sequence.
|
||||
|
||||
// Examples:
|
||||
// Array<int,1> A(7);
|
||||
// A = 0,1,2,3,4,5,6;
|
||||
// A(Range::all()); [0,1,2,3,4,5,6]
|
||||
// A(Range(3,5)); [3,4,5]
|
||||
// A(Range(3,toEnd)); [3,4,5,6]
|
||||
// A(Range(fromStart,3)); [0,1,2,3]
|
||||
// A(Range(1,5,2)); [1,3,5]
|
||||
// A(Range(5,1,-2)); [5,3,1]
|
||||
// A(Range(fromStart,toEnd,2)); [0,2,4,6]
|
||||
|
||||
template<int N_rank> class RectDomain;
|
||||
class nilArraySection;
|
||||
|
||||
const int fromStart = INT_MIN;
|
||||
const int toEnd = INT_MAX;
|
||||
|
||||
// Class Range
|
||||
class Range : public ETBase<Range> {
|
||||
public:
|
||||
typedef int T_numtype;
|
||||
typedef opType<T_numtype>::T_optype T_optype;
|
||||
|
||||
typedef asET<T_numtype>::T_wrapped T_typeprop;
|
||||
typedef unwrapET<T_typeprop>::T_unwrapped T_result;
|
||||
|
||||
typedef void T_ctorArg1;
|
||||
typedef char T_ctorArg2; // dummy
|
||||
typedef TinyVector<int, 1> T_index;
|
||||
typedef Range T_range_result;
|
||||
static const int
|
||||
numArrayOperands = 0,
|
||||
numTVOperands = 0,
|
||||
numTMOperands = 0,
|
||||
numIndexPlaceholders = 1,
|
||||
minWidth = simdTypes<T_numtype>::vecWidth,
|
||||
maxWidth = simdTypes<T_numtype>::vecWidth,
|
||||
rank_ = 1;
|
||||
|
||||
/** The vectorized return type for a Range should be another range,
|
||||
but that's not useful since a vectorized TinyVector assignment
|
||||
can not contain index placeholders. In fact, since vectorization
|
||||
doesn't work for index expressions anyway, we can just set this
|
||||
to a dummy. */
|
||||
template<int N> struct tvresult {
|
||||
typedef FastTV2Iterator<T_numtype, N> Type;
|
||||
};
|
||||
|
||||
Range()
|
||||
{
|
||||
first_ = fromStart;
|
||||
last_ = toEnd;
|
||||
stride_ = 1;
|
||||
}
|
||||
|
||||
Range(const Range& r)
|
||||
{
|
||||
first_ = r.first_;
|
||||
last_ = r.last_;
|
||||
stride_ = r.stride_;
|
||||
}
|
||||
|
||||
explicit Range(T_numtype slicePosition)
|
||||
{
|
||||
first_ = slicePosition;
|
||||
last_ = slicePosition;
|
||||
stride_ = 1;
|
||||
}
|
||||
|
||||
Range(T_numtype first, T_numtype last, diffType stride=1)
|
||||
: first_(first), last_(last), stride_(stride)
|
||||
{
|
||||
BZPRECHECK((first == fromStart) || (last == toEnd) ||
|
||||
((first < last) && (stride > 0)) ||
|
||||
((first > last) && (stride < 0)) ||
|
||||
(first == last), (*this) << " is an invalid range.");
|
||||
BZPRECHECK((first == fromStart) || (last == toEnd) ||
|
||||
(last-first) % stride == 0,
|
||||
(*this) << ": the stride must evenly divide the range");
|
||||
}
|
||||
|
||||
T_numtype operator*() const { BZPRECONDITION(0); return 0; }
|
||||
T_numtype first_value() const { BZPRECONDITION(0); return 0; }
|
||||
|
||||
int ascending(const int) const { return true; }
|
||||
int ordering(const int) const { return 0; }
|
||||
int lbound(const int) const { return 0; }
|
||||
int ubound(const int) const { return length()-1; }
|
||||
|
||||
RectDomain<rank_> domain() const;
|
||||
|
||||
bool assertInRange(const T_index& BZ_DEBUG_PARAM(index)) const;
|
||||
|
||||
#ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
|
||||
template<int N_rank>
|
||||
T_numtype operator()(const TinyVector<int,N_rank> i) const
|
||||
{ assertInRange(i); return operator[](i[0]); }
|
||||
#else
|
||||
template<int N_rank>
|
||||
T_numtype operator()(const TinyVector<int,N_rank>& i) const
|
||||
{ assertInRange(i); return operator[](i[0]); }
|
||||
#endif
|
||||
|
||||
T_numtype operator[](int i) const;
|
||||
|
||||
T_numtype operator()(int i) const
|
||||
{
|
||||
return operator[](i);
|
||||
}
|
||||
|
||||
// we could work out how this should work.
|
||||
template<int N_rank>
|
||||
const Range operator()(const RectDomain<N_rank>& d) const
|
||||
{
|
||||
BZPRECONDITION(0); return *this;
|
||||
}
|
||||
|
||||
void push(int) { }
|
||||
void pop(int) { }
|
||||
void advance() { }
|
||||
void advance(int) { }
|
||||
void loadStride(int) { }
|
||||
|
||||
bool isUnitStride(int) const
|
||||
{ BZPRECONDITION(0); return 0; }
|
||||
|
||||
void advanceUnitStride()
|
||||
{ }
|
||||
|
||||
bool canCollapse(int,int) const
|
||||
{ return true; }
|
||||
|
||||
T_numtype fastRead(diffType) const
|
||||
{ BZPRECONDITION(0); return 0; }
|
||||
|
||||
template<int N>
|
||||
typename tvresult<N>::Type fastRead_tv(diffType) const
|
||||
{ BZPRECONDITION(0); return 0; }
|
||||
|
||||
// this is needed for the stencil expression fastRead to work
|
||||
void _bz_offsetData(sizeType i) const{BZPRECONDITION(0);};
|
||||
|
||||
// and these are needed for stencil expression shift to work
|
||||
void _bz_offsetData(sizeType offset, int dim) const {BZPRECONDITION(0);};
|
||||
|
||||
void _bz_offsetData(sizeType offset1, int dim1, sizeType offset2, int dim2) const {BZPRECONDITION(0);};
|
||||
|
||||
diffType suggestStride(int) const
|
||||
{ return 1; }
|
||||
|
||||
bool isStride(int,diffType) const
|
||||
{ return true; }
|
||||
|
||||
void moveTo(int) const { BZPRECONDITION(0); }
|
||||
|
||||
T_numtype shift(int offset, int dim) const {
|
||||
BZPRECONDITION(0); return T_numtype(); }
|
||||
|
||||
T_numtype shift(int offset1, int dim1,int offset2, int dim2) const
|
||||
{ BZPRECONDITION(0); return T_numtype(); }
|
||||
|
||||
template<int N_rank>
|
||||
void moveTo(const TinyVector<int,N_rank>&) const { BZPRECONDITION(0); }
|
||||
|
||||
void prettyPrint(BZ_STD_SCOPE(string) &str,
|
||||
prettyPrintFormat& format) const
|
||||
{
|
||||
#ifdef BZ_HAVE_STD
|
||||
BZ_STD_SCOPE(ostringstream) ostr;
|
||||
#else
|
||||
ostrstream ostr;
|
||||
#endif
|
||||
ostr << "Range(" << first_ << ", " << last_
|
||||
<< ", " << stride_ << ")";
|
||||
str += ostr.str();
|
||||
}
|
||||
|
||||
|
||||
// old range stuff below. what is needed for the range interface and
|
||||
// what is old vecexpr stuff?
|
||||
|
||||
T_numtype first(T_numtype lowRange = 0) const
|
||||
{
|
||||
if (first_ == fromStart)
|
||||
return lowRange;
|
||||
return first_;
|
||||
}
|
||||
|
||||
T_numtype last(T_numtype highRange = 0) const
|
||||
{
|
||||
if (last_ == toEnd)
|
||||
return highRange;
|
||||
return last_;
|
||||
}
|
||||
|
||||
int length(int =0) const
|
||||
{
|
||||
BZPRECONDITION(first_ != fromStart);
|
||||
BZPRECONDITION(last_ != toEnd);
|
||||
BZPRECONDITION((last_ - first_) % stride_ == 0);
|
||||
return (last_ - first_) / stride_ + 1;
|
||||
}
|
||||
|
||||
diffType stride() const
|
||||
{ return stride_; }
|
||||
|
||||
bool isAscendingContiguous() const
|
||||
{
|
||||
return (((first_ < last_) && (stride_ == 1)) || (first_ == last_));
|
||||
}
|
||||
|
||||
void setRange(T_numtype first, T_numtype last, diffType stride=1)
|
||||
{
|
||||
BZPRECONDITION(((first < last) && (stride > 0)) ||
|
||||
((first > last) && (stride < 0)) ||
|
||||
(first == last));
|
||||
BZPRECONDITION((last-first) % stride == 0);
|
||||
first_ = first;
|
||||
last_ = last;
|
||||
stride_ = stride;
|
||||
}
|
||||
|
||||
static Range all()
|
||||
{ return Range(fromStart,toEnd,1); }
|
||||
|
||||
/// \todo this talks about the stride of the RANGE, not the expression stride.
|
||||
bool isUnitStride() const
|
||||
{ return stride_ == 1; }
|
||||
|
||||
// Operators
|
||||
Range operator-(T_numtype shift) const
|
||||
{
|
||||
BZPRECONDITION(first_ != fromStart);
|
||||
BZPRECONDITION(last_ != toEnd);
|
||||
return Range(first_ - shift, last_ - shift, stride_);
|
||||
}
|
||||
|
||||
Range operator+(T_numtype shift) const
|
||||
{
|
||||
BZPRECONDITION(first_ != fromStart);
|
||||
BZPRECONDITION(last_ != toEnd);
|
||||
return Range(first_ + shift, last_ + shift, stride_);
|
||||
}
|
||||
|
||||
friend inline ostream& operator<<(ostream& os, const Range& range)
|
||||
{
|
||||
os << "Range(" << range.first() << "," << range.last() << ","
|
||||
<< range.stride() << ")";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
// we can't reduce the rank of a range, so we can't slice it
|
||||
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 void 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 *this;
|
||||
}
|
||||
|
||||
private:
|
||||
T_numtype first_, last_;
|
||||
diffType stride_;
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_RANGE_H
|
||||
@@ -1,44 +0,0 @@
|
||||
#ifndef BZ_RANKS_H
|
||||
#define BZ_RANKS_H
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* Rank numbers start with zero, which may be confusing to users coming
|
||||
* from Fortran. To make code more readable, the following constants
|
||||
* may help. Example: instead of
|
||||
*
|
||||
* int firstRankExtent = A.extent(0);
|
||||
*
|
||||
* One can write:
|
||||
*
|
||||
* int firstRankExtent = A.extent(firstRank);
|
||||
*/
|
||||
|
||||
const int firstRank = 0;
|
||||
const int secondRank = 1;
|
||||
const int thirdRank = 2;
|
||||
const int fourthRank = 3;
|
||||
const int fifthRank = 4;
|
||||
const int sixthRank = 5;
|
||||
const int seventhRank = 6;
|
||||
const int eighthRank = 7;
|
||||
const int ninthRank = 8;
|
||||
const int tenthRank = 9;
|
||||
const int eleventhRank = 10;
|
||||
|
||||
const int firstDim = 0;
|
||||
const int secondDim = 1;
|
||||
const int thirdDim = 2;
|
||||
const int fourthDim = 3;
|
||||
const int fifthDim = 4;
|
||||
const int sixthDim = 5;
|
||||
const int seventhDim = 6;
|
||||
const int eighthDim = 7;
|
||||
const int ninthDim = 8;
|
||||
const int tenthDim = 9;
|
||||
const int eleventhDim = 10;
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,524 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/reduce.h Reduction operators: sum, mean, min, max,
|
||||
* minIndex, 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_REDUCE_H
|
||||
#define BZ_REDUCE_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/numtrait.h>
|
||||
#include <blitz/numinquire.h>
|
||||
#include <blitz/tinyvec2.h>
|
||||
|
||||
|
||||
// The various reduce classes.
|
||||
// The prototype of the reset method is mandated by the class _bz_ReduceReset
|
||||
// in file array/reduce.h
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename P_sourcetype, typename P_resulttype = BZ_SUMTYPE(P_sourcetype)>
|
||||
class ReduceSum {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef P_resulttype T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = false, needInit = false;
|
||||
|
||||
ReduceSum() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x,const int=0) const {
|
||||
sum_ += x;
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int) const { return sum_; }
|
||||
|
||||
void reset() const { sum_ = zero(T_resulttype()); }
|
||||
|
||||
static const char* name() { return "sum"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_resulttype sum_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype, typename P_resulttype = BZ_FLOATTYPE(P_sourcetype)>
|
||||
class ReduceMean {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef P_resulttype T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = false, needInit = false;
|
||||
|
||||
ReduceMean() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x,const int=0) const {
|
||||
sum_ += x;
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int count) const { return sum_ / count; }
|
||||
|
||||
void reset() const { sum_ = zero(T_resulttype()); }
|
||||
|
||||
static const char* name() { return "mean"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_resulttype sum_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype>
|
||||
class ReduceMin {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef P_sourcetype T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = false, needInit = false;
|
||||
|
||||
ReduceMin() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x,const int=0) const {
|
||||
if (x < min_)
|
||||
min_ = x;
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int) const { return min_; }
|
||||
|
||||
void reset() const { min_ = huge(P_sourcetype()); }
|
||||
|
||||
static const char* name() { return "min"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_resulttype min_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype>
|
||||
class ReduceMax {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef P_sourcetype T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = false, needInit = false;
|
||||
|
||||
ReduceMax() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x,const int=0) const {
|
||||
if (x > max_)
|
||||
max_ = x;
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int) const { return max_; }
|
||||
|
||||
void reset() const { max_ = neghuge(P_sourcetype()); }
|
||||
|
||||
static const char* name() { return "max"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_resulttype max_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct MinMaxValue {
|
||||
void operator=(const T& val) { min = max = val; }
|
||||
T min;
|
||||
T max;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype>
|
||||
class ReduceMinMax {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef MinMaxValue<P_sourcetype> T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = false, needInit = true;
|
||||
|
||||
ReduceMinMax() { }
|
||||
|
||||
bool operator()(T_sourcetype x,const int=0) const {
|
||||
if (x > minmax_.max)
|
||||
minmax_.max = x;
|
||||
else if (x < minmax_.min)
|
||||
minmax_.min = x;
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(int) { return minmax_; }
|
||||
|
||||
void reset(P_sourcetype initialValue) const { minmax_ = initialValue; }
|
||||
|
||||
static const char* name() { return "minmax"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_resulttype minmax_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype>
|
||||
class ReduceMinIndex {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef int T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = true, needInit = false;
|
||||
|
||||
ReduceMinIndex() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x,const T_resulttype& index) const {
|
||||
if (x < min_) {
|
||||
min_ = x;
|
||||
index_ = index;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int) const { return index_; }
|
||||
|
||||
void reset(const T_resulttype& index) const {
|
||||
min_ = huge(T_sourcetype());
|
||||
index_ = index;
|
||||
}
|
||||
|
||||
static const char* name() { return "minIndex"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_sourcetype min_;
|
||||
mutable T_resulttype index_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype, int N>
|
||||
class ReduceMinIndexVector {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef TinyVector<int,N> T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = true, needInit = false;
|
||||
|
||||
ReduceMinIndexVector() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x, const T_resulttype& index) const {
|
||||
if (x < min_) {
|
||||
min_ = x;
|
||||
index_ = index;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int) const { return index_; }
|
||||
|
||||
void reset(const T_resulttype& index) const {
|
||||
min_ = huge(T_sourcetype());
|
||||
index_ = index;
|
||||
}
|
||||
|
||||
static const char* name() { return "minIndexVector"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_sourcetype min_;
|
||||
mutable T_resulttype index_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype>
|
||||
class ReduceMaxIndex {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef int T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = true, needInit = false;
|
||||
|
||||
ReduceMaxIndex() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x,const T_resulttype& index) const {
|
||||
if (x > max_) {
|
||||
max_ = x;
|
||||
index_ = index;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(int) const { return index_; }
|
||||
|
||||
void reset(const T_resulttype& index) const {
|
||||
max_ = neghuge(T_sourcetype());
|
||||
index_ = index;
|
||||
}
|
||||
|
||||
static const char* name() { return "maxIndex"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_sourcetype max_;
|
||||
mutable T_resulttype index_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype, int N_rank>
|
||||
class ReduceMaxIndexVector {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef TinyVector<int,N_rank> T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = true, needInit = false;
|
||||
|
||||
ReduceMaxIndexVector() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x, const T_resulttype& index) const {
|
||||
if (x > max_) {
|
||||
max_ = x;
|
||||
index_ = index;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int) const { return index_; }
|
||||
|
||||
void reset(const T_resulttype& index) const {
|
||||
max_ = neghuge(T_sourcetype());
|
||||
index_ = index;
|
||||
}
|
||||
|
||||
static const char* name() { return "maxIndexVector"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_sourcetype max_;
|
||||
mutable T_resulttype index_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype>
|
||||
class ReduceFirst {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef int T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = false, needInit = false;
|
||||
|
||||
ReduceFirst() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x,const T_resulttype& index) const {
|
||||
if (x) {
|
||||
index_ = index;
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int) const { return index_; }
|
||||
|
||||
void reset() const { index_ = tiny(int()); }
|
||||
|
||||
static const char* name() { return "first"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_resulttype index_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype>
|
||||
class ReduceLast {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef int T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = false, needInit = false;
|
||||
|
||||
ReduceLast() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x,const T_resulttype& index) const {
|
||||
if (x) {
|
||||
index_ = index;
|
||||
return true;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int) const { return index_; }
|
||||
|
||||
void reset() const { index_ = huge(int()); }
|
||||
|
||||
static const char* name() { return "last"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_resulttype index_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype, typename P_resulttype = BZ_SUMTYPE(P_sourcetype)>
|
||||
class ReduceProduct {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef P_resulttype T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = false, needInit = false;
|
||||
|
||||
ReduceProduct() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x,const int=0) const {
|
||||
product_ *= x;
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int) const { return product_; }
|
||||
|
||||
void reset() const { product_ = one(T_resulttype()); }
|
||||
|
||||
static const char* name() { return "product"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_resulttype product_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype>
|
||||
class ReduceCount {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef int T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = false, needInit = false;
|
||||
|
||||
ReduceCount() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x,const int=0) const {
|
||||
if (bool(x))
|
||||
++count_;
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int) const { return count_; }
|
||||
|
||||
void reset() const { count_ = zero(T_resulttype()); }
|
||||
|
||||
static const char* name() { return "count"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_resulttype count_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype>
|
||||
class ReduceAny {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef bool T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = false, needInit = false;
|
||||
|
||||
ReduceAny() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x,const int=0) const {
|
||||
if (bool(x)) {
|
||||
any_ = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int) const { return any_; }
|
||||
|
||||
void reset() const { any_ = false; }
|
||||
|
||||
static const char* name() { return "any"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_resulttype any_;
|
||||
};
|
||||
|
||||
template<typename P_sourcetype>
|
||||
class ReduceAll {
|
||||
public:
|
||||
|
||||
typedef P_sourcetype T_sourcetype;
|
||||
typedef bool T_resulttype;
|
||||
typedef T_resulttype T_numtype;
|
||||
|
||||
static const bool needIndex = false, needInit = false;
|
||||
|
||||
ReduceAll() { }
|
||||
|
||||
bool operator()(const T_sourcetype& x,const int=0) const {
|
||||
if (!bool(x)) {
|
||||
all_ = false;
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
T_resulttype result(const int) const { return all_; }
|
||||
|
||||
void reset() const { all_ = true; }
|
||||
|
||||
static const char* name() { return "all"; }
|
||||
|
||||
protected:
|
||||
|
||||
mutable T_resulttype all_;
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_REDUCE_H
|
||||
@@ -1,83 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/shapecheck.h Functions for checking conformability 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_SHAPECHECK_H
|
||||
#define BZ_SHAPECHECK_H
|
||||
|
||||
#include <iostream>
|
||||
#include <blitz/blitz.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* The function areShapesConformable(A,B) checks that the shapes
|
||||
* A and B are conformable (i.e. the same size/geometry). Typically
|
||||
* the A and B parameters are of type TinyVector<int,N_rank> and represent
|
||||
* the extent of the arrays. It's possible that in the future jagged-edged
|
||||
* arrays will be supported, in which case shapes may be lists
|
||||
* of subdomains.
|
||||
*/
|
||||
|
||||
template<typename T_shape1, typename T_shape2>
|
||||
inline bool areShapesConformable(const T_shape1&, const T_shape2&)
|
||||
{
|
||||
// If the shape objects are different types, this means
|
||||
// that the arrays are different ranks, or one is jagged
|
||||
// edged, etc. In this case the two arrays are not
|
||||
// conformable.
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T_shape>
|
||||
inline bool areShapesConformable(const T_shape& a, const T_shape& b)
|
||||
{
|
||||
// The shape objects are the same type, so compare them.
|
||||
|
||||
// NEEDS_WORK-- once the "all" reduction is implemented, should
|
||||
// use it.
|
||||
// return all(a == b);
|
||||
|
||||
for (int i=0; i < a.length(); ++i)
|
||||
{
|
||||
if (a[i] != b[i])
|
||||
{
|
||||
BZ_DEBUG_MESSAGE("Incompatible shapes detected: " << std::endl
|
||||
<< a << std::endl << b << std::endl);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,73 +0,0 @@
|
||||
#ifndef BZ_SIMDTYPES_H
|
||||
#define BZ_SIMDTYPES_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <stdint.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<class T,int N> class TinyVector;
|
||||
|
||||
/** This metaprogram returns the number of bits necessary to fit the
|
||||
specified number. The metaprogram result for I is obtained as
|
||||
_bz_meta_bitwidth<I,0>::width. */
|
||||
template<size_t I, size_t L> struct _bz_meta_bitwidth {
|
||||
static const size_t width = _bz_meta_bitwidth<(I>>1), L+1>::width;
|
||||
};
|
||||
|
||||
template<size_t L> struct _bz_meta_bitwidth<0,L> {
|
||||
static const size_t width = L;
|
||||
};
|
||||
|
||||
|
||||
/** Helper class that defines the width of the simd instructions for a
|
||||
given type. It also defines a type that is a TinyVector of the
|
||||
appropriate length to fill the simd width. This is used as the
|
||||
"evaluation type" to facilitate automatic vectorization. Because
|
||||
TinyVectors are aligned on BZ_SIMD_WIDTH, an array of vecType will
|
||||
be dense in memory, which is required to reinterpret an array of T
|
||||
to an array of vecType. \todo How do we check that the type fits
|
||||
evenly into the simd width? */
|
||||
template<typename T> class simdTypes {
|
||||
public:
|
||||
/// SIMD width of type in bytes (sizeof(T) if simd width does not
|
||||
/// fit a T)
|
||||
static const size_t byteWidth =
|
||||
BZ_SIMD_WIDTH>sizeof(T) ? BZ_SIMD_WIDTH : sizeof(T);
|
||||
|
||||
/// SIMD width of types in number of elements.
|
||||
static const size_t vecWidth =
|
||||
BZ_SIMD_WIDTH>sizeof(T) ? BZ_SIMD_WIDTH/sizeof(T) : 1;
|
||||
|
||||
/// TinyVector type of T that fills the simd width.
|
||||
typedef TinyVector<T, vecWidth> vecType;
|
||||
|
||||
/** Test if a pointer to T is simd aligned. */
|
||||
static inline bool isVectorAligned(const T* restrict pointer)
|
||||
{ return (uintptr_t)((void*)pointer) % BZ_SIMD_WIDTH == 0; }
|
||||
|
||||
/** Return number of elements from pointer to next simd width
|
||||
boundary. This is used to figure out how many scalar operations
|
||||
need to be done before beginning vectorized operations. */
|
||||
static inline diffType offsetToAlignment(const T* restrict pointer) {
|
||||
const uintptr_t m = (uintptr_t)((void*)pointer) & (byteWidth-1);
|
||||
return m ? (byteWidth - m)/sizeof(T) : 0;
|
||||
}
|
||||
|
||||
/** Return a length which has been padded to next larger even SIMD
|
||||
width. */
|
||||
static inline size_t paddedLength(size_t length) {
|
||||
return (length & (vecWidth-1)) ?
|
||||
(length & ~(vecWidth-1)) + vecWidth : length;
|
||||
};
|
||||
};
|
||||
|
||||
/** General function just forwards to the simdTypes class. */
|
||||
template <typename T>
|
||||
inline bool isVectorAligned(const T* restrict pointer) {
|
||||
return simdTypes<T>::isVectorAligned(pointer); }
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -1,55 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/tau.h Integration with the Tau profiling package.
|
||||
* See http://www.acl.lanl.gov/tau/
|
||||
*
|
||||
* $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_TAU_H
|
||||
#define BZ_TAU_H
|
||||
|
||||
#ifdef BZ_TAU_PROFILING
|
||||
#define TAU_BLITZ TAU_USER1
|
||||
#include <Profile/Profiler.h>
|
||||
|
||||
#else
|
||||
#define TYPE_STRING(profileString, str)
|
||||
#define PROFILED_BLOCK(name, type)
|
||||
#define TAU_TYPE_STRING(profileString, str)
|
||||
#define TAU_PROFILE(name, type, group)
|
||||
#define TAU_PROFILE_TIMER(var, name, type, group)
|
||||
#define TAU_PROFILE_START(var)
|
||||
#define TAU_PROFILE_STOP(var)
|
||||
#define TAU_PROFILE_STMT(stmt)
|
||||
#define TAU_PROFILE_EXIT(msg)
|
||||
#define TAU_PROFILE_INIT(argc, argv)
|
||||
#define TAU_PROFILE_SET_NODE(node)
|
||||
#define CT(obj)
|
||||
#endif // ! BZ_TAU_PROFILING
|
||||
|
||||
#endif // BZ_TAU_H
|
||||
@@ -1,191 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/Timer.h Timer class, for use in benchmarking
|
||||
*
|
||||
* $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/
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
// This class is not portable to non System V platforms.
|
||||
// It will need to be rewritten for Windows, NT, Mac.
|
||||
// NEEDS_WORK
|
||||
|
||||
#ifndef BZ_TIMER_H
|
||||
#define BZ_TIMER_H
|
||||
|
||||
#ifndef BZ_BLITZ_H
|
||||
#include <blitz/blitz.h>
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_RUSAGE
|
||||
#include <sys/resource.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
#ifndef BZ_HAVE_LIBPAPI
|
||||
|
||||
class Timer {
|
||||
|
||||
public:
|
||||
Timer()
|
||||
{
|
||||
state_ = uninitialized;
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
state_ = running;
|
||||
t1_ = systemTime();
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
t2_ = systemTime();
|
||||
BZPRECONDITION(state_ == running);
|
||||
state_ = stopped;
|
||||
}
|
||||
|
||||
/* Compaq cxx compiler in ansi mode cannot print out long double type! */
|
||||
#if defined(__DECCXX)
|
||||
double elapsed() const
|
||||
#else
|
||||
/** Return elapsed time in seconds. */
|
||||
double elapsed() const
|
||||
#endif
|
||||
{
|
||||
BZPRECONDITION(state_ == stopped);
|
||||
return (t2_ - t1_)/1e6;
|
||||
}
|
||||
|
||||
long long instr() const { return 0; };
|
||||
long long flops() const { return 0; };
|
||||
|
||||
static const string& indep_var() { return ivar_; };
|
||||
|
||||
private:
|
||||
Timer(Timer&) { }
|
||||
void operator=(Timer&) { }
|
||||
|
||||
long int systemTime()
|
||||
{
|
||||
#ifdef BZ_HAVE_RUSAGE
|
||||
getrusage(RUSAGE_SELF, &resourceUsage_);
|
||||
long int sec = resourceUsage_.ru_utime.tv_sec
|
||||
+ resourceUsage_.ru_stime.tv_sec;
|
||||
long int usec = resourceUsage_.ru_utime.tv_usec
|
||||
+ resourceUsage_.ru_stime.tv_usec;
|
||||
return sec*1000000+usec;
|
||||
#else
|
||||
return 1000000*clock() / (long int) CLOCKS_PER_SEC;
|
||||
#endif
|
||||
}
|
||||
|
||||
enum { uninitialized, running, stopped } state_;
|
||||
|
||||
static const string ivar_;
|
||||
|
||||
#ifdef BZ_HAVE_RUSAGE
|
||||
struct rusage resourceUsage_;
|
||||
#endif
|
||||
|
||||
long int t1_, t2_;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
// implementation using PAPI performance counters
|
||||
|
||||
#include <papi.h>
|
||||
|
||||
class Timer {
|
||||
|
||||
public:
|
||||
Timer()
|
||||
{
|
||||
// maybe overhead is less from just reading counters
|
||||
if(PAPI_start_counters((int*)Events, nevents)!=PAPI_OK) {
|
||||
cerr << "Error starting counters\n";
|
||||
}
|
||||
state_ = uninitialized;
|
||||
}
|
||||
~Timer()
|
||||
{
|
||||
PAPI_stop_counters(counters_.data(), nevents);
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
state_ = running;
|
||||
// this resets the counters
|
||||
PAPI_read_counters(counters_.data(), nevents);
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
PAPI_read_counters(counters_.data(), nevents);
|
||||
BZPRECONDITION(state_ == running);
|
||||
state_ = stopped;
|
||||
}
|
||||
|
||||
/** since we don't know the clock frequency of the processor, we
|
||||
instead output "flops/clock cycle" which seems like a better
|
||||
measure of code performance and not machine performance. */
|
||||
long long elapsed() const
|
||||
{
|
||||
BZPRECONDITION(state_ == stopped);
|
||||
return counters_[0];
|
||||
}
|
||||
|
||||
long long instr() const { return counters_[1]; };
|
||||
long long flops() const { return counters_[2]; };
|
||||
|
||||
static const string& indep_var() { return ivar_; };
|
||||
|
||||
private:
|
||||
Timer(Timer&) { }
|
||||
void operator=(Timer&) { }
|
||||
|
||||
enum { uninitialized, running, stopped } state_;
|
||||
|
||||
static const int nevents=3;
|
||||
static const int Events[nevents];
|
||||
static const string ivar_;
|
||||
|
||||
TinyVector<long long, nevents> counters_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_TIMER_H
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
/***************************************************************************
|
||||
* blitz/tinyvec.cc Declaration of TinyVector 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_TINYMAT2_CC
|
||||
#define BZ_TINYMAT2_CC
|
||||
|
||||
#include <blitz/tmevaluate.h>
|
||||
#include <blitz/tinymat2io.cc>
|
||||
#include <blitz/array/domain.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
inline TinyMatrix<P_numtype, N_rows, N_columns>::TinyMatrix(T_numtype initValue)
|
||||
{
|
||||
for (sizeType i=0; i < numElements(); ++i)
|
||||
data_[i] = initValue;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
inline TinyMatrix<P_numtype, N_rows, N_columns>::TinyMatrix(const T_matrix& x)
|
||||
{
|
||||
for (sizeType i=0; i < numElements(); ++i)
|
||||
data_[i] = x.data_[i];
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
template<typename P_numtype2>
|
||||
inline
|
||||
TinyMatrix<P_numtype, N_rows, N_columns>::TinyMatrix(const TinyMatrix<P_numtype2, N_rows, N_columns>& x)
|
||||
{
|
||||
for (sizeType i=0; i < numElements(); ++i)
|
||||
data_[i] = static_cast<P_numtype>(x.data_[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Assignment-type operators
|
||||
*/
|
||||
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
TinyMatrix<P_numtype, N_rows, N_columns>&
|
||||
TinyMatrix<P_numtype, N_rows, N_columns>::initialize(T_numtype x)
|
||||
{
|
||||
(*this) = _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
template<typename T_expr>
|
||||
inline
|
||||
TinyMatrix<P_numtype, N_rows, N_columns>&
|
||||
TinyMatrix<P_numtype, N_rows, N_columns>::operator=(const ETBase<T_expr>& expr)
|
||||
{
|
||||
_tm_evaluate(_bz_typename asExpr<T_expr>::T_expr(expr.unwrap()),
|
||||
_bz_update<T_numtype, _bz_typename asExpr<T_expr>::T_expr::T_result>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
#define BZ_TM2_UPDATE(op,name) \
|
||||
template<typename P_numtype, int N_rows, int N_columns> \
|
||||
template<typename T> \
|
||||
inline TinyMatrix<P_numtype, N_rows, N_columns>& \
|
||||
TinyMatrix<P_numtype, N_rows, N_columns>::operator op(const T& expr) \
|
||||
{ \
|
||||
_tm_evaluate(_bz_typename asExpr<T>::T_expr(expr), \
|
||||
name<T_numtype, _bz_typename asExpr<T>::T_expr::T_result>()); \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
BZ_TM2_UPDATE(+=, _bz_plus_update)
|
||||
BZ_TM2_UPDATE(-=, _bz_minus_update)
|
||||
BZ_TM2_UPDATE(*=, _bz_multiply_update)
|
||||
BZ_TM2_UPDATE(/=, _bz_divide_update)
|
||||
BZ_TM2_UPDATE(%=, _bz_mod_update)
|
||||
BZ_TM2_UPDATE(^=, _bz_xor_update)
|
||||
BZ_TM2_UPDATE(&=, _bz_bitand_update)
|
||||
BZ_TM2_UPDATE(|=, _bz_bitor_update)
|
||||
BZ_TM2_UPDATE(<<=, _bz_shiftl_update)
|
||||
BZ_TM2_UPDATE(>>=, _bz_shiftr_update)
|
||||
|
||||
/*
|
||||
* Other member functions
|
||||
*/
|
||||
|
||||
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
inline RectDomain<2>
|
||||
TinyMatrix<P_numtype, N_rows, N_columns>::domain()
|
||||
{
|
||||
return RectDomain<2>(lbound(), ubound());
|
||||
}
|
||||
|
||||
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
template<int N0, int N1>
|
||||
inline _bz_ArrayExpr<ArrayIndexMapping<typename asExpr<TinyMatrix<P_numtype, N_rows, N_columns> >::T_expr, N0, N1> >
|
||||
TinyMatrix<P_numtype, N_rows, N_columns>::operator()(IndexPlaceholder<N0>, IndexPlaceholder<N1>) const
|
||||
{
|
||||
return _bz_ArrayExpr<ArrayIndexMapping<typename asExpr<T_matrix>::T_expr,
|
||||
N0, N1> >(noConst());
|
||||
}
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_TINYVEC_CC
|
||||
@@ -1,358 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/tinymat.h Declaration of TinyMatrix<T, N, M>
|
||||
*
|
||||
* $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_TINYMAT_H
|
||||
#define BZ_TINYMAT_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/tinyvec2.h>
|
||||
#include <blitz/tinyvec2io.cc> // fix this - for some reason it doesn't get included through tinyvec2.h
|
||||
#include <blitz/listinit.h>
|
||||
#include <blitz/etbase.h>
|
||||
#include <blitz/array/slice.h>
|
||||
#include <blitz/indexmap-forward.h>
|
||||
//#include <blitz/meta/vecassign.h>
|
||||
//#include <blitz/update.h>
|
||||
|
||||
#ifdef BZ_HAVE_BOOST_SERIALIZATION
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*****************************************************************************
|
||||
* Forward declarations
|
||||
*/
|
||||
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
class FastTM2Iterator;
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
class FastTM2CopyIterator;
|
||||
|
||||
template<typename P_expr>
|
||||
class _bz_ArrayExpr;
|
||||
|
||||
template<int N0>
|
||||
class IndexPlaceholder;
|
||||
|
||||
/*****************************************************************************
|
||||
* Declaration of class TinyMatrix
|
||||
*/
|
||||
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
class TinyMatrix : public ETBase<TinyMatrix<P_numtype, N_rows, N_columns> >
|
||||
{
|
||||
public:
|
||||
typedef P_numtype T_numtype;
|
||||
// typedef _bz_tinyMatrixRef<T_numtype, N_rows, N_columns, N_columns, 1>
|
||||
// T_reference;
|
||||
typedef TinyVector<int, 2> T_index;
|
||||
typedef TinyMatrix<T_numtype, N_rows, N_columns> T_matrix;
|
||||
typedef FastTM2Iterator<T_numtype,N_rows, N_columns> T_iterator;
|
||||
typedef T_numtype* iterator;
|
||||
typedef const T_numtype* const_iterator;
|
||||
typedef FastTM2CopyIterator<P_numtype, N_rows, N_columns> T_range_result;
|
||||
|
||||
static const int
|
||||
//numArrayOperands = 1,
|
||||
//numIndexPlaceholders = 0,
|
||||
rank_ = 2;
|
||||
|
||||
TinyMatrix() { }
|
||||
|
||||
inline TinyMatrix(const T_matrix&);
|
||||
|
||||
template <typename T_numtype2>
|
||||
inline TinyMatrix(const TinyMatrix<T_numtype2, N_rows, N_columns>& x);
|
||||
|
||||
inline TinyMatrix(T_numtype initValue);
|
||||
|
||||
static TinyVector<int, 2> base()
|
||||
{ return 0; }
|
||||
|
||||
static int base(int rank)
|
||||
{ return 0; }
|
||||
|
||||
iterator begin()
|
||||
{ return iterator(*this); }
|
||||
|
||||
const_iterator begin() const
|
||||
{ return const_iterator(*this); }
|
||||
|
||||
T_iterator beginFast() const
|
||||
{ return T_iterator(*this); }
|
||||
|
||||
static int cols()
|
||||
{ return N_columns; }
|
||||
|
||||
static int columns()
|
||||
{ return N_columns; }
|
||||
|
||||
const T_numtype* restrict data() const
|
||||
{ return data_; }
|
||||
|
||||
T_numtype* restrict data()
|
||||
{ return data_; }
|
||||
|
||||
const T_numtype* restrict dataFirst() const
|
||||
{ return data_; }
|
||||
|
||||
T_numtype* restrict dataFirst()
|
||||
{ return data_; }
|
||||
|
||||
static int dimensions()
|
||||
{ return 2; }
|
||||
|
||||
static RectDomain<2> domain();
|
||||
|
||||
iterator end()
|
||||
{ return data_+size(); }
|
||||
|
||||
const_iterator end() const
|
||||
{ return data_+size(); }
|
||||
|
||||
static int extent(int rank)
|
||||
{ BZPRECONDITION(rank<2); return rank==0 ? N_rows : N_columns; }
|
||||
|
||||
static const TinyVector<int,2> extent()
|
||||
{ return TinyVector<int,2>(N_rows, N_columns); }
|
||||
|
||||
static bool isMajorRank(int rank)
|
||||
{ BZPRECONDITION(rank<2); return rank==0; }
|
||||
static bool isMinorRank(int rank)
|
||||
{ BZPRECONDITION(rank<2); return rank==1; }
|
||||
static bool isRankStoredAscending(int rank)
|
||||
{ BZPRECONDITION(rank<2); return true; }
|
||||
|
||||
static int lbound(int rank)
|
||||
{ BZPRECONDITION(rank<2); return 0; }
|
||||
static TinyVector<int,2> lbound()
|
||||
{ return 0; }
|
||||
|
||||
static int length(int rank)
|
||||
{ BZPRECONDITION(rank<2); return rank==0 ? N_rows : N_columns; }
|
||||
static TinyVector<int, 2> length()
|
||||
{ return TinyVector<int,2>(N_rows, N_columns); }
|
||||
|
||||
static sizeType numElements()
|
||||
{ return N_rows*N_columns; }
|
||||
|
||||
static int ordering(int rank)
|
||||
{ BZPRECONDITION(rank<2); return 1-rank; }
|
||||
|
||||
static TinyVector<int, 2> ordering()
|
||||
{ return TinyVector<int,2>(0,1); }
|
||||
|
||||
static int rank()
|
||||
{ return rank_; }
|
||||
|
||||
static int rows()
|
||||
{ return N_rows; }
|
||||
|
||||
static TinyVector<int, 2> shape()
|
||||
{ return length(); }
|
||||
|
||||
static sizeType size()
|
||||
{ return numElements(); }
|
||||
|
||||
static TinyVector<diffType, 2> stride()
|
||||
{ return TinyVector<int,2>(N_columns,1); }
|
||||
|
||||
static diffType stride(int rank)
|
||||
{ BZPRECONDITION(rank<2); return rank==0 ? N_columns : 1; }
|
||||
|
||||
static int ubound(int rank)
|
||||
{ return length(rank) - 1; }
|
||||
|
||||
static TinyVector<int, 2> ubound()
|
||||
{ return length()-1; }
|
||||
|
||||
static int zeroOffset()
|
||||
{ return 0; }
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Debugging routines
|
||||
//////////////////////////////////////////////
|
||||
|
||||
bool isInRange(const T_index& index) const {
|
||||
for (int i=0; i < rank_; ++i)
|
||||
if (index[i] < base(i) || (index[i] - base(i)) >= length(i))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isInRange(int i0, int i1) const {
|
||||
return i0 >= base(0) && (i0 - base(0)) < length(0)
|
||||
&& i1 >= base(1) && (i1 - base(1)) < length(1);
|
||||
}
|
||||
|
||||
bool assertInRange(const T_index& BZ_DEBUG_PARAM(index)) const {
|
||||
BZPRECHECK(isInRange(index), "TinyMatrix index out of range: " << index
|
||||
<< endl << "Lower bounds: " << base() << endl
|
||||
<< "Length: " << length() << endl);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool assertInRange(int BZ_DEBUG_PARAM(i0), int BZ_DEBUG_PARAM(i1)) const {
|
||||
BZPRECHECK(isInRange(i0,i1), "TinyMatrix index out of range: ("
|
||||
<< i0 << ", " << i1 << ")"
|
||||
<< endl << "Lower bounds: " << base() << endl
|
||||
<< "Length: " << length() << endl);
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Subscripting operators
|
||||
//////////////////////////////////////////////
|
||||
|
||||
|
||||
T_matrix& noConst() const
|
||||
{ return const_cast<T_matrix&>(*this); }
|
||||
|
||||
const T_numtype& restrict operator()(unsigned i, unsigned j) const
|
||||
{
|
||||
assertInRange(i,j);
|
||||
return data_[i*N_columns + j];
|
||||
}
|
||||
|
||||
T_numtype& restrict operator()(unsigned i, unsigned j)
|
||||
{
|
||||
assertInRange(i,j);
|
||||
return data_[i*N_columns + j];
|
||||
}
|
||||
|
||||
const T_numtype& restrict operator()(T_index i) const
|
||||
{
|
||||
assertInRange(i);
|
||||
return data_[i[0]*N_columns + i[1]];
|
||||
}
|
||||
|
||||
T_numtype& restrict operator()(T_index i)
|
||||
{
|
||||
assertInRange(i);
|
||||
return data_[i[0]*N_columns + i[1]];
|
||||
}
|
||||
|
||||
template<int N0, int N1>
|
||||
inline
|
||||
_bz_ArrayExpr<ArrayIndexMapping<typename asExpr<T_matrix>::T_expr, N0, N1> >
|
||||
operator()(IndexPlaceholder<N0>, IndexPlaceholder<N1>) const;
|
||||
|
||||
/** Fastread must return reference so the iterator can turn it into an
|
||||
iterator for the contained in case we have a multicomponent. */
|
||||
const T_numtype& fastRead(diffType i) const
|
||||
{ return data_[i]; }
|
||||
|
||||
/** Since data_ is simd aligned by construction, we just have
|
||||
to check the offest. */
|
||||
bool isVectorAligned(diffType offset) const
|
||||
{ return (offset%simdTypes<T_numtype>::vecWidth)==0; }
|
||||
|
||||
// T_reference getRef()
|
||||
// { return T_reference((T_numtype*)data_); }
|
||||
|
||||
// const T_reference getRef() const
|
||||
// { return T_reference((T_numtype*)data_); }
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Assignment Operators
|
||||
//////////////////////////////////////////////
|
||||
|
||||
// Scalar operand
|
||||
ListInitializationSwitch<T_matrix,T_numtype*>
|
||||
operator=(T_numtype x)
|
||||
{
|
||||
return ListInitializationSwitch<T_matrix,T_numtype*>(*this, x);
|
||||
}
|
||||
|
||||
T_matrix& initialize(T_numtype x);
|
||||
|
||||
T_numtype* restrict getInitializationIterator()
|
||||
{ return dataFirst(); }
|
||||
|
||||
template<typename T_expr>
|
||||
T_matrix& operator=(const ETBase<T_expr>&);
|
||||
|
||||
template<typename T> T_matrix& operator+=(const T&);
|
||||
template<typename T> T_matrix& operator-=(const T&);
|
||||
template<typename T> T_matrix& operator*=(const T&);
|
||||
template<typename T> T_matrix& operator/=(const T&);
|
||||
template<typename T> T_matrix& operator%=(const T&);
|
||||
template<typename T> T_matrix& operator^=(const T&);
|
||||
template<typename T> T_matrix& operator&=(const T&);
|
||||
template<typename T> T_matrix& operator|=(const T&);
|
||||
template<typename T> T_matrix& operator>>=(const T&);
|
||||
template<typename T> T_matrix& operator<<=(const T&);
|
||||
|
||||
static bool canCollapse(int outerRank, int innerRank) {
|
||||
#ifdef BZ_DEBUG_TRAVERSE
|
||||
BZ_DEBUG_MESSAGE("stride(" << innerRank << ")=" << stride(innerRank)
|
||||
<< ", extent()=" << extent(innerRank) << ", stride(outerRank)="
|
||||
<< stride(outerRank));
|
||||
#endif
|
||||
return (stride(innerRank) * extent(innerRank) == stride(outerRank));
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
template<typename T_expr, typename T_update>
|
||||
void _tm_evaluate(const T_expr& expr, T_update);
|
||||
|
||||
#ifdef BZ_HAVE_BOOST_SERIALIZATION
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template<class T_arch>
|
||||
void serialize(T_arch& ar, const unsigned int version) {
|
||||
ar & data_;
|
||||
};
|
||||
#endif
|
||||
|
||||
BZ_ALIGN_VARIABLE(T_numtype, data_[N_rows * N_columns], BZ_SIMD_WIDTH)
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#ifdef BZ_HAVE_BOOST_SERIALIZATION
|
||||
namespace boost {
|
||||
namespace mpi {
|
||||
template<typename T> struct is_mpi_datatype;
|
||||
template <typename T, int N, int M>
|
||||
struct is_mpi_datatype<blitz::TinyMatrix<T, N, M> >
|
||||
: public is_mpi_datatype<T> { };
|
||||
} };
|
||||
#endif
|
||||
|
||||
#include <blitz/tm2fastiter.h> // Iterators
|
||||
|
||||
#endif // BZ_TINYMAT_H
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
/***************************************************************************
|
||||
* blitz/tinymatio.cc TinyMatrix I/O 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_TINYMAT2IO_CC
|
||||
#define BZ_TINYMAT2IO_CC
|
||||
|
||||
#include <blitz/tinymat2.h>
|
||||
|
||||
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 P_numtype, int N_rows, int N_columns>
|
||||
ostream& operator<<(ostream& os,
|
||||
const TinyMatrix<P_numtype, N_rows, N_columns>& x)
|
||||
{
|
||||
os << "(";
|
||||
for (int i=0; i < N_rows-1; ++i)
|
||||
{
|
||||
os << x(i,0);
|
||||
for (int j=1; j < N_columns; ++j)
|
||||
{
|
||||
os << "," << x(i,j);
|
||||
}
|
||||
os << "; ";
|
||||
}
|
||||
os << x(N_rows-1,0);
|
||||
for (int j=1; j < N_columns; ++j)
|
||||
{
|
||||
os << "," << x(N_rows-1,j);
|
||||
}
|
||||
os << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
template <typename P_numtype, int N_rows, int N_columns>
|
||||
istream& operator>>(istream& is,
|
||||
TinyMatrix<P_numtype, N_rows, N_columns>& x)
|
||||
{
|
||||
char sep;
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == '(', "Format error while scanning input TinyMatrix"
|
||||
<< endl << " (expected '(' opening TinyMatrix)");
|
||||
|
||||
for (int i=0; i<N_rows-1; i++) {
|
||||
is >> x(i,0);
|
||||
for (int j=1; j<N_columns; j++) {
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == ',', "Format error while scanning input TinyMatrix"
|
||||
<< endl << " (expected ',' between TinyMatrix components)");
|
||||
is >> x(i,j);
|
||||
}
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == ';', "Format error while scanning input TinyMatrix"
|
||||
<< endl << " (expected ';' between TinyMatrix rows)");
|
||||
}
|
||||
is >> x(N_rows-1,0);
|
||||
for (int j=1; j<N_columns; j++) {
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == ',', "Format error while scanning input TinyMatrix"
|
||||
<< endl << " (expected ',' between TinyMatrix components)");
|
||||
is >> x(N_rows-1,j);
|
||||
}
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == ')', "Format error while scanning input TinyMatrix"
|
||||
<< endl << " (expected ')' closing TinyMatrix)");
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_TINYMATIO_CC
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
/***************************************************************************
|
||||
* blitz/tinyvec.cc Declaration of TinyVector 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_TINYVEC2_CC
|
||||
#define BZ_TINYVEC2_CC
|
||||
|
||||
#include <blitz/tinyvec2.h>
|
||||
#include <blitz/update.h>
|
||||
#include <blitz/tvevaluate.h>
|
||||
#include <blitz/array/asexpr.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
template<typename P_numtype, int N_length>
|
||||
_bz_forceinline
|
||||
TinyVector<P_numtype, N_length>::TinyVector(const T_numtype initValue) {
|
||||
for (int i=0; i < N_length; ++i)
|
||||
data_[i] = initValue;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_length>
|
||||
_bz_forceinline
|
||||
TinyVector<P_numtype, N_length>::TinyVector(const TinyVector<T_numtype, N_length>& x) {
|
||||
for (int i=0; i < N_length; ++i)
|
||||
data_[i] = x.data_[i];
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_length>
|
||||
template<typename P_numtype2>
|
||||
_bz_forceinline
|
||||
TinyVector<P_numtype, N_length>::TinyVector(const TinyVector<P_numtype2, N_length>& x) {
|
||||
for (int i=0; i < N_length; ++i)
|
||||
data_[i] = static_cast<P_numtype>(x[i]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Assignment-type operators
|
||||
*/
|
||||
|
||||
template<typename P_numtype, int N_length>
|
||||
_bz_forceinline
|
||||
TinyVector<P_numtype, N_length>&
|
||||
TinyVector<P_numtype,N_length>::initialize(T_numtype x)
|
||||
{
|
||||
(*this) = _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename P_numtype, int N_length> template<typename T_expr>
|
||||
_bz_forceinline
|
||||
TinyVector<P_numtype,N_length>&
|
||||
TinyVector<P_numtype,N_length>::operator=(const ETBase<T_expr>& expr)
|
||||
{
|
||||
_tv_evaluate(_bz_typename asExpr<T_expr>::T_expr(expr.unwrap()),
|
||||
_bz_update<
|
||||
T_numtype,
|
||||
_bz_typename asExpr<T_expr>::T_expr::T_result>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
#define BZ_TV2_UPDATE(op,name) \
|
||||
template<typename P_numtype, int N_length> \
|
||||
template<typename T> \
|
||||
_bz_forceinline \
|
||||
TinyVector<P_numtype,N_length>& \
|
||||
TinyVector<P_numtype,N_length>::operator op(const T& expr) \
|
||||
{ \
|
||||
_tv_evaluate(_bz_typename asExpr<T>::T_expr(expr), \
|
||||
name<T_numtype, \
|
||||
_bz_typename asExpr<T>::T_expr::T_result>()); \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
|
||||
BZ_TV2_UPDATE(+=, _bz_plus_update)
|
||||
BZ_TV2_UPDATE(-=, _bz_minus_update)
|
||||
BZ_TV2_UPDATE(*=, _bz_multiply_update)
|
||||
BZ_TV2_UPDATE(/=, _bz_divide_update)
|
||||
BZ_TV2_UPDATE(%=, _bz_mod_update)
|
||||
BZ_TV2_UPDATE(^=, _bz_xor_update)
|
||||
BZ_TV2_UPDATE(&=, _bz_bitand_update)
|
||||
BZ_TV2_UPDATE(|=, _bz_bitor_update)
|
||||
BZ_TV2_UPDATE(<<=, _bz_shiftl_update)
|
||||
BZ_TV2_UPDATE(>>=, _bz_shiftr_update)
|
||||
|
||||
/*
|
||||
* Other member functions
|
||||
*/
|
||||
|
||||
template<typename P_numtype, int N_length>
|
||||
template<int N0>
|
||||
_bz_forceinline
|
||||
_bz_ArrayExpr<ArrayIndexMapping<typename asExpr<TinyVector<P_numtype, N_length> >::T_expr, N0> >
|
||||
TinyVector<P_numtype, N_length>::operator()(IndexPlaceholder<N0>) const
|
||||
{
|
||||
return _bz_ArrayExpr<ArrayIndexMapping<typename asExpr<T_vector>::T_expr, N0> >
|
||||
(noConst());
|
||||
}
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#include <blitz/tv2fastiter.h> // Iterators
|
||||
//#include <blitz/tv2assign.h> unused now?
|
||||
#include <blitz/tinyvec2io.cc>
|
||||
|
||||
#endif // BZ_TINYVEC_CC
|
||||
@@ -1,461 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/tinyvec.h Declaration of the TinyVector<T, N> 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_TINYVEC_H
|
||||
#define BZ_TINYVEC_H
|
||||
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/listinit.h>
|
||||
#include <blitz/et-forward.h>
|
||||
#include <blitz/etbase.h>
|
||||
#include <blitz/simdtypes.h>
|
||||
#include <blitz/array/slice.h>
|
||||
|
||||
#ifdef BZ_HAVE_BOOST_SERIALIZATION
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
#endif
|
||||
#ifdef BZ_HAVE_BOOST_MPI
|
||||
#include <boost/mpi/datatype.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef BZ_HAVE_CSTRING
|
||||
#include <cstring> // For memcpy
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
/*****************************************************************************
|
||||
* Forward declarations
|
||||
*/
|
||||
|
||||
template<typename P_numtype, int N_length>
|
||||
class FastTV2Iterator;
|
||||
template<typename P_numtype, int N_length>
|
||||
class FastTV2CopyIterator;
|
||||
|
||||
|
||||
/** The TinyVector class is a one-dimensional, fixed length vector
|
||||
that implements the blitz expression template
|
||||
machinery. TinyVector-only expressions are very fast because they
|
||||
usually get reduced to just the unrolled (and vectorized, if
|
||||
enabled) assembly instructions. TinyVectors can also be used in
|
||||
mixed expressions with other ET classes. */
|
||||
template<typename P_numtype, int N_length>
|
||||
class TinyVector : public ETBase<TinyVector<P_numtype, N_length> >
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Public Types
|
||||
//////////////////////////////////////////////
|
||||
|
||||
typedef P_numtype T_numtype;
|
||||
typedef TinyVector<T_numtype,N_length> T_vector;
|
||||
typedef FastTV2Iterator<T_numtype,N_length> T_iterator;
|
||||
typedef T_numtype* iterator;
|
||||
typedef const T_numtype* const_iterator;
|
||||
typedef FastTV2CopyIterator<P_numtype, N_length> T_range_result;
|
||||
|
||||
static const int
|
||||
//numArrayOperands = 1,
|
||||
//numIndexPlaceholders = 0,
|
||||
rank_ = 1;
|
||||
|
||||
TinyVector() { }
|
||||
~TinyVector() { }
|
||||
|
||||
TinyVector(const TinyVector<T_numtype,N_length>& x);
|
||||
|
||||
template <typename T_numtype2>
|
||||
TinyVector(const TinyVector<T_numtype2,N_length>& x);
|
||||
|
||||
/** This constructor creates a TinyVector from another ETBase
|
||||
object. It needs to be explicit to avoid all kinds of
|
||||
ambiguities. */
|
||||
template <typename T_expr>
|
||||
inline explicit TinyVector(const ETBase<T_expr>& expr) {
|
||||
*this = expr; }
|
||||
|
||||
/** This constructor creates a TinyVector specifically from an
|
||||
expression. This one we do NOT want to be explicit because that
|
||||
breaks simple construction assignments like "TinyVector<double,
|
||||
1> v = a+b;", forcing the user to explicitly write it like a
|
||||
construction. */
|
||||
template <typename T_expr>
|
||||
inline TinyVector(const _bz_ArrayExpr<T_expr>& expr) {
|
||||
*this = expr; }
|
||||
|
||||
inline TinyVector(const T_numtype initValue);
|
||||
|
||||
inline TinyVector(const T_numtype x[]) {
|
||||
memcpy(data_,x,N_length*sizeof(T_numtype));
|
||||
}
|
||||
|
||||
|
||||
TinyVector(T_numtype x0, T_numtype x1)
|
||||
{
|
||||
data_[0] = x0;
|
||||
data_[1] = x1;
|
||||
}
|
||||
|
||||
TinyVector(T_numtype x0, T_numtype x1, T_numtype x2)
|
||||
{
|
||||
data_[0] = x0;
|
||||
data_[1] = x1;
|
||||
data_[2] = x2;
|
||||
}
|
||||
|
||||
TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
||||
T_numtype x3)
|
||||
{
|
||||
data_[0] = x0;
|
||||
data_[1] = x1;
|
||||
data_[2] = x2;
|
||||
data_[3] = x3;
|
||||
}
|
||||
|
||||
TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
||||
T_numtype x3, T_numtype x4)
|
||||
{
|
||||
data_[0] = x0;
|
||||
data_[1] = x1;
|
||||
data_[2] = x2;
|
||||
data_[3] = x3;
|
||||
data_[4] = x4;
|
||||
}
|
||||
|
||||
TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
||||
T_numtype x3, T_numtype x4, T_numtype x5)
|
||||
{
|
||||
data_[0] = x0;
|
||||
data_[1] = x1;
|
||||
data_[2] = x2;
|
||||
data_[3] = x3;
|
||||
data_[4] = x4;
|
||||
data_[5] = x5;
|
||||
}
|
||||
|
||||
TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
||||
T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6)
|
||||
{
|
||||
data_[0] = x0;
|
||||
data_[1] = x1;
|
||||
data_[2] = x2;
|
||||
data_[3] = x3;
|
||||
data_[4] = x4;
|
||||
data_[5] = x5;
|
||||
data_[6] = x6;
|
||||
}
|
||||
|
||||
TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
||||
T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
|
||||
T_numtype x7)
|
||||
{
|
||||
data_[0] = x0;
|
||||
data_[1] = x1;
|
||||
data_[2] = x2;
|
||||
data_[3] = x3;
|
||||
data_[4] = x4;
|
||||
data_[5] = x5;
|
||||
data_[6] = x6;
|
||||
data_[7] = x7;
|
||||
}
|
||||
|
||||
TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
||||
T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
|
||||
T_numtype x7, T_numtype x8)
|
||||
{
|
||||
data_[0] = x0;
|
||||
data_[1] = x1;
|
||||
data_[2] = x2;
|
||||
data_[3] = x3;
|
||||
data_[4] = x4;
|
||||
data_[5] = x5;
|
||||
data_[6] = x6;
|
||||
data_[7] = x7;
|
||||
data_[8] = x8;
|
||||
}
|
||||
|
||||
TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
||||
T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
|
||||
T_numtype x7, T_numtype x8, T_numtype x9)
|
||||
{
|
||||
data_[0] = x0;
|
||||
data_[1] = x1;
|
||||
data_[2] = x2;
|
||||
data_[3] = x3;
|
||||
data_[4] = x4;
|
||||
data_[5] = x5;
|
||||
data_[6] = x6;
|
||||
data_[7] = x7;
|
||||
data_[8] = x8;
|
||||
data_[9] = x9;
|
||||
}
|
||||
|
||||
TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
||||
T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
|
||||
T_numtype x7, T_numtype x8, T_numtype x9, T_numtype x10)
|
||||
{
|
||||
data_[0] = x0;
|
||||
data_[1] = x1;
|
||||
data_[2] = x2;
|
||||
data_[3] = x3;
|
||||
data_[4] = x4;
|
||||
data_[5] = x5;
|
||||
data_[6] = x6;
|
||||
data_[7] = x7;
|
||||
data_[8] = x8;
|
||||
data_[9] = x9;
|
||||
data_[10] = x10;
|
||||
}
|
||||
|
||||
static int base()
|
||||
{ return 0; }
|
||||
|
||||
static int base(int rank)
|
||||
{ BZPRECONDITION(rank==0); return 0; }
|
||||
|
||||
|
||||
T_iterator beginFast() const { return T_iterator(*this); }
|
||||
|
||||
iterator begin() { return data_; }
|
||||
const_iterator begin() const { return data_; }
|
||||
|
||||
static int dimensions()
|
||||
{ return 1; }
|
||||
|
||||
iterator end() { return data_ + N_length; }
|
||||
const_iterator end() const { return data_ + N_length; }
|
||||
|
||||
T_numtype * restrict data()
|
||||
{ return data_; }
|
||||
|
||||
const T_numtype * restrict data() const
|
||||
{ return data_; }
|
||||
|
||||
T_numtype * restrict dataFirst()
|
||||
{ return data_; }
|
||||
|
||||
const T_numtype * restrict dataFirst() const
|
||||
{ return data_; }
|
||||
|
||||
const TinyVector<int, rank_> shape() const
|
||||
{ return N_length; }
|
||||
|
||||
static int lbound(int rank)
|
||||
{ BZPRECONDITION(rank==0); return 0; }
|
||||
static int lbound()
|
||||
{ return 0; }
|
||||
|
||||
static int length(int rank)
|
||||
{ BZPRECONDITION(rank==0); return N_length; }
|
||||
static int length()
|
||||
{ return N_length; }
|
||||
|
||||
static int extent(int rank)
|
||||
{ BZPRECONDITION(rank==0); return N_length; }
|
||||
|
||||
static int ordering(int storageRankIndex)
|
||||
{ return 0; }
|
||||
|
||||
static int ordering()
|
||||
{ return 0; }
|
||||
|
||||
static int rank()
|
||||
{ return rank_; }
|
||||
|
||||
static sizeType numElements()
|
||||
{ return length(); }
|
||||
|
||||
static diffType stride()
|
||||
{ return 1; }
|
||||
|
||||
static diffType stride(int rank)
|
||||
{ BZPRECONDITION(rank==0); return 1; }
|
||||
|
||||
static int ubound(int rank)
|
||||
{ BZPRECONDITION(rank==0); return length()-1; }
|
||||
|
||||
static int ubound()
|
||||
{ return length()-1; }
|
||||
|
||||
template<typename P_expr, typename P_updater>
|
||||
void _bz_assign(P_expr, P_updater);
|
||||
|
||||
T_numtype operator*() const
|
||||
{ return *data_; }
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Subscripting operators
|
||||
//////////////////////////////////////////////
|
||||
|
||||
T_vector& noConst() const
|
||||
{ return const_cast<T_vector&>(*this); }
|
||||
|
||||
static bool lengthCheck(unsigned i)
|
||||
{
|
||||
BZPRECHECK(i < N_length,
|
||||
"TinyVector<" << BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(T_numtype)
|
||||
<< "," << N_length << "> index out of bounds: " << i);
|
||||
return true;
|
||||
}
|
||||
|
||||
const T_numtype& operator()(unsigned i) const
|
||||
{
|
||||
BZPRECONDITION(lengthCheck(i));
|
||||
return data_[i];
|
||||
}
|
||||
|
||||
T_numtype& restrict operator()(unsigned i)
|
||||
{
|
||||
BZPRECONDITION(lengthCheck(i));
|
||||
return data_[i];
|
||||
}
|
||||
|
||||
T_numtype operator()(TinyVector<int,1> i) const
|
||||
{
|
||||
BZPRECONDITION(lengthCheck(i[0]));
|
||||
return data_[i[0]];
|
||||
}
|
||||
|
||||
template<int N0>
|
||||
_bz_ArrayExpr<ArrayIndexMapping<typename asExpr<T_vector>::T_expr, N0> >
|
||||
operator()(IndexPlaceholder<N0>) const;
|
||||
|
||||
const T_numtype& operator[](unsigned i) const
|
||||
{
|
||||
BZPRECONDITION(lengthCheck(i));
|
||||
return data_[i];
|
||||
}
|
||||
|
||||
T_numtype& restrict operator[](unsigned i)
|
||||
{
|
||||
BZPRECONDITION(lengthCheck(i));
|
||||
return data_[i];
|
||||
}
|
||||
|
||||
// must return reference so the iterator can turn it into an
|
||||
// iterator for the contained in case we have a multicomponent.
|
||||
const T_numtype& fastRead(diffType i) const
|
||||
{ return data_[i]; }
|
||||
|
||||
/** Since data_ is simd aligned by construction, we just have
|
||||
to check the offest. */
|
||||
bool isVectorAligned(diffType offset) const
|
||||
{ return (offset%simdTypes<T_numtype>::vecWidth)==0; }
|
||||
|
||||
bool canCollapse(int outerLoopRank, int innerLoopRank) const
|
||||
{
|
||||
BZPRECONDITION(outerLoopRank==0);
|
||||
BZPRECONDITION(innerLoopRank==0);
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Assignment operators
|
||||
//////////////////////////////////////////////
|
||||
|
||||
// Scalar operand
|
||||
ListInitializationSwitch<T_vector,T_numtype*> operator=(T_numtype x)
|
||||
{
|
||||
return ListInitializationSwitch<T_vector,T_numtype*>(*this, x);
|
||||
}
|
||||
|
||||
T_vector& initialize(T_numtype);
|
||||
|
||||
template<typename T_expr>
|
||||
T_vector& operator=(const ETBase<T_expr>&);
|
||||
|
||||
template<typename T> T_vector& operator+=(const T&);
|
||||
template<typename T> T_vector& operator-=(const T&);
|
||||
template<typename T> T_vector& operator*=(const T&);
|
||||
template<typename T> T_vector& operator/=(const T&);
|
||||
template<typename T> T_vector& operator%=(const T&);
|
||||
template<typename T> T_vector& operator^=(const T&);
|
||||
template<typename T> T_vector& operator&=(const T&);
|
||||
template<typename T> T_vector& operator|=(const T&);
|
||||
template<typename T> T_vector& operator>>=(const T&);
|
||||
template<typename T> T_vector& operator<<=(const T&);
|
||||
|
||||
T_numtype* restrict getInitializationIterator()
|
||||
{ return dataFirst(); }
|
||||
|
||||
// // vectors can't be sliced
|
||||
// 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 void T_slice;
|
||||
// };
|
||||
|
||||
private:
|
||||
template<typename T_expr, typename T_update>
|
||||
void _tv_evaluate(const T_expr& expr, T_update);
|
||||
|
||||
#ifdef BZ_HAVE_BOOST_SERIALIZATION
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template<class T_arch>
|
||||
void serialize(T_arch& ar, const unsigned int version) {
|
||||
ar & data_;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
BZ_ALIGN_VARIABLE(T_numtype, data_[N_length], BZ_SIMD_WIDTH)
|
||||
};
|
||||
|
||||
// Specialization for N = 0: KCC is giving some
|
||||
// peculiar errors, perhaps this will fix.
|
||||
|
||||
template<typename T>
|
||||
class TinyVector<T,0> {
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#ifdef BZ_HAVE_BOOST_SERIALIZATION
|
||||
namespace boost {
|
||||
namespace mpi {
|
||||
template<typename T> struct is_mpi_datatype;
|
||||
template <typename T, int N>
|
||||
struct is_mpi_datatype<blitz::TinyVector<T, N> >
|
||||
: public is_mpi_datatype<T> { };
|
||||
} };
|
||||
#endif
|
||||
|
||||
|
||||
#endif // BZ_TINYVEC_H
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/***************************************************************************
|
||||
* blitz/tinyvecio.cc TinyVector I/O 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_TINYVEC2IO_CC
|
||||
#define BZ_TINYVEC2IO_CC
|
||||
|
||||
#include <blitz/tinyvec2.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// NEEDS_WORK???
|
||||
// This version of operator<< is updated on August 2005
|
||||
// by Sergei Mingaleev <mingaleev@gmail.com>. The output
|
||||
// format for 2D TinyVector is the same as for complex
|
||||
// numbers - so that one can read Array of complex numbers
|
||||
// into Array of TinyVectors for speed-up of calculations.
|
||||
// Also, the corresponding operator>> is updated.
|
||||
|
||||
template<typename P_numtype, int N_length>
|
||||
ostream& operator<<(ostream& os, const TinyVector<P_numtype, N_length>& x)
|
||||
{
|
||||
os << "(" << x[0];
|
||||
for (int i=1; i < N_length; ++i)
|
||||
{
|
||||
os << "," << x[i];
|
||||
}
|
||||
os << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
// Input of tinyvec contribute by Adam Levar <adaml@mcneilhouse.com>
|
||||
// and updated by Sergei Mingaleev <mingaleev@gmail.com>
|
||||
template <typename T_numtype, int N_length>
|
||||
istream& operator>>(istream& is, TinyVector<T_numtype, N_length>& x)
|
||||
{
|
||||
char sep;
|
||||
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == '(', "Format error while scanning input TinyVector"
|
||||
<< endl << " (expected '(' opening TinyVector)");
|
||||
|
||||
is >> x(0);
|
||||
for (int i = 1; i < N_length; ++i)
|
||||
{
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == ',', "Format error while scanning input TinyVector"
|
||||
<< endl << " (expected ',' between TinyVector components)");
|
||||
BZPRECHECK(!is.bad(), "Premature end of input while scanning TinyVector");
|
||||
is >> x(i);
|
||||
}
|
||||
is >> sep;
|
||||
BZPRECHECK(sep == ')', "Format error while scanning input TinyVector"
|
||||
<< endl << " (expected ')' closing TinyVector)");
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_TINYVECIO_CC
|
||||
@@ -1,481 +0,0 @@
|
||||
// -*- 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_TM2FASTITER_H
|
||||
#define BZ_ARRAY_TM2FASTITER_H
|
||||
|
||||
#ifdef BZ_HAVE_STD
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream.h>
|
||||
#endif
|
||||
|
||||
#include <blitz/constpointerstack.h>
|
||||
#include <blitz/bzdebug.h>
|
||||
#include <blitz/shapecheck.h>
|
||||
#include <blitz/prettyprint.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// forward declaration
|
||||
template<typename, int, int> class FastTM2Iterator;
|
||||
template<typename, int, int> class FastTM2CopyIterator;
|
||||
|
||||
|
||||
template<typename P_numtype, int N_rows, int N_columns, typename P_arraytype>
|
||||
class FastTM2IteratorBase {
|
||||
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. This should
|
||||
only be used for mixed TM/Array expressions. */
|
||||
typedef ETBase<FastTV2Iterator<T_numtype,
|
||||
simdTypes<T_numtype>::vecWidth> > T_tvtypeprop;
|
||||
typedef typename unwrapET<T_tvtypeprop>::T_unwrapped T_tvresult;
|
||||
|
||||
typedef TinyMatrix<T_numtype, N_rows, N_columns> T_matrix;
|
||||
typedef FastTM2IteratorBase<P_numtype, N_rows, N_columns, P_arraytype> T_iterator;
|
||||
typedef const T_matrix& T_ctorArg1;
|
||||
typedef int T_ctorArg2; // dummy
|
||||
typedef FastTM2CopyIterator<P_numtype, N_rows, N_columns> T_range_result;
|
||||
|
||||
static const int
|
||||
numArrayOperands = 0,
|
||||
numTVOperands = 0,
|
||||
numTMOperands = 1,
|
||||
numIndexPlaceholders = 0,
|
||||
minWidth = simdTypes<T_numtype>::vecWidth,
|
||||
maxWidth = simdTypes<T_numtype>::vecWidth,
|
||||
rank_ = 2;
|
||||
|
||||
/** 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;
|
||||
};
|
||||
|
||||
FastTM2IteratorBase(const T_iterator& x)
|
||||
: data_(x.data_), array_(x.array_)
|
||||
{ }
|
||||
|
||||
void operator=(const T_iterator& x)
|
||||
{
|
||||
BZPRECONDITION(0);
|
||||
// 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_;
|
||||
}
|
||||
|
||||
FastTM2IteratorBase(const T_matrix& array)
|
||||
: array_(array)
|
||||
{
|
||||
data_ = array_.data();
|
||||
}
|
||||
|
||||
~FastTM2IteratorBase()
|
||||
{ }
|
||||
|
||||
T_result operator()(TinyVector<int,2> i) const
|
||||
{
|
||||
return array_(i);
|
||||
}
|
||||
|
||||
static int ascending(const int r)
|
||||
{
|
||||
if (r<rank_)
|
||||
return T_matrix::isRankStoredAscending(r);
|
||||
else
|
||||
return INT_MIN;
|
||||
}
|
||||
|
||||
static int ordering(const int r)
|
||||
{
|
||||
if (r<rank_)
|
||||
return T_matrix::ordering(r);
|
||||
else
|
||||
return INT_MIN;
|
||||
}
|
||||
|
||||
static int lbound(const int r)
|
||||
{
|
||||
if (r<rank_)
|
||||
return T_matrix::lbound(r);
|
||||
else
|
||||
return INT_MIN;
|
||||
}
|
||||
|
||||
static int ubound(const int r)
|
||||
{
|
||||
if (r<rank_)
|
||||
return T_matrix::ubound(r);
|
||||
else
|
||||
return INT_MAX;
|
||||
}
|
||||
|
||||
//RectDomain<rank_> domain() const { return T_matrix::domain(); };
|
||||
|
||||
T_result first_value() const { return *data_; }
|
||||
|
||||
T_result operator*() const
|
||||
{ return *data_; }
|
||||
|
||||
T_result operator[](int i) const
|
||||
{ return data_[i * stride_]; }
|
||||
|
||||
T_result fastRead(diffType i) const
|
||||
{ return array_.fastRead(i); }
|
||||
|
||||
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])); }
|
||||
|
||||
/** Since data_ is simd aligned by construction, we just have
|
||||
to check the offest. */
|
||||
bool isVectorAligned(diffType offset) const
|
||||
{ return (offset%simdTypes<T_numtype>::vecWidth==0) ? true : false; }
|
||||
|
||||
static int suggestStride(int r)
|
||||
{ return T_matrix::stride(r); }
|
||||
|
||||
static bool isStride(int r, diffType stride)
|
||||
{ return T_matrix::stride(r) == 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_ = T_matrix::stride(rank);
|
||||
}
|
||||
|
||||
// This is used as lvalue, so it should return the actual data
|
||||
const T_numtype * restrict data() const
|
||||
{ return data_; }
|
||||
|
||||
const T_matrix& 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*T_matrix::stride(dim); }
|
||||
|
||||
void _bz_offsetData(sizeType offset1, int dim1, sizeType offset2, int dim2)
|
||||
{ data_ += offset1*T_matrix::stride(dim1);
|
||||
data_ += offset2*T_matrix::stride(dim2); }
|
||||
|
||||
int stride() const
|
||||
{ return stride_; }
|
||||
|
||||
static bool isUnitStride(int r)
|
||||
{ return T_matrix::stride(r) == 1; }
|
||||
|
||||
bool isUnitStride() const
|
||||
{ return stride() == 1; }
|
||||
|
||||
void advanceUnitStride()
|
||||
{ ++data_; }
|
||||
|
||||
bool canCollapse(int outerLoopRank, int innerLoopRank) const
|
||||
{ return T_matrix::canCollapse(outerLoopRank, innerLoopRank); }
|
||||
|
||||
template<typename T_shape>
|
||||
bool shapeCheck(const T_shape& s) const
|
||||
{ return areShapesConformable(s, T_matrix::length()); }
|
||||
|
||||
/*
|
||||
// Experimental
|
||||
T_numtype& operator()(int i) const
|
||||
{
|
||||
return (T_numtype&)data_[i*T_matrix::stride(0)];
|
||||
}
|
||||
|
||||
// Experimental
|
||||
T_numtype& operator()(int i, int j) const
|
||||
{
|
||||
return (T_numtype&)data_[i*T_matrix::stride(0) + j*T_matrix::stride(1)];
|
||||
}
|
||||
|
||||
// Experimental
|
||||
|
||||
void moveTo(int i)
|
||||
{
|
||||
data_ = &const_cast<T_matrix&>(array_)(i);
|
||||
}
|
||||
|
||||
void moveTo(int i, int j)
|
||||
{
|
||||
data_ = &const_cast<T_matrix&>(array_)(i,j);
|
||||
}
|
||||
|
||||
template<int N_rank2>
|
||||
void moveTo(const TinyVector<int,N_rank2>& i)
|
||||
{
|
||||
data_ = &const_cast<T_matrix&>(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<T_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*T_matrix::stride(dim)];
|
||||
}
|
||||
|
||||
// Experimental
|
||||
T_result shift(int offset1, int dim1, int offset2, int dim2) const
|
||||
{
|
||||
return data_[offset1*T_matrix::stride(dim1)
|
||||
+ offset2*T_matrix::stride(dim2)];
|
||||
}
|
||||
|
||||
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 << T_matrix::shape();
|
||||
str += ostr.str();
|
||||
}
|
||||
else {
|
||||
str += "TinyMatrix<";
|
||||
str += BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(T_numtype);
|
||||
str += ",";
|
||||
|
||||
char tmpBuf[10];
|
||||
sprintf(tmpBuf, "%d", N_rows);
|
||||
|
||||
str += tmpBuf;
|
||||
str += ",";
|
||||
sprintf(tmpBuf, "%d", N_columns);
|
||||
|
||||
str += tmpBuf;
|
||||
str += ">";
|
||||
}
|
||||
}
|
||||
|
||||
// tiny matrices can't be sliced
|
||||
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 void T_slice;
|
||||
};
|
||||
|
||||
protected:
|
||||
const T_numtype * restrict data_;
|
||||
P_arraytype array_;
|
||||
ConstPointerStack<T_numtype,rank_> stack_;
|
||||
diffType stride_;
|
||||
};
|
||||
|
||||
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
class FastTM2CopyIterator;
|
||||
|
||||
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
class FastTM2Iterator :
|
||||
public FastTM2IteratorBase<P_numtype, N_rows, N_columns,
|
||||
const TinyMatrix<P_numtype, N_rows, N_columns>&>
|
||||
{
|
||||
public:
|
||||
typedef FastTM2IteratorBase<P_numtype, N_rows, N_columns,
|
||||
const TinyMatrix<P_numtype, N_rows, N_columns>&> T_base;
|
||||
typedef typename T_base::T_numtype T_numtype;
|
||||
typedef typename T_base::T_matrix T_matrix;
|
||||
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.
|
||||
FastTM2Iterator(const FastTM2Iterator& x)
|
||||
: T_base(x)
|
||||
{ }
|
||||
|
||||
FastTM2Iterator(const T_matrix& array) : T_base(array) {}
|
||||
|
||||
using T_base::operator=;
|
||||
void operator=(const FastTM2Iterator<P_numtype, N_rows, N_columns>& x)
|
||||
{
|
||||
T_base::operator=(x);
|
||||
}
|
||||
|
||||
using T_base::operator();
|
||||
|
||||
// template<int N>
|
||||
// T_range_result operator()(const RectDomain<N>& d) const
|
||||
// {
|
||||
// return T_range_result(T_base::array_(d));
|
||||
// }
|
||||
|
||||
// template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
|
||||
// typename T7, typename T8, typename T9, typename T10, typename T11>
|
||||
// FastTM2CopyIterator<T_numtype, T_base::template SliceInfo<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_slice::rank>
|
||||
// operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6, T7 r7, T8 r8, T9 r9, T10 r10, T11 r11) const
|
||||
// {
|
||||
// typedef FastTM2CopyIterator<T_numtype, T_base::template SliceInfo<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_slice::rank> slice;
|
||||
|
||||
// return slice(array_(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11));
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
/* This version of the FastTM2Iterator 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_rows, int N_columns>
|
||||
class FastTM2CopyIterator :
|
||||
public FastTM2IteratorBase<P_numtype, N_rows, N_columns, const TinyMatrix<P_numtype, N_rows, N_columns> >
|
||||
{
|
||||
public:
|
||||
typedef FastTM2IteratorBase<P_numtype, N_rows, N_columns,
|
||||
const TinyMatrix<P_numtype, N_rows, N_columns> > T_base;
|
||||
typedef typename T_base::T_numtype T_numtype;
|
||||
typedef typename T_base::T_matrix T_matrix;
|
||||
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.
|
||||
FastTM2CopyIterator(const FastTM2CopyIterator& x)
|
||||
: T_base(x)
|
||||
{ }
|
||||
|
||||
FastTM2CopyIterator(const T_matrix& array) : T_base(array) { }
|
||||
|
||||
using T_base::operator=;
|
||||
void operator=(const FastTM2CopyIterator& x)
|
||||
{
|
||||
T_base::operator=(x);
|
||||
}
|
||||
|
||||
using T_base::operator();
|
||||
|
||||
// template<int N>
|
||||
// T_range_result operator()(const RectDomain<N>& d) const
|
||||
// {
|
||||
// return T_range_result(T_base::array_(d));
|
||||
// }
|
||||
|
||||
// template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
|
||||
// typename T7, typename T8, typename T9, typename T10, typename T11>
|
||||
// FastTM2CopyIterator<T_numtype, T_base::template SliceInfo<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_slice::rank>
|
||||
// operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6, T7 r7, T8 r8, T9 r9, T10 r10, T11 r11) const
|
||||
// {
|
||||
// typedef FastTM2CopyIterator<T_numtype, T_base::template SliceInfo<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_slice::rank> slice;
|
||||
|
||||
// return slice(array_(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11));
|
||||
// }
|
||||
};
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_ARRAY_FASTITER_H
|
||||
@@ -1,179 +0,0 @@
|
||||
/***************************************************************************
|
||||
* blitz/tinyvec.cc Declaration of TinyVector 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_TMEVALUATE_H
|
||||
#define BZ_TMEVALUATE_H
|
||||
|
||||
#include <blitz/tinymat2.h>
|
||||
#include <blitz/update.h>
|
||||
#include <blitz/blitz.h>
|
||||
#include <blitz/meta/vecassign.h>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
|
||||
/** The _tm_evaluator class has a bool template argument that is used
|
||||
to select code paths at compile time. */
|
||||
template<bool unroll, int N_rows, int N_columns>
|
||||
struct _tm_evaluator {
|
||||
|
||||
/** The select_evaluation function redirects expressions that do not
|
||||
contains solely TinyMatrix operands to the general evaluation
|
||||
function. The generic template (for unroll=false, note that
|
||||
"unroll" us the wrong name for this function, the template
|
||||
parameter in this context really means "use_full_eval") uses the
|
||||
TinyMatrix-only evaluation. Since TinyMatrixs can't have funny
|
||||
storage, ordering, stride, or anything, it's now just a matter
|
||||
of evaluating it like in the old vecassign. */
|
||||
template<typename T, typename T_expr, typename T_update>
|
||||
static _bz_forceinline void
|
||||
select_evaluation(TinyMatrix<T, N_rows, N_columns>& dest,
|
||||
const T_expr& expr, T_update) {
|
||||
|
||||
// since we can't resize tinyvectors, there are two options: all
|
||||
// vectors have our size or the expression is malformed.
|
||||
// Check that all operands have the same shape
|
||||
#ifdef BZ_DEBUG
|
||||
if (!expr.shapeCheck(dest.shape()))
|
||||
{
|
||||
if (assertFailMode == false)
|
||||
{
|
||||
cerr << "[Blitz++] Shape check failed: Module " << __FILE__
|
||||
<< " line " << __LINE__ << endl
|
||||
<< " Expression: ";
|
||||
prettyPrintFormat format(true); // Use terse formatting
|
||||
BZ_STD_SCOPE(string) str;
|
||||
expr.prettyPrint(str, format);
|
||||
cerr << str << endl ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
BZPRECHECK(expr.shapeCheck(dest.shape()),
|
||||
"Shape check failed." << endl << "Expression:");
|
||||
|
||||
// now call the aligned (unrolled or not) evaluation function
|
||||
const bool do_unroll = N_rows*N_columns < BZ_TV_EVALUATE_UNROLL_LENGTH;
|
||||
_tm_evaluator<do_unroll, N_rows, N_columns>::evaluate_aligned(dest.data(), expr, T_update());
|
||||
}
|
||||
|
||||
/** This version of the evaluation function assumes that the
|
||||
TinyMatrixs have appropriate alignment (as will always be the
|
||||
case if they are actual TinyMatrix objects and not created using
|
||||
reinterpret_cast in the chunked_updater. */
|
||||
template<typename T_numtype, typename T_expr, typename T_update>
|
||||
static _bz_forceinline void
|
||||
evaluate_aligned(T_numtype* data, const T_expr& expr, T_update) {
|
||||
#ifdef BZ_USE_ALIGNMENT_PRAGMAS
|
||||
#pragma ivdep
|
||||
#pragma vector aligned
|
||||
#endif
|
||||
for (int i=0; i < N_rows*N_columns; ++i)
|
||||
T_update::update(data[i], expr.fastRead(i));
|
||||
}
|
||||
|
||||
/** This version of the evaluation function is used when vectorizing
|
||||
expressions that we know can't be aligned. The only difference
|
||||
with evaluate_aligned is the compiler pragma that tells the
|
||||
compiler it is unaligned. */
|
||||
template<typename T_numtype, typename T_expr, typename T_update>
|
||||
static _bz_forceinline void
|
||||
evaluate_unaligned(T_numtype* data, const T_expr& expr, T_update) {
|
||||
#ifdef BZ_USE_ALIGNMENT_PRAGMAS
|
||||
#pragma ivdep
|
||||
#pragma vector unaligned
|
||||
#endif
|
||||
for (int i=0; i < N_rows*N_columns; ++i)
|
||||
T_update::update(data[i], expr.fastRead(i));
|
||||
}
|
||||
};
|
||||
|
||||
/** Specialization of the _tm_evaluator class for false template arguments. */
|
||||
template<int N_rows, int N_columns>
|
||||
struct _tm_evaluator<true, N_rows, N_columns> {
|
||||
|
||||
/** The false version of select_evaluation is picked for expressions
|
||||
that contain operands other than TinyMatrixs. It just redirects
|
||||
to the general evaluation function. */
|
||||
template<typename T, typename T_expr, typename T_update>
|
||||
static _bz_forceinline void
|
||||
select_evaluation(TinyMatrix<T, N_rows, N_columns>& dest,
|
||||
const T_expr& expr, T_update) {
|
||||
_bz_evaluate(dest, expr, T_update());
|
||||
}
|
||||
|
||||
/** This version of the evaluation function assumes that the
|
||||
TinyMatrixs have appropriate alignment (as will always be the
|
||||
case if they are actual TinyMatrix objects and not created using
|
||||
reinterpret_cast in the chunked_updater. */
|
||||
template<typename T_numtype, typename T_expr, typename T_update>
|
||||
static _bz_forceinline void
|
||||
evaluate_aligned(T_numtype* data, const T_expr& expr, T_update) {
|
||||
#ifdef BZ_USE_ALIGNMENT_PRAGMAS
|
||||
//#pragma ivdep
|
||||
//#pragma vector aligned
|
||||
#endif
|
||||
_bz_meta_vecAssign<N_rows*N_columns, 0>::fastAssign(data, expr, T_update());
|
||||
}
|
||||
|
||||
/** This version of the evaluation function is used when vectorizing
|
||||
expressions that we know can't be aligned. The only difference
|
||||
with evaluate_aligned is the compiler pragma that tells the
|
||||
compiler it is unaligned. */
|
||||
template<typename T_numtype, typename T_expr, typename T_update>
|
||||
static _bz_forceinline void
|
||||
evaluate_unaligned(T_numtype* data, const T_expr& expr, T_update) {
|
||||
//#pragma ivdep
|
||||
//#pragma vector unaligned
|
||||
_bz_meta_vecAssign<N_rows*N_columns, 0>::fastAssign(data, expr, T_update());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** This function selects evaluation path by calling select_evaluation
|
||||
with a bool argument which is false if the expression only
|
||||
contains TinyMatrix operands. */
|
||||
template<typename P_numtype, int N_rows, int N_columns>
|
||||
template<typename T_expr, typename T_update>
|
||||
_bz_forceinline
|
||||
void
|
||||
TinyMatrix<P_numtype,N_rows, N_columns>::_tm_evaluate(const T_expr& expr, T_update)
|
||||
{
|
||||
const bool mixed_expr =
|
||||
(T_expr::numArrayOperands>0) ||
|
||||
(T_expr::numTVOperands>0) ||
|
||||
(T_expr::numIndexPlaceholders>0);
|
||||
_tm_evaluator<mixed_expr, N_rows, N_columns>::select_evaluation(*this, expr, T_update());
|
||||
}
|
||||
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_TVEVALUATE_H
|
||||
@@ -1,134 +0,0 @@
|
||||
/***************************************************************************
|
||||
* blitz/traversal.cc Space-filling curve based traversal orders
|
||||
*
|
||||
* $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_TRAVERSAL_CC
|
||||
#define BZ_TRAVERSAL_CC
|
||||
|
||||
#ifndef BZ_TRAVERSAL_H
|
||||
#error <blitz/traversal.cc> must be included via <blitz/traversal.h>
|
||||
#endif
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
// Next line is a workaround for Intel C++ V4.0 oddity, due
|
||||
// to Allan Stokes.
|
||||
static set<TraversalOrder<2> > *_bz_intel_kludge;
|
||||
|
||||
//template<int N_dimensions>
|
||||
//_bz_typename TraversalOrderCollection<N_dimensions>::T_set
|
||||
// TraversalOrderCollection<N_dimensions>::traversals_;
|
||||
|
||||
template<int N>
|
||||
void makeHilbert(Vector<TinyVector<int,N> >& coord,
|
||||
int x0, int y0, int xis, int xjs,
|
||||
int yis, int yjs, int n, int& i)
|
||||
{
|
||||
// N != 2 is not yet implemented.
|
||||
BZPRECONDITION(N == 2);
|
||||
|
||||
if (!n)
|
||||
{
|
||||
if (i > coord.length(firstDim))
|
||||
{
|
||||
cerr << "makeHilbert: vector not long enough" << endl;
|
||||
exit(1);
|
||||
}
|
||||
coord(i)[0] = x0 + (xis+yis)/2;
|
||||
coord(i)[1] = y0 + (xjs+yjs)/2;
|
||||
++i;
|
||||
}
|
||||
else {
|
||||
makeHilbert(coord,x0,y0,yis/2, yjs/2, xis/2, xjs/2, n-1, i);
|
||||
makeHilbert(coord,x0+xis/2,y0+xjs/2,xis/2,xjs/2,yis/2,yjs/2,n-1,i);
|
||||
makeHilbert(coord,x0+xis/2+yis/2,y0+xjs/2+yjs/2,xis/2,xjs/2,yis/2,
|
||||
yjs/2,n-1,i);
|
||||
makeHilbert(coord,x0+xis/2+yis, y0+xjs/2+yjs, -yis/2,-yjs/2,-xis/2,
|
||||
-xjs/2,n-1,i);
|
||||
}
|
||||
}
|
||||
|
||||
template<int N_dimensions>
|
||||
void MakeHilbertTraversal(Vector<TinyVector<int,N_dimensions> >& coord,
|
||||
int length)
|
||||
{
|
||||
// N_dimensions != 2 not yet implemented
|
||||
BZPRECONDITION(N_dimensions == 2);
|
||||
|
||||
// The constant on the next line is ln(2)
|
||||
int d = (int)(::ceil(::log((double)length) / 0.693147180559945309417));
|
||||
|
||||
int N = 1 << d;
|
||||
const int Npoints = N*N;
|
||||
Vector<TinyVector<int,2> > coord2(Npoints);
|
||||
|
||||
int i=0;
|
||||
makeHilbert(coord2,0,0,32768,0,0,32768,d,i);
|
||||
|
||||
int xp0 = coord2(0)[0];
|
||||
int yp0 = coord2(0)[1];
|
||||
|
||||
int j=0;
|
||||
|
||||
coord.resize(length * length);
|
||||
|
||||
for (int i=0; i < Npoints; ++i)
|
||||
{
|
||||
coord2(i)[0] = (coord2(i)[0]-xp0)/(2*xp0);
|
||||
coord2(i)[1] = (coord2(i)[1]-yp0)/(2*yp0);
|
||||
|
||||
if ((coord2(i)[0] < length) && (coord2(i)[1] < length)
|
||||
&& (coord2(i)[0] >= 0) && (coord2(i)[1] >= 0))
|
||||
{
|
||||
coord(j)[0] = coord2(i)[0];
|
||||
coord(j)[1] = coord2(i)[1];
|
||||
++j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<int N_dimensions>
|
||||
void generateFastTraversalOrder(const TinyVector<int,N_dimensions>& size)
|
||||
{
|
||||
BZPRECONDITION(N_dimensions == 2);
|
||||
BZPRECONDITION(size[0] == size[1]);
|
||||
|
||||
TraversalOrderCollection<2> travCol;
|
||||
if (travCol.find(size))
|
||||
return;
|
||||
|
||||
Vector<TinyVector<int,2> > ordering(size[0]);
|
||||
|
||||
MakeHilbertTraversal(ordering, size[0]);
|
||||
travCol.insert(TraversalOrder<2>(size, ordering));
|
||||
}
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#endif // BZ_TRAVERSAL_CC
|
||||
@@ -1,165 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/***************************************************************************
|
||||
* blitz/traversal.h Declaration of the TraversalOrder classes
|
||||
*
|
||||
* $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/
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
// Fast traversal orders require the ISO/ANSI C++ standard library
|
||||
// (particularly set).
|
||||
#ifdef BZ_HAVE_STD
|
||||
|
||||
#ifndef BZ_TRAVERSAL_H
|
||||
#define BZ_TRAVERSAL_H
|
||||
|
||||
#include <blitz/vector2.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
BZ_NAMESPACE(blitz)
|
||||
|
||||
template<int N_dimensions>
|
||||
class TraversalOrder {
|
||||
|
||||
public:
|
||||
typedef TinyVector<int, N_dimensions> T_coord;
|
||||
typedef Vector<T_coord> T_traversal;
|
||||
|
||||
TraversalOrder()
|
||||
{
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
TraversalOrder(const T_coord& size, T_traversal& order)
|
||||
: size_(size), order_(order)
|
||||
{ }
|
||||
|
||||
TraversalOrder(const T_coord& size)
|
||||
: size_(size)
|
||||
{ }
|
||||
|
||||
T_coord operator[](int i) const
|
||||
{ return order_[i]; }
|
||||
|
||||
T_coord& operator[](int i)
|
||||
{ return order_[i]; }
|
||||
|
||||
int length() const
|
||||
{ return order_.length(); }
|
||||
|
||||
bool operator<(const TraversalOrder<N_dimensions>& x) const
|
||||
{
|
||||
for (int i=0; i < N_dimensions; ++i)
|
||||
{
|
||||
if (size_[i] < x.size_[i])
|
||||
return true;
|
||||
else if (size_[i] > x.size_[i])
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const TraversalOrder<N_dimensions>& x) const
|
||||
{
|
||||
for (int i=0; i < N_dimensions; ++i)
|
||||
{
|
||||
if (size_[i] != x.size_[i])
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
T_traversal order_;
|
||||
T_coord size_;
|
||||
};
|
||||
|
||||
/*
|
||||
* This specialization is provided to avoid problems with zero-length
|
||||
* vectors.
|
||||
*/
|
||||
template<>
|
||||
class TraversalOrder<0> {
|
||||
public:
|
||||
TraversalOrder () {} // AJS
|
||||
};
|
||||
|
||||
template<int N_dimensions>
|
||||
class TraversalOrderCollection {
|
||||
public:
|
||||
typedef TraversalOrder<N_dimensions> T_traversal;
|
||||
typedef _bz_typename T_traversal::T_coord T_coord;
|
||||
typedef set<T_traversal> T_set;
|
||||
typedef _bz_typename set<T_traversal>::const_iterator T_iterator;
|
||||
|
||||
const T_traversal* find(const T_coord& size)
|
||||
{
|
||||
T_iterator iter = traversals_.find(T_traversal(size));
|
||||
if (iter != traversals_.end())
|
||||
return &(*iter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void insert(T_traversal x)
|
||||
{
|
||||
traversals_.insert(x);
|
||||
}
|
||||
|
||||
protected:
|
||||
static T_set traversals_;
|
||||
};
|
||||
|
||||
template<int N_dimensions>
|
||||
_bz_typename TraversalOrderCollection<N_dimensions>::T_set
|
||||
TraversalOrderCollection<N_dimensions>::traversals_;
|
||||
|
||||
/*
|
||||
* This specialization is provided to avoid problems with zero-length
|
||||
* vectors.
|
||||
*/
|
||||
|
||||
template<>
|
||||
class TraversalOrderCollection<0> {
|
||||
public:
|
||||
typedef int T_traversal;
|
||||
typedef int T_coord;
|
||||
typedef int T_set;
|
||||
typedef int T_iterator;
|
||||
|
||||
const T_traversal* find(const T_coord& size)
|
||||
{ return 0; }
|
||||
};
|
||||
|
||||
BZ_NAMESPACE_END
|
||||
|
||||
#include <blitz/traversal.cc>
|
||||
|
||||
#endif // BZ_TRAVERSAL_H
|
||||
|
||||
#endif // BZ_HAVE_STD
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user