Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
transv.h
1 /*
2 This file is distributed as part of the BIAS library (Basic ImageAlgorithmS)
3 but it has not been developed by the authors of BIAS.
4 
5 For copyright, author and license information see below.
6 */
7 
8 
9 /*
10 *
11 * Template Numerical Toolkit (TNT): Linear Algebra Module
12 *
13 * Mathematical and Computational Sciences Division
14 * National Institute of Technology,
15 * Gaithersburg, MD USA
16 *
17 *
18 * This software was developed at the National Institute of Standards and
19 * Technology (NIST) by employees of the Federal Government in the course
20 * of their official duties. Pursuant to title 17 Section 105 of the
21 * United States Code, this software is not subject to copyright protection
22 * and is in the public domain. The Template Numerical Toolkit (TNT) is
23 * an experimental system. NIST assumes no responsibility whatsoever for
24 * its use by other parties, and makes no guarantees, expressed or implied,
25 * about its quality, reliability, or any other characteristic.
26 *
27 * BETA VERSION INCOMPLETE AND SUBJECT TO CHANGE
28 * see http://math.nist.gov/tnt for latest updates.
29 *
30 */
31 
32 
33 
34 // Matrix Transpose Views
35 
36 #ifndef TRANSV_H
37 #define TRANSV_H
38 
39 #include <iostream>
40 #include <cassert>
41 #include "vec.h"
42 
43 namespace TNT
44 {
45 
46  template <class Array2D>
48  {
49  protected:
50 
51  const Array2D & A_;
52 
53  public:
54 
55  typedef typename Array2D::element_type T;
56  typedef T value_type;
57  typedef T element_type;
58  typedef T* pointer;
59  typedef T* iterator;
60  typedef T& reference;
61  typedef const T* const_iterator;
62  typedef const T& const_reference;
63 
64 
65  const Array2D & array() const { return A_; }
66  Subscript num_rows() const { return A_.num_cols();}
67  Subscript num_cols() const { return A_.num_rows();}
68  Subscript lbound() const { return A_.lbound(); }
70  {
71 #ifdef TNT_BOUNDS_CHECK
72  BIASASSERT( A_.lbound() <= i);
73  BIASASSERT( i<= A_.lbound()+1);
74 #endif
75  if (i== A_.lbound())
76  return num_rows();
77  else
78  return num_cols();
79  }
80 
81 
83  Transpose_View(const Array2D &A) : A_(A) {};
84 
85 
86  inline const typename Array2D::element_type & operator()(
87  Subscript i, Subscript j) const
88  {
89 #ifdef TNT_BOUNDS_CHECK
90  BIASASSERT(lbound()<=i);
91  BIASASSERT(i<=A_.num_cols() + lbound() - 1);
92  BIASASSERT(lbound()<=j);
93  BIASASSERT(j<=A_.num_rows() + lbound() - 1);
94 #endif
95 
96  return A_(j,i);
97  }
98 
99 
100  };
101 
102  template <class Matrix>
104  {
105  return Transpose_View<Matrix>(A);
106  }
107 
108  template <class Matrix, class T>
110  const Transpose_View<Matrix> & A,
111  const Vector<T> &B)
112  {
113  Subscript M = A.num_rows();
114  Subscript N = A.num_cols();
115 
116  BIASASSERT(B.dim() == N);
117 
118  Vector<T> x(N);
119 
120  Subscript i, j;
121  T tmp = 0;
122 
123  for (i=1; i<=M; i++)
124  {
125  tmp = 0;
126  for (j=1; j<=N; j++)
127  tmp += A(i,j) * B(j);
128  x(i) = tmp;
129  }
130 
131  return x;
132  }
133 
134  template <class Matrix, class T>
136  {
137  return matmult(A,B);
138  }
139 
140 
141  template <class Matrix>
142  std::ostream& operator<<(std::ostream &s, const Transpose_View<Matrix> &A)
143  {
144  Subscript M=A.num_rows();
145  Subscript N=A.num_cols();
146 
147  Subscript start = A.lbound();
148  Subscript Mend = M + A.lbound() - 1;
149  Subscript Nend = N + A.lbound() - 1;
150 
151  s << M << " " << N << endl;
152  for (Subscript i=start; i<=Mend; i++)
153  {
154  for (Subscript j=start; j<=Nend; j++)
155  {
156  s << A(i,j) << " ";
157  }
158  s << endl;
159  }
160 
161 
162  return s;
163  }
164 
165 } // namespace TNT
166 
167 #endif
168 // TRANSV_H
const Array2D & A_
Definition: transv.h:51
const Array2D & array() const
Definition: transv.h:65
Subscript num_cols() const
Definition: transv.h:67
TNT_SUBSCRIPT_TYPE Subscript
Definition: subscript.h:55
Subscript dim() const
Definition: vec.h:257
Transpose_View< Matrix > Transpose_view(const Matrix &A)
Definition: transv.h:103
Subscript lbound() const
Definition: transv.h:68
const Array2D::element_type & operator()(Subscript i, Subscript j) const
Definition: transv.h:86
Matrix< T > matmult(const Matrix< T > &A, const Matrix< T > &B)
Definition: cmat.h:811
Subscript dim(Subscript i) const
Definition: transv.h:69
Transpose_View(const Transpose_View< Array2D > &A)
Definition: transv.h:82
Transpose_View(const Array2D &A)
Definition: transv.h:83
Fortran_Matrix< T > operator*(const Fortran_Matrix< T > &A, const Fortran_Matrix< T > &B)
Definition: fmat.h:484
const T & const_reference
Definition: transv.h:62
const T * const_iterator
Definition: transv.h:61
Array2D::element_type T
Definition: transv.h:55
Subscript num_rows() const
Definition: transv.h:66