⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 et.h

📁 数值计算工具库,C语言编写的,可以直接调用.
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef BZ_ARRAY_ET_H
#define BZ_ARRAY_ET_H

#ifndef BZ_ARRAYEXPR_H
 #error <blitz/array/et.h> must be included after <blitz/arrayexpr.h>
#endif

#include <blitz/array/asexpr.h>

#ifndef BZ_OPS_H
 #include <blitz/ops.h>
#endif

#ifndef BZ_MATHFUNC_H
 #include <blitz/mathfunc.h>
#endif

BZ_NAMESPACE(blitz)

/*
 * Array expression templates: the macro BZ_DECLARE_ARRAY_ET(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(name, applic)                                 \
                                                                          \
template<class T_numtype1, int N_rank1, class T_other>                    \
_bz_inline_et                                                             \
_bz_ArrayExpr<_bz_ArrayExprOp<FastArrayIterator<T_numtype1, N_rank1>,     \
    _bz_typename asExpr<T_other>::T_expr,                                 \
    applic<T_numtype1,                                                    \
    _bz_typename asExpr<T_other>::T_expr::T_numtype> > >                  \
name (const Array<T_numtype1,N_rank1>& d1,                                \
    const T_other& d2)                                                    \
{                                                                         \
    return _bz_ArrayExpr<_bz_ArrayExprOp<FastArrayIterator<T_numtype1,    \
        N_rank1>,                                                         \
        _bz_typename asExpr<T_other>::T_expr,                             \
        applic<T_numtype1,                                                \
        _bz_typename asExpr<T_other>::T_expr::T_numtype> > >              \
      (d1.beginFast(),d2);                                                \
}                                                                         \
                                                                          \
template<class T_expr1, class T_other>                                    \
_bz_inline_et                                                             \
_bz_ArrayExpr<_bz_ArrayExprOp<_bz_ArrayExpr<T_expr1>,                     \
    _bz_typename asExpr<T_other>::T_expr,                                 \
    applic<_bz_typename T_expr1::T_numtype,                               \
        _bz_typename asExpr<T_other>::T_expr::T_numtype> > >              \
name(const _bz_ArrayExpr<T_expr1>& d1,                                    \
    const T_other& d2)                                                    \
{                                                                         \
    return _bz_ArrayExpr<_bz_ArrayExprOp<_bz_ArrayExpr<T_expr1>,          \
        _bz_typename asExpr<T_other>::T_expr,                             \
        applic<_bz_typename T_expr1::T_numtype,                           \
            _bz_typename asExpr<T_other>::T_expr::T_numtype> > >(d1,d2);  \
}                                                                         \
                                                                          \
template<class T1, class T2>                                              \
_bz_inline_et                                                             \
_bz_ArrayExpr<_bz_ArrayExprOp<_bz_typename asExpr<T1>::T_expr,            \
    _bz_typename asExpr<T2>::T_expr,                                      \
    applic<_bz_typename asExpr<T1>::T_expr::T_numtype,                    \
        _bz_typename asExpr<T2>::T_expr::T_numtype> > >                   \
name(const ETBase<T1>& d1, const T2& d2)                                  \
{                                                                         \
    return _bz_ArrayExpr<_bz_ArrayExprOp<_bz_typename asExpr<T1>::T_expr, \
        _bz_typename asExpr<T2>::T_expr,                                  \
        applic<_bz_typename asExpr<T1>::T_expr::T_numtype,                \
            _bz_typename asExpr<T2>::T_expr::T_numtype> > >               \
        (static_cast<const T1&>(d1), d2);                                 \
}                                                                         \
                                                                          \
template<class T1, class T2>                                              \
_bz_inline_et                                                             \
_bz_ArrayExpr<_bz_ArrayExprOp<_bz_typename asExpr<T1>::T_expr,            \
_bz_typename asExpr<T2>::T_expr,                                          \
    applic<_bz_typename asExpr<T1>::T_expr::T_numtype,                    \
        _bz_typename asExpr<T2>::T_expr::T_numtype> > >                   \
name(const T1& d1,                                                        \
    const ETBase<T2>& d2)                                                 \
{                                                                         \
    return _bz_ArrayExpr<_bz_ArrayExprOp<_bz_typename                     \
        asExpr<T1>::T_expr,                                               \
        _bz_typename asExpr<T2>::T_expr,                                  \
        applic<_bz_typename asExpr<T1>::T_expr::T_numtype,                \
            _bz_typename asExpr<T2>::T_expr::T_numtype> > >               \
        (d1, static_cast<const T2&>(d2));                                 \
}                                                                         \
                                                                          \
template<int N1, class T_other>                                           \
_bz_inline_et                                                             \
_bz_ArrayExpr<_bz_ArrayExprOp<IndexPlaceholder<N1>,                       \
    _bz_typename asExpr<T_other>::T_expr,                                 \
    applic<int,                                                           \
        _bz_typename asExpr<T_other>::T_expr::T_numtype> > >              \
name(IndexPlaceholder<N1> d1,                                             \
    const T_other& d2)                                                    \
{                                                                         \
    return _bz_ArrayExpr<_bz_ArrayExprOp<IndexPlaceholder<N1>,            \
        _bz_typename asExpr<T_other>::T_expr,                             \
        applic<int,                                                       \
            _bz_typename asExpr<T_other>::T_expr::T_numtype> > >(d1,d2);  \
}                                                                         \


// operator<< has been commented out because it causes ambiguity
// with statements like "cout << A".  NEEDS_WORK
// ditto operator<<

BZ_DECLARE_ARRAY_ET(operator+,  Add)
BZ_DECLARE_ARRAY_ET(operator-,  Subtract)
BZ_DECLARE_ARRAY_ET(operator*,  Multiply)
BZ_DECLARE_ARRAY_ET(operator/,  Divide)
BZ_DECLARE_ARRAY_ET(operator%,  Modulo)
BZ_DECLARE_ARRAY_ET(operator^,  BitwiseXor)
BZ_DECLARE_ARRAY_ET(operator&,  BitwiseAnd)
BZ_DECLARE_ARRAY_ET(operator|,  BitwiseOr)
// BZ_DECLARE_ARRAY_ET(operator>>, ShiftRight)
// BZ_DECLARE_ARRAY_ET(operator<<, ShiftLeft)
BZ_DECLARE_ARRAY_ET(operator>,  Greater)
BZ_DECLARE_ARRAY_ET(operator<,  Less)
BZ_DECLARE_ARRAY_ET(operator>=, GreaterOrEqual)
BZ_DECLARE_ARRAY_ET(operator<=, LessOrEqual)
BZ_DECLARE_ARRAY_ET(operator==, Equal)
BZ_DECLARE_ARRAY_ET(operator!=, NotEqual)
BZ_DECLARE_ARRAY_ET(operator&&, LogicalAnd)
BZ_DECLARE_ARRAY_ET(operator||, LogicalOr)

BZ_DECLARE_ARRAY_ET(atan2,      _bz_atan2)
BZ_DECLARE_ARRAY_ET(pow,        _bz_pow)

#ifdef BZ_HAVE_COMPLEX_MATH
BZ_DECLARE_ARRAY_ET(polar,     _bz_polar)
#endif

#ifdef BZ_HAVE_SYSTEM_V_MATH
BZ_DECLARE_ARRAY_ET(copysign,  _bz_copysign)
BZ_DECLARE_ARRAY_ET(drem,      _bz_drem)
BZ_DECLARE_ARRAY_ET(fmod,      _bz_fmod)
BZ_DECLARE_ARRAY_ET(hypot,     _bz_hypot)
BZ_DECLARE_ARRAY_ET(nextafter, _bz_nextafter)
BZ_DECLARE_ARRAY_ET(remainder, _bz_remainder)
BZ_DECLARE_ARRAY_ET(scalb,     _bz_scalb)
BZ_DECLARE_ARRAY_ET(unordered, _bz_unordered)
#endif

/*
 * Unary functions and operators
 */

#define BZ_DECLARE_ARRAY_ET_UOP(name, functor)                        \
template<class T1>                                                    \
_bz_inline_et                                                         \
_bz_ArrayExpr<_bz_ArrayExprUnaryOp<                                   \
    _bz_typename asExpr<T1>::T_expr,                                  \
    functor<_bz_typename asExpr<T1>::T_expr::T_numtype> > >           \
name(const ETBase<T1>& d1)                                            \
{                                                                     \
    return _bz_ArrayExpr<_bz_ArrayExprUnaryOp<                        \
        _bz_typename asExpr<T1>::T_expr,                              \
        functor<_bz_typename asExpr<T1>::T_expr::T_numtype> > >       \
      (static_cast<const T1&>(d1));                                   \
}

BZ_DECLARE_ARRAY_ET_UOP(operator-, _bz_negate)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -