/usr/include/blitz/ops.h is in libblitz0-dev 1:0.10-3.3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | // -*- 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
|