ARTS  2.2.66
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 
31 #ifndef m_reduce_h
32 #define m_reduce_h
33 
34 #include "array.h"
35 #include "exceptions.h"
36 #include "matpackVII.h"
37 #include <cstring>
38 
39 
41 
42 
44 {
45  Index m = 1;
46  for (ArrayOfIndex::const_iterator it = dim_sizes.begin();
47  it != dim_sizes.end(); it++)
48  m *= *it;
49 
50  return m;
51 }
52 
53 
54 // Need this for each matpack type: Vector
56  const Index min_num_elem,
57  const Vector &type)
58 {
59  dim_sizes.resize(0);
60  if (type.nelem() > min_num_elem) dim_sizes.push_back(type.nelem());
61 }
62 
63 
64 // Need this for each matpack type: Matrix
66  const Index min_num_elem,
67  const Matrix &type)
68 {
69  dim_sizes.resize(0);
70  if (type.nrows() > min_num_elem) dim_sizes.push_back(type.nrows());
71  if (type.ncols() > min_num_elem) dim_sizes.push_back(type.ncols());
72 }
73 
74 
75 // Need this for each matpack type: Tensor3
77  const Index min_num_elem,
78  const Tensor3 &type)
79 {
80  dim_sizes.resize(0);
81  if (type.npages() > min_num_elem) dim_sizes.push_back(type.npages());
82  if (type.nrows() > min_num_elem) dim_sizes.push_back(type.nrows());
83  if (type.ncols() > min_num_elem) dim_sizes.push_back(type.ncols());
84 }
85 
86 
87 // Need this for each matpack type: Tensor4
89  const Index min_num_elem,
90  const Tensor4 &type)
91 {
92  dim_sizes.resize(0);
93  if (type.nbooks() > min_num_elem) dim_sizes.push_back(type.nbooks());
94  if (type.npages() > min_num_elem) dim_sizes.push_back(type.npages());
95  if (type.nrows() > min_num_elem) dim_sizes.push_back(type.nrows());
96  if (type.ncols() > min_num_elem) dim_sizes.push_back(type.ncols());
97 }
98 
99 
100 // Need this for each matpack type: Tensor5
102  const Index min_num_elem,
103  const Tensor5 &type)
104 {
105  dim_sizes.resize(0);
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 
114 // Need this for each matpack type: Tensor6
116  const Index min_num_elem,
117  const Tensor6 &type)
118 {
119  dim_sizes.resize(0);
120  if (type.nvitrines() > min_num_elem) dim_sizes.push_back(type.nvitrines());
121  if (type.nshelves() > min_num_elem) dim_sizes.push_back(type.nshelves());
122  if (type.nbooks() > min_num_elem) dim_sizes.push_back(type.nbooks());
123  if (type.npages() > min_num_elem) dim_sizes.push_back(type.npages());
124  if (type.nrows() > min_num_elem) dim_sizes.push_back(type.nrows());
125  if (type.ncols() > min_num_elem) dim_sizes.push_back(type.ncols());
126 }
127 
128 
129 // Need this for each matpack type: Tensor7
131  const Index min_num_elem,
132  const Tensor7 &type)
133 {
134  dim_sizes.resize(0);
135  if (type.nlibraries() > min_num_elem) dim_sizes.push_back(type.nlibraries());
136  if (type.nvitrines() > min_num_elem) dim_sizes.push_back(type.nvitrines());
137  if (type.nshelves() > min_num_elem) dim_sizes.push_back(type.nshelves());
138  if (type.nbooks() > min_num_elem) dim_sizes.push_back(type.nbooks());
139  if (type.npages() > min_num_elem) dim_sizes.push_back(type.npages());
140  if (type.nrows() > min_num_elem) dim_sizes.push_back(type.nrows());
141  if (type.ncols() > min_num_elem) dim_sizes.push_back(type.ncols());
142 }
143 
144 
146 
147 
148 // To Numeric
149 
150 
151 /* Workspace method: Doxygen documentation will be auto-generated */
152 void Reduce(
153  // WS Generic Output:
154  Numeric& o,
155  // WS Input:
156  // WS Generic Input:
157  const Vector& i,
158  const Verbosity&)
159 {
160  if( i.nelem() == 1 )
161  o=i[0];
162  else
163  {
164  ostringstream os;
165  os << "The Vector is not also a Numeric";
166  throw std::runtime_error( os.str() );
167  }
168 }
169 
170 
171 /* Workspace method: Doxygen documentation will be auto-generated */
172 void Reduce(
173  // WS Generic Output:
174  Numeric& o,
175  // WS Input:
176  // WS Generic Input:
177  const Matrix& i,
178  const Verbosity&)
179 {
180  if( i.ncols() == 1 &&
181  i.nrows() == 1 )
182  o=i(0,0);
183  else
184  {
185  ostringstream os;
186  os << "The Matrix is not also a Numeric";
187  throw std::runtime_error( os.str() );
188  }
189 }
190 
191 
192 /* Workspace method: Doxygen documentation will be auto-generated */
193 void Reduce(
194  // WS Generic Output:
195  Numeric& o,
196  // WS Input:
197  // WS Generic Input:
198  const Tensor3& i,
199  const Verbosity&)
200 {
201  if( i.ncols() == 1 &&
202  i.nrows() == 1 &&
203  i.npages() == 1 )
204  o=i(0,0,0);
205  else
206  {
207  ostringstream os;
208  os << "The Tensor3 is not also a Numeric";
209  throw std::runtime_error( os.str() );
210  }
211 }
212 
213 
214 /* Workspace method: Doxygen documentation will be auto-generated */
215 void Reduce(
216  // WS Generic Output:
217  Numeric& o,
218  // WS Input:
219  // WS Generic Input:
220  const Tensor4& i,
221  const Verbosity&)
222 {
223  if( i.ncols() == 1 &&
224  i.nrows() == 1 &&
225  i.npages() == 1 &&
226  i.nbooks() == 1 )
227  o=i(0,0,0,0);
228  else
229  {
230  ostringstream os;
231  os << "The Tensor4 is not also a Numeric";
232  throw std::runtime_error( os.str() );
233  }
234 }
235 
236 
237 /* Workspace method: Doxygen documentation will be auto-generated */
238 void Reduce(
239  // WS Generic Output:
240  Numeric& o,
241  // WS Input:
242  // WS Generic Input:
243  const Tensor5& i,
244  const Verbosity&)
245 {
246  if( i.ncols() == 1 &&
247  i.nrows() == 1 &&
248  i.npages() == 1 &&
249  i.nbooks() == 1 &&
250  i.nshelves() == 1 )
251  o=i(0,0,0,0,0);
252  else
253  {
254  ostringstream os;
255  os << "The Tensor5 is not also a Numeric";
256  throw std::runtime_error( os.str() );
257  }
258 }
259 
260 
261 /* Workspace method: Doxygen documentation will be auto-generated */
262 void Reduce(
263  // WS Generic Output:
264  Numeric& o,
265  // WS Input:
266  // WS Generic Input:
267  const Tensor6& i,
268  const Verbosity&)
269 {
270  if( i.ncols() == 1 &&
271  i.nrows() == 1 &&
272  i.npages() == 1 &&
273  i.nbooks() == 1 &&
274  i.nshelves() == 1 &&
275  i.nvitrines() == 1 )
276  o=i(0,0,0,0,0,0);
277  else
278  {
279  ostringstream os;
280  os << "The Tensor6 is not also a Numeric";
281  throw std::runtime_error( os.str() );
282  }
283 }
284 
285 
286 /* Workspace method: Doxygen documentation will be auto-generated */
287 void Reduce(
288  // WS Generic Output:
289  Numeric& o,
290  // WS Input:
291  // WS Generic Input:
292  const Tensor7& i,
293  const Verbosity&)
294 {
295  if( i.ncols() == 1 &&
296  i.nrows() == 1 &&
297  i.npages() == 1 &&
298  i.nbooks() == 1 &&
299  i.nshelves() == 1 &&
300  i.nvitrines() == 1 &&
301  i.nlibraries() == 1 )
302  o=i(0,0,0,0,0,0,0);
303  else
304  {
305  ostringstream os;
306  os << "The Tensor7 is not also a Numeric";
307  throw std::runtime_error( os.str() );
308  }
309 }
310 
311 
312 //To Vector
313 
314 
315 /* Workspace method: Doxygen documentation will be auto-generated */
316 void Reduce(
317  // WS Generic Output:
318  Vector& o,
319  // WS Input:
320  // WS Generic Input:
321  const Matrix& i,
322  const Verbosity&)
323 {
324  ArrayOfIndex dim_sizes;
325  Index test = 1;
326 
327  select_dims_by_size(dim_sizes, 1, i);
328  Index num = dim_sizes.nelem();
329  if( num == test)
330  {
331  o.resize(dim_sizes[0]);
332  memcpy(o.get_c_array(),
333  i.get_c_array(),
334  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
335  }
336  else
337  {
338  ostringstream os;
339  os << "The Matrix of size (" << dim_sizes << ") \n"
340  << "does not fit a Vector";
341  throw std::runtime_error(os.str());
342  }
343 }
344 
345 
346 /* Workspace method: Doxygen documentation will be auto-generated */
347 void Reduce(
348  // WS Generic Output:
349  Vector& o,
350  // WS Input:
351  // WS Generic Input:
352  const Tensor3& i,
353  const Verbosity&)
354 {
355  ArrayOfIndex dim_sizes;
356  Index test = 1;
357 
358  select_dims_by_size(dim_sizes, 1, i);
359  Index num = dim_sizes.nelem();
360  if( num == test)
361  {
362  o.resize(dim_sizes[0]);
363  memcpy(o.get_c_array(),
364  i.get_c_array(),
365  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
366  }
367  else
368  {
369  ostringstream os;
370  os << "The Tensor3 of size (" << dim_sizes << ") \n"
371  << "does not fit a Vector";
372  throw std::runtime_error(os.str());
373  }
374 }
375 
376 
377 /* Workspace method: Doxygen documentation will be auto-generated */
378 void Reduce(
379  // WS Generic Output:
380  Vector& o,
381  // WS Input:
382  // WS Generic Input:
383  const Tensor4& i,
384  const Verbosity&)
385 {
386  ArrayOfIndex dim_sizes;
387  Index test = 1;
388 
389  select_dims_by_size(dim_sizes, 1, i);
390  Index num = dim_sizes.nelem();
391  if( num == test)
392  {
393  o.resize(dim_sizes[0]);
394  memcpy(o.get_c_array(),
395  i.get_c_array(),
396  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
397  }
398  else
399  {
400  ostringstream os;
401  os << "The Tensor4 of size (" << dim_sizes << ") \n"
402  << "does not fit a Vector";
403  throw std::runtime_error(os.str());
404  }
405 }
406 
407 
408 /* Workspace method: Doxygen documentation will be auto-generated */
409 void Reduce(
410  // WS Generic Output:
411  Vector& o,
412  // WS Input:
413  // WS Generic Input:
414  const Tensor5& i,
415  const Verbosity&)
416 {
417  ArrayOfIndex dim_sizes;
418  Index test = 1;
419 
420  select_dims_by_size(dim_sizes, 1, i);
421  Index num = dim_sizes.nelem();
422  if( num == test)
423  {
424  o.resize(dim_sizes[0]);
425  memcpy(o.get_c_array(),
426  i.get_c_array(),
427  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
428  }
429  else
430  {
431  ostringstream os;
432  os << "The Tensor5 of size (" << dim_sizes << ") \n"
433  << "does not fit a Vector";
434  throw std::runtime_error(os.str());
435  }
436 }
437 
438 
439 /* Workspace method: Doxygen documentation will be auto-generated */
440 void Reduce(
441  // WS Generic Output:
442  Vector& o,
443  // WS Input:
444  // WS Generic Input:
445  const Tensor6& i,
446  const Verbosity&)
447 {
448  ArrayOfIndex dim_sizes;
449  Index test = 1;
450 
451  select_dims_by_size(dim_sizes, 1, i);
452  Index num = dim_sizes.nelem();
453  if( num == test)
454  {
455  o.resize(dim_sizes[0]);
456  memcpy(o.get_c_array(),
457  i.get_c_array(),
458  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
459  }
460  else
461  {
462  ostringstream os;
463  os << "The Tensor6 of size (" << dim_sizes << ") \n"
464  << "does not fit a Vector";
465  throw std::runtime_error(os.str());
466  }
467 }
468 
469 
470 /* Workspace method: Doxygen documentation will be auto-generated */
471 void Reduce(
472  // WS Generic Output:
473  Vector& o,
474  // WS Input:
475  // WS Generic Input:
476  const Tensor7& i,
477  const Verbosity&)
478 {
479  ArrayOfIndex dim_sizes;
480  Index test = 1;
481 
482  select_dims_by_size(dim_sizes, 1, i);
483  Index num = dim_sizes.nelem();
484  if( num == test)
485  {
486  o.resize(dim_sizes[0]);
487  memcpy(o.get_c_array(),
488  i.get_c_array(),
489  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
490  }
491  else
492  {
493  ostringstream os;
494  os << "The Tensor7 of size (" << dim_sizes << ") \n"
495  << "does not fit a Vector";
496  throw std::runtime_error(os.str());
497  }
498 }
499 
500 
501 // To Matrix
502 
503 
504 /* Workspace method: Doxygen documentation will be auto-generated */
505 void Reduce(
506  // WS Generic Output:
507  Matrix& o,
508  // WS Input:
509  // WS Generic Input:
510  const Tensor3& i,
511  const Verbosity&)
512 {
513  ArrayOfIndex dim_sizes;
514  Index test = 2;
515 
516  select_dims_by_size(dim_sizes, 1, i);
517  Index num = dim_sizes.nelem();
518  if( num == test)
519  {
520  o.resize(dim_sizes[0],
521  dim_sizes[1]);
522  memcpy(o.get_c_array(),
523  i.get_c_array(),
524  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
525  }
526  else
527  {
528  ostringstream os;
529  os << "The Tensor3 of size (" << dim_sizes << ") \n"
530  << "does not fit a Matrix";
531  throw std::runtime_error(os.str());
532  }
533 }
534 
535 
536 /* Workspace method: Doxygen documentation will be auto-generated */
537 void Reduce(
538  // WS Generic Output:
539  Matrix& o,
540  // WS Input:
541  // WS Generic Input:
542  const Tensor4& i,
543  const Verbosity&)
544 {
545  ArrayOfIndex dim_sizes;
546  Index test = 2;
547 
548  select_dims_by_size(dim_sizes, 1, i);
549  Index num = dim_sizes.nelem();
550  if( num == test)
551  {
552  o.resize(dim_sizes[0],
553  dim_sizes[1]);
554  memcpy(o.get_c_array(),
555  i.get_c_array(),
556  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
557  }
558  else
559  {
560  ostringstream os;
561  os << "The Tensor4 of size (" << dim_sizes << ") \n"
562  << "does not fit a Matrix";
563  throw std::runtime_error(os.str());
564  }
565 }
566 
567 
568 /* Workspace method: Doxygen documentation will be auto-generated */
569 void Reduce(
570  // WS Generic Output:
571  Matrix& o,
572  // WS Input:
573  // WS Generic Input:
574  const Tensor5& i,
575  const Verbosity&)
576 {
577  ArrayOfIndex dim_sizes;
578  Index test = 2;
579 
580  select_dims_by_size(dim_sizes, 1, i);
581  Index num = dim_sizes.nelem();
582  if( num == test)
583  {
584  o.resize(dim_sizes[0],
585  dim_sizes[1]);
586  memcpy(o.get_c_array(),
587  i.get_c_array(),
588  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
589  }
590  else
591  {
592  ostringstream os;
593  os << "The Tensor5 of size (" << dim_sizes << ") \n"
594  << "does not fit a Matrix";
595  throw std::runtime_error(os.str());
596  }
597 }
598 
599 
600 /* Workspace method: Doxygen documentation will be auto-generated */
601 void Reduce(
602  // WS Generic Output:
603  Matrix& o,
604  // WS Input:
605  // WS Generic Input:
606  const Tensor6& i,
607  const Verbosity&)
608 {
609  ArrayOfIndex dim_sizes;
610  Index test = 2;
611 
612  select_dims_by_size(dim_sizes, 1, i);
613  Index num = dim_sizes.nelem();
614  if( num == test)
615  {
616  o.resize(dim_sizes[0],
617  dim_sizes[1]);
618  memcpy(o.get_c_array(),
619  i.get_c_array(),
620  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
621  }
622  else
623  {
624  ostringstream os;
625  os << "The Tensor6 of size (" << dim_sizes << ") \n"
626  << "does not fit a Matrix";
627  throw std::runtime_error(os.str());
628  }
629 }
630 
631 
632 /* Workspace method: Doxygen documentation will be auto-generated */
633 void Reduce(
634  // WS Generic Output:
635  Matrix& o,
636  // WS Input:
637  // WS Generic Input:
638  const Tensor7& i,
639  const Verbosity&)
640 {
641  ArrayOfIndex dim_sizes;
642  Index test = 2;
643 
644  select_dims_by_size(dim_sizes, 1, i);
645  Index num = dim_sizes.nelem();
646  if( num == test)
647  {
648  o.resize(dim_sizes[0],
649  dim_sizes[1]);
650  memcpy(o.get_c_array(),
651  i.get_c_array(),
652  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
653  }
654  else
655  {
656  ostringstream os;
657  os << "The Tensor7 of size (" << dim_sizes << ") \n"
658  << "does not fit a Matrix";
659  throw std::runtime_error(os.str());
660  }
661 }
662 
663 
664 // To Tensor 3
665 
666 
667 /* Workspace method: Doxygen documentation will be auto-generated */
668 void Reduce(
669  // WS Generic Output:
670  Tensor3& o,
671  // WS Input:
672  // WS Generic Input:
673  const Tensor4& i,
674  const Verbosity&)
675 {
676  ArrayOfIndex dim_sizes;
677  Index test = 3;
678 
679  select_dims_by_size(dim_sizes, 1, i);
680  Index num = dim_sizes.nelem();
681  if( num == test)
682  {
683  o.resize(dim_sizes[0],
684  dim_sizes[1],
685  dim_sizes[2]);
686  memcpy(o.get_c_array(),
687  i.get_c_array(),
688  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
689  }
690  else
691  {
692  ostringstream os;
693  os << "The Tensor4 of size (" << dim_sizes << ") \n"
694  << "does not fit a Tensor3";
695  throw std::runtime_error(os.str());
696  }
697 }
698 
699 
700 /* Workspace method: Doxygen documentation will be auto-generated */
701 void Reduce(
702  // WS Generic Output:
703  Tensor3& o,
704  // WS Input:
705  // WS Generic Input:
706  const Tensor5& i,
707  const Verbosity&)
708 {
709  ArrayOfIndex dim_sizes;
710  Index test = 3;
711 
712  select_dims_by_size(dim_sizes, 1, i);
713  Index num = dim_sizes.nelem();
714  if( num == test)
715  {
716  o.resize(dim_sizes[0],
717  dim_sizes[1],
718  dim_sizes[2]);
719  memcpy(o.get_c_array(),
720  i.get_c_array(),
721  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
722  }
723  else
724  {
725  ostringstream os;
726  os << "The Tensor5 of size (" << dim_sizes << ") \n"
727  << "does not fit a Tensor3";
728  throw std::runtime_error(os.str());
729  }
730 }
731 
732 
733 /* Workspace method: Doxygen documentation will be auto-generated */
734 void Reduce(
735  // WS Generic Output:
736  Tensor3& o,
737  // WS Input:
738  // WS Generic Input:
739  const Tensor6& i,
740  const Verbosity&)
741 {
742  ArrayOfIndex dim_sizes;
743  Index test = 3;
744 
745  select_dims_by_size(dim_sizes, 1, i);
746  Index num = dim_sizes.nelem();
747  if( num == test)
748  {
749  o.resize(dim_sizes[0],
750  dim_sizes[1],
751  dim_sizes[2]);
752  memcpy(o.get_c_array(),
753  i.get_c_array(),
754  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
755  }
756  else
757  {
758  ostringstream os;
759  os << "The Tensor6 of size (" << dim_sizes << ") \n"
760  << "does not fit a Tensor3";
761  throw std::runtime_error(os.str());
762  }
763 }
764 
765 
766 /* Workspace method: Doxygen documentation will be auto-generated */
767 void Reduce(
768  // WS Generic Output:
769  Tensor3& o,
770  // WS Input:
771  // WS Generic Input:
772  const Tensor7& i,
773  const Verbosity&)
774 {
775  ArrayOfIndex dim_sizes;
776  Index test = 3;
777 
778  select_dims_by_size(dim_sizes, 1, i);
779  Index num = dim_sizes.nelem();
780  if( num == test)
781  {
782  o.resize(dim_sizes[0],
783  dim_sizes[1],
784  dim_sizes[2]);
785  memcpy(o.get_c_array(),
786  i.get_c_array(),
787  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
788  }
789  else
790  {
791  ostringstream os;
792  os << "The Tensor7 of size (" << dim_sizes << ") \n"
793  << "does not fit a Tensor3";
794  throw std::runtime_error(os.str());
795  }
796 }
797 
798 
799 // To Tensor4
800 
801 
802 /* Workspace method: Doxygen documentation will be auto-generated */
803 void Reduce(
804  // WS Generic Output:
805  Tensor4& o,
806  // WS Input:
807  // WS Generic Input:
808  const Tensor5& i,
809  const Verbosity&)
810 {
811  ArrayOfIndex dim_sizes;
812  Index test = 4;
813 
814  select_dims_by_size(dim_sizes, 1, i);
815  Index num = dim_sizes.nelem();
816  if( num == test)
817  {
818  o.resize(dim_sizes[0],
819  dim_sizes[1],
820  dim_sizes[2],
821  dim_sizes[3]);
822  memcpy(o.get_c_array(),
823  i.get_c_array(),
824  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
825  }
826  else
827  {
828  ostringstream os;
829  os << "The Tensor5 of size (" << dim_sizes << ") \n"
830  << "does not fit a Tensor4";
831  throw std::runtime_error(os.str());
832  }
833 }
834 
835 
836 /* Workspace method: Doxygen documentation will be auto-generated */
837 void Reduce(
838  // WS Generic Output:
839  Tensor4& o,
840  // WS Input:
841  // WS Generic Input:
842  const Tensor6& i,
843  const Verbosity&)
844 {
845  ArrayOfIndex dim_sizes;
846  Index test = 4;
847 
848  select_dims_by_size(dim_sizes, 1, i);
849  Index num = dim_sizes.nelem();
850  if( num == test)
851  {
852  o.resize(dim_sizes[0],
853  dim_sizes[1],
854  dim_sizes[2],
855  dim_sizes[3]);
856  memcpy(o.get_c_array(),
857  i.get_c_array(),
858  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
859  }
860  else
861  {
862  ostringstream os;
863  os << "The Tensor6 of size (" << dim_sizes << ") \n"
864  << "does not fit a Tensor4";
865  throw std::runtime_error(os.str());
866  }
867 }
868 
869 
870 /* Workspace method: Doxygen documentation will be auto-generated */
871 void Reduce(
872  // WS Generic Output:
873  Tensor4& o,
874  // WS Input:
875  // WS Generic Input:
876  const Tensor7& i,
877  const Verbosity&)
878 {
879  ArrayOfIndex dim_sizes;
880  Index test = 4;
881 
882  select_dims_by_size(dim_sizes, 1, i);
883  Index num = dim_sizes.nelem();
884  if( num == test)
885  {
886  o.resize(dim_sizes[0],
887  dim_sizes[1],
888  dim_sizes[2],
889  dim_sizes[3]);
890  memcpy(o.get_c_array(),
891  i.get_c_array(),
892  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
893  }
894  else
895  {
896  ostringstream os;
897  os << "The Tensor7 of size (" << dim_sizes << ") \n"
898  << "does not fit a Tensor4";
899  throw std::runtime_error(os.str());
900  }
901 }
902 
903 
904 // To Tensor5
905 
906 
907 /* Workspace method: Doxygen documentation will be auto-generated */
908 void Reduce(
909  // WS Generic Output:
910  Tensor5& o,
911  // WS Input:
912  // WS Generic Input:
913  const Tensor6& i,
914  const Verbosity&)
915 {
916  ArrayOfIndex dim_sizes;
917  Index test = 5;
918 
919  select_dims_by_size(dim_sizes, 1, i);
920  Index num = dim_sizes.nelem();
921  if( num == test)
922  {
923  o.resize(dim_sizes[0],
924  dim_sizes[1],
925  dim_sizes[2],
926  dim_sizes[3],
927  dim_sizes[4]);
928  memcpy(o.get_c_array(),
929  i.get_c_array(),
930  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
931  }
932  else
933  {
934  ostringstream os;
935  os << "The Tensor6 of size (" << dim_sizes << ") \n"
936  << "does not fit a Tensor5";
937  throw std::runtime_error(os.str());
938  }
939 }
940 
941 
942 /* Workspace method: Doxygen documentation will be auto-generated */
943 void Reduce(
944  // WS Generic Output:
945  Tensor5& o,
946  // WS Input:
947  // WS Generic Input:
948  const Tensor7& i,
949  const Verbosity&)
950 {
951  ArrayOfIndex dim_sizes;
952  Index test = 5;
953 
954  select_dims_by_size(dim_sizes, 1, i);
955  Index num = dim_sizes.nelem();
956  if( num == test)
957  {
958  o.resize(dim_sizes[0],
959  dim_sizes[1],
960  dim_sizes[2],
961  dim_sizes[3],
962  dim_sizes[4]);
963  memcpy(o.get_c_array(),
964  i.get_c_array(),
965  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
966  }
967  else
968  {
969  ostringstream os;
970  os << "The Tensor7 of size (" << dim_sizes << ") \n"
971  << "does not fit a Tensor5";
972  throw std::runtime_error(os.str());
973  }
974 }
975 
976 
977 // To Tensor6
978 
979 
980 /* Workspace method: Doxygen documentation will be auto-generated */
981 void Reduce(
982  // WS Generic Output:
983  Tensor6& o,
984  // WS Input:
985  // WS Generic Input:
986  const Tensor7& i,
987  const Verbosity&)
988 {
989  ArrayOfIndex dim_sizes;
990  Index test = 6;
991 
992  select_dims_by_size(dim_sizes, 1, i);
993  Index num = dim_sizes.nelem();
994  if( num == test)
995  {
996  o.resize(dim_sizes[0],
997  dim_sizes[1],
998  dim_sizes[2],
999  dim_sizes[3],
1000  dim_sizes[4],
1001  dim_sizes[5]);
1002  memcpy(o.get_c_array(),
1003  i.get_c_array(),
1004  sizeof(Numeric)* num_elem_from_dim_sizes(dim_sizes));
1005  }
1006  else
1007  {
1008  ostringstream os;
1009  os << "The Tensor7 of size (" << dim_sizes << ") \n"
1010  << "does not fit a Tensor6";
1011  throw std::runtime_error(os.str());
1012  }
1013 }
1014 
1015 
1016 #endif /* m_reduce_h */
1017 
Index npages() const
Returns the number of pages.
Definition: matpackV.cc:47
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
Index nrows() const
Returns the number of rows.
Definition: matpackV.cc:53
Index nelem() const
Number of elements.
Definition: array.h:176
void resize(Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackV.cc:2430
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackI.cc:1214
The Vector class.
Definition: matpackI.h:556
Index nvitrines() const
Returns the number of vitrines.
Definition: matpackVI.cc:32
The Tensor4 class.
Definition: matpackIV.h:383
Index nrows() const
Returns the number of rows.
Definition: matpackVII.cc:62
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:69
Index num_elem_from_dim_sizes(const ArrayOfIndex &dim_sizes)
Definition: m_reduce.h:43
The Tensor7 class.
Definition: matpackVII.h:1931
Index nbooks() const
Returns the number of books.
Definition: matpackV.cc:41
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:146
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:75
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:180
This file contains the definition of Array.
Index ncols() const
Returns the number of columns.
Definition: matpackI.cc:838
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackI.cc:542
The Tensor3 class.
Definition: matpackIII.h:348
Index nshelves() const
Returns the number of shelves.
Definition: matpackV.cc:35
void Reduce(Numeric &o, const Vector &i, const Verbosity &)
WORKSPACE METHOD: Reduce.
Definition: m_reduce.h:152
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:149
The declarations of all the exception classes.
Index nrows() const
Returns the number of rows.
Definition: matpackVI.cc:56
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
The Matrix class.
Definition: matpackI.h:788
Index nlibraries() const
Returns the number of libraries.
Definition: matpackVII.cc:32
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackVII.cc:4885
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackV.cc:778
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.cc:862
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:143
This can be used to make arrays out of anything.
Definition: array.h:40
Index nshelves() const
Returns the number of shelves.
Definition: matpackVI.cc:38
Index ncols() const
Returns the number of columns.
Definition: matpackVI.cc:62
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackVI.cc:2407
void resize(Index n)
Assignment operator from VectorView.
Definition: matpackI.cc:798
The Tensor6 class.
Definition: matpackVI.h:950
Index npages() const
Returns the number of pages.
Definition: matpackVI.cc:50
Index nshelves() const
Returns the number of shelves.
Definition: matpackVII.cc:44
Index npages() const
Returns the number of pages.
Definition: matpackVII.cc:56
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:63
void resize(Index v, Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackVI.cc:2879
void select_dims_by_size(ArrayOfIndex &dim_sizes, const Index min_num_elem, const Vector &type)
Definition: m_reduce.h:55
Index ncols() const
Returns the number of columns.
Definition: matpackV.cc:59
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackIII.cc:455
Index nvitrines() const
Returns the number of vitrines.
Definition: matpackVII.cc:38
Index ncols() const
Returns the number of columns.
Definition: matpackVII.cc:68
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:81
Index nrows() const
Returns the number of rows.
Definition: matpackI.cc:832
Index nbooks() const
Returns the number of books.
Definition: matpackVII.cc:50
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1403
The Tensor5 class.
Definition: matpackV.h:451
void resize(Index r, Index c)
Resize function.
Definition: matpackI.cc:1580
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackIV.cc:402
Index nbooks() const
Returns the number of books.
Definition: matpackVI.cc:44