BayesOpt
ublas_elementwise.hpp
Go to the documentation of this file.
1 
2 /*
3 -------------------------------------------------------------------------
4  This file is part of BayesOpt, an efficient C++ library for
5  Bayesian optimization.
6 
7  Copyright (C) 2011-2015 Ruben Martinez-Cantin <rmcantin@unizar.es>
8 
9  BayesOpt is free software: you can redistribute it and/or modify it
10  under the terms of the GNU Affero 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  BayesOpt is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Affero General Public License for more details.
18 
19  You should have received a copy of the GNU Affero General Public License
20  along with BayesOpt. If not, see <http://www.gnu.org/licenses/>.
21 ------------------------------------------------------------------------
22 */
23 
24 #ifndef _ELEMENTWISE_UBLAS_HPP_
25 #define _ELEMENTWISE_UBLAS_HPP_
26 
27 #include <algorithm>
28 #include <boost/numeric/ublas/vector.hpp>
29 
30 namespace bayesopt
31 {
32  namespace utils
33  {
34 
39  template <class v1, class v2>
40  v1 ublas_elementwise_prod(const v1& a, const v2& b)
41  {
42  typedef typename v1::value_type D;
43  v1 c(a.size());
44  std::transform(a.begin(),a.end(),b.begin(),c.begin(),std::multiplies<D>());
45  return c;
46  }
47 
52  template <class v1, class v2>
53  v1 ublas_elementwise_div(const v1& a, const v2& b)
54  {
55  typedef typename v1::value_type D;
56  v1 c(a.size());
57  std::transform(a.begin(),a.end(),b.begin(),c.begin(),std::divides<D>());
58  return c;
59  }
60 
61  } //namespace utils
62 } //namespace bayesopt
63 
64 #endif
Namespace of the library interface.
Definition: using.dox:1
v1 ublas_elementwise_prod(const v1 &a, const v2 &b)
Computes the elementwise product of two vectors or matrices.
v1 ublas_elementwise_div(const v1 &a, const v2 &b)
Computes the elementwise division of two vectors or matrices.