SheafSystem  0.0.0.0
general_matrix_3x2.impl.h
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 // Implementation for general_matrix_3x2.
19 
20 
21 #ifndef GENERAL_MATRIX_3X2_IMPL_H
22 #define GENERAL_MATRIX_3X2_IMPL_H
23 
24 #ifndef SHEAF_DLL_SPEC_H
25 #include "SheafSystem/sheaf_dll_spec.h"
26 #endif
27 
28 #ifndef ASSERT_CONTRACT_H
29 #include "SheafSystem/assert_contract.h"
30 #endif
31 
32 #ifndef ERROR_MESSAGE_H
33 #include "SheafSystem/error_message.h"
34 #endif
35 
36 #ifndef GENERAL_MATRIX_1X2_H
37 #include "SheafSystem/general_matrix_1x2.h"
38 #endif
39 
40 #ifndef GENERAL_MATRIX_2X1_H
41 #include "SheafSystem/general_matrix_2x1.h"
42 #endif
43 
44 #ifndef GENERAL_MATRIX_2X2_H
45 #include "SheafSystem/general_matrix_2x2.h"
46 #endif
47 
48 #ifndef GENERAL_MATRIX_2X3_H
49 #include "SheafSystem/general_matrix_2x3.h"
50 #endif
51 
52 #ifndef GENERAL_MATRIX_3X1_H
53 #include "SheafSystem/general_matrix_3x1.h"
54 #endif
55 
56 #ifndef GENERAL_MATRIX_3X2_H
57 #include "SheafSystem/general_matrix_3x2.h"
58 #endif
59 
60 #ifndef GENERAL_MATRIX_3X3_H
61 #include "SheafSystem/general_matrix_3x3.h"
62 #endif
63 
64 #ifndef STD_SSTREAM_H
65 #include "SheafSystem/std_sstream.h"
66 #endif
67 
68 #ifndef STD_CMATH_H
69 #include "SheafSystem/std_cmath.h"
70 #endif
71 
72 namespace fiber_bundle
73 {
74 
75 using namespace sheaf;
76 
77 //==============================================================================
78 // MEMBER FUNCTIONS
79 //==============================================================================
80 
82 template <typename T>
83 general_matrix_3x2<T>::
84 operator jcb_e23_row_dofs_type<T>& () const
85 {
86  // Preconditions:
87 
88  // Body:
89 
90  T* lcomps = const_cast<T*>(components);
91 
92  jcb_e23_row_dofs_type<T>& result =
93  reinterpret_cast<jcb_e23_row_dofs_type<T>&>(*lcomps);
94 
95  // Postconditions:
96 
97  // Exit:
98 
99  return result;
100 }
101 
102 
104 template <typename T>
105 int
108 {
109  // Preconditions:
110 
111  // Body:
112 
113  // Postconditions:
114 
115  // Exit:
116 
117  return 3;
118 }
119 
121 template <typename T>
122 int
125 {
126  // Preconditions:
127 
128  // Body:
129 
130  // Postconditions:
131 
132  // Exit:
133 
134  return 2;
135 }
136 
138 template <typename T>
139 int
141 d()
142 {
143  // Preconditions:
144 
145  // Body:
146 
147  // Postconditions:
148 
149  // Exit:
150 
151  return 6;
152 }
153 
155 template <typename T>
156 T*
158 operator[](int nrow)
159 {
160  // Preconditions:
161 
162  require(nrow >= 0 && nrow < number_of_rows());
163 
164  // Body:
165 
166  T* result = &components[row_index(nrow)];
167 
168  // Postconditions:
169 
170  ensure(result != 0);
171 
172  // Exit:
173 
174  return result;
175 }
176 
177 template <typename T>
178 const T*
180 operator[](int nrow) const
181 {
182  // Preconditions:
183 
184  require(nrow >= 0 && nrow < number_of_rows());
185 
186  // Body:
187 
188  const T* result = &components[row_index(nrow)];
189 
190  // Postconditions:
191 
192  ensure(result != 0);
193 
194  // Exit:
195 
196  return result;
197 }
198 
200 template <typename T>
202 operator T* ()
203 {
204  // Preconditions:
205 
206  // Body:
207 
208  //cout << "general_matrix_3x2<T>::operator T* () " << std::endl;
209 
210  T* result = components;
211 
212  // Postconditions:
213 
214  ensure(result != 0);
215 
216  // Exit:
217 
218  return result;
219 }
220 
222 template <typename T>
224 operator const T* () const
225 {
226  // Preconditions:
227 
228  // Body:
229 
230  //cout << "general_matrix_3x2<T>::operator const T* () const " << std::endl;
231 
232  const T* result = components;
233 
234  // Postconditions:
235 
236  ensure(result != 0);
237 
238  // Exit:
239 
240  return result;
241 }
242 
244 template <typename T>
245 int
247 row_index(int xrow) const
248 {
249 
250  // Preconditions:
251 
252  require(xrow >= 0 && xrow < number_of_rows());
253 
254  // Body:
255 
256  int result = number_of_columns()*xrow;
257 
258  // Postconditions:
259 
260  ensure(result == number_of_columns()*xrow);
261 
262  // Exit:
263 
264  return result;
265 }
266 
268 template <typename T>
271 row(int xrow) const
272 {
273  // Preconditions:
274 
275  require(xrow >= 0 && xrow < number_of_rows());
276 
277  // Body:
278 
279  general_matrix_1x2<T> result;
280 
281  int lindex = row_index(xrow);
282  result.components[0] = components[lindex++];
283  result.components[1] = components[lindex];
284 
285  // Postconditions:
286 
287  // Exit:
288 
289  return result;
290 
291 }
292 
294 template <typename T>
297 column(int xcolumn) const
298 {
299  // Preconditions:
300 
301  require(xcolumn >= 0 && xcolumn < number_of_columns());
302 
303  // Body:
304 
305  general_matrix_3x1<T> result;
306 
307  int lindex = xcolumn;
308  result.components[0] = components[lindex];
309  lindex += 2; //+= number_of_columns();
310  result.components[1] = components[lindex];
311  lindex += 2; //+= number_of_columns();
312  result.components[2] = components[lindex];
313 
314  // Postconditions:
315 
316  // Exit:
317 
318  return result;
319 }
320 
322 template <typename T>
323 void
325 assign(const T& xvalue)
326 {
327  // Preconditions:
328 
329  // Body:
330 
331  for(int i=0; i<d(); ++i)
332  {
333  components[i] = xvalue;
334  }
335 
336  // Postconditions:
337 
338  ensure_for_all(i, 0, d(), components[i] == xvalue);
339 
340  // Exit:
341 
342 }
343 
344 
346 template <typename T>
347 void
349 multiply(const T& xscalar, general_matrix_3x2<T>& xresult) const
350 {
351  // Preconditions:
352 
353  // Body:
354 
355  for(int i=0; i<d(); ++i)
356  {
357  xresult.components[i] = xscalar*components[i];
358  }
359 
360  // Postconditions:
361 
362  //@issue $$ISSUE: We can't make the following comparison because of
363  // floating point roundoff.
364  //ensure_for_all(i, 0, d(), xresult.components[i] == xscalar*components[i]);
365 
366  // Exit:
367 
368 }
369 
371 template <typename T>
374 multiply(const T& xscalar) const
375 {
376  // Preconditions:
377 
378  // Body:
379 
380  general_matrix_3x2<T> result;
381  multiply(xscalar, result);
382 
383  // Postconditions:
384 
385  // Exit:
386 
387  return result;
388 }
389 
391 template <typename T>
392 void
395  general_matrix_3x3<T>& xresult) const
396 {
397  // Preconditions:
398 
399  // Body:
400 
401  // Multiply [A][B] where [A] = *this & [B] = xother.
402 
403  const general_matrix_3x2<T>& lm = *this;
404 
405  int nra = number_of_rows();
406  int nca = number_of_columns();
407  int ncb = xother.number_of_columns();
408 
409  for(int i=0; i<nra; ++i)
410  {
411  for(int j=0; j<ncb; ++j)
412  {
413  T sum = T(0);
414 
415  for(int k=0; k<nca; ++k)
416  {
417  sum += lm[i][k]*xother[k][j];
418  }
419 
420  xresult[i][j] = sum;
421  }
422  }
423 
424  // Postconditions:
425 
426  // Exit:
427 
428 }
429 
431 template <typename T>
434 multiply(const general_matrix_2x3<T>& xother) const
435 {
436  // Preconditions:
437 
438  // Body:
439 
440  general_matrix_3x3<T> result;
441  multiply(xother, result);
442 
443  // Postconditions:
444 
445  // Exit:
446 
447  return result;
448 }
449 
450 
452 template <typename T>
453 void
456  general_matrix_3x2<T>& xresult) const
457 {
458  // Preconditions:
459 
460  // Body:
461 
462  // Multiply [A][B] where [A] = *this & [B] = xother.
463 
464  const general_matrix_3x2<T>& lm = *this;
465 
466  int nra = number_of_rows();
467  int nca = number_of_columns();
468  int ncb = xother.number_of_columns();
469 
470  for(int i=0; i<nra; ++i)
471  {
472  for(int j=0; j<ncb; ++j)
473  {
474  T sum = T(0);
475 
476  for(int k=0; k<nca; ++k)
477  {
478  sum += lm[i][k]*xother[k][j];
479  }
480 
481  xresult[i][j] = sum;
482  }
483  }
484 
485  // Postconditions:
486 
487  // Exit:
488 
489 }
490 
492 template <typename T>
495 multiply(const general_matrix_2x2<T>& xother) const
496 {
497  // Preconditions:
498 
499  // Body:
500 
501  general_matrix_3x2<T> result;
502  multiply(xother, result);
503 
504  // Postconditions:
505 
506  // Exit:
507 
508  return result;
509 }
510 
512 template <typename T>
513 void
516  general_matrix_3x1<T>& xresult) const
517 {
518  // Preconditions:
519 
520  // Body:
521 
522  // Multiply [A][B] where [A] = *this & [B] = xother.
523 
524  const general_matrix_3x2<T>& lm = *this;
525 
526  int nra = number_of_rows();
527  int nca = number_of_columns();
528  int ncb = xother.number_of_columns();
529 
530  for(int i=0; i<nra; ++i)
531  {
532  for(int j=0; j<ncb; ++j)
533  {
534  T sum = T(0);
535 
536  for(int k=0; k<nca; ++k)
537  {
538  sum += lm[i][k]*xother[k][j];
539  }
540 
541  xresult[i][j] = sum;
542  }
543  }
544 
545  // Postconditions:
546 
547  // Exit:
548 
549 }
550 
552 template <typename T>
555 multiply(const general_matrix_2x1<T>& xother) const
556 {
557  // Preconditions:
558 
559  // Body:
560 
561  general_matrix_3x1<T> result;
562  multiply(xother, result);
563 
564  // Postconditions:
565 
566  // Exit:
567 
568  return result;
569 }
570 
572 template <typename T>
573 void
576 {
577  // Preconditions:
578 
579  // Body:
580 
581  const general_matrix_3x2<T>& lm = *this;
582 
583  int nrows = xresult.number_of_rows();
584  int ncols = xresult.number_of_columns();
585 
586  for(int i=0; i<nrows; ++i)
587  {
588  for(int j=0; j<ncols; ++j)
589  {
590  xresult[i][j] = lm[j][i];
591  }
592  }
593 
594  // Postconditions:
595 
596  // Exit:
597 
598 }
599 
601 template <typename T>
604 transpose() const
605 {
606  // Preconditions:
607 
608  // Body:
609 
610  general_matrix_2x3<T> result;
611  transpose(result);
612 
613  // Postconditions:
614 
615  // Exit:
616 
617  return result;
618 }
619 
620 
621 
622 // =============================================================================
623 // NON-MEMBER FUNCTIONS
624 // =============================================================================
625 
626 #ifndef DOXYGEN_SKIP_IMPLEMENTATIONS
627 
629 template <typename T>
630 std::ostream& operator<<(std::ostream& xos, const general_matrix_3x2<T>& xm)
631 {
632  // Preconditions:
633 
634  // Body:
635 
636  int nrows = xm.number_of_rows();
637  int ncols = xm.number_of_columns();
638 
639  for(int i=0; i<nrows; ++i)
640  {
641  for(int j=0; j<ncols; ++j)
642  {
643  xos << " " << xm[i][j];
644  }
645  xos << std::endl;
646  }
647 
648  // Postconditions:
649 
650  // Exit:
651 
652  return xos;
653 }
654 
655 #endif // ifndef DOXYGEN_SKIP_IMPLEMENTATIONS
656 
657 //==============================================================================
658 //==============================================================================
659 
660 } // namespace fiber_bundle
661 
662 #endif // GENERAL_MATRIX_3X2_IMPL_H
663 
T components[2]
Linear storage array.
general_matrix_2x3< T > transpose() const
The transpose of the matrix (auto-allocated).
static int number_of_columns()
The number of columns.
static int number_of_columns()
The number of columns.
static int number_of_rows()
The number of rows.
Row dofs type for class jcb_e23.
Definition: jcb_e23.h:49
General matrix with 3 rows and 2 columns.
General matrix with 1 row and 2 columns.
General matrix with 2 rows and 2 columns.
T * operator[](int xrow)
Pointer to the first element in row xrow of this matrix. Facilitates accessing elements via matrix[i]...
general_matrix_1x2< T > row(int xrow) const
A 1x2 matrix containing the elements or row xrow.
static int number_of_rows()
The number of rows.
static int d()
Dimension of the underlying elements.
General matrix with 3 rows and 1 column.
General matrix with 2 rows and 1 column.
void multiply(const T &xscalar, general_matrix_3x2< T > &xresult) const
This matrix multiplied by a scalar (pre-allocated).
int row_index(int xrow) const
Index for row xrow in the linear storage array.
static int number_of_columns()
The number of columns.
general_matrix_3x1< T > column(int xcolumn) const
A 3x1 matrix containing the elements or column xcolumn.
General matrix with 3 rows and 3 columns.
Namespace for the sheaves component of the sheaf system.
General matrix with 2 rows and 3 columns.
void assign(const T &xvalue)
Assign all elements of this matrix to the value xvalue.
static int number_of_columns()
The number of columns.
T components[3]
Linear storage array.
SHEAF_DLL_SPEC void multiply(const vd &x0, const vd_value_type &x1, vd &xresult, bool xauto_access)
Vector x0 multiplied by scalar x1 (pre-allocated version for persistent types).
Definition: vd.cc:1924
T components[6]
Linear storage array.
Namespace for the fiber_bundles component of the sheaf system.