Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
349 lines (312 loc) · 10.8 KB

File metadata and controls

349 lines (312 loc) · 10.8 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// -*- c++ -*-
/*
* Copyright (c) 2010-2012, Jim Bosch
* All rights reserved.
*
* ndarray is distributed under a simple BSD-like license;
* see the LICENSE file that should be present in the root
* of the source distribution, or alternately available at:
* https://github.com/ndarray/ndarray
*/
// THIS FILE IS MACHINE GENERATED BY SCONS. DO NOT EDIT MANUALLY.
changecom(`###')dnl
define(`FUNCTION_TAG',
`
struct $1 : public AdaptableFunctionTag<$1> {
template <typename A, typename B>
struct ScalarFunction : public $2<A,B> {
typename $2<A,B>::result_type operator()(
typename $2<A,B>::ParamA a,
typename $2<A,B>::ParamB b
) const {
return a $3 b;
}
};
};')dnl
define(`BINARY_OP',
`
template <typename Operand, typename Scalar>
#ifndef DOXYGEN
typename boost::enable_if<
typename ExpressionTraits<Scalar>::IsScalar,
detail::UnaryOpExpression< Operand, typename $1::template ExprScalar<Operand,Scalar>::Bound >
>::type
#else
<unspecified-expression-type>
#endif
$2(ExpressionBase<Operand> const & operand, Scalar const & scalar) {
return vectorize($1::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
}
template <typename Operand, typename Scalar>
#ifndef DOXYGEN
typename boost::enable_if<
typename ExpressionTraits<Scalar>::IsScalar,
detail::UnaryOpExpression< Operand, typename $1::template ScalarExpr<Operand,Scalar>::Bound >
>::type
#else
<unspecified-expression-type>
#endif
$2(Scalar const & scalar, ExpressionBase<Operand> const & operand) {
return vectorize($1::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
}
template <typename Operand1, typename Operand2>
#ifndef DOXYGEN
detail::BinaryOpExpression<
Operand1, Operand2,
typename $1::template ExprExpr<Operand1,Operand2>::BinaryFunction
>
#else
<unspecified-expression-type>
#endif
$2(ExpressionBase<Operand1> const & operand1, ExpressionBase<Operand2> const & operand2) {
return vectorize(
typename $1::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
operand1,
operand2
);
}')dnl
define(`UNARY_OP',
`
template <typename Operand>
#ifndef DOXYGEN
detail::UnaryOpExpression< Operand, $1<typename ExpressionTraits<Operand>::Element> >
#else
<unspecified-expression-type>
#endif
$2(ExpressionBase<Operand> const & operand) {
return vectorize($1<typename ExpressionTraits<Operand>::Element>(),operand);
}')dnl
#ifndef NDARRAY_operators_h_INCLUDED
#define NDARRAY_operators_h_INCLUDED
/**
* \file ndarray/operators.h \brief Arithmetic and logical operators for Array.
*/
#include "ndarray/Array.h"
#include <boost/call_traits.hpp>
#include <boost/functional.hpp>
#include <boost/utility/enable_if.hpp>
#include "ndarray/detail/UnaryOp.h"
#include "ndarray/detail/BinaryOp.h"
#include "ndarray/types.h"
namespace ndarray {
/// \cond INTERNAL
namespace detail {
/**
* \internal @class PromotingBinaryFunction
* \brief A typedef-providing base class for binary functors with numeric type promotion.
*
* \ingroup InternalGroup
*/
template <typename A, typename B>
struct PromotingBinaryFunction {
typedef A ElementA;
typedef B ElementB;
typedef A first_argument_type;
typedef B second_argument_type;
typedef typename boost::call_traits<A>::param_type ParamA;
typedef typename boost::call_traits<B>::param_type ParamB;
typedef typename Promote<A,B>::Type result_type;
};
/**
* \internal @class BinaryPredicate
* \brief A typedef-providing base class for binary predicates.
*
* \ingroup InternalGroup
*/
template <typename A, typename B>
struct BinaryPredicate {
typedef A ElementA;
typedef B ElementB;
typedef A first_argument_type;
typedef B second_argument_type;
typedef typename boost::call_traits<A>::param_type ParamA;
typedef typename boost::call_traits<B>::param_type ParamB;
typedef bool result_type;
};
/**
* \internal @class AdaptableFunctionTag
* \brief A CRTP base class for non-template classes that contain a templated functor.
*
* \ingroup InternalGroup
*/
template <typename Derived>
struct AdaptableFunctionTag {
template <typename OperandB, typename A>
struct ScalarExpr {
typedef typename Derived::template ScalarFunction<
A, typename ExpressionTraits<OperandB>::Element
> BinaryFunction;
typedef boost::binder1st<BinaryFunction> Bound;
static Bound bind(A const & scalar) {
return Bound(BinaryFunction(),scalar);
}
};
template <typename OperandA, typename B>
struct ExprScalar {
typedef typename Derived::template ScalarFunction<
typename ExpressionTraits<OperandA>::Element, B
> BinaryFunction;
typedef boost::binder2nd<BinaryFunction> Bound;
static Bound bind(B const & scalar) {
return Bound(BinaryFunction(),scalar);
}
};
template <typename OperandA, typename OperandB>
struct ExprExpr {
typedef typename Derived::template ScalarFunction<
typename ExpressionTraits<OperandA>::Element,
typename ExpressionTraits<OperandB>::Element
> BinaryFunction;
};
};
/**
* \internal @class BitwiseNot
* \ingroup InternalGroup
* \brief An STL Unary Function class for bitwise NOT (unary ~).
*/
template <typename T>
struct BitwiseNot {
typedef T argument_type;
typedef T result_type;
result_type operator()(argument_type arg) const { return ~arg; }
};
FUNCTION_TAG(PlusTag,PromotingBinaryFunction,+)
FUNCTION_TAG(MinusTag,PromotingBinaryFunction,-)
FUNCTION_TAG(MultipliesTag,PromotingBinaryFunction,*)
FUNCTION_TAG(DividesTag,PromotingBinaryFunction,/)
FUNCTION_TAG(ModulusTag,PromotingBinaryFunction,%)
FUNCTION_TAG(BitwiseXorTag,PromotingBinaryFunction,^)
FUNCTION_TAG(BitwiseOrTag,PromotingBinaryFunction,|)
FUNCTION_TAG(BitwiseAndTag,PromotingBinaryFunction,&)
FUNCTION_TAG(BitwiseLeftShiftTag,PromotingBinaryFunction,<<)
FUNCTION_TAG(BitwiseRightShiftTag,PromotingBinaryFunction,>>)
FUNCTION_TAG(EqualToTag,BinaryPredicate,==)
FUNCTION_TAG(NotEqualToTag,BinaryPredicate,!=)
FUNCTION_TAG(LessTag,BinaryPredicate,<)
FUNCTION_TAG(GreaterTag,BinaryPredicate,>)
FUNCTION_TAG(LessEqualTag,BinaryPredicate,<=)
FUNCTION_TAG(GreaterEqualTag,BinaryPredicate,>=)
FUNCTION_TAG(LogicalAnd,BinaryPredicate,&&)
FUNCTION_TAG(LogicalOr,BinaryPredicate,||)
} // namespace detail
/// \endcond
/// \addtogroup ndarrayOpGroup
/// @{
BINARY_OP(detail::PlusTag,operator+)
BINARY_OP(detail::MinusTag,operator-)
BINARY_OP(detail::MultipliesTag,operator*)
BINARY_OP(detail::DividesTag,operator/)
BINARY_OP(detail::ModulusTag,operator%)
BINARY_OP(detail::BitwiseXorTag,operator^)
BINARY_OP(detail::BitwiseOrTag,operator|)
BINARY_OP(detail::BitwiseAndTag,operator&)
BINARY_OP(detail::BitwiseLeftShiftTag,operator<<)
BINARY_OP(detail::BitwiseRightShiftTag,operator>>)
BINARY_OP(detail::EqualToTag, equal)
BINARY_OP(detail::NotEqualToTag, not_equal)
BINARY_OP(detail::LessTag, less)
BINARY_OP(detail::GreaterTag, greater)
BINARY_OP(detail::LessEqualTag, less_equal)
BINARY_OP(detail::GreaterEqualTag, great_equal)
BINARY_OP(detail::LogicalAnd, logical_and)
BINARY_OP(detail::LogicalOr, logical_or)
UNARY_OP(std::negate,operator-)
UNARY_OP(std::logical_not, logical_not)
UNARY_OP(detail::BitwiseNot,operator~)
/// @}
template <typename Scalar>
inline typename boost::enable_if<typename ExpressionTraits<Scalar>::IsScalar, bool>::type
any(Scalar const & scalar) {
return bool(scalar);
}
/**
* \brief Return true if any of the elements of the given expression are true.
*
* \ingroup MainGroup
*/
template <typename Derived>
inline bool
any(ExpressionBase<Derived> const & expr) {
typename Derived::Iterator const i_end = expr.end();
for (typename Derived::Iterator i = expr.begin(); i != i_end; ++i) {
if (any(*i)) return true;
}
return false;
}
template <typename Scalar>
inline typename boost::enable_if<typename ExpressionTraits<Scalar>::IsScalar, bool>::type
all(Scalar const & scalar) {
return bool(scalar);
}
/**
* \brief Return true if all of the elements of the given expression are true.
*
* \ingroup MainGroup
*/
template <typename Derived>
inline bool
all(ExpressionBase<Derived> const & expr) {
typename Derived::Iterator const i_end = expr.end();
for (typename Derived::Iterator i = expr.begin(); i != i_end; ++i) {
if (!all(*i)) return false;
}
return true;
}
template <typename Scalar1, typename Scalar2>
inline typename boost::enable_if<
boost::mpl::and_<
typename ExpressionTraits<Scalar1>::IsScalar,
typename ExpressionTraits<Scalar2>::IsScalar
>,
bool
>::type
allclose(Scalar1 const & scalar1, Scalar2 const & scalar2, double tol=1E-8) {
ApproximatelyEqual<Scalar1,Scalar2> func(tol);
return func(scalar1, scalar2);
}
template <typename Scalar, typename Derived>
inline typename boost::enable_if<typename ExpressionTraits<Scalar>::IsScalar,bool>::type
allclose(Scalar const & scalar, ExpressionBase<Derived> const & expr, double tol=1E-8) {
ApproximatelyEqual<Scalar,typename Derived::Element> func(tol);
typename Derived::Iterator const i_end = expr.end();
for (typename Derived::Iterator i = expr.begin(); i != i_end; ++i) {
if (!allclose(scalar, *i, tol)) return false;
}
return true;
}
template <typename Scalar, typename Derived>
inline typename boost::enable_if<typename ExpressionTraits<Scalar>::IsScalar,bool>::type
allclose(ExpressionBase<Derived> const & expr, Scalar const & scalar, double tol=1E-8) {
return allclose(scalar, expr, tol);
}
template <typename Derived1, typename Derived2>
inline bool
allclose(ExpressionBase<Derived1> const & expr1, ExpressionBase<Derived2> const & expr2, double tol=1E-8) {
typename Derived1::Iterator const i_end = expr1.end();
typename Derived1::Iterator i = expr1.begin();
typename Derived2::Iterator j = expr2.begin();
for (; i != i_end; ++i, ++j) {
if (!allclose(*i, *j, tol)) return false;
}
return true;
}
template <typename Scalar>
inline typename boost::enable_if<typename ExpressionTraits<Scalar>::IsScalar, Scalar>::type
sum(Scalar const & scalar) { return scalar; }
/**
* \brief Return the sum of all elements of the given expression.
*
* \ingroup MainGroup
*/
template <typename Derived>
inline typename Derived::Element
sum(ExpressionBase<Derived> const & expr) {
typename Derived::Iterator const i_end = expr.end();
typename Derived::Element total = static_cast<typename Derived::Element>(0);
for (typename Derived::Iterator i = expr.begin(); i != i_end; ++i) {
total += sum(*i);
}
return total;
}
} // namespace ndarray
#endif // !NDARRAY_operators_h_INCLUDED
Morty Proxy This is a proxified and sanitized view of the page, visit original site.