cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vctFixedSizeMatrixLoopEngines.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Ofri Sadowsky, Anton Deguet
7  Created on: 2003-12-16
8 
9  (C) Copyright 2003-2013 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
21 #pragma once
22 #ifndef _vctFixedSizeMatrixLoopEngines_h
23 #define _vctFixedSizeMatrixLoopEngines_h
24 
36 
37 public:
38 
42  inline static void ThrowSharedPointersException(void) throw(std::runtime_error) {
43  cmnThrow(std::runtime_error("vctFixedSizeMatrixLoopEngines: Output base pointer is same as one of input base pointers."));
44  }
45 
77  template<class _elementOperationType>
78  class MoMiMi {
79  public:
80  template<class _outputMatrixType, class _input1MatrixType, class _input2MatrixType>
81  static void Run(_outputMatrixType & outputMatrix,
82  const _input1MatrixType & input1Matrix,
83  const _input2MatrixType & input2Matrix)
84  {
85  typedef _outputMatrixType OutputMatrixType;
86  typedef typename OutputMatrixType::size_type size_type;
87  typedef typename OutputMatrixType::pointer OutputPointerType;
88 
89  typedef _input1MatrixType Input1MatrixType;
90  typedef typename Input1MatrixType::const_pointer Input1PointerType;
91  typedef _input2MatrixType Input2MatrixType;
92  typedef typename Input2MatrixType::const_pointer Input2PointerType;
93 
94  enum {
95  ROWS = OutputMatrixType::ROWS,
96  COLS = OutputMatrixType::COLS,
97  OUTPUT_COL_STRIDE = OutputMatrixType::COLSTRIDE,
98  OUTPUT_ROW_STRIDE = OutputMatrixType::ROWSTRIDE,
99  OUTPUT_STRIDE_TO_NEXT_ROW = OUTPUT_ROW_STRIDE - COLS * OUTPUT_COL_STRIDE
100  };
101 
102  enum {
103  INPUT1_COL_STRIDE = Input1MatrixType::COLSTRIDE,
104  INPUT1_ROW_STRIDE = Input1MatrixType::ROWSTRIDE,
105  INPUT1_STRIDE_TO_NEXT_ROW = INPUT1_ROW_STRIDE - COLS * INPUT1_COL_STRIDE
106  };
107 
108  enum {
109  INPUT2_COL_STRIDE = Input2MatrixType::COLSTRIDE,
110  INPUT2_ROW_STRIDE = Input2MatrixType::ROWSTRIDE,
111  INPUT2_STRIDE_TO_NEXT_ROW = INPUT2_ROW_STRIDE - COLS * INPUT2_COL_STRIDE
112  };
113 
114  OutputPointerType outputPointer = outputMatrix.Pointer();
115  Input1PointerType input1Pointer = input1Matrix.Pointer();
116  Input2PointerType input2Pointer = input2Matrix.Pointer();
117 
118  size_type rowIndex, colIndex;
119  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
120  outputPointer += OUTPUT_STRIDE_TO_NEXT_ROW,
121  input1Pointer += INPUT1_STRIDE_TO_NEXT_ROW,
122  input2Pointer += INPUT2_STRIDE_TO_NEXT_ROW)
123  {
124  for (colIndex = 0; colIndex < COLS; ++colIndex,
125  outputPointer += OUTPUT_COL_STRIDE,
126  input1Pointer += INPUT1_COL_STRIDE,
127  input2Pointer += INPUT2_COL_STRIDE)
128  {
129  *outputPointer = _elementOperationType::Operate(*input1Pointer, *input2Pointer);
130  }
131  }
132  } // Run method
133  }; // MoMiMi class
134 
135 
136  template<class _elementOperationType>
137  class MoMi {
138  public:
139  template<class _outputMatrixType, class _inputMatrixType>
140  static inline void Run(_outputMatrixType & outputMatrix,
141  const _inputMatrixType & inputMatrix)
142  {
143  typedef _outputMatrixType OutputMatrixType;
144  typedef typename OutputMatrixType::size_type size_type;
145  typedef typename OutputMatrixType::pointer OutputPointerType;
146 
147  typedef _inputMatrixType InputMatrixType;
148  typedef typename InputMatrixType::const_pointer InputPointerType;
149 
150  enum {
151  ROWS = OutputMatrixType::ROWS,
152  COLS = OutputMatrixType::COLS,
153  OUTPUT_COL_STRIDE = OutputMatrixType::COLSTRIDE,
154  OUTPUT_ROW_STRIDE = OutputMatrixType::ROWSTRIDE,
155  OUTPUT_STRIDE_TO_NEXT_ROW = OUTPUT_ROW_STRIDE - COLS * OUTPUT_COL_STRIDE
156  };
157 
158  enum {
159  INPUT_COL_STRIDE = InputMatrixType::COLSTRIDE,
160  INPUT_ROW_STRIDE = InputMatrixType::ROWSTRIDE,
161  INPUT_STRIDE_TO_NEXT_ROW = INPUT_ROW_STRIDE - COLS * INPUT_COL_STRIDE
162  };
163 
164 
165  OutputPointerType outputPointer = outputMatrix.Pointer();
166  InputPointerType inputPointer = inputMatrix.Pointer();
167 
168  size_type rowIndex, colIndex;
169  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
170  outputPointer += OUTPUT_STRIDE_TO_NEXT_ROW,
171  inputPointer += INPUT_STRIDE_TO_NEXT_ROW)
172  {
173  for (colIndex = 0; colIndex < COLS; ++colIndex,
174  outputPointer += OUTPUT_COL_STRIDE,
175  inputPointer += INPUT_COL_STRIDE)
176  {
177  *outputPointer = _elementOperationType::Operate(*inputPointer);
178  }
179  }
180  } // Run method
181  }; // MoMi class
182 
183 
184  template<class _elementOperationType>
185  class Mio {
186  public:
187  template<class _inputOutputMatrixType>
188  static inline void Run(_inputOutputMatrixType & inputOutputMatrix)
189  {
190  typedef _inputOutputMatrixType InputOutputMatrixType;
192  typedef typename InputOutputMatrixType::pointer InputOutputPointerType;
193 
194  enum {
195  ROWS = InputOutputMatrixType::ROWS,
196  COLS = InputOutputMatrixType::COLS,
197  COL_STRIDE = InputOutputMatrixType::COLSTRIDE,
198  ROW_STRIDE = InputOutputMatrixType::ROWSTRIDE,
199  STRIDE_TO_NEXT_ROW = ROW_STRIDE - COLS * COL_STRIDE
200  };
201 
202  InputOutputPointerType inputOutputPointer = inputOutputMatrix.Pointer();
203 
204  size_type rowIndex, colIndex;
205  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
206  inputOutputPointer += STRIDE_TO_NEXT_ROW)
207  {
208  for (colIndex = 0; colIndex < COLS; ++colIndex,
209  inputOutputPointer += COL_STRIDE)
210  {
211  _elementOperationType::Operate(*inputOutputPointer);
212  }
213  }
214  } // Run method
215  }; // Mio class
216 
217 
218  template<class _elementOperationType>
219  class MioMi {
220  public:
221  template<class _inputOutputMatrixType, class _inputMatrixType>
222  static inline void Run(_inputOutputMatrixType & inputOutputMatrix,
223  const _inputMatrixType & inputMatrix)
224  {
225  typedef _inputOutputMatrixType InputOutputMatrixType;
227  typedef typename InputOutputMatrixType::pointer InputOutputPointerType;
228 
229  typedef _inputMatrixType InputMatrixType;
230  typedef typename InputMatrixType::const_pointer InputPointerType;
231 
232  enum {
233  ROWS = InputOutputMatrixType::ROWS,
234  COLS = InputOutputMatrixType::COLS,
235  INPUT_OUTPUT_COL_STRIDE = InputOutputMatrixType::COLSTRIDE,
236  INPUT_OUTPUT_ROW_STRIDE = InputOutputMatrixType::ROWSTRIDE,
237  INPUT_OUTPUT_STRIDE_TO_NEXT_ROW = INPUT_OUTPUT_ROW_STRIDE - COLS * INPUT_OUTPUT_COL_STRIDE
238  };
239 
240  enum {
241  INPUT_COL_STRIDE = InputMatrixType::COLSTRIDE,
242  INPUT_ROW_STRIDE = InputMatrixType::ROWSTRIDE,
243  INPUT_STRIDE_TO_NEXT_ROW = INPUT_ROW_STRIDE - COLS * INPUT_COL_STRIDE
244  };
245 
246 
247  InputOutputPointerType inputOutputPointer = inputOutputMatrix.Pointer();
248  InputPointerType inputPointer = inputMatrix.Pointer();
249 
250  size_type rowIndex, colIndex;
251  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
252  inputOutputPointer += INPUT_OUTPUT_STRIDE_TO_NEXT_ROW,
253  inputPointer += INPUT_STRIDE_TO_NEXT_ROW)
254  {
255  for (colIndex = 0; colIndex < COLS; ++colIndex,
256  inputOutputPointer += INPUT_OUTPUT_COL_STRIDE,
257  inputPointer += INPUT_COL_STRIDE)
258  {
259  _elementOperationType::Operate(*inputOutputPointer, *inputPointer);
260  }
261  }
262  } // Run method
263  }; // MioMi class
264 
265 
266  template<class _elementOperationType>
267  class MoMiSi {
268  public:
269  template<class _outputMatrixType, class _inputMatrixType, class _inputScalarType>
270  static void Run(_outputMatrixType & outputMatrix,
271  const _inputMatrixType & inputMatrix,
272  const _inputScalarType inputScalar)
273  {
274  typedef _outputMatrixType OutputMatrixType;
275  typedef typename OutputMatrixType::size_type size_type;
276  typedef typename OutputMatrixType::pointer OutputPointerType;
277 
278  typedef _inputMatrixType InputMatrixType;
279  typedef typename InputMatrixType::const_pointer InputPointerType;
280 
281  enum {
282  ROWS = OutputMatrixType::ROWS,
283  COLS = OutputMatrixType::COLS,
284  OUTPUT_COL_STRIDE = OutputMatrixType::COLSTRIDE,
285  OUTPUT_ROW_STRIDE = OutputMatrixType::ROWSTRIDE,
286  OUTPUT_STRIDE_TO_NEXT_ROW = OUTPUT_ROW_STRIDE - COLS * OUTPUT_COL_STRIDE
287  };
288 
289  enum {
290  INPUT_COL_STRIDE = InputMatrixType::COLSTRIDE,
291  INPUT_ROW_STRIDE = InputMatrixType::ROWSTRIDE,
292  INPUT_STRIDE_TO_NEXT_ROW = INPUT_ROW_STRIDE - COLS * INPUT_COL_STRIDE
293  };
294 
295 
296  OutputPointerType outputPointer = outputMatrix.Pointer();
297  InputPointerType inputPointer = inputMatrix.Pointer();
298 
299  size_type rowIndex, colIndex;
300  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
301  outputPointer += OUTPUT_STRIDE_TO_NEXT_ROW,
302  inputPointer += INPUT_STRIDE_TO_NEXT_ROW)
303  {
304  for (colIndex = 0; colIndex < COLS; ++colIndex,
305  outputPointer += OUTPUT_COL_STRIDE,
306  inputPointer += INPUT_COL_STRIDE)
307  {
308  *outputPointer = _elementOperationType::Operate(*inputPointer, inputScalar);
309  }
310  }
311  } // Run method
312  }; // MoMiSi class
313 
314 
315  template<class _elementOperationType>
316  class MoSiMi {
317  public:
318  template<class _outputMatrixType, class _inputScalarType, class _inputMatrixType>
319  static void Run(_outputMatrixType & outputMatrix,
320  const _inputScalarType inputScalar,
321  const _inputMatrixType & inputMatrix)
322  {
323  typedef _outputMatrixType OutputMatrixType;
324  typedef typename OutputMatrixType::size_type size_type;
325  typedef typename OutputMatrixType::pointer OutputPointerType;
326 
327  typedef _inputMatrixType InputMatrixType;
328  typedef typename InputMatrixType::const_pointer InputPointerType;
329 
330  enum {
331  ROWS = OutputMatrixType::ROWS,
332  COLS = OutputMatrixType::COLS,
333  OUTPUT_COL_STRIDE = OutputMatrixType::COLSTRIDE,
334  OUTPUT_ROW_STRIDE = OutputMatrixType::ROWSTRIDE,
335  OUTPUT_STRIDE_TO_NEXT_ROW = OUTPUT_ROW_STRIDE - COLS * OUTPUT_COL_STRIDE
336  };
337 
338  enum {
339  INPUT_COL_STRIDE = InputMatrixType::COLSTRIDE,
340  INPUT_ROW_STRIDE = InputMatrixType::ROWSTRIDE,
341  INPUT_STRIDE_TO_NEXT_ROW = INPUT_ROW_STRIDE - COLS * INPUT_COL_STRIDE
342  };
343 
344 
345  OutputPointerType outputPointer = outputMatrix.Pointer();
346  InputPointerType inputPointer = inputMatrix.Pointer();
347 
348  size_type rowIndex, colIndex;
349  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
350  outputPointer += OUTPUT_STRIDE_TO_NEXT_ROW,
351  inputPointer += INPUT_STRIDE_TO_NEXT_ROW)
352  {
353  for (colIndex = 0; colIndex < COLS; ++colIndex,
354  outputPointer += OUTPUT_COL_STRIDE,
355  inputPointer += INPUT_COL_STRIDE)
356  {
357  *outputPointer = _elementOperationType::Operate(inputScalar, *inputPointer);
358  }
359  }
360  } // Run method
361  }; // MoSiMi class
362 
363 
364  template<class _elementOperationType>
365  class MioSi {
366  public:
367  template<class _inputOutputMatrixType, class _inputScalarType>
368  static void Run(_inputOutputMatrixType & inputOutputMatrix,
369  const _inputScalarType inputScalar)
370  {
371  typedef _inputOutputMatrixType InputOutputMatrixType;
373  typedef typename InputOutputMatrixType::pointer InputOutputPointerType;
374 
375  enum {
376  ROWS = InputOutputMatrixType::ROWS,
377  COLS = InputOutputMatrixType::COLS,
378  COL_STRIDE = InputOutputMatrixType::COLSTRIDE,
379  ROW_STRIDE = InputOutputMatrixType::ROWSTRIDE,
380  STRIDE_TO_NEXT_ROW = ROW_STRIDE - COLS * COL_STRIDE
381  };
382 
383  InputOutputPointerType inputOutputPointer = inputOutputMatrix.Pointer();
384 
385  size_type rowIndex, colIndex;
386  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
387  inputOutputPointer += STRIDE_TO_NEXT_ROW)
388  {
389  for (colIndex = 0; colIndex < COLS; ++colIndex,
390  inputOutputPointer += COL_STRIDE)
391  {
392  _elementOperationType::Operate(*inputOutputPointer, inputScalar);
393  }
394  }
395  } // Run method
396  }; // MioSi class
397 
398 
399  template<class _incrementalOperationType, class _elementOperationType>
400  class SoMi {
401  public:
402  typedef typename _incrementalOperationType::OutputType OutputType;
403 
404  template<class _inputMatrixType>
405  static OutputType Run(const _inputMatrixType & inputMatrix)
406  {
407  typedef _inputMatrixType InputMatrixType;
408  typedef typename InputMatrixType::size_type size_type;
409  typedef typename InputMatrixType::const_pointer InputPointerType;
410 
411  OutputType incrementalResult = _incrementalOperationType::NeutralElement();
412 
413  enum {
414  ROWS = InputMatrixType::ROWS,
415  COLS = InputMatrixType::COLS,
416  INPUT_COL_STRIDE = InputMatrixType::COLSTRIDE,
417  INPUT_ROW_STRIDE = InputMatrixType::ROWSTRIDE,
418  INPUT_STRIDE_TO_NEXT_ROW = INPUT_ROW_STRIDE - COLS * INPUT_COL_STRIDE
419  };
420 
421  InputPointerType inputPointer = inputMatrix.Pointer();
422 
423  size_type rowIndex, colIndex;
424  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
425  inputPointer += INPUT_STRIDE_TO_NEXT_ROW)
426  {
427  for (colIndex = 0; colIndex < COLS; ++colIndex,
428  inputPointer += INPUT_COL_STRIDE)
429  {
430  incrementalResult = _incrementalOperationType::Operate(incrementalResult,
431  _elementOperationType::Operate(*inputPointer) );
432  }
433  }
434  return incrementalResult;
435  } // Run method
436  }; // SoMi class
437 
438 
439  template<class _incrementalOperationType, class _elementOperationType>
440  class SoMiMi {
441  public:
442  typedef typename _incrementalOperationType::OutputType OutputType;
443 
444  template<class _input1MatrixType, class _input2MatrixType>
445  static OutputType Run(const _input1MatrixType & input1Matrix,
446  const _input2MatrixType & input2Matrix)
447  {
448  typedef _input1MatrixType Input1MatrixType;
449  typedef typename Input1MatrixType::size_type size_type;
450  typedef typename Input1MatrixType::const_pointer Input1PointerType;
451  typedef _input2MatrixType Input2MatrixType;
452  typedef typename Input2MatrixType::const_pointer Input2PointerType;
453 
454  OutputType incrementalResult = _incrementalOperationType::NeutralElement();
455 
456  enum {
457  ROWS = Input1MatrixType::ROWS,
458  COLS = Input1MatrixType::COLS,
459  INPUT1_COL_STRIDE = Input1MatrixType::COLSTRIDE,
460  INPUT1_ROW_STRIDE = Input1MatrixType::ROWSTRIDE,
461  INPUT1_STRIDE_TO_NEXT_ROW = INPUT1_ROW_STRIDE - COLS * INPUT1_COL_STRIDE
462  };
463 
464  enum {
465  INPUT2_COL_STRIDE = Input2MatrixType::COLSTRIDE,
466  INPUT2_ROW_STRIDE = Input2MatrixType::ROWSTRIDE,
467  INPUT2_STRIDE_TO_NEXT_ROW = INPUT2_ROW_STRIDE - COLS * INPUT2_COL_STRIDE
468  };
469 
470  Input1PointerType input1Pointer = input1Matrix.Pointer();
471  Input2PointerType input2Pointer = input2Matrix.Pointer();
472 
473  size_type rowIndex, colIndex;
474  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
475  input1Pointer += INPUT1_STRIDE_TO_NEXT_ROW,
476  input2Pointer += INPUT2_STRIDE_TO_NEXT_ROW)
477  {
478  for (colIndex = 0; colIndex < COLS; ++colIndex,
479  input1Pointer += INPUT1_COL_STRIDE,
480  input2Pointer += INPUT2_COL_STRIDE)
481  {
482  incrementalResult = _incrementalOperationType::Operate(incrementalResult,
483  _elementOperationType::Operate(*input1Pointer, *input2Pointer) );
484  }
485  }
486  return incrementalResult;
487  } // Run method
488  }; // SoMiMi class
489 
490 
516  template<class _ioElementOperationType, class _scalarMatrixElementOperationType>
517  class
518  MioSiMi {
519  public:
520 
521  template<class _ioMatrixType, class _inputScalarType, class _inputMatrixType>
522  static inline void Run(_ioMatrixType & ioMatrix,
523  const _inputScalarType & inputScalar, const _inputMatrixType & inputMatrix)
524  {
525  typedef _ioMatrixType IoMatrixType;
526  typedef typename IoMatrixType::size_type size_type;
527  typedef typename IoMatrixType::pointer IoPointerType;
528  typedef _inputMatrixType InputMatrixType;
529  typedef typename InputMatrixType::const_pointer InputPointerType;
530 
531  enum {
532  ROWS = IoMatrixType::ROWS,
533  COLS = IoMatrixType::COLS,
534  IO_COL_STRIDE = IoMatrixType::COLSTRIDE,
535  IO_ROW_STRIDE = IoMatrixType::ROWSTRIDE,
536  IO_STRIDE_TO_NEXT_ROW = IO_ROW_STRIDE - COLS * IO_COL_STRIDE,
537  INPUT_COL_STRIDE = InputMatrixType::COLSTRIDE,
538  INPUT_ROW_STRIDE = InputMatrixType::ROWSTRIDE,
539  INPUT_STRIDE_TO_NEXT_ROW = INPUT_ROW_STRIDE - COLS * INPUT_COL_STRIDE
540  };
541 
542  IoPointerType ioPointer = ioMatrix.Pointer();
543  InputPointerType inputPointer = inputMatrix.Pointer();
544 
545  size_type rowIndex, colIndex;
546  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
547  ioPointer += IO_STRIDE_TO_NEXT_ROW,
548  inputPointer += INPUT_STRIDE_TO_NEXT_ROW)
549  {
550  for (colIndex = 0; colIndex < COLS; ++colIndex,
551  ioPointer += IO_COL_STRIDE,
552  inputPointer += INPUT_COL_STRIDE)
553  {
554  _ioElementOperationType::Operate(
555  *ioPointer,
556  _scalarMatrixElementOperationType::Operate(inputScalar, *inputPointer)
557  );
558  }
559  }
560  }
561  };
562 
563 
590  template<class _ioElementOperationType, class _matrixElementOperationType>
591  class
592  MioMiMi {
593  public:
594 
595  template<class _ioMatrixType, class _input1MatrixType, class _input2MatrixType>
596  static inline void Run(_ioMatrixType & ioMatrix,
597  const _input1MatrixType & input1Matrix,
598  const _input2MatrixType & input2Matrix)
599  {
600  typedef _ioMatrixType IoMatrixType;
601  typedef typename IoMatrixType::size_type size_type;
602  typedef typename IoMatrixType::pointer IoPointerType;
603  typedef _input1MatrixType Input1MatrixType;
604  typedef typename Input1MatrixType::const_pointer Input1PointerType;
605  typedef _input2MatrixType Input2MatrixType;
606  typedef typename Input2MatrixType::const_pointer Input2PointerType;
607 
608  enum {
609  ROWS = IoMatrixType::ROWS,
610  COLS = IoMatrixType::COLS,
611  IO_COL_STRIDE = IoMatrixType::COLSTRIDE,
612  IO_ROW_STRIDE = IoMatrixType::ROWSTRIDE,
613  IO_STRIDE_TO_NEXT_ROW = IO_ROW_STRIDE - COLS * IO_COL_STRIDE,
614  INPUT1_COL_STRIDE = Input1MatrixType::COLSTRIDE,
615  INPUT1_ROW_STRIDE = Input1MatrixType::ROWSTRIDE,
616  INPUT1_STRIDE_TO_NEXT_ROW = INPUT1_ROW_STRIDE - COLS * INPUT1_COL_STRIDE,
617  INPUT2_COL_STRIDE = Input2MatrixType::COLSTRIDE,
618  INPUT2_ROW_STRIDE = Input2MatrixType::ROWSTRIDE,
619  INPUT2_STRIDE_TO_NEXT_ROW = INPUT2_ROW_STRIDE - COLS * INPUT2_COL_STRIDE
620  };
621 
622  IoPointerType ioPointer = ioMatrix.Pointer();
623  Input1PointerType input1Pointer = input1Matrix.Pointer();
624  Input2PointerType input2Pointer = input2Matrix.Pointer();
625 
626  size_type rowIndex, colIndex;
627  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
628  ioPointer += IO_STRIDE_TO_NEXT_ROW,
629  input1Pointer += INPUT1_STRIDE_TO_NEXT_ROW,
630  input2Pointer += INPUT2_STRIDE_TO_NEXT_ROW)
631  {
632  for (colIndex = 0; colIndex < COLS; ++colIndex,
633  ioPointer += IO_COL_STRIDE,
634  input1Pointer += INPUT1_COL_STRIDE,
635  input2Pointer += INPUT2_COL_STRIDE)
636  {
637  _ioElementOperationType::Operate(
638  *ioPointer,
639  _matrixElementOperationType::Operate(*input1Pointer, *input2Pointer)
640  );
641  }
642  }
643  }
644  };
645 
646 
647  template<class _incrementalOperationType, class _elementOperationType>
648  class SoMiSi {
649  public:
650  typedef typename _incrementalOperationType::OutputType OutputType;
651 
652  template<class _inputMatrixType, class _inputScalarType>
653  static OutputType Run(const _inputMatrixType & inputMatrix,
654  const _inputScalarType & inputScalar)
655  {
656  typedef _inputMatrixType InputMatrixType;
657  typedef typename InputMatrixType::size_type size_type;
658  typedef typename InputMatrixType::const_pointer InputPointerType;
659 
660  OutputType incrementalResult = _incrementalOperationType::NeutralElement();
661 
662  enum {
663  ROWS = InputMatrixType::ROWS,
664  COLS = InputMatrixType::COLS,
665  INPUT_COL_STRIDE = InputMatrixType::COLSTRIDE,
666  INPUT_ROW_STRIDE = InputMatrixType::ROWSTRIDE,
667  INPUT_STRIDE_TO_NEXT_ROW = INPUT_ROW_STRIDE - COLS * INPUT_COL_STRIDE
668  };
669 
670  InputPointerType inputPointer = inputMatrix.Pointer();
671 
672  size_type rowIndex, colIndex;
673  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
674  inputPointer += INPUT_STRIDE_TO_NEXT_ROW)
675  {
676  for (colIndex = 0; colIndex < COLS; ++colIndex,
677  inputPointer += INPUT_COL_STRIDE)
678  {
679  incrementalResult = _incrementalOperationType::Operate(incrementalResult,
680  _elementOperationType::Operate(*inputPointer, inputScalar) );
681  }
682  }
683  return incrementalResult;
684  } // Run method
685  }; // SoMiSi class
686 
687 
688 
689  template<class _operationType>
690  class Product {
691  public:
692  template<class _outputMatrixType, class _input1MatrixType, class _input2MatrixType>
693  static void Run(_outputMatrixType & outputMatrix,
694  const _input1MatrixType & input1Matrix,
695  const _input2MatrixType & input2Matrix)
696  {
697  typedef _outputMatrixType OutputMatrixType;
698  typedef typename OutputMatrixType::size_type size_type;
699  typedef typename OutputMatrixType::pointer OutputPointerType;
700 
701  typedef _input1MatrixType Input1MatrixType;
702  typedef typename Input1MatrixType::const_pointer Input1PointerType;
703 
704  typedef _input2MatrixType Input2MatrixType;
705  typedef typename Input2MatrixType::const_pointer Input2PointerType;
706 
707  enum {
708  ROWS = OutputMatrixType::ROWS,
709  COLS = OutputMatrixType::COLS,
710  OUTPUT_COL_STRIDE = OutputMatrixType::COLSTRIDE,
711  OUTPUT_ROW_STRIDE = OutputMatrixType::ROWSTRIDE,
712  OUTPUT_STRIDE_TO_NEXT_ROW = OUTPUT_ROW_STRIDE - COLS * OUTPUT_COL_STRIDE
713  };
714 
715  enum {
716  INPUT1_COL_STRIDE = Input1MatrixType::COLSTRIDE,
717  INPUT1_ROW_STRIDE = Input1MatrixType::ROWSTRIDE
718  };
719 
720  enum {
721  INPUT2_COL_STRIDE = Input2MatrixType::COLSTRIDE,
722  INPUT2_ROW_STRIDE = Input2MatrixType::ROWSTRIDE
723  };
724 
725  OutputPointerType outputPointer = outputMatrix.Pointer();
726 
727  Input1PointerType input1Pointer = input1Matrix.Pointer();
728  Input2PointerType input2Pointer = input2Matrix.Pointer();
729 
730  typename Input1MatrixType::ConstRowRefType input1Row;
731  typename Input2MatrixType::ConstColumnRefType input2Col;
732 
733  if ((outputPointer == input1Pointer) ||
734  (outputPointer == input2Pointer)) {
736  }
737 
738  size_type rowIndex, colIndex;
739  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
740  outputPointer += OUTPUT_STRIDE_TO_NEXT_ROW,
741  input1Pointer += INPUT1_ROW_STRIDE,
742  input2Pointer = input2Matrix.Pointer())
743  {
744  input1Row.SetRef(input1Pointer);
745  for (colIndex = 0; colIndex < COLS; ++colIndex,
746  outputPointer += OUTPUT_COL_STRIDE,
747  input2Pointer += INPUT2_COL_STRIDE)
748  {
749  input2Col.SetRef(input2Pointer);
750  *outputPointer = _operationType::Operate(input1Row, input2Col);
751  }
752  }
753  } // Run method
754  }; // Product class
755 
760  class MinAndMax
761  {
762  public:
763  template<class _inputMatrixType>
764  static void Run(const _inputMatrixType & inputMatrix,
765  typename _inputMatrixType::value_type & minValue, typename _inputMatrixType::value_type & maxValue)
766  {
767  typedef _inputMatrixType InputMatrixType;
768  typedef typename InputMatrixType::size_type size_type;
769  typedef typename InputMatrixType::const_pointer InputPointerType;
770  typedef typename InputMatrixType::value_type value_type;
771 
772  enum {
773  ROWS = InputMatrixType::ROWS,
774  COLS = InputMatrixType::COLS,
775  INPUT_COL_STRIDE = InputMatrixType::COLSTRIDE,
776  INPUT_ROW_STRIDE = InputMatrixType::ROWSTRIDE,
777  INPUT_STRIDE_TO_NEXT_ROW = INPUT_ROW_STRIDE - COLS * INPUT_COL_STRIDE
778  };
779 
780  InputPointerType inputPointer = inputMatrix.Pointer();
781  if (inputPointer == 0)
782  return;
783 
784  value_type minElement, maxElement;
785  maxElement = minElement = *inputPointer;
786 
787  size_type rowIndex, colIndex;
788  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
789  inputPointer += INPUT_STRIDE_TO_NEXT_ROW)
790  {
791  for (colIndex = 0; colIndex < COLS; ++colIndex,
792  inputPointer += INPUT_COL_STRIDE)
793  {
794  const value_type element = *inputPointer;
795  if (element < minElement) {
796  minElement = element;
797  }
798  else if (maxElement < element) {
799  maxElement = element;
800  }
801  }
802  }
803 
804  minValue = minElement;
805  maxValue = maxElement;
806  } // Run method
807  }; // MinAndMax class
808 
809 
811  {
812  public:
813  template<class _outputMatrixType, class _inputMatrixType, class _indexVectorType>
814  static void Run(_outputMatrixType & outputMatrix, const _inputMatrixType & inputMatrix,
815  const _indexVectorType & indexVector)
816  {
817  typedef _outputMatrixType OutputMatrixType;
818  typedef typename OutputMatrixType::size_type size_type;
819  typedef typename OutputMatrixType::pointer OutputPointerType;
820 
821  typedef _inputMatrixType InputMatrixType;
822  typedef typename InputMatrixType::const_pointer InputPointerType;
823  typedef _indexVectorType IndexVectorType;
824  typedef typename IndexVectorType::const_pointer IndexPointerType;
825 
826  enum {
827  ROWS = OutputMatrixType::ROWS,
828  COLS = OutputMatrixType::COLS,
829  OUTPUT_COL_STRIDE = OutputMatrixType::COLSTRIDE,
830  OUTPUT_ROW_STRIDE = OutputMatrixType::ROWSTRIDE,
831  OUTPUT_STRIDE_TO_NEXT_ROW = OUTPUT_ROW_STRIDE - COLS * OUTPUT_COL_STRIDE
832  };
833 
834  enum {
835  INPUT_COL_STRIDE = InputMatrixType::COLSTRIDE,
836  };
837 
838  enum {
839  INDEX_STRIDE = IndexVectorType::STRIDE,
840  };
841 
842  OutputPointerType outputPointer = outputMatrix.Pointer();
843  InputPointerType inputPointer = inputMatrix.Pointer();
844  IndexPointerType indexPointer = indexVector.Pointer();
845 
846  size_type rowIndex, colIndex;
847  for (rowIndex = 0; rowIndex < ROWS; ++rowIndex,
848  outputPointer += OUTPUT_STRIDE_TO_NEXT_ROW,
849  indexPointer += INDEX_STRIDE)
850  {
851  inputPointer = inputMatrix.Pointer(*indexPointer, 0);
852  for (colIndex = 0; colIndex < COLS; ++colIndex,
853  outputPointer += OUTPUT_COL_STRIDE,
854  inputPointer += INPUT_COL_STRIDE)
855  {
856  *outputPointer = *inputPointer;
857  }
858  }
859  }
860  };
861 
862 
863 };
864 
865 
866 #endif // _vctFixedSizeMatrixLoopEngines_h
867 
Definition: vctFixedSizeMatrixLoopEngines.h:760
_incrementalOperationType::OutputType OutputType
Definition: vctFixedSizeMatrixLoopEngines.h:402
static void Run(_inputOutputMatrixType &inputOutputMatrix, const _inputScalarType inputScalar)
Definition: vctFixedSizeMatrixLoopEngines.h:368
static void Run(_ioMatrixType &ioMatrix, const _input1MatrixType &input1Matrix, const _input2MatrixType &input2Matrix)
Definition: vctFixedSizeMatrixLoopEngines.h:596
static void Run(_ioMatrixType &ioMatrix, const _inputScalarType &inputScalar, const _inputMatrixType &inputMatrix)
Definition: vctFixedSizeMatrixLoopEngines.h:522
static OutputType Run(const _inputMatrixType &inputMatrix, const _inputScalarType &inputScalar)
Definition: vctFixedSizeMatrixLoopEngines.h:653
static OutputType Run(const _inputMatrixType &inputMatrix)
Definition: vctFixedSizeMatrixLoopEngines.h:405
static void Run(_outputMatrixType &outputMatrix, const _input1MatrixType &input1Matrix, const _input2MatrixType &input2Matrix)
Definition: vctFixedSizeMatrixLoopEngines.h:81
Definition: vctFixedSizeMatrixLoopEngines.h:690
static void Run(_outputMatrixType &outputMatrix, const _input1MatrixType &input1Matrix, const _input2MatrixType &input2Matrix)
Definition: vctFixedSizeMatrixLoopEngines.h:693
Definition: vctFixedSizeMatrixLoopEngines.h:137
size_t size_type
Definition: vctContainerTraits.h:35
Container class for the matrix engines.
Definition: vctFixedSizeMatrixLoopEngines.h:35
Definition: vctFixedSizeMatrixLoopEngines.h:810
Definition: vctFixedSizeMatrixLoopEngines.h:440
Definition: vctFixedSizeMatrixLoopEngines.h:267
static void Run(_inputOutputMatrixType &inputOutputMatrix)
Definition: vctFixedSizeMatrixLoopEngines.h:188
static void Run(_outputMatrixType &outputMatrix, const _inputMatrixType &inputMatrix, const _indexVectorType &indexVector)
Definition: vctFixedSizeMatrixLoopEngines.h:814
Definition: vctFixedSizeMatrixLoopEngines.h:365
Implement operation of the form for fixed size matrices.
Definition: vctFixedSizeMatrixLoopEngines.h:591
Definition: vctFixedSizeMatrixLoopEngines.h:400
#define cmnThrow(a)
Definition: MinimalCmn.h:4
static OutputType Run(const _input1MatrixType &input1Matrix, const _input2MatrixType &input2Matrix)
Definition: vctFixedSizeMatrixLoopEngines.h:445
Definition: vctFixedSizeMatrixLoopEngines.h:185
static void Run(_inputOutputMatrixType &inputOutputMatrix, const _inputMatrixType &inputMatrix)
Definition: vctFixedSizeMatrixLoopEngines.h:222
static void ThrowSharedPointersException(void)
Definition: vctFixedSizeMatrixLoopEngines.h:42
static void Run(const _inputMatrixType &inputMatrix, typename _inputMatrixType::value_type &minValue, typename _inputMatrixType::value_type &maxValue)
Definition: vctFixedSizeMatrixLoopEngines.h:764
_incrementalOperationType::OutputType OutputType
Definition: vctFixedSizeMatrixLoopEngines.h:442
Definition: vctFixedSizeMatrixLoopEngines.h:219
static void Run(_outputMatrixType &outputMatrix, const _inputMatrixType &inputMatrix)
Definition: vctFixedSizeMatrixLoopEngines.h:140
Definition: vctFixedSizeMatrixLoopEngines.h:648
Definition: vctFixedSizeMatrixLoopEngines.h:78
_incrementalOperationType::OutputType OutputType
Definition: vctFixedSizeMatrixLoopEngines.h:650
Implement operation of the form for fixed size matrices.
Definition: vctFixedSizeMatrixLoopEngines.h:517
static void Run(_outputMatrixType &outputMatrix, const _inputMatrixType &inputMatrix, const _inputScalarType inputScalar)
Definition: vctFixedSizeMatrixLoopEngines.h:270
static void Run(_outputMatrixType &outputMatrix, const _inputScalarType inputScalar, const _inputMatrixType &inputMatrix)
Definition: vctFixedSizeMatrixLoopEngines.h:319
Definition: vctFixedSizeMatrixLoopEngines.h:316