23 #ifndef NDARRAY_operators_h_INCLUDED
24 #define NDARRAY_operators_h_INCLUDED
31 #include <boost/call_traits.hpp>
32 #include <boost/functional.hpp>
33 #include <boost/utility/enable_if.hpp>
50 template <
typename A,
typename B>
51 struct PromotingBinaryFunction {
54 typedef A first_argument_type;
55 typedef B second_argument_type;
56 typedef typename boost::call_traits<A>::param_type ParamA;
57 typedef typename boost::call_traits<B>::param_type ParamB;
58 typedef typename Promote<A,B>::Type result_type;
67 template <
typename A,
typename B>
68 struct BinaryPredicate {
71 typedef A first_argument_type;
72 typedef B second_argument_type;
73 typedef typename boost::call_traits<A>::param_type ParamA;
74 typedef typename boost::call_traits<B>::param_type ParamB;
75 typedef bool result_type;
84 template <
typename Derived>
85 struct AdaptableFunctionTag {
87 template <
typename OperandB,
typename A>
89 typedef typename Derived::template ScalarFunction<
90 A,
typename ExpressionTraits<OperandB>::Element
92 typedef boost::binder1st<BinaryFunction> Bound;
93 static Bound bind(A
const & scalar) {
94 return Bound(BinaryFunction(),scalar);
98 template <
typename OperandA,
typename B>
100 typedef typename Derived::template ScalarFunction<
101 typename ExpressionTraits<OperandA>::Element, B
103 typedef boost::binder2nd<BinaryFunction> Bound;
104 static Bound bind(B
const & scalar) {
105 return Bound(BinaryFunction(),scalar);
109 template <
typename OperandA,
typename OperandB>
111 typedef typename Derived::template ScalarFunction<
112 typename ExpressionTraits<OperandA>::Element,
113 typename ExpressionTraits<OperandB>::Element
124 template <
typename T>
126 typedef T argument_type;
127 typedef T result_type;
129 result_type operator()(argument_type arg)
const {
return ~arg; }
133 struct PlusTag :
public AdaptableFunctionTag<PlusTag> {
134 template <
typename A,
typename B>
135 struct ScalarFunction :
public PromotingBinaryFunction<A,B> {
136 typename PromotingBinaryFunction<A,B>::result_type operator()(
137 typename PromotingBinaryFunction<A,B>::ParamA a,
138 typename PromotingBinaryFunction<A,B>::ParamB
b
145 struct MinusTag :
public AdaptableFunctionTag<MinusTag> {
146 template <
typename A,
typename B>
147 struct ScalarFunction :
public PromotingBinaryFunction<A,B> {
148 typename PromotingBinaryFunction<A,B>::result_type operator()(
149 typename PromotingBinaryFunction<A,B>::ParamA a,
150 typename PromotingBinaryFunction<A,B>::ParamB
b
157 struct MultipliesTag :
public AdaptableFunctionTag<MultipliesTag> {
158 template <
typename A,
typename B>
159 struct ScalarFunction :
public PromotingBinaryFunction<A,B> {
160 typename PromotingBinaryFunction<A,B>::result_type operator()(
161 typename PromotingBinaryFunction<A,B>::ParamA a,
162 typename PromotingBinaryFunction<A,B>::ParamB
b
169 struct DividesTag :
public AdaptableFunctionTag<DividesTag> {
170 template <
typename A,
typename B>
171 struct ScalarFunction :
public PromotingBinaryFunction<A,B> {
172 typename PromotingBinaryFunction<A,B>::result_type operator()(
173 typename PromotingBinaryFunction<A,B>::ParamA a,
174 typename PromotingBinaryFunction<A,B>::ParamB
b
181 struct ModulusTag :
public AdaptableFunctionTag<ModulusTag> {
182 template <
typename A,
typename B>
183 struct ScalarFunction :
public PromotingBinaryFunction<A,B> {
184 typename PromotingBinaryFunction<A,B>::result_type operator()(
185 typename PromotingBinaryFunction<A,B>::ParamA a,
186 typename PromotingBinaryFunction<A,B>::ParamB
b
193 struct BitwiseXorTag :
public AdaptableFunctionTag<BitwiseXorTag> {
194 template <
typename A,
typename B>
195 struct ScalarFunction :
public PromotingBinaryFunction<A,B> {
196 typename PromotingBinaryFunction<A,B>::result_type operator()(
197 typename PromotingBinaryFunction<A,B>::ParamA a,
198 typename PromotingBinaryFunction<A,B>::ParamB
b
205 struct BitwiseOrTag :
public AdaptableFunctionTag<BitwiseOrTag> {
206 template <
typename A,
typename B>
207 struct ScalarFunction :
public PromotingBinaryFunction<A,B> {
208 typename PromotingBinaryFunction<A,B>::result_type operator()(
209 typename PromotingBinaryFunction<A,B>::ParamA a,
210 typename PromotingBinaryFunction<A,B>::ParamB
b
217 struct BitwiseAndTag :
public AdaptableFunctionTag<BitwiseAndTag> {
218 template <
typename A,
typename B>
219 struct ScalarFunction :
public PromotingBinaryFunction<A,B> {
220 typename PromotingBinaryFunction<A,B>::result_type operator()(
221 typename PromotingBinaryFunction<A,B>::ParamA a,
222 typename PromotingBinaryFunction<A,B>::ParamB
b
229 struct BitwiseLeftShiftTag :
public AdaptableFunctionTag<BitwiseLeftShiftTag> {
230 template <
typename A,
typename B>
231 struct ScalarFunction :
public PromotingBinaryFunction<A,B> {
232 typename PromotingBinaryFunction<A,B>::result_type operator()(
233 typename PromotingBinaryFunction<A,B>::ParamA a,
234 typename PromotingBinaryFunction<A,B>::ParamB
b
241 struct BitwiseRightShiftTag :
public AdaptableFunctionTag<BitwiseRightShiftTag> {
242 template <
typename A,
typename B>
243 struct ScalarFunction :
public PromotingBinaryFunction<A,B> {
244 typename PromotingBinaryFunction<A,B>::result_type operator()(
245 typename PromotingBinaryFunction<A,B>::ParamA a,
246 typename PromotingBinaryFunction<A,B>::ParamB
b
254 struct EqualToTag :
public AdaptableFunctionTag<EqualToTag> {
255 template <
typename A,
typename B>
256 struct ScalarFunction :
public BinaryPredicate<A,B> {
257 typename BinaryPredicate<A,B>::result_type operator()(
258 typename BinaryPredicate<A,B>::ParamA a,
259 typename BinaryPredicate<A,B>::ParamB
b
266 struct NotEqualToTag :
public AdaptableFunctionTag<NotEqualToTag> {
267 template <
typename A,
typename B>
268 struct ScalarFunction :
public BinaryPredicate<A,B> {
269 typename BinaryPredicate<A,B>::result_type operator()(
270 typename BinaryPredicate<A,B>::ParamA a,
271 typename BinaryPredicate<A,B>::ParamB
b
278 struct LessTag :
public AdaptableFunctionTag<LessTag> {
279 template <
typename A,
typename B>
280 struct ScalarFunction :
public BinaryPredicate<A,B> {
281 typename BinaryPredicate<A,B>::result_type operator()(
282 typename BinaryPredicate<A,B>::ParamA a,
283 typename BinaryPredicate<A,B>::ParamB
b
290 struct GreaterTag :
public AdaptableFunctionTag<GreaterTag> {
291 template <
typename A,
typename B>
292 struct ScalarFunction :
public BinaryPredicate<A,B> {
293 typename BinaryPredicate<A,B>::result_type operator()(
294 typename BinaryPredicate<A,B>::ParamA a,
295 typename BinaryPredicate<A,B>::ParamB
b
302 struct LessEqualTag :
public AdaptableFunctionTag<LessEqualTag> {
303 template <
typename A,
typename B>
304 struct ScalarFunction :
public BinaryPredicate<A,B> {
305 typename BinaryPredicate<A,B>::result_type operator()(
306 typename BinaryPredicate<A,B>::ParamA a,
307 typename BinaryPredicate<A,B>::ParamB
b
314 struct GreaterEqualTag :
public AdaptableFunctionTag<GreaterEqualTag> {
315 template <
typename A,
typename B>
316 struct ScalarFunction :
public BinaryPredicate<A,B> {
317 typename BinaryPredicate<A,B>::result_type operator()(
318 typename BinaryPredicate<A,B>::ParamA a,
319 typename BinaryPredicate<A,B>::ParamB
b
326 struct LogicalAnd :
public AdaptableFunctionTag<LogicalAnd> {
327 template <
typename A,
typename B>
328 struct ScalarFunction :
public BinaryPredicate<A,B> {
329 typename BinaryPredicate<A,B>::result_type operator()(
330 typename BinaryPredicate<A,B>::ParamA a,
331 typename BinaryPredicate<A,B>::ParamB
b
338 struct LogicalOr :
public AdaptableFunctionTag<LogicalOr> {
339 template <
typename A,
typename B>
340 struct ScalarFunction :
public BinaryPredicate<A,B> {
341 typename BinaryPredicate<A,B>::result_type operator()(
342 typename BinaryPredicate<A,B>::ParamA a,
343 typename BinaryPredicate<A,B>::ParamB
b
356 template <
typename Operand,
typename Scalar>
358 typename boost::enable_if<
359 typename ExpressionTraits<Scalar>::IsScalar,
360 detail::UnaryOpExpression< Operand, typename detail::PlusTag::template ExprScalar<Operand,Scalar>::Bound >
363 <unspecified-expression-type>
366 return vectorize(detail::PlusTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
369 template <
typename Operand,
typename Scalar>
371 typename boost::enable_if<
372 typename ExpressionTraits<Scalar>::IsScalar,
373 detail::UnaryOpExpression< Operand, typename detail::PlusTag::template ScalarExpr<Operand,Scalar>::Bound >
376 <unspecified-expression-type>
379 return vectorize(detail::PlusTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
382 template <
typename Operand1,
typename Operand2>
384 detail::BinaryOpExpression<
386 typename detail::PlusTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
389 <unspecified-expression-type>
393 typename detail::PlusTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
399 template <
typename Operand,
typename Scalar>
401 typename boost::enable_if<
402 typename ExpressionTraits<Scalar>::IsScalar,
403 detail::UnaryOpExpression< Operand, typename detail::MinusTag::template ExprScalar<Operand,Scalar>::Bound >
406 <unspecified-expression-type>
409 return vectorize(detail::MinusTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
412 template <
typename Operand,
typename Scalar>
414 typename boost::enable_if<
415 typename ExpressionTraits<Scalar>::IsScalar,
416 detail::UnaryOpExpression< Operand, typename detail::MinusTag::template ScalarExpr<Operand,Scalar>::Bound >
419 <unspecified-expression-type>
422 return vectorize(detail::MinusTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
425 template <
typename Operand1,
typename Operand2>
427 detail::BinaryOpExpression<
429 typename detail::MinusTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
432 <unspecified-expression-type>
436 typename detail::MinusTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
442 template <
typename Operand,
typename Scalar>
444 typename boost::enable_if<
445 typename ExpressionTraits<Scalar>::IsScalar,
446 detail::UnaryOpExpression< Operand, typename detail::MultipliesTag::template ExprScalar<Operand,Scalar>::Bound >
449 <unspecified-expression-type>
452 return vectorize(detail::MultipliesTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
455 template <
typename Operand,
typename Scalar>
457 typename boost::enable_if<
458 typename ExpressionTraits<Scalar>::IsScalar,
459 detail::UnaryOpExpression< Operand, typename detail::MultipliesTag::template ScalarExpr<Operand,Scalar>::Bound >
462 <unspecified-expression-type>
465 return vectorize(detail::MultipliesTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
468 template <
typename Operand1,
typename Operand2>
470 detail::BinaryOpExpression<
472 typename detail::MultipliesTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
475 <unspecified-expression-type>
479 typename detail::MultipliesTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
485 template <
typename Operand,
typename Scalar>
487 typename boost::enable_if<
488 typename ExpressionTraits<Scalar>::IsScalar,
489 detail::UnaryOpExpression< Operand, typename detail::DividesTag::template ExprScalar<Operand,Scalar>::Bound >
492 <unspecified-expression-type>
495 return vectorize(detail::DividesTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
498 template <
typename Operand,
typename Scalar>
500 typename boost::enable_if<
501 typename ExpressionTraits<Scalar>::IsScalar,
502 detail::UnaryOpExpression< Operand, typename detail::DividesTag::template ScalarExpr<Operand,Scalar>::Bound >
505 <unspecified-expression-type>
508 return vectorize(detail::DividesTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
511 template <
typename Operand1,
typename Operand2>
513 detail::BinaryOpExpression<
515 typename detail::DividesTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
518 <unspecified-expression-type>
522 typename detail::DividesTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
528 template <
typename Operand,
typename Scalar>
530 typename boost::enable_if<
531 typename ExpressionTraits<Scalar>::IsScalar,
532 detail::UnaryOpExpression< Operand, typename detail::ModulusTag::template ExprScalar<Operand,Scalar>::Bound >
535 <unspecified-expression-type>
538 return vectorize(detail::ModulusTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
541 template <
typename Operand,
typename Scalar>
543 typename boost::enable_if<
544 typename ExpressionTraits<Scalar>::IsScalar,
545 detail::UnaryOpExpression< Operand, typename detail::ModulusTag::template ScalarExpr<Operand,Scalar>::Bound >
548 <unspecified-expression-type>
551 return vectorize(detail::ModulusTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
554 template <
typename Operand1,
typename Operand2>
556 detail::BinaryOpExpression<
558 typename detail::ModulusTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
561 <unspecified-expression-type>
565 typename detail::ModulusTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
571 template <
typename Operand,
typename Scalar>
573 typename boost::enable_if<
574 typename ExpressionTraits<Scalar>::IsScalar,
575 detail::UnaryOpExpression< Operand, typename detail::BitwiseXorTag::template ExprScalar<Operand,Scalar>::Bound >
578 <unspecified-expression-type>
581 return vectorize(detail::BitwiseXorTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
584 template <
typename Operand,
typename Scalar>
586 typename boost::enable_if<
587 typename ExpressionTraits<Scalar>::IsScalar,
588 detail::UnaryOpExpression< Operand, typename detail::BitwiseXorTag::template ScalarExpr<Operand,Scalar>::Bound >
591 <unspecified-expression-type>
594 return vectorize(detail::BitwiseXorTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
597 template <
typename Operand1,
typename Operand2>
599 detail::BinaryOpExpression<
601 typename detail::BitwiseXorTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
604 <unspecified-expression-type>
608 typename detail::BitwiseXorTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
614 template <
typename Operand,
typename Scalar>
616 typename boost::enable_if<
617 typename ExpressionTraits<Scalar>::IsScalar,
618 detail::UnaryOpExpression< Operand, typename detail::BitwiseOrTag::template ExprScalar<Operand,Scalar>::Bound >
621 <unspecified-expression-type>
624 return vectorize(detail::BitwiseOrTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
627 template <
typename Operand,
typename Scalar>
629 typename boost::enable_if<
630 typename ExpressionTraits<Scalar>::IsScalar,
631 detail::UnaryOpExpression< Operand, typename detail::BitwiseOrTag::template ScalarExpr<Operand,Scalar>::Bound >
634 <unspecified-expression-type>
637 return vectorize(detail::BitwiseOrTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
640 template <
typename Operand1,
typename Operand2>
642 detail::BinaryOpExpression<
644 typename detail::BitwiseOrTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
647 <unspecified-expression-type>
651 typename detail::BitwiseOrTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
657 template <
typename Operand,
typename Scalar>
659 typename boost::enable_if<
660 typename ExpressionTraits<Scalar>::IsScalar,
661 detail::UnaryOpExpression< Operand, typename detail::BitwiseAndTag::template ExprScalar<Operand,Scalar>::Bound >
664 <unspecified-expression-type>
667 return vectorize(detail::BitwiseAndTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
670 template <
typename Operand,
typename Scalar>
672 typename boost::enable_if<
673 typename ExpressionTraits<Scalar>::IsScalar,
674 detail::UnaryOpExpression< Operand, typename detail::BitwiseAndTag::template ScalarExpr<Operand,Scalar>::Bound >
677 <unspecified-expression-type>
680 return vectorize(detail::BitwiseAndTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
683 template <
typename Operand1,
typename Operand2>
685 detail::BinaryOpExpression<
687 typename detail::BitwiseAndTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
690 <unspecified-expression-type>
694 typename detail::BitwiseAndTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
700 template <
typename Operand,
typename Scalar>
702 typename boost::enable_if<
703 typename ExpressionTraits<Scalar>::IsScalar,
704 detail::UnaryOpExpression< Operand, typename detail::BitwiseLeftShiftTag::template ExprScalar<Operand,Scalar>::Bound >
707 <unspecified-expression-type>
709 operator<<(ExpressionBase<Operand>
const & operand, Scalar
const & scalar) {
710 return vectorize(detail::BitwiseLeftShiftTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
713 template <
typename Operand,
typename Scalar>
715 typename boost::enable_if<
716 typename ExpressionTraits<Scalar>::IsScalar,
717 detail::UnaryOpExpression< Operand, typename detail::BitwiseLeftShiftTag::template ScalarExpr<Operand,Scalar>::Bound >
720 <unspecified-expression-type>
722 operator<<(Scalar const & scalar, ExpressionBase<Operand>
const & operand) {
723 return vectorize(detail::BitwiseLeftShiftTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
726 template <
typename Operand1,
typename Operand2>
728 detail::BinaryOpExpression<
730 typename detail::BitwiseLeftShiftTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
733 <unspecified-expression-type>
737 typename detail::BitwiseLeftShiftTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
743 template <
typename Operand,
typename Scalar>
745 typename boost::enable_if<
746 typename ExpressionTraits<Scalar>::IsScalar,
747 detail::UnaryOpExpression< Operand, typename detail::BitwiseRightShiftTag::template ExprScalar<Operand,Scalar>::Bound >
750 <unspecified-expression-type>
753 return vectorize(detail::BitwiseRightShiftTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
756 template <
typename Operand,
typename Scalar>
758 typename boost::enable_if<
759 typename ExpressionTraits<Scalar>::IsScalar,
760 detail::UnaryOpExpression< Operand, typename detail::BitwiseRightShiftTag::template ScalarExpr<Operand,Scalar>::Bound >
763 <unspecified-expression-type>
766 return vectorize(detail::BitwiseRightShiftTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
769 template <
typename Operand1,
typename Operand2>
771 detail::BinaryOpExpression<
773 typename detail::BitwiseRightShiftTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
776 <unspecified-expression-type>
780 typename detail::BitwiseRightShiftTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
787 template <
typename Operand,
typename Scalar>
789 typename boost::enable_if<
790 typename ExpressionTraits<Scalar>::IsScalar,
791 detail::UnaryOpExpression< Operand, typename detail::EqualToTag::template ExprScalar<Operand,Scalar>::Bound >
794 <unspecified-expression-type>
797 return vectorize(detail::EqualToTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
800 template <
typename Operand,
typename Scalar>
802 typename boost::enable_if<
803 typename ExpressionTraits<Scalar>::IsScalar,
804 detail::UnaryOpExpression< Operand, typename detail::EqualToTag::template ScalarExpr<Operand,Scalar>::Bound >
807 <unspecified-expression-type>
810 return vectorize(detail::EqualToTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
813 template <
typename Operand1,
typename Operand2>
815 detail::BinaryOpExpression<
817 typename detail::EqualToTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
820 <unspecified-expression-type>
824 typename detail::EqualToTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
830 template <
typename Operand,
typename Scalar>
832 typename boost::enable_if<
833 typename ExpressionTraits<Scalar>::IsScalar,
834 detail::UnaryOpExpression< Operand, typename detail::NotEqualToTag::template ExprScalar<Operand,Scalar>::Bound >
837 <unspecified-expression-type>
840 return vectorize(detail::NotEqualToTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
843 template <
typename Operand,
typename Scalar>
845 typename boost::enable_if<
846 typename ExpressionTraits<Scalar>::IsScalar,
847 detail::UnaryOpExpression< Operand, typename detail::NotEqualToTag::template ScalarExpr<Operand,Scalar>::Bound >
850 <unspecified-expression-type>
853 return vectorize(detail::NotEqualToTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
856 template <
typename Operand1,
typename Operand2>
858 detail::BinaryOpExpression<
860 typename detail::NotEqualToTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
863 <unspecified-expression-type>
867 typename detail::NotEqualToTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
873 template <
typename Operand,
typename Scalar>
875 typename boost::enable_if<
876 typename ExpressionTraits<Scalar>::IsScalar,
877 detail::UnaryOpExpression< Operand, typename detail::LessTag::template ExprScalar<Operand,Scalar>::Bound >
880 <unspecified-expression-type>
883 return vectorize(detail::LessTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
886 template <
typename Operand,
typename Scalar>
888 typename boost::enable_if<
889 typename ExpressionTraits<Scalar>::IsScalar,
890 detail::UnaryOpExpression< Operand, typename detail::LessTag::template ScalarExpr<Operand,Scalar>::Bound >
893 <unspecified-expression-type>
896 return vectorize(detail::LessTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
899 template <
typename Operand1,
typename Operand2>
901 detail::BinaryOpExpression<
903 typename detail::LessTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
906 <unspecified-expression-type>
910 typename detail::LessTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
916 template <
typename Operand,
typename Scalar>
918 typename boost::enable_if<
919 typename ExpressionTraits<Scalar>::IsScalar,
920 detail::UnaryOpExpression< Operand, typename detail::GreaterTag::template ExprScalar<Operand,Scalar>::Bound >
923 <unspecified-expression-type>
926 return vectorize(detail::GreaterTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
929 template <
typename Operand,
typename Scalar>
931 typename boost::enable_if<
932 typename ExpressionTraits<Scalar>::IsScalar,
933 detail::UnaryOpExpression< Operand, typename detail::GreaterTag::template ScalarExpr<Operand,Scalar>::Bound >
936 <unspecified-expression-type>
939 return vectorize(detail::GreaterTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
942 template <
typename Operand1,
typename Operand2>
944 detail::BinaryOpExpression<
946 typename detail::GreaterTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
949 <unspecified-expression-type>
953 typename detail::GreaterTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
959 template <
typename Operand,
typename Scalar>
961 typename boost::enable_if<
962 typename ExpressionTraits<Scalar>::IsScalar,
963 detail::UnaryOpExpression< Operand, typename detail::LessEqualTag::template ExprScalar<Operand,Scalar>::Bound >
966 <unspecified-expression-type>
969 return vectorize(detail::LessEqualTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
972 template <
typename Operand,
typename Scalar>
974 typename boost::enable_if<
975 typename ExpressionTraits<Scalar>::IsScalar,
976 detail::UnaryOpExpression< Operand, typename detail::LessEqualTag::template ScalarExpr<Operand,Scalar>::Bound >
979 <unspecified-expression-type>
982 return vectorize(detail::LessEqualTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
985 template <
typename Operand1,
typename Operand2>
987 detail::BinaryOpExpression<
989 typename detail::LessEqualTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
992 <unspecified-expression-type>
996 typename detail::LessEqualTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
1002 template <
typename Operand,
typename Scalar>
1004 typename boost::enable_if<
1005 typename ExpressionTraits<Scalar>::IsScalar,
1006 detail::UnaryOpExpression< Operand, typename detail::GreaterEqualTag::template ExprScalar<Operand,Scalar>::Bound >
1009 <unspecified-expression-type>
1012 return vectorize(detail::GreaterEqualTag::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
1015 template <
typename Operand,
typename Scalar>
1017 typename boost::enable_if<
1018 typename ExpressionTraits<Scalar>::IsScalar,
1019 detail::UnaryOpExpression< Operand, typename detail::GreaterEqualTag::template ScalarExpr<Operand,Scalar>::Bound >
1022 <unspecified-expression-type>
1025 return vectorize(detail::GreaterEqualTag::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
1028 template <
typename Operand1,
typename Operand2>
1030 detail::BinaryOpExpression<
1032 typename detail::GreaterEqualTag::template ExprExpr<Operand1,Operand2>::BinaryFunction
1035 <unspecified-expression-type>
1039 typename detail::GreaterEqualTag::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
1045 template <
typename Operand,
typename Scalar>
1047 typename boost::enable_if<
1048 typename ExpressionTraits<Scalar>::IsScalar,
1049 detail::UnaryOpExpression< Operand, typename detail::LogicalAnd::template ExprScalar<Operand,Scalar>::Bound >
1052 <unspecified-expression-type>
1055 return vectorize(detail::LogicalAnd::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
1058 template <
typename Operand,
typename Scalar>
1060 typename boost::enable_if<
1061 typename ExpressionTraits<Scalar>::IsScalar,
1062 detail::UnaryOpExpression< Operand, typename detail::LogicalAnd::template ScalarExpr<Operand,Scalar>::Bound >
1065 <unspecified-expression-type>
1068 return vectorize(detail::LogicalAnd::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
1071 template <
typename Operand1,
typename Operand2>
1073 detail::BinaryOpExpression<
1075 typename detail::LogicalAnd::template ExprExpr<Operand1,Operand2>::BinaryFunction
1078 <unspecified-expression-type>
1082 typename detail::LogicalAnd::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
1088 template <
typename Operand,
typename Scalar>
1090 typename boost::enable_if<
1091 typename ExpressionTraits<Scalar>::IsScalar,
1092 detail::UnaryOpExpression< Operand, typename detail::LogicalOr::template ExprScalar<Operand,Scalar>::Bound >
1095 <unspecified-expression-type>
1098 return vectorize(detail::LogicalOr::template ExprScalar<Operand,Scalar>::bind(scalar),operand);
1101 template <
typename Operand,
typename Scalar>
1103 typename boost::enable_if<
1104 typename ExpressionTraits<Scalar>::IsScalar,
1105 detail::UnaryOpExpression< Operand, typename detail::LogicalOr::template ScalarExpr<Operand,Scalar>::Bound >
1108 <unspecified-expression-type>
1111 return vectorize(detail::LogicalOr::template ScalarExpr<Operand,Scalar>::bind(scalar),operand);
1114 template <
typename Operand1,
typename Operand2>
1116 detail::BinaryOpExpression<
1118 typename detail::LogicalOr::template ExprExpr<Operand1,Operand2>::BinaryFunction
1121 <unspecified-expression-type>
1125 typename detail::LogicalOr::template ExprExpr<Operand1,Operand2>::BinaryFunction(),
1132 template <
typename Operand>
1134 detail::UnaryOpExpression< Operand, std::negate<typename ExpressionTraits<Operand>::Element> >
1136 <unspecified-expression-type>
1142 template <
typename Operand>
1144 detail::UnaryOpExpression< Operand, std::logical_not<typename ExpressionTraits<Operand>::Element> >
1146 <unspecified-expression-type>
1152 template <
typename Operand>
1154 detail::UnaryOpExpression< Operand, detail::BitwiseNot<typename ExpressionTraits<Operand>::Element> >
1156 <unspecified-expression-type>
1163 template <
typename Scalar>
1164 inline typename boost::enable_if<typename ExpressionTraits<Scalar>::IsScalar,
bool>::type
1166 return bool(scalar);
1174 template <
typename Derived>
1177 typename Derived::Iterator
const i_end = expr.
end();
1178 for (
typename Derived::Iterator i = expr.
begin(); i != i_end; ++i) {
1179 if (
any(*i))
return true;
1184 template <
typename Scalar>
1185 inline typename boost::enable_if<typename ExpressionTraits<Scalar>::IsScalar,
bool>::type
1187 return bool(scalar);
1195 template <
typename Derived>
1198 typename Derived::Iterator
const i_end = expr.
end();
1199 for (
typename Derived::Iterator i = expr.
begin(); i != i_end; ++i) {
1200 if (!
all(*i))
return false;
1205 template <
typename Scalar1,
typename Scalar2>
1206 inline typename boost::enable_if<
1208 typename ExpressionTraits<Scalar1>::IsScalar,
1209 typename ExpressionTraits<Scalar2>::IsScalar
1213 allclose(Scalar1
const & scalar1, Scalar2
const & scalar2,
double tol=1E-8) {
1215 return func(scalar1, scalar2);
1218 template <
typename Scalar,
typename Derived>
1219 inline typename boost::enable_if<typename ExpressionTraits<Scalar>::IsScalar,
bool>::type
1222 typename Derived::Iterator
const i_end = expr.
end();
1223 for (
typename Derived::Iterator i = expr.
begin(); i != i_end; ++i) {
1224 if (!
allclose(scalar, *i, tol))
return false;
1229 template <
typename Scalar,
typename Derived>
1230 inline typename boost::enable_if<typename ExpressionTraits<Scalar>::IsScalar,
bool>::type
1232 return allclose(scalar, expr, tol);
1235 template <
typename Derived1,
typename Derived2>
1238 typename Derived1::Iterator
const i_end = expr1.
end();
1239 typename Derived1::Iterator i = expr1.
begin();
1240 typename Derived2::Iterator j = expr2.
begin();
1241 for (; i != i_end; ++i, ++j) {
1242 if (!
allclose(*i, *j, tol))
return false;
1248 template <
typename Scalar>
1249 inline typename boost::enable_if<typename ExpressionTraits<Scalar>::IsScalar, Scalar>::type
1250 sum(Scalar
const & scalar) {
return scalar; }
1258 template <
typename Derived>
1259 inline typename Derived::Element
1261 typename Derived::Iterator
const i_end = expr.
end();
1262 typename Derived::Element total =
static_cast<typename Derived::Element
>(0);
1263 for (
typename Derived::Iterator i = expr.
begin(); i != i_end; ++i) {
1272 #endif // !NDARRAY_operators_h_INCLUDED
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)
< unspecified-expression-type > operator-(ExpressionBase< Operand > const &operand, Scalar const &scalar)
< unspecified-expression-type > not_equal(ExpressionBase< Operand > const &operand, Scalar const &scalar)
< unspecified-expression-type > less(ExpressionBase< Operand > const &operand, Scalar const &scalar)
< unspecified-expression-type > logical_and(ExpressionBase< Operand > const &operand, Scalar const &scalar)
< unspecified-expression-type > operator~(ExpressionBase< Operand > const &operand)
< unspecified-expression-type > operator/(ExpressionBase< Operand > const &operand, Scalar const &scalar)
< unspecified-expression-type > less_equal(ExpressionBase< Operand > const &operand, Scalar const &scalar)
< unspecified-expression-type > greater(ExpressionBase< Operand > const &operand, Scalar const &scalar)
< unspecified-expression-type > operator+(ExpressionBase< Operand > const &operand, Scalar const &scalar)
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, bool >::type all(Scalar const &scalar)
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
Binary predicate for floating point equality comparison with tolerance.
Lazy binary expression templates.
< unspecified-expression-type > great_equal(ExpressionBase< Operand > const &operand, Scalar const &scalar)
< unspecified-expression-type > operator*(ExpressionBase< Operand > const &operand, Scalar const &scalar)
Lazy unary expression templates.
< unspecified-expression-type > operator^(ExpressionBase< Operand > const &operand, Scalar const &scalar)
< unspecified-expression-type > operator%(ExpressionBase< Operand > const &operand, Scalar const &scalar)
UnaryFunction::result_type vectorize(UnaryFunction const &functor, Scalar const &scalar)
Apply a non-mutating unary function object to a scalar.
Iterator begin() const
Return an Iterator to the beginning of the expression.
< unspecified-expression-type > equal(ExpressionBase< Operand > const &operand, Scalar const &scalar)
< unspecified-expression-type > logical_not(ExpressionBase< Operand > const &operand)
< unspecified-expression-type > logical_or(ExpressionBase< Operand > const &operand, Scalar const &scalar)
Iterator end() const
Return an Iterator to one past the end of the expression.
< unspecified-expression-type > operator&(ExpressionBase< Operand > const &operand, Scalar const &scalar)
afw::table::Key< double > b
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, bool >::type any(Scalar const &scalar)
< unspecified-expression-type > operator|(ExpressionBase< Operand > const &operand, Scalar const &scalar)
< unspecified-expression-type > operator>>(ExpressionBase< Operand > const &operand, Scalar const &scalar)
CRTP base class for all multidimensional expressions.