ARTS 2.5.0 (git: 9ee3ac6c)
m_reduce.h
Go to the documentation of this file.
1/* Copyright (C) 2014 Richard Larsson <ric.larsson@gmail.com>
2
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 USA. */
17
30#ifndef m_reduce_h
31#define m_reduce_h
32
33#include <cstring>
34#include "array.h"
35#include "exceptions.h"
36#include "matpackVII.h"
37
39
40inline Index num_elem_from_dim_sizes(const ArrayOfIndex& dim_sizes) {
41 Index m = 1;
42 for (ArrayOfIndex::const_iterator it = dim_sizes.begin();
43 it != dim_sizes.end();
44 it++)
45 m *= *it;
46
47 return m;
48}
49
50// Need this for each matpack type: Vector
51inline void select_dims_by_size(ArrayOfIndex& dim_sizes,
52 const Index min_num_elem,
53 const Vector& type) {
54 dim_sizes.resize(0);
55 if (type.nelem() > min_num_elem) dim_sizes.push_back(type.nelem());
56}
57
58// Need this for each matpack type: Matrix
59inline void select_dims_by_size(ArrayOfIndex& dim_sizes,
60 const Index min_num_elem,
61 const Matrix& type) {
62 dim_sizes.resize(0);
63 if (type.nrows() > min_num_elem) dim_sizes.push_back(type.nrows());
64 if (type.ncols() > min_num_elem) dim_sizes.push_back(type.ncols());
65}
66
67// Need this for each matpack type: Tensor3
68inline void select_dims_by_size(ArrayOfIndex& dim_sizes,
69 const Index min_num_elem,
70 const Tensor3& type) {
71 dim_sizes.resize(0);
72 if (type.npages() > min_num_elem) dim_sizes.push_back(type.npages());
73 if (type.nrows() > min_num_elem) dim_sizes.push_back(type.nrows());
74 if (type.ncols() > min_num_elem) dim_sizes.push_back(type.ncols());
75}
76
77// Need this for each matpack type: Tensor4
78inline void select_dims_by_size(ArrayOfIndex& dim_sizes,
79 const Index min_num_elem,
80 const Tensor4& type) {
81 dim_sizes.resize(0);
82 if (type.nbooks() > min_num_elem) dim_sizes.push_back(type.nbooks());
83 if (type.npages() > min_num_elem) dim_sizes.push_back(type.npages());
84 if (type.nrows() > min_num_elem) dim_sizes.push_back(type.nrows());
85 if (type.ncols() > min_num_elem) dim_sizes.push_back(type.ncols());
86}
87
88// Need this for each matpack type: Tensor5
89inline void select_dims_by_size(ArrayOfIndex& dim_sizes,
90 const Index min_num_elem,
91 const Tensor5& type) {
92 dim_sizes.resize(0);
93 if (type.nshelves() > min_num_elem) dim_sizes.push_back(type.nshelves());
94 if (type.nbooks() > min_num_elem) dim_sizes.push_back(type.nbooks());
95 if (type.npages() > min_num_elem) dim_sizes.push_back(type.npages());
96 if (type.nrows() > min_num_elem) dim_sizes.push_back(type.nrows());
97 if (type.ncols() > min_num_elem) dim_sizes.push_back(type.ncols());
98}
99
100// Need this for each matpack type: Tensor6
101inline void select_dims_by_size(ArrayOfIndex& dim_sizes,
102 const Index min_num_elem,
103 const Tensor6& type) {
104 dim_sizes.resize(0);
105 if (type.nvitrines() > min_num_elem) dim_sizes.push_back(type.nvitrines());
106 if (type.nshelves() > min_num_elem) dim_sizes.push_back(type.nshelves());
107 if (type.nbooks() > min_num_elem) dim_sizes.push_back(type.nbooks());
108 if (type.npages() > min_num_elem) dim_sizes.push_back(type.npages());
109 if (type.nrows() > min_num_elem) dim_sizes.push_back(type.nrows());
110 if (type.ncols() > min_num_elem) dim_sizes.push_back(type.ncols());
111}
112
113// Need this for each matpack type: Tensor7
114inline void select_dims_by_size(ArrayOfIndex& dim_sizes,
115 const Index min_num_elem,
116 const Tensor7& type) {
117 dim_sizes.resize(0);
118 if (type.nlibraries() > min_num_elem) dim_sizes.push_back(type.nlibraries());
119 if (type.nvitrines() > min_num_elem) dim_sizes.push_back(type.nvitrines());
120 if (type.nshelves() > min_num_elem) dim_sizes.push_back(type.nshelves());
121 if (type.nbooks() > min_num_elem) dim_sizes.push_back(type.nbooks());
122 if (type.npages() > min_num_elem) dim_sizes.push_back(type.npages());
123 if (type.nrows() > min_num_elem) dim_sizes.push_back(type.nrows());
124 if (type.ncols() > min_num_elem) dim_sizes.push_back(type.ncols());
125}
126
128
129// To Numeric
130
131/* Workspace method: Doxygen documentation will be auto-generated */
132inline void Reduce(
133 // WS Generic Output:
134 Numeric& o,
135 // WS Input:
136 // WS Generic Input:
137 const Vector& i,
138 const Verbosity&) {
139 if (i.nelem() == 1)
140 o = i[0];
141 else {
142 ostringstream os;
143 os << "The Vector is not also a Numeric";
144 throw std::runtime_error(os.str());
145 }
146}
147
148/* Workspace method: Doxygen documentation will be auto-generated */
149inline void Reduce(
150 // WS Generic Output:
151 Numeric& o,
152 // WS Input:
153 // WS Generic Input:
154 const Matrix& i,
155 const Verbosity&) {
156 if (i.ncols() == 1 && i.nrows() == 1)
157 o = i(0, 0);
158 else {
159 ostringstream os;
160 os << "The Matrix is not also a Numeric";
161 throw std::runtime_error(os.str());
162 }
163}
164
165/* Workspace method: Doxygen documentation will be auto-generated */
166inline void Reduce(
167 // WS Generic Output:
168 Numeric& o,
169 // WS Input:
170 // WS Generic Input:
171 const Tensor3& i,
172 const Verbosity&) {
173 if (i.ncols() == 1 && i.nrows() == 1 && i.npages() == 1)
174 o = i(0, 0, 0);
175 else {
176 ostringstream os;
177 os << "The Tensor3 is not also a Numeric";
178 throw std::runtime_error(os.str());
179 }
180}
181
182/* Workspace method: Doxygen documentation will be auto-generated */
183inline void Reduce(
184 // WS Generic Output:
185 Numeric& o,
186 // WS Input:
187 // WS Generic Input:
188 const Tensor4& i,
189 const Verbosity&) {
190 if (i.ncols() == 1 && i.nrows() == 1 && i.npages() == 1 && i.nbooks() == 1)
191 o = i(0, 0, 0, 0);
192 else {
193 ostringstream os;
194 os << "The Tensor4 is not also a Numeric";
195 throw std::runtime_error(os.str());
196 }
197}
198
199/* Workspace method: Doxygen documentation will be auto-generated */
200inline void Reduce(
201 // WS Generic Output:
202 Numeric& o,
203 // WS Input:
204 // WS Generic Input:
205 const Tensor5& i,
206 const Verbosity&) {
207 if (i.ncols() == 1 && i.nrows() == 1 && i.npages() == 1 && i.nbooks() == 1 &&
208 i.nshelves() == 1)
209 o = i(0, 0, 0, 0, 0);
210 else {
211 ostringstream os;
212 os << "The Tensor5 is not also a Numeric";
213 throw std::runtime_error(os.str());
214 }
215}
216
217/* Workspace method: Doxygen documentation will be auto-generated */
218inline void Reduce(
219 // WS Generic Output:
220 Numeric& o,
221 // WS Input:
222 // WS Generic Input:
223 const Tensor6& i,
224 const Verbosity&) {
225 if (i.ncols() == 1 && i.nrows() == 1 && i.npages() == 1 && i.nbooks() == 1 &&
226 i.nshelves() == 1 && i.nvitrines() == 1)
227 o = i(0, 0, 0, 0, 0, 0);
228 else {
229 ostringstream os;
230 os << "The Tensor6 is not also a Numeric";
231 throw std::runtime_error(os.str());
232 }
233}
234
235/* Workspace method: Doxygen documentation will be auto-generated */
236inline void Reduce(
237 // WS Generic Output:
238 Numeric& o,
239 // WS Input:
240 // WS Generic Input:
241 const Tensor7& i,
242 const Verbosity&) {
243 if (i.ncols() == 1 && i.nrows() == 1 && i.npages() == 1 && i.nbooks() == 1 &&
244 i.nshelves() == 1 && i.nvitrines() == 1 && i.nlibraries() == 1)
245 o = i(0, 0, 0, 0, 0, 0, 0);
246 else {
247 ostringstream os;
248 os << "The Tensor7 is not also a Numeric";
249 throw std::runtime_error(os.str());
250 }
251}
252
253//To Vector
254
255/* Workspace method: Doxygen documentation will be auto-generated */
256inline void Reduce(
257 // WS Generic Output:
258 Vector& o,
259 // WS Input:
260 // WS Generic Input:
261 const Matrix& i,
262 const Verbosity&) {
263 ArrayOfIndex dim_sizes;
264 Index test = 1;
265
266 select_dims_by_size(dim_sizes, 1, i);
267 Index num = dim_sizes.nelem();
268 if (num == test) {
269 o.resize(dim_sizes[0]);
270 memcpy(o.get_c_array(),
271 i.get_c_array(),
272 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
273 } else {
274 ostringstream os;
275 os << "The Matrix of size (" << dim_sizes << ") \n"
276 << "does not fit a Vector";
277 throw std::runtime_error(os.str());
278 }
279}
280
281/* Workspace method: Doxygen documentation will be auto-generated */
282inline void Reduce(
283 // WS Generic Output:
284 Vector& o,
285 // WS Input:
286 // WS Generic Input:
287 const Tensor3& i,
288 const Verbosity&) {
289 ArrayOfIndex dim_sizes;
290 Index test = 1;
291
292 select_dims_by_size(dim_sizes, 1, i);
293 Index num = dim_sizes.nelem();
294 if (num == test) {
295 o.resize(dim_sizes[0]);
296 memcpy(o.get_c_array(),
297 i.get_c_array(),
298 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
299 } else {
300 ostringstream os;
301 os << "The Tensor3 of size (" << dim_sizes << ") \n"
302 << "does not fit a Vector";
303 throw std::runtime_error(os.str());
304 }
305}
306
307/* Workspace method: Doxygen documentation will be auto-generated */
308inline void Reduce(
309 // WS Generic Output:
310 Vector& o,
311 // WS Input:
312 // WS Generic Input:
313 const Tensor4& i,
314 const Verbosity&) {
315 ArrayOfIndex dim_sizes;
316 Index test = 1;
317
318 select_dims_by_size(dim_sizes, 1, i);
319 Index num = dim_sizes.nelem();
320 if (num == test) {
321 o.resize(dim_sizes[0]);
322 memcpy(o.get_c_array(),
323 i.get_c_array(),
324 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
325 } else {
326 ostringstream os;
327 os << "The Tensor4 of size (" << dim_sizes << ") \n"
328 << "does not fit a Vector";
329 throw std::runtime_error(os.str());
330 }
331}
332
333/* Workspace method: Doxygen documentation will be auto-generated */
334inline void Reduce(
335 // WS Generic Output:
336 Vector& o,
337 // WS Input:
338 // WS Generic Input:
339 const Tensor5& i,
340 const Verbosity&) {
341 ArrayOfIndex dim_sizes;
342 Index test = 1;
343
344 select_dims_by_size(dim_sizes, 1, i);
345 Index num = dim_sizes.nelem();
346 if (num == test) {
347 o.resize(dim_sizes[0]);
348 memcpy(o.get_c_array(),
349 i.get_c_array(),
350 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
351 } else {
352 ostringstream os;
353 os << "The Tensor5 of size (" << dim_sizes << ") \n"
354 << "does not fit a Vector";
355 throw std::runtime_error(os.str());
356 }
357}
358
359/* Workspace method: Doxygen documentation will be auto-generated */
360inline void Reduce(
361 // WS Generic Output:
362 Vector& o,
363 // WS Input:
364 // WS Generic Input:
365 const Tensor6& i,
366 const Verbosity&) {
367 ArrayOfIndex dim_sizes;
368 Index test = 1;
369
370 select_dims_by_size(dim_sizes, 1, i);
371 Index num = dim_sizes.nelem();
372 if (num == test) {
373 o.resize(dim_sizes[0]);
374 memcpy(o.get_c_array(),
375 i.get_c_array(),
376 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
377 } else {
378 ostringstream os;
379 os << "The Tensor6 of size (" << dim_sizes << ") \n"
380 << "does not fit a Vector";
381 throw std::runtime_error(os.str());
382 }
383}
384
385/* Workspace method: Doxygen documentation will be auto-generated */
386inline void Reduce(
387 // WS Generic Output:
388 Vector& o,
389 // WS Input:
390 // WS Generic Input:
391 const Tensor7& i,
392 const Verbosity&) {
393 ArrayOfIndex dim_sizes;
394 Index test = 1;
395
396 select_dims_by_size(dim_sizes, 1, i);
397 Index num = dim_sizes.nelem();
398 if (num == test) {
399 o.resize(dim_sizes[0]);
400 memcpy(o.get_c_array(),
401 i.get_c_array(),
402 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
403 } else {
404 ostringstream os;
405 os << "The Tensor7 of size (" << dim_sizes << ") \n"
406 << "does not fit a Vector";
407 throw std::runtime_error(os.str());
408 }
409}
410
411// To Matrix
412
413/* Workspace method: Doxygen documentation will be auto-generated */
414inline void Reduce(
415 // WS Generic Output:
416 Matrix& o,
417 // WS Input:
418 // WS Generic Input:
419 const Tensor3& i,
420 const Verbosity&) {
421 ArrayOfIndex dim_sizes;
422 Index test = 2;
423
424 select_dims_by_size(dim_sizes, 1, i);
425 Index num = dim_sizes.nelem();
426 if (num == test) {
427 o.resize(dim_sizes[0], dim_sizes[1]);
428 memcpy(o.get_c_array(),
429 i.get_c_array(),
430 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
431 } else {
432 ostringstream os;
433 os << "The Tensor3 of size (" << dim_sizes << ") \n"
434 << "does not fit a Matrix";
435 throw std::runtime_error(os.str());
436 }
437}
438
439/* Workspace method: Doxygen documentation will be auto-generated */
440inline void Reduce(
441 // WS Generic Output:
442 Matrix& o,
443 // WS Input:
444 // WS Generic Input:
445 const Tensor4& i,
446 const Verbosity&) {
447 ArrayOfIndex dim_sizes;
448 Index test = 2;
449
450 select_dims_by_size(dim_sizes, 1, i);
451 Index num = dim_sizes.nelem();
452 if (num == test) {
453 o.resize(dim_sizes[0], dim_sizes[1]);
454 memcpy(o.get_c_array(),
455 i.get_c_array(),
456 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
457 } else {
458 ostringstream os;
459 os << "The Tensor4 of size (" << dim_sizes << ") \n"
460 << "does not fit a Matrix";
461 throw std::runtime_error(os.str());
462 }
463}
464
465/* Workspace method: Doxygen documentation will be auto-generated */
466inline void Reduce(
467 // WS Generic Output:
468 Matrix& o,
469 // WS Input:
470 // WS Generic Input:
471 const Tensor5& i,
472 const Verbosity&) {
473 ArrayOfIndex dim_sizes;
474 Index test = 2;
475
476 select_dims_by_size(dim_sizes, 1, i);
477 Index num = dim_sizes.nelem();
478 if (num == test) {
479 o.resize(dim_sizes[0], dim_sizes[1]);
480 memcpy(o.get_c_array(),
481 i.get_c_array(),
482 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
483 } else {
484 ostringstream os;
485 os << "The Tensor5 of size (" << dim_sizes << ") \n"
486 << "does not fit a Matrix";
487 throw std::runtime_error(os.str());
488 }
489}
490
491/* Workspace method: Doxygen documentation will be auto-generated */
492inline void Reduce(
493 // WS Generic Output:
494 Matrix& o,
495 // WS Input:
496 // WS Generic Input:
497 const Tensor6& i,
498 const Verbosity&) {
499 ArrayOfIndex dim_sizes;
500 Index test = 2;
501
502 select_dims_by_size(dim_sizes, 1, i);
503 Index num = dim_sizes.nelem();
504 if (num == test) {
505 o.resize(dim_sizes[0], dim_sizes[1]);
506 memcpy(o.get_c_array(),
507 i.get_c_array(),
508 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
509 } else {
510 ostringstream os;
511 os << "The Tensor6 of size (" << dim_sizes << ") \n"
512 << "does not fit a Matrix";
513 throw std::runtime_error(os.str());
514 }
515}
516
517/* Workspace method: Doxygen documentation will be auto-generated */
518inline void Reduce(
519 // WS Generic Output:
520 Matrix& o,
521 // WS Input:
522 // WS Generic Input:
523 const Tensor7& i,
524 const Verbosity&) {
525 ArrayOfIndex dim_sizes;
526 Index test = 2;
527
528 select_dims_by_size(dim_sizes, 1, i);
529 Index num = dim_sizes.nelem();
530 if (num == test) {
531 o.resize(dim_sizes[0], dim_sizes[1]);
532 memcpy(o.get_c_array(),
533 i.get_c_array(),
534 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
535 } else {
536 ostringstream os;
537 os << "The Tensor7 of size (" << dim_sizes << ") \n"
538 << "does not fit a Matrix";
539 throw std::runtime_error(os.str());
540 }
541}
542
543// To Tensor 3
544
545/* Workspace method: Doxygen documentation will be auto-generated */
546inline void Reduce(
547 // WS Generic Output:
548 Tensor3& o,
549 // WS Input:
550 // WS Generic Input:
551 const Tensor4& i,
552 const Verbosity&) {
553 ArrayOfIndex dim_sizes;
554 Index test = 3;
555
556 select_dims_by_size(dim_sizes, 1, i);
557 Index num = dim_sizes.nelem();
558 if (num == test) {
559 o.resize(dim_sizes[0], dim_sizes[1], dim_sizes[2]);
560 memcpy(o.get_c_array(),
561 i.get_c_array(),
562 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
563 } else {
564 ostringstream os;
565 os << "The Tensor4 of size (" << dim_sizes << ") \n"
566 << "does not fit a Tensor3";
567 throw std::runtime_error(os.str());
568 }
569}
570
571/* Workspace method: Doxygen documentation will be auto-generated */
572inline void Reduce(
573 // WS Generic Output:
574 Tensor3& o,
575 // WS Input:
576 // WS Generic Input:
577 const Tensor5& i,
578 const Verbosity&) {
579 ArrayOfIndex dim_sizes;
580 Index test = 3;
581
582 select_dims_by_size(dim_sizes, 1, i);
583 Index num = dim_sizes.nelem();
584 if (num == test) {
585 o.resize(dim_sizes[0], dim_sizes[1], dim_sizes[2]);
586 memcpy(o.get_c_array(),
587 i.get_c_array(),
588 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
589 } else {
590 ostringstream os;
591 os << "The Tensor5 of size (" << dim_sizes << ") \n"
592 << "does not fit a Tensor3";
593 throw std::runtime_error(os.str());
594 }
595}
596
597/* Workspace method: Doxygen documentation will be auto-generated */
598inline void Reduce(
599 // WS Generic Output:
600 Tensor3& o,
601 // WS Input:
602 // WS Generic Input:
603 const Tensor6& i,
604 const Verbosity&) {
605 ArrayOfIndex dim_sizes;
606 Index test = 3;
607
608 select_dims_by_size(dim_sizes, 1, i);
609 Index num = dim_sizes.nelem();
610 if (num == test) {
611 o.resize(dim_sizes[0], dim_sizes[1], dim_sizes[2]);
612 memcpy(o.get_c_array(),
613 i.get_c_array(),
614 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
615 } else {
616 ostringstream os;
617 os << "The Tensor6 of size (" << dim_sizes << ") \n"
618 << "does not fit a Tensor3";
619 throw std::runtime_error(os.str());
620 }
621}
622
623/* Workspace method: Doxygen documentation will be auto-generated */
624inline void Reduce(
625 // WS Generic Output:
626 Tensor3& o,
627 // WS Input:
628 // WS Generic Input:
629 const Tensor7& i,
630 const Verbosity&) {
631 ArrayOfIndex dim_sizes;
632 Index test = 3;
633
634 select_dims_by_size(dim_sizes, 1, i);
635 Index num = dim_sizes.nelem();
636 if (num == test) {
637 o.resize(dim_sizes[0], dim_sizes[1], dim_sizes[2]);
638 memcpy(o.get_c_array(),
639 i.get_c_array(),
640 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
641 } else {
642 ostringstream os;
643 os << "The Tensor7 of size (" << dim_sizes << ") \n"
644 << "does not fit a Tensor3";
645 throw std::runtime_error(os.str());
646 }
647}
648
649// To Tensor4
650
651/* Workspace method: Doxygen documentation will be auto-generated */
652inline void Reduce(
653 // WS Generic Output:
654 Tensor4& o,
655 // WS Input:
656 // WS Generic Input:
657 const Tensor5& i,
658 const Verbosity&) {
659 ArrayOfIndex dim_sizes;
660 Index test = 4;
661
662 select_dims_by_size(dim_sizes, 1, i);
663 Index num = dim_sizes.nelem();
664 if (num == test) {
665 o.resize(dim_sizes[0], dim_sizes[1], dim_sizes[2], dim_sizes[3]);
666 memcpy(o.get_c_array(),
667 i.get_c_array(),
668 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
669 } else {
670 ostringstream os;
671 os << "The Tensor5 of size (" << dim_sizes << ") \n"
672 << "does not fit a Tensor4";
673 throw std::runtime_error(os.str());
674 }
675}
676
677/* Workspace method: Doxygen documentation will be auto-generated */
678inline void Reduce(
679 // WS Generic Output:
680 Tensor4& o,
681 // WS Input:
682 // WS Generic Input:
683 const Tensor6& i,
684 const Verbosity&) {
685 ArrayOfIndex dim_sizes;
686 Index test = 4;
687
688 select_dims_by_size(dim_sizes, 1, i);
689 Index num = dim_sizes.nelem();
690 if (num == test) {
691 o.resize(dim_sizes[0], dim_sizes[1], dim_sizes[2], dim_sizes[3]);
692 memcpy(o.get_c_array(),
693 i.get_c_array(),
694 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
695 } else {
696 ostringstream os;
697 os << "The Tensor6 of size (" << dim_sizes << ") \n"
698 << "does not fit a Tensor4";
699 throw std::runtime_error(os.str());
700 }
701}
702
703/* Workspace method: Doxygen documentation will be auto-generated */
704inline void Reduce(
705 // WS Generic Output:
706 Tensor4& o,
707 // WS Input:
708 // WS Generic Input:
709 const Tensor7& i,
710 const Verbosity&) {
711 ArrayOfIndex dim_sizes;
712 Index test = 4;
713
714 select_dims_by_size(dim_sizes, 1, i);
715 Index num = dim_sizes.nelem();
716 if (num == test) {
717 o.resize(dim_sizes[0], dim_sizes[1], dim_sizes[2], dim_sizes[3]);
718 memcpy(o.get_c_array(),
719 i.get_c_array(),
720 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
721 } else {
722 ostringstream os;
723 os << "The Tensor7 of size (" << dim_sizes << ") \n"
724 << "does not fit a Tensor4";
725 throw std::runtime_error(os.str());
726 }
727}
728
729// To Tensor5
730
731/* Workspace method: Doxygen documentation will be auto-generated */
732inline void Reduce(
733 // WS Generic Output:
734 Tensor5& o,
735 // WS Input:
736 // WS Generic Input:
737 const Tensor6& i,
738 const Verbosity&) {
739 ArrayOfIndex dim_sizes;
740 Index test = 5;
741
742 select_dims_by_size(dim_sizes, 1, i);
743 Index num = dim_sizes.nelem();
744 if (num == test) {
745 o.resize(
746 dim_sizes[0], dim_sizes[1], dim_sizes[2], dim_sizes[3], dim_sizes[4]);
747 memcpy(o.get_c_array(),
748 i.get_c_array(),
749 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
750 } else {
751 ostringstream os;
752 os << "The Tensor6 of size (" << dim_sizes << ") \n"
753 << "does not fit a Tensor5";
754 throw std::runtime_error(os.str());
755 }
756}
757
758/* Workspace method: Doxygen documentation will be auto-generated */
759inline void Reduce(
760 // WS Generic Output:
761 Tensor5& o,
762 // WS Input:
763 // WS Generic Input:
764 const Tensor7& i,
765 const Verbosity&) {
766 ArrayOfIndex dim_sizes;
767 Index test = 5;
768
769 select_dims_by_size(dim_sizes, 1, i);
770 Index num = dim_sizes.nelem();
771 if (num == test) {
772 o.resize(
773 dim_sizes[0], dim_sizes[1], dim_sizes[2], dim_sizes[3], dim_sizes[4]);
774 memcpy(o.get_c_array(),
775 i.get_c_array(),
776 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
777 } else {
778 ostringstream os;
779 os << "The Tensor7 of size (" << dim_sizes << ") \n"
780 << "does not fit a Tensor5";
781 throw std::runtime_error(os.str());
782 }
783}
784
785// To Tensor6
786
787/* Workspace method: Doxygen documentation will be auto-generated */
788inline void Reduce(
789 // WS Generic Output:
790 Tensor6& o,
791 // WS Input:
792 // WS Generic Input:
793 const Tensor7& i,
794 const Verbosity&) {
795 ArrayOfIndex dim_sizes;
796 Index test = 6;
797
798 select_dims_by_size(dim_sizes, 1, i);
799 Index num = dim_sizes.nelem();
800 if (num == test) {
801 o.resize(dim_sizes[0],
802 dim_sizes[1],
803 dim_sizes[2],
804 dim_sizes[3],
805 dim_sizes[4],
806 dim_sizes[5]);
807 memcpy(o.get_c_array(),
808 i.get_c_array(),
809 sizeof(Numeric) * num_elem_from_dim_sizes(dim_sizes));
810 } else {
811 ostringstream os;
812 os << "The Tensor7 of size (" << dim_sizes << ") \n"
813 << "does not fit a Tensor6";
814 throw std::runtime_error(os.str());
815 }
816}
817
818#endif /* m_reduce_h */
This file contains the definition of Array.
Index nelem() const ARTS_NOEXCEPT
Number of elements.
Definition: array.h:195
Index nrows() const ARTS_NOEXCEPT
Returns the number of rows.
Definition: matpackI.cc:433
Index ncols() const ARTS_NOEXCEPT
Returns the number of columns.
Definition: matpackI.cc:436
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:144
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:147
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:150
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:58
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:55
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:64
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:61
Index ncols() const
Returns the number of columns.
Definition: matpackV.cc:56
Index nshelves() const
Returns the number of shelves.
Definition: matpackV.cc:44
Index npages() const
Returns the number of pages.
Definition: matpackV.cc:50
Index nrows() const
Returns the number of rows.
Definition: matpackV.cc:53
Index nbooks() const
Returns the number of books.
Definition: matpackV.cc:47
Index ncols() const
Returns the number of columns.
Definition: matpackVI.cc:57
Index npages() const
Returns the number of pages.
Definition: matpackVI.cc:51
Index nrows() const
Returns the number of rows.
Definition: matpackVI.cc:54
Index nshelves() const
Returns the number of shelves.
Definition: matpackVI.cc:45
Index nbooks() const
Returns the number of books.
Definition: matpackVI.cc:48
Index nvitrines() const
Returns the number of vitrines.
Definition: matpackVI.cc:42
Index nshelves() const
Returns the number of shelves.
Definition: matpackVII.cc:48
Index nrows() const
Returns the number of rows.
Definition: matpackVII.cc:57
Index nvitrines() const
Returns the number of vitrines.
Definition: matpackVII.cc:45
Index npages() const
Returns the number of pages.
Definition: matpackVII.cc:54
Index ncols() const
Returns the number of columns.
Definition: matpackVII.cc:60
Index nlibraries() const
Returns the number of libraries.
Definition: matpackVII.cc:42
Index nbooks() const
Returns the number of books.
Definition: matpackVII.cc:51
Index nelem() const ARTS_NOEXCEPT
Returns the number of elements.
Definition: matpackI.cc:48
const Numeric * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array.
Definition: matpackI.cc:739
The Matrix class.
Definition: matpackI.h:1225
void resize(Index r, Index c)
Resize function.
Definition: matpackI.cc:1056
const Numeric * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array.
Definition: matpackIII.cc:317
The Tensor3 class.
Definition: matpackIII.h:339
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.cc:658
const Numeric * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array.
Definition: matpackIV.cc:354
The Tensor4 class.
Definition: matpackIV.h:421
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1058
const Numeric * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array.
Definition: matpackV.cc:674
The Tensor5 class.
Definition: matpackV.h:506
void resize(Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackV.cc:1741
const Numeric * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array.
Definition: matpackVI.cc:1732
The Tensor6 class.
Definition: matpackVI.h:1088
void resize(Index v, Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackVI.cc:2171
const Numeric * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array.
Definition: matpackVII.cc:5011
The Tensor7 class.
Definition: matpackVII.h:2382
const Numeric * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array, const-version.
Definition: matpackI.cc:271
The Vector class.
Definition: matpackI.h:876
void resize(Index n)
Resize function.
Definition: matpackI.cc:408
The declarations of all the exception classes.
void Reduce(Numeric &o, const Vector &i, const Verbosity &)
WORKSPACE METHOD: Reduce.
Definition: m_reduce.h:132
Index num_elem_from_dim_sizes(const ArrayOfIndex &dim_sizes)
Definition: m_reduce.h:40
void select_dims_by_size(ArrayOfIndex &dim_sizes, const Index min_num_elem, const Vector &type)
Definition: m_reduce.h:51
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
char Type type