Added blitz
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
// -*- 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
|
||||
@@ -0,0 +1,85 @@
|
||||
// -*- 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
|
||||
@@ -0,0 +1,128 @@
|
||||
// -*- 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
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
// -*- 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
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
// -*- 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
|
||||
@@ -0,0 +1,91 @@
|
||||
// -*- 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
|
||||
@@ -0,0 +1,89 @@
|
||||
// -*- 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
|
||||
@@ -0,0 +1,97 @@
|
||||
// -*- 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
|
||||
Reference in New Issue
Block a user