cheshirekow  v0.1.0
scale.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of fiber.
5  *
6  * fiber is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * fiber is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with fiber. If not, see <http://www.gnu.org/licenses/>.
18  */
25 #ifndef FIBER_SCALE_H_
26 #define FIBER_SCALE_H_
27 
28 
29 namespace fiber {
30 
31 template <typename Scalar, class Exp>
32 class _Scale : public _RValue<Scalar, _Scale<Scalar, Exp> > {
33  Scalar s_;
34  Exp const& M_;
35 
36  public:
37  enum {
38  ROWS_ = Exp::ROWS_,
39  COLS_ = Exp::COLS_,
40  SIZE_ = Exp::SIZE_
41  };
42 
43  _Scale(Scalar s, Exp const& A) : s_(s), M_(A) {}
44 
45  Size size() const { return M_.size(); }
46  Size rows() const { return M_.rows(); }
47  Size cols() const { return M_.cols(); }
48 
49  Scalar operator[](Size i) const { return s_ * M_[i]; }
50  Scalar operator()(Size i, Size j) const { return s_ * M_(i, j); }
51 };
52 
53 template <typename Scalar, class Exp>
55  return _Scale<Scalar, Exp>(s, static_cast<Exp const&>(A));
56 }
57 
58 template <typename Scalar, class Exp>
60  return _Scale<Scalar, Exp>(s, static_cast<Exp const&>(A));
61 }
62 
63 } // namespace fiber
64 
65 
66 #endif // FIBER_SCALE_H_
Scalar operator()(Size i, Size j) const
Definition: scale.h:50
expression template for rvalues
Definition: rvalue.h:33
Size size() const
Definition: scale.h:45
Size rows() const
Definition: scale.h:46
unsigned int Size
Definition: fiber.h:32
_Scale(Scalar s, Exp const &A)
Definition: scale.h:43
Scalar s_
Definition: scale.h:33
Exp const & M_
Definition: scale.h:34
Scalar operator[](Size i) const
Definition: scale.h:49
Matrix< Scalar, Exp1::ROWS_, Exp2::COLS_ > operator*(_RValue< Scalar, Exp1 > const &A, _RValue< Scalar, Exp2 > const &B)
Matrix multiplication.
Definition: product.h:34
Size cols() const
Definition: scale.h:47