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