LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
vectorize.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008, 2009, 2010, 2011 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 #ifndef NDARRAY_vectorize_h_INCLUDED
24 #define NDARRAY_vectorize_h_INCLUDED
25 
30 #include "ndarray_fwd.h"
31 #include "ndarray/detail/UnaryOp.h"
32 
33 #include <boost/mpl/and.hpp>
34 #include <boost/utility/enable_if.hpp>
35 
36 namespace ndarray {
37 namespace result_of {
38 
39 template <typename T1, typename T2, typename T3=void>
40 struct vectorize {
41  typedef T1 BinaryFunction;
42  typedef T2 Argument1;
43  typedef T3 Argument2;
44 
45  typename boost::mpl::if_<
46  boost::mpl::and_<
49  >,
50  typename BinaryFunction::result_type,
53 
54 };
55 
56 template <typename T1, typename T2>
57 struct vectorize<T1,T2,void> {
58  typedef T1 UnaryFunction;
59  typedef T2 Argument;
60 
61  typedef typename boost::mpl::if_<
63  typename UnaryFunction::result_type,
66 };
67 
68 } // namespace result_of
69 
72 
78 template <typename Scalar, typename UnaryFunction>
79 #ifndef DOXYGEN
80 typename boost::enable_if<typename ExpressionTraits<Scalar>::IsScalar,
81  typename UnaryFunction::result_type>::type
82 #else
83 typename UnaryFunction::result_type
84 #endif
86  UnaryFunction const & functor,
87  Scalar const & scalar
88 ) {
89  return functor(scalar);
90 }
91 
97 template <typename Derived, typename UnaryFunction>
98 detail::UnaryOpExpression<Derived,UnaryFunction>
100  UnaryFunction const & functor,
101  ExpressionBase<Derived> const & operand
102 ) {
104  static_cast<Derived const &>(operand),
105  functor
106  );
107 }
108 
114 template <typename Scalar1, typename Scalar2, typename BinaryFunction>
115 #ifndef DOXYGEN
116 typename boost::enable_if_c<
117  (ExpressionTraits<Scalar1>::IsScalar::value
118  && ExpressionTraits<Scalar2>::IsScalar::value),
119  typename BinaryFunction::result_type
120  >::type
121 #else
122 typename BinaryFunction::result_type
123 #endif
125  BinaryFunction const & functor,
126  Scalar1 const & scalar1,
127  Scalar2 const & scalar2
128 ) {
129  return functor(scalar1,scalar2);
130 }
131 
138 template <typename Derived1, typename Derived2, typename BinaryFunction>
139 detail::BinaryOpExpression<Derived1,Derived2,BinaryFunction>
141  BinaryFunction const & functor,
142  ExpressionBase<Derived1> const & operand1,
143  ExpressionBase<Derived2> const & operand2
144 ) {
146  static_cast<Derived1 const &>(operand1),
147  static_cast<Derived2 const &>(operand2),
148  functor
149  );
150 }
151 
153 
154 } // namespace ndarray
155 
156 #endif // !NDARRAY_vectorize_h_INCLUDED
Forward declarations and default template parameters for ndarray.
boost::mpl::if_< boost::mpl::and_< typename ExpressionTraits< Argument1 >::IsScalar, typename ExpressionTraits< Argument2 >::IsScalar >, typename BinaryFunction::result_type, detail::BinaryOpExpression< Argument1, Argument2, BinaryFunction > >::type type
Definition: vectorize.h:52
Lazy unary expression templates.
UnaryFunction::result_type vectorize(UnaryFunction const &functor, Scalar const &scalar)
Apply a non-mutating unary function object to a scalar.
Definition: vectorize.h:85
boost::mpl::if_< typename ExpressionTraits< Argument >::IsScalar, typename UnaryFunction::result_type, detail::UnaryOpExpression< Argument, UnaryFunction > >::type type
Definition: vectorize.h:65
boost::mpl::true_ IsScalar
CRTP base class for all multidimensional expressions.