So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Operators.hpp
1 /*
2  * This file is part of bogus, a C++ sparse block matrix library.
3  *
4  * Copyright 2013 Gilles Daviet <gdaviet@gmail.com>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
10 
11 #ifndef BOGUS_BLOCK_OPERATORS_HPP
12 #define BOGUS_BLOCK_OPERATORS_HPP
13 
14 #include "Expressions.hpp"
15 
16 // operators +, -, *, /
17 
18 namespace bogus {
19 
20 template < typename LhsT, typename RhsT >
21 Addition< LhsT, RhsT > operator+ ( const BlockObjectBase< LhsT >& lhs,
22  const BlockObjectBase< RhsT > &rhs )
23 {
24  return Addition< LhsT, RhsT >( lhs.derived(), rhs.derived() ) ;
25 }
26 
27 template < typename LhsT, typename RhsT >
28 Addition< LhsT, RhsT > operator- ( const BlockObjectBase< LhsT >& lhs,
29  const BlockObjectBase< RhsT > &rhs )
30 {
31  return Addition< LhsT, RhsT >( lhs.derived(), rhs.derived(), 1, -1 ) ;
32 }
33 
34 template < typename Derived >
35 Scaling< Derived > operator* ( const BlockObjectBase< Derived >& lhs,
36  typename Derived::Scalar rhs )
37 {
38  return Scaling< Derived >( lhs.derived(), rhs ) ;
39 }
40 
41 template < typename Derived >
42 Scaling< Derived > operator* ( typename Derived::Scalar lhs ,
43  const BlockObjectBase< Derived >& rhs)
44 {
45  return Scaling< Derived >( rhs.derived(), lhs ) ;
46 }
47 
48 template < typename LhsT, typename RhsT >
49 Product< LhsT, RhsT > operator* ( const BlockObjectBase< LhsT >& lhs,
50  const BlockObjectBase< RhsT > &rhs )
51 {
52  return Product< LhsT, RhsT >( lhs.derived(), rhs.derived() ) ;
53 }
54 
55 template < typename Derived >
56 Scaling< Derived > operator/ ( const BlockObjectBase< Derived >& lhs,
57  typename Derived::Scalar rhs )
58 {
59  return Scaling< Derived >( lhs.derived(), 1/rhs ) ;
60 }
61 
62 } //namespace bogus
63 
64 #endif