cheshirekow  v0.1.0
identity.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 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_IDENTITY_H_
26 #define FIBER_IDENTITY_H_
27 
28 namespace fiber {
29 
31 template <typename Scalar, int N>
32 class Eye : public _RValue<Scalar, Eye<Scalar, N> > {
33  public:
34  enum {
35  ROWS_ = N,
36  COLS_ = N,
37  SIZE_ = N * N
38  };
39 
40  Size size() const { return N*N; }
41  Size rows() const { return N; }
42  Size cols() const { return N; }
43 
45  Scalar operator[](Index i) const {
46  if(i % N == i/N) {
47  return Scalar(1.0);
48  } else {
49  return Scalar(0.0);
50  }
51  }
52 
54  Scalar operator()(int i, int j) const {
55  assert(i < N && j < N);
56  return (i == j) ? Scalar(1.0) : Scalar(0.0);
57  }
58 };
59 
63 
67 
68 } // namespace fiber
69 
70 #endif // FIBER_IDENTITY_H_
Size cols() const
Definition: identity.h:42
expression template for rvalues
Definition: rvalue.h:33
Eye< float, 4 > Eye4f
Definition: identity.h:66
Scalar operator[](Index i) const
vector accessor
Definition: identity.h:45
Scalar operator()(int i, int j) const
matrix accessor
Definition: identity.h:54
unsigned int Size
Definition: fiber.h:32
Eye< double, 2 > Eye2d
Definition: identity.h:60
Size size() const
Definition: identity.h:40
Eye< float, 3 > Eye3f
Definition: identity.h:65
int Index
Definition: fiber.h:31
Eye< float, 2 > Eye2f
Definition: identity.h:64
Eye< double, 3 > Eye3d
Definition: identity.h:61
Size rows() const
Definition: identity.h:41
A N x N matrix expression for the identity matrix.
Definition: identity.h:32
Eye< double, 4 > Eye4d
Definition: identity.h:62