ARTS  2.0.49
m_basic_types.cc
Go to the documentation of this file.
1 /* Copyright (C) 2002-2008
2  Patrick Eriksson <Patrick.Eriksson@rss.chalmers.se>
3  Stefan Buehler <sbuehler@ltu.se>
4 
5  This program is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License as published by the
7  Free Software Foundation; either version 2, or (at your option) any
8  later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18  USA. */
19 
20 
21 
22 /*===========================================================================
23  === File description
24  ===========================================================================*/
25 
45 /*===========================================================================
46  === External declarations
47  ===========================================================================*/
48 
49 #include <cmath>
50 #include "arts.h"
51 #include "array.h"
52 #include "matpackI.h"
53 #include "matpackII.h"
54 #include "matpackIII.h"
55 #include "matpackIV.h"
56 #include "matpackV.h"
57 #include "matpackVI.h"
58 #include "matpackVII.h"
59 #include "mystring.h"
60 #include "exceptions.h"
61 #include "make_array.h"
62 #include "math_funcs.h"
63 #include "messages.h"
64 #include "logic.h"
65 #include "sorting.h"
66 
67 
68 /*===========================================================================
69  === The functions (in alphabetical order)
70  ===========================================================================*/
71 
72 
73 /* Workspace method: Doxygen documentation will be auto-generated */
75  const ArrayOfIndex& values,
76  const Verbosity&)
77 {
78  aoi = values;
79 }
80 
81 
82 /* Workspace method: Doxygen documentation will be auto-generated */
84  const Index& nelem,
85  const Index& value,
86  const Verbosity&)
87 {
88  aoi.resize(nelem);
89  for( Index i=0; i<nelem; i++ )
90  aoi[i] = value;
91 }
92 
93 
94 /* Workspace method: Doxygen documentation will be auto-generated */
96  const ArrayOfString& sa2,
97  const Verbosity&)
98 {
99  sa.resize(sa2.nelem());
100  sa = sa2;
101 }
102 
103 
104 /* Workspace method: Doxygen documentation will be auto-generated */
105 void FlagOff(Index& x, const Verbosity&)
106 {
107  x = 0;
108 }
109 
110 
111 /* Workspace method: Doxygen documentation will be auto-generated */
112 void FlagOn(Index& x, const Verbosity&)
113 {
114  x = 1;
115 }
116 
117 
118 /* Workspace method: Doxygen documentation will be auto-generated */
119 void IndexSet(Index& x,
120  const Index& value,
121  const Verbosity&)
122 {
123  x = value;
124 }
125 
126 /* Workspace method: Doxygen documentation will be auto-generated */
127 void IndexStep(Index& xout,
128  const Index& xin,
129  const Verbosity&)
130 {
131  xout = xin + 1;
132 }
133 
134 
135 /* Workspace method: Doxygen documentation will be auto-generated */
136 void MatrixMatrixMultiply(// WS Generic Output:
137  Matrix& Y,
138  // WS Generic Input:
139  const Matrix& M,
140  const Matrix& X,
141  const Verbosity&)
142 {
143  // Check that dimensions are right, M.ncols() must match X.nrows():
144  if (M.ncols()!=X.nrows())
145  {
146  ostringstream os;
147  os << "Matrix dimensions must be consistent!\n"
148  << "Matrix1.ncols() = " << M.ncols() << "\n"
149  << "Matrix2.nrows() = " << X.nrows();
150  throw runtime_error( os.str() );
151  }
152 
153  // Temporary for the result:
154  Matrix dummy( M.nrows(), X.ncols() );
155 
156  mult( dummy, M, X );
157 
158  // Copy result to Y:
159 
160  Y.resize( dummy.nrows(), dummy.ncols() );
161 
162  Y = dummy;
163 }
164 
165 /* Workspace method: Doxygen documentation will be auto-generated */
166 void Matrix1ColFromVector(// WS Generic Output:
167  Matrix& m,
168  // WS Generic Input:
169  const Vector& v,
170  const Verbosity&)
171 {
172  const Index nv = v.nelem();
173 
174  m.resize( nv, 1 );
175  m( joker,0 ) = v;
176 }
177 
178 
179 /* Workspace method: Doxygen documentation will be auto-generated */
180 void Matrix2ColFromVectors(// WS Generic Output:
181  Matrix& m,
182  // WS Generic Input:
183  const Vector& v1,
184  const Vector& v2,
185  const Verbosity&)
186 {
187  const Index nv = v1.nelem();
188 
189  if( v2.nelem() != nv )
190  throw runtime_error("Vectors must be of the same size.");
191 
192  m.resize( nv, 2 );
193  m( joker,0 ) = v1;
194  m( joker,1 ) = v2;
195 
196 }
197 
198 
199 /* Workspace method: Doxygen documentation will be auto-generated */
200 void Matrix3ColFromVectors(// WS Generic Output:
201  Matrix& m,
202  // WS Generic Input:
203  const Vector& v1,
204  const Vector& v2,
205  const Vector& v3,
206  const Verbosity&)
207 {
208  const Index nv = v1.nelem();
209 
210  if( v3.nelem() != nv || v2.nelem() != nv )
211  throw runtime_error("Vectors must be of the same size.");
212 
213  m.resize( nv, 3 );
214  m( joker,0 ) = v1;
215  m( joker,1 ) = v2;
216  m( joker,2 ) = v3;
217 }
218 
219 
220 /* Workspace method: Doxygen documentation will be auto-generated */
221 void MatrixCompare(const Matrix& matrix1,
222  const Matrix& matrix2,
223  const Numeric& maxabsdiff,
224  const Verbosity& verbosity )
225 {
226  const Index nrows = matrix1.nrows();
227  const Index ncols = matrix1.ncols();
228 
229  if( matrix2.nrows() != nrows || matrix2.ncols() != ncols )
230  throw runtime_error( "The two matrices do not have the same size." );
231 
232  Numeric maxdiff = 0.0;
233 
234  for( Index r=0; r<nrows; r++ )
235  {
236  for( Index c=0; c<ncols; c++ )
237  {
238  Numeric diff = fabs( matrix1(r,c) - matrix2(r,c) );
239  if( diff > maxdiff )
240  { maxdiff = diff; }
241  }
242  }
243 
244  if( maxdiff > maxabsdiff )
245  {
246  ostringstream os;
247  os << "A difference of " << maxdiff << " was found, which is larger "
248  << "than the specified threshold of " << maxabsdiff << ".";
249  throw runtime_error(os.str());
250  }
251 
253  out2 << " Check OK (maximum difference = " << maxdiff << ").\n";
254 }
255 
256 
257 
258 /* Workspace method: Doxygen documentation will be auto-generated */
259 void Matrix1RowFromVector(// WS Generic Output:
260  Matrix& m,
261  // WS Generic Input:
262  const Vector& v,
263  const Verbosity&)
264 {
265  const Index nv = v.nelem();
266 
267  m.resize( 1, nv );
268  m( 0, joker ) = v;
269 }
270 
271 
272 /* Workspace method: Doxygen documentation will be auto-generated */
273 void Matrix2RowFromVectors(// WS Generic Output:
274  Matrix& m,
275  // WS Generic Input:
276  const Vector& v1,
277  const Vector& v2,
278  const Verbosity&)
279 {
280  const Index nv = v1.nelem();
281 
282  if( v2.nelem() != nv )
283  throw runtime_error("Vectors must be of the same size.");
284 
285  m.resize( 2, nv );
286  m( 0, joker ) = v1;
287  m( 1, joker ) = v2;
288 
289 }
290 
291 
292 /* Workspace method: Doxygen documentation will be auto-generated */
293 void Matrix3RowFromVectors(// WS Generic Output:
294  Matrix& m,
295  // WS Generic Input:
296  const Vector& v1,
297  const Vector& v2,
298  const Vector& v3,
299  const Verbosity&)
300 {
301  const Index nv = v1.nelem();
302 
303  if( v3.nelem() != nv || v2.nelem() != nv )
304  throw runtime_error("Vectors must be of the same size.");
305 
306  m.resize( 3, nv );
307  m( 0, joker ) = v1;
308  m( 1, joker ) = v2;
309  m( 2, joker ) = v3;
310 
311 }
312 
313 
314 /* Workspace method: Doxygen documentation will be auto-generated */
315 void MatrixScale(Matrix& out,
316  const Matrix& in,
317  const Numeric& value,
318  const Verbosity&)
319 {
320  // Note that in and out can be the same matrix
321  if (&out==&in)
322  {
323  // Out and in are the same. Just multiply by the scalar value.
324  out *= value;
325  }
326  else
327  {
328  // Out and in are different. We first have to copy in to out,
329  // then multiply by the scalar value.
330  out.resize( in.nrows(), in.ncols() );
331  out = in;
332  out *= value;
333  }
334 }
335 
336 
337 /* Workspace method: Doxygen documentation will be auto-generated */
338 void MatrixSet(Matrix& x,
339  const Matrix& values,
340  const Verbosity&)
341 {
342  x = values;
343 }
344 
345 
346 /* Workspace method: Doxygen documentation will be auto-generated */
348  const Index& nrows,
349  const Index& ncols,
350  const Numeric& value,
351  const Verbosity&)
352 {
353  x.resize( nrows, ncols );
354  x = value;
355 }
356 
357 
358 /* Workspace method: Doxygen documentation will be auto-generated */
359 void NumericAdd(Numeric& out,
360  const Numeric& in,
361  const Numeric& value,
362  const Verbosity&)
363 {
364  out = value + in;
365 }
366 
367 
368 /* Workspace method: Doxygen documentation will be auto-generated */
370  const Numeric& in,
371  const Numeric& value,
372  const Verbosity&)
373 {
374  out = value * in;
375 }
376 
377 
378 /* Workspace method: Doxygen documentation will be auto-generated */
380  const Numeric& value,
381  const Verbosity&)
382 {
383  x = value;
384 }
385 
386 
387 /* Workspace method: Doxygen documentation will be auto-generated */
388 void SparseSparseMultiply(// WS Generic Output:
389  Sparse& Y,
390  // WS Generic Input:
391  const Sparse& M,
392  const Sparse& X,
393  const Verbosity&)
394 {
395  // Check that dimensions are right, M.ncols() must match X.nrows():
396  if (M.ncols()!=X.nrows())
397  {
398  ostringstream os;
399  os << "Matrix dimensions must be consistent!\n"
400  << "Matrix1.ncols() = " << M.ncols() << "\n"
401  << "Matrix2.nrows() = " << X.nrows();
402  throw runtime_error( os.str() );
403  }
404 
405  // Temporary for the result:
406  Sparse dummy( M.nrows(), X.ncols() );
407 
408  mult( dummy, M, X );
409 
410  // Copy result to Y:
411  Y = dummy;
412 }
413 
414 
415 /* Workspace method: Doxygen documentation will be auto-generated */
416 void StringSet(String& s,
417  const String& s2,
418  const Verbosity&)
419 {
420  s = s2;
421 }
422 
423 
424 /* Workspace method: Doxygen documentation will be auto-generated */
426  const Tensor3& in,
427  const Numeric& value,
428  const Verbosity&)
429 {
430  // Note that in and out can be the same vector
431  if (&out==&in) {
432  // Out and in are the same. Just multiply by the scalar value.
433  out += value;
434  } else {
435  // Out and in are different. We first have to copy in to out,
436  // then multiply by the scalar value.
437  out.resize( in.npages(), in.nrows(), in.ncols() );
438  out = in;
439  out += value;
440  }
441 }
442 
443 
444 /* Workspace method: Doxygen documentation will be auto-generated */
446  const Tensor3& in,
447  const Numeric& value,
448  const Verbosity&)
449 {
450  // Note that in and out can be the same vector
451  if (&out==&in) {
452  // Out and in are the same. Just multiply by the scalar value.
453  out *= value;
454  } else {
455  // Out and in are different. We first have to copy in to out,
456  // then multiply by the scalar value.
457  out.resize( in.npages(), in.nrows(), in.ncols() );
458  out = in;
459  out *= value;
460  }
461 }
462 
463 
464 /* Workspace method: Doxygen documentation will be auto-generated */
466  const Index& npages,
467  const Index& nrows,
468  const Index& ncols,
469  const Numeric& value,
470  const Verbosity& verbosity)
471 {
474 
475  x.resize( npages, nrows, ncols );
476  x = value;
477 
478  out2 << " Tensor3 = " << value << "\n";
479  out3 << " npages : " << npages << "\n";
480  out3 << " nrows : " << nrows << "\n";
481  out3 << " ncols : " << ncols << "\n";
482 }
483 
484 
485 /* Workspace method: Doxygen documentation will be auto-generated */
487  const Tensor4& in,
488  const Numeric& value,
489  const Verbosity&)
490 {
491  // Note that in and out can be the same vector
492  if (&out==&in) {
493  // Out and in are the same. Just multiply by the scalar value.
494  out *= value;
495  } else {
496  // Out and in are different. We first have to copy in to out,
497  // then multiply by the scalar value.
498  out.resize( in.nbooks(), in.npages(), in.nrows(), in.ncols() );
499  out = in;
500  out *= value;
501  }
502 }
503 
504 
505 /* Workspace method: Doxygen documentation will be auto-generated */
507  const Index& nbooks,
508  const Index& npages,
509  const Index& nrows,
510  const Index& ncols,
511  const Numeric& value,
512  const Verbosity& verbosity)
513 {
516 
517  x.resize( nbooks, npages, nrows, ncols );
518  x = value;
519 
520  out2 << " Tensor4 = " << value << "\n";
521  out3 << " nbooks : " << nbooks << "\n";
522  out3 << " npages : " << npages << "\n";
523  out3 << " nrows : " << nrows << "\n";
524  out3 << " ncols : " << ncols << "\n";
525 }
526 
527 
528 /* Workspace method: Doxygen documentation will be auto-generated */
530  const Tensor5& in,
531  const Numeric& value,
532  const Verbosity&)
533 {
534  // Note that in and out can be the same vector
535  if (&out==&in) {
536  // Out and in are the same. Just multiply by the scalar value.
537  out *= value;
538  } else {
539  // Out and in are different. We first have to copy in to out,
540  // then multiply by the scalar value.
541  out.resize( in.nshelves(), in.nbooks(), in.npages(),
542  in.nrows(), in.ncols() );
543  out = in;
544  out *= value;
545  }
546 }
547 
548 
549 /* Workspace method: Doxygen documentation will be auto-generated */
551  const Index& nshelves,
552  const Index& nbooks,
553  const Index& npages,
554  const Index& nrows,
555  const Index& ncols,
556  const Numeric& value,
557  const Verbosity& verbosity)
558 {
561 
562  x.resize( nshelves, nbooks, npages, nrows, ncols );
563  x = value;
564 
565  out2 << " Tensor5 = " << value << "\n";
566  out3 << " nshelves : " << nshelves << "\n";
567  out3 << " nbooks : " << nbooks << "\n";
568  out3 << " npages : " << npages << "\n";
569  out3 << " nrows : " << nrows << "\n";
570  out3 << " ncols : " << ncols << "\n";
571 }
572 
573 
574 /* Workspace method: Doxygen documentation will be auto-generated */
576  const Tensor6& in,
577  const Numeric& value,
578  const Verbosity&)
579 {
580  // Note that in and out can be the same vector
581  if (&out==&in) {
582  // Out and in are the same. Just multiply by the scalar value.
583  out *= value;
584  } else {
585  // Out and in are different. We first have to copy in to out,
586  // then multiply by the scalar value.
587  out.resize( in.nvitrines(), in.nshelves(), in.nbooks(),
588  in.npages(), in.nrows(), in.ncols() );
589  out = in;
590  out *= value;
591  }
592 }
593 
594 
595 /* Workspace method: Doxygen documentation will be auto-generated */
597  const Index& nvitrines,
598  const Index& nshelves,
599  const Index& nbooks,
600  const Index& npages,
601  const Index& nrows,
602  const Index& ncols,
603  const Numeric& value,
604  const Verbosity& verbosity)
605 {
608 
609  x.resize( nvitrines, nshelves, nbooks, npages, nrows, ncols );
610  x = value;
611 
612  out2 << " Tensor6 = " << value << "\n";
613  out3 << " nvitrines : " << nvitrines << "\n";
614  out3 << " nshelves : " << nshelves << "\n";
615  out3 << " nbooks : " << nbooks << "\n";
616  out3 << " npages : " << npages << "\n";
617  out3 << " nrows : " << nrows << "\n";
618  out3 << " ncols : " << ncols << "\n";
619 }
620 
621 
622 /* Workspace method: Doxygen documentation will be auto-generated */
624  const Tensor7& in,
625  const Numeric& value,
626  const Verbosity&)
627 {
628  // Note that in and out can be the same vector
629  if (&out==&in) {
630  // Out and in are the same. Just multiply by the scalar value.
631  out *= value;
632  } else {
633  // Out and in are different. We first have to copy in to out,
634  // then multiply by the scalar value.
635  out.resize( in.nlibraries(), in.nvitrines(), in.nshelves(),
636  in.nbooks(), in.npages(), in.nrows(), in.ncols() );
637  out = in;
638  out *= value;
639  }
640 }
641 
642 
643 /* Workspace method: Doxygen documentation will be auto-generated */
645  const Index& nlibraries,
646  const Index& nvitrines,
647  const Index& nshelves,
648  const Index& nbooks,
649  const Index& npages,
650  const Index& nrows,
651  const Index& ncols,
652  const Numeric& value,
653  const Verbosity& verbosity)
654 {
657 
658  x.resize( nlibraries, nvitrines, nshelves, nbooks, npages, nrows, ncols );
659  x = value;
660 
661  out2 << " Tensor7 = " << value << "\n";
662  out3 << " nlibraries : " << nlibraries << "\n";
663  out3 << " nvitrines : " << nvitrines << "\n";
664  out3 << " nshelves : " << nshelves << "\n";
665  out3 << " nbooks : " << nbooks << "\n";
666  out3 << " npages : " << npages << "\n";
667  out3 << " nrows : " << nrows << "\n";
668  out3 << " ncols : " << ncols << "\n";
669 }
670 
671 
672 /* Workspace method: Doxygen documentation will be auto-generated */
674  const Vector& in,
675  const Numeric& value,
676  const Verbosity&)
677 {
678  // Note that in and out can be the same vector
679  if (&out==&in)
680  {
681  // Out and in are the same. Just add the scalar value.
682  out += value;
683  }
684  else
685  {
686  // Out and in are different. We first have to copy in to out,
687  // then add the scalar value.
688  out.resize( in.nelem() );
689  out = in;
690  out += value;
691  }
692 }
693 
694 
695 /* Workspace method: Doxygen documentation will be auto-generated */
696 void VectorFlip(Vector& out,
697  const Vector& in,
698  const Verbosity&)
699 {
700  const Index n = in.nelem();
701 
702  // Note that in and out can be the same vector
703  if (&out==&in)
704  {
705  // Out and in are the same. A copy is needed
706  const Vector v = in;
707  for( Index i=0; i<n; i++ )
708  out[i] = v[n-1-i];
709  }
710  else
711  {
712  // Out and in are different.
713  out.resize( n );
714  for( Index i=0; i<n; i++ )
715  out[i] = in[n-1-i];
716  }
717 }
718 
719 /* Workspace method: Doxygen documentation will be auto-generated */
720 void VectorInsertGridPoints(// WS Generic Output:
721  Vector& og, // Output grid
722  // WS Generic Input:
723  const Vector& ingrid, // Input grid
724  const Vector& points, // Points to insert
725  const Verbosity& verbosity)
726 {
729 
730  // First make duplikates of the input vectors, in case one of them
731  // happens to be identical to the output vector. Also, we can fool
732  // around with these, if we want.
733  Vector ig(ingrid);
734  Vector p(points);
735 
736  // Check how the input grid is sorted. If the grid is sorted in
737  // descending order, we simply turn it around. (But don't
738  // forget to turn it back at the end!)
739  Index ascending; // 1=ascending, 0=descending
740  if (is_increasing(ig))
741  {
742  ascending = 1;
743  }
744  else if (is_decreasing(ig))
745  {
746  ascending = 0;
747 
748  // Turn grid round.
749 
750  // Copy ig to dummy vector in reverse order:
751  const Vector dummy = ig[Range(ig.nelem()-1,ig.nelem(),-1)];
752 
753  // Copy dummy back to ig vector:
754  ig = dummy;
755  }
756  else
757  {
758  ostringstream os;
759  os << "The input Vector must be either\n"
760  << "strictly increasing or strictly decreasing,\n"
761  << "but this is not the case.\n";
762  os << "The vector contains:\n"
763  << ig;
764  throw runtime_error( os.str() );
765  }
766 
767  // Sort also the vector of points to insert in increasing order:
768  {
769  ArrayOfIndex si; // Sorted indices
770  get_sorted_indexes (si, p); // Get sorted p indices
771  const Vector dummy = p; // Copy p to dummy
772  // Copy back dummy to p in right order:
773  for (Index j = 0; j < p.nelem(); j++)
774  p[j] = dummy[si[j]];
775  }
776 
777  // The idea is to step through both ig and p, and build up the
778  // output in a temporary array.
779  Array<Numeric> x;
780  Index iig=0, ip=0; // indices to ig and p
781  Index sk=0; // skip count
782  while ( iig<ig.nelem() && ip<p.nelem() )
783  {
784  if ( p[ip]<ig[iig] )
785  {
786  x.push_back(p[ip]);
787  ++ip;
788  }
789  else if ( p[ip]>ig[iig] )
790  {
791  x.push_back(ig[iig]);
792  ++iig;
793  }
794  else
795  {
796  out3 << " Skipping point " << p[ip] << ", which is already "
797  << "in the original grid.\n";
798  ++ip;
799  ++sk;
800  }
801  }
802 
803  out2 << " " << sk << " points skipped.\n";
804 
805  // Add remaining points of either p or ig, depending on which is
806  // longer:
807  if ( ip==p.nelem() )
808  {
809  // p has reached its end.
810  while ( iig<ig.nelem() )
811  {
812  x.push_back(ig[iig]);
813  ++iig;
814  }
815  }
816  else if ( iig==ig.nelem() )
817  {
818  // ig has reached its end
819  while ( ip<p.nelem() )
820  {
821  x.push_back(p[ip]);
822  ++ip;
823  }
824  }
825  else
826  {
827  // We should never be here.
828  assert(false);
829  arts_exit();
830  }
831 
832  // Ok, x should now contain the new grid.
833 
834  og.resize(x.nelem());
835 
836  // Copy to result vector, turn around if necessary.
837  if (ascending)
838  for ( Index i=0; i<x.nelem(); ++i )
839  og[i] = x[i]; // Just copy.
840  else
841  for ( Index i=0; i<x.nelem(); ++i )
842  og[i] = x[x.nelem()-1-i]; // Copy in reverse order.
843 
844 }
845 
846 
847 /* Workspace method: Doxygen documentation will be auto-generated */
849  const Numeric& start,
850  const Numeric& stop,
851  const Numeric& step,
852  const Verbosity& verbosity)
853 {
856 
857  linspace(x,start,stop,step);
858 
859  out2 << " Creating a linearly spaced vector.\n";
860  out3 << " length : " << x.nelem() << "\n";
861  out3 << " first value : " << x[0] << "\n";
862 
863  if ( x.nelem() > 1 )
864  {
865  out3 << " step size : " << x[1]-x[0] << "\n";
866  out3 << " last value : " << x[x.nelem()-1] << "\n";
867  }
868 }
869 
870 /* Workspace method: Doxygen documentation will be auto-generated */
872  const Numeric& start,
873  const Numeric& stop,
874  const Numeric& step,
875  const Verbosity& verbosity)
876 {
879 
880  linspace(x,log(start),log(stop),step);
881  transform(x,exp,x);
882 
883  out2 << " Creating a logarithmically spaced vector.\n";
884  out3 << " length : " << x.nelem() << "\n";
885  out3 << " first value : " << x[0] << "\n";
886 
887  if ( x.nelem() > 1 )
888  {
889  out3 << " step size : " << x[1]-x[0] << "\n";
890  out3 << " last value : " << x[x.nelem()-1] << "\n";
891  }
892 }
893 
894 /* Workspace method: Doxygen documentation will be auto-generated */
895 void VectorMatrixMultiply(// WS Generic Output:
896  Vector& y,
897  // WS Generic Input:
898  const Matrix& M,
899  const Vector& x,
900  const Verbosity&)
901 {
902  // Check that dimensions are right, x must match columns of M:
903  if (M.ncols()!=x.nelem())
904  {
905  ostringstream os;
906  os << "Matrix and vector dimensions must be consistent!\n"
907  << "Matrix.ncols() = " << M.ncols() << "\n"
908  << "Vector.nelem() = " << x.nelem();
909  throw runtime_error( os.str() );
910  }
911 
912  // Temporary for the result:
913  Vector dummy( M.nrows() );
914 
915  mult(dummy,M,x);
916 
917  y.resize(dummy.nelem());
918 
919  y = dummy;
920 }
921 
922 /* Workspace method: Doxygen documentation will be auto-generated */
924  const Index& n,
925  const Numeric& start,
926  const Numeric& stop,
927  const Verbosity& verbosity)
928 {
931 
932  if ( n<2 )
933  throw runtime_error("The number of points must be > 1.");
934  nlinspace(x,start,stop,n);
935 
936  out2 << " Creating a linearly spaced vector.\n";
937  out3 << " length : " << n << "\n";
938  out3 << " first value : " << x[0] << "\n";
939 
940  if ( x.nelem() > 1 )
941  {
942  out3 << " step size : " << x[1]-x[0] << "\n";
943  out3 << " last value : " << x[x.nelem()-1] << "\n";
944  }
945 }
946 
947 
948 /* Workspace method: Doxygen documentation will be auto-generated */
950  const Index& n,
951  const Numeric& start,
952  const Numeric& stop,
953  const Verbosity& verbosity)
954 {
957 
958  if ( n<2 )
959  throw runtime_error("The number of points must be > 1.");
960  if ( (start<=0) || (stop<=0) )
961  throw runtime_error("Only positive numbers are allowed.");
962 
963  nlogspace(x,start,stop,n);
964 
965  out2 << " Creating a logarithmically spaced vector.\n";
966  out3 << " length : " << n << "\n";
967  out3 << " first value : " << x[0] << "\n";
968 
969  if ( x.nelem() > 1 )
970  out3 << " last value : " << x[x.nelem()-1] << "\n";
971 }
972 
973 
974 /* Workspace method: Doxygen documentation will be auto-generated */
975 void VectorScale(Vector& out,
976  const Vector& in,
977  const Numeric& value,
978  const Verbosity&)
979 {
980  // Note that in and out can be the same vector
981  if (&out==&in)
982  {
983  // Out and in are the same. Just multiply by the scalar value.
984  out *= value;
985  }
986  else
987  {
988  // Out and in are different. We first have to copy in to out,
989  // then multiply by the scalar value.
990  out.resize( in.nelem() );
991  out = in;
992  out *= value;
993  }
994 }
995 
996 
997 /* Workspace method: Doxygen documentation will be auto-generated */
999  const Index& n,
1000  const Numeric& value,
1001  const Verbosity& verbosity)
1002 {
1003  CREATE_OUT2
1004  CREATE_OUT3
1005 
1006  x.resize(n);
1007  x = value;
1008 
1009  out2 << " Creating a constant vector.\n";
1010  out3 << " length : " << n << "\n";
1011  out3 << " value : " << value << "\n";
1012 }
1013 
1014 
1015 /* Workspace method: Doxygen documentation will be auto-generated */
1017  const Vector& values,
1018  const Verbosity&)
1019 {
1020  x = values;
1021 }
1022 
Matrix
The Matrix class.
Definition: matpackI.h:767
transform
void transform(VectorView y, double(&my_func)(double), ConstVectorView x)
A generic transform function for vectors, which can be used to implement mathematical functions opera...
Definition: matpackI.cc:1728
Tensor4::resize
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1404
ConstTensor7View::nshelves
Index nshelves() const
Returns the number of shelves.
Definition: matpackVII.cc:43
NumericScale
void NumericScale(Numeric &out, const Numeric &in, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: NumericScale.
Definition: m_basic_types.cc:369
ConstTensor6View::nshelves
Index nshelves() const
Returns the number of shelves.
Definition: matpackVI.cc:37
ConstTensor5View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackV.cc:38
exceptions.h
The declarations of all the exception classes.
ArrayOfIndexSet
void ArrayOfIndexSet(ArrayOfIndex &aoi, const ArrayOfIndex &values, const Verbosity &)
WORKSPACE METHOD: ArrayOfIndexSet.
Definition: m_basic_types.cc:74
Tensor6::resize
void resize(Index v, Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackVI.cc:2845
VectorAddScalar
void VectorAddScalar(Vector &out, const Vector &in, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: VectorAddScalar.
Definition: m_basic_types.cc:673
ArrayOfStringSet
void ArrayOfStringSet(ArrayOfString &sa, const ArrayOfString &sa2, const Verbosity &)
WORKSPACE METHOD: ArrayOfStringSet.
Definition: m_basic_types.cc:95
Sparse::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackII.cc:59
Matrix1RowFromVector
void Matrix1RowFromVector(Matrix &m, const Vector &v, const Verbosity &)
WORKSPACE METHOD: Matrix1RowFromVector.
Definition: m_basic_types.cc:259
Tensor3
The Tensor3 class.
Definition: matpackIII.h:340
MatrixSet
void MatrixSet(Matrix &x, const Matrix &values, const Verbosity &)
WORKSPACE METHOD: MatrixSet.
Definition: m_basic_types.cc:338
ConstTensor5View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackV.cc:56
ConstTensor6View::npages
Index npages() const
Returns the number of pages.
Definition: matpackVI.cc:49
Matrix2ColFromVectors
void Matrix2ColFromVectors(Matrix &m, const Vector &v1, const Vector &v2, const Verbosity &)
WORKSPACE METHOD: Matrix2ColFromVectors.
Definition: m_basic_types.cc:180
ConstTensor7View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackVII.cc:67
joker
const Joker joker
Sparse
The Sparse class.
Definition: matpackII.h:55
ConstTensor6View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackVI.cc:55
Vector::resize
void resize(Index n)
Resize function.
Definition: matpackI.cc:771
Tensor4Scale
void Tensor4Scale(Tensor4 &out, const Tensor4 &in, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: Tensor4Scale.
Definition: m_basic_types.cc:486
Tensor6SetConstant
void Tensor6SetConstant(Tensor6 &x, const Index &nvitrines, const Index &nshelves, const Index &nbooks, const Index &npages, const Index &nrows, const Index &ncols, const Numeric &value, const Verbosity &verbosity)
WORKSPACE METHOD: Tensor6SetConstant.
Definition: m_basic_types.cc:596
ConstMatrixView::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackI.cc:796
NumericSet
void NumericSet(Numeric &x, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: NumericSet.
Definition: m_basic_types.cc:379
Tensor7Scale
void Tensor7Scale(Tensor7 &out, const Tensor7 &in, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: Tensor7Scale.
Definition: m_basic_types.cc:623
CREATE_OUT2
#define CREATE_OUT2
Definition: messages.h:207
Tensor3AddScalar
void Tensor3AddScalar(Tensor3 &out, const Tensor3 &in, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: Tensor3AddScalar.
Definition: m_basic_types.cc:425
Matrix2RowFromVectors
void Matrix2RowFromVectors(Matrix &m, const Vector &v1, const Vector &v2, const Verbosity &)
WORKSPACE METHOD: Matrix2RowFromVectors.
Definition: m_basic_types.cc:273
Tensor4
The Tensor4 class.
Definition: matpackIV.h:375
array.h
This file contains the definition of Array.
NumericAdd
void NumericAdd(Numeric &out, const Numeric &in, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: NumericAdd.
Definition: m_basic_types.cc:359
Tensor3::resize
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.cc:863
ConstTensor5View::npages
Index npages() const
Returns the number of pages.
Definition: matpackV.cc:44
VectorLogSpace
void VectorLogSpace(Vector &x, const Numeric &start, const Numeric &stop, const Numeric &step, const Verbosity &verbosity)
WORKSPACE METHOD: VectorLogSpace.
Definition: m_basic_types.cc:871
ConstTensor3View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:151
matpackIV.h
ConstTensor7View::nlibraries
Index nlibraries() const
Returns the number of libraries.
Definition: matpackVII.cc:31
nlogspace
void nlogspace(Vector &x, const Numeric start, const Numeric stop, const Index n)
nlogspace
Definition: math_funcs.cc:294
matpackI.h
MatrixCompare
void MatrixCompare(const Matrix &matrix1, const Matrix &matrix2, const Numeric &maxabsdiff, const Verbosity &verbosity)
WORKSPACE METHOD: MatrixCompare.
Definition: m_basic_types.cc:221
Array< Index >
IndexSet
void IndexSet(Index &x, const Index &value, const Verbosity &)
WORKSPACE METHOD: IndexSet.
Definition: m_basic_types.cc:119
Tensor4SetConstant
void Tensor4SetConstant(Tensor4 &x, const Index &nbooks, const Index &npages, const Index &nrows, const Index &ncols, const Numeric &value, const Verbosity &verbosity)
WORKSPACE METHOD: Tensor4SetConstant.
Definition: m_basic_types.cc:506
is_decreasing
bool is_decreasing(ConstVectorView x)
Checks if a vector is sorted in reversed order and is strictly decreasing.
Definition: logic.cc:303
get_sorted_indexes
void get_sorted_indexes(ArrayOfIndex &sorted, const T &data)
get_sorted_indexes
Definition: sorting.h:79
Tensor6Scale
void Tensor6Scale(Tensor6 &out, const Tensor6 &in, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: Tensor6Scale.
Definition: m_basic_types.cc:575
ConstTensor6View::nvitrines
Index nvitrines() const
Returns the number of vitrines.
Definition: matpackVI.cc:31
MatrixScale
void MatrixScale(Matrix &out, const Matrix &in, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: MatrixScale.
Definition: m_basic_types.cc:315
Tensor7::resize
void resize(Index l, Index v, Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackVII.cc:5341
mult
void mult(VectorView y, const ConstMatrixView &M, const ConstVectorView &x)
Matrix Vector multiplication.
Definition: matpackI.cc:1607
CREATE_OUT3
#define CREATE_OUT3
Definition: messages.h:208
Tensor5::resize
void resize(Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackV.cc:2435
Matrix3RowFromVectors
void Matrix3RowFromVectors(Matrix &m, const Vector &v1, const Vector &v2, const Vector &v3, const Verbosity &)
WORKSPACE METHOD: Matrix3RowFromVectors.
Definition: m_basic_types.cc:293
messages.h
Declarations having to do with the four output streams.
VectorFlip
void VectorFlip(Vector &out, const Vector &in, const Verbosity &)
WORKSPACE METHOD: VectorFlip.
Definition: m_basic_types.cc:696
VectorNLinSpace
void VectorNLinSpace(Vector &x, const Index &n, const Numeric &start, const Numeric &stop, const Verbosity &verbosity)
WORKSPACE METHOD: VectorNLinSpace.
Definition: m_basic_types.cc:923
ConstMatrixView::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackI.cc:802
my_basic_string
The implementation for String, the ARTS string class.
Definition: mystring.h:62
VectorInsertGridPoints
void VectorInsertGridPoints(Vector &og, const Vector &ingrid, const Vector &points, const Verbosity &verbosity)
WORKSPACE METHOD: VectorInsertGridPoints.
Definition: m_basic_types.cc:720
ConstVectorView::nelem
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:175
StringSet
void StringSet(String &s, const String &s2, const Verbosity &)
WORKSPACE METHOD: StringSet.
Definition: m_basic_types.cc:416
ConstTensor7View::nvitrines
Index nvitrines() const
Returns the number of vitrines.
Definition: matpackVII.cc:37
ConstTensor4View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:78
Tensor3SetConstant
void Tensor3SetConstant(Tensor3 &x, const Index &npages, const Index &nrows, const Index &ncols, const Numeric &value, const Verbosity &verbosity)
WORKSPACE METHOD: Tensor3SetConstant.
Definition: m_basic_types.cc:465
ConstTensor7View::npages
Index npages() const
Returns the number of pages.
Definition: matpackVII.cc:55
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Verbosity
Definition: messages.h:50
ConstTensor4View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:66
matpackIII.h
ConstTensor4View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:60
math_funcs.h
make_array.h
Implements the class MakeArray, which is a derived class of Array, allowing explicit initialization.
Tensor5SetConstant
void Tensor5SetConstant(Tensor5 &x, const Index &nshelves, const Index &nbooks, const Index &npages, const Index &nrows, const Index &ncols, const Numeric &value, const Verbosity &verbosity)
WORKSPACE METHOD: Tensor5SetConstant.
Definition: m_basic_types.cc:550
SparseSparseMultiply
void SparseSparseMultiply(Sparse &Y, const Sparse &M, const Sparse &X, const Verbosity &)
WORKSPACE METHOD: SparseSparseMultiply.
Definition: m_basic_types.cc:388
Matrix::resize
void resize(Index r, Index c)
Resize function.
Definition: matpackI.cc:1549
VectorScale
void VectorScale(Vector &out, const Vector &in, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: VectorScale.
Definition: m_basic_types.cc:975
ConstTensor3View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:154
VectorLinSpace
void VectorLinSpace(Vector &x, const Numeric &start, const Numeric &stop, const Numeric &step, const Verbosity &verbosity)
WORKSPACE METHOD: VectorLinSpace.
Definition: m_basic_types.cc:848
nlinspace
void nlinspace(Vector &x, const Numeric start, const Numeric stop, const Index n)
nlinspace
Definition: math_funcs.cc:261
ConstTensor6View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackVI.cc:43
Tensor5
The Tensor5 class.
Definition: matpackV.h:443
ConstTensor4View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:72
MatrixSetConstant
void MatrixSetConstant(Matrix &x, const Index &nrows, const Index &ncols, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: MatrixSetConstant.
Definition: m_basic_types.cc:347
Range
The range class.
Definition: matpackI.h:148
ArrayOfIndexSetConstant
void ArrayOfIndexSetConstant(ArrayOfIndex &aoi, const Index &nelem, const Index &value, const Verbosity &)
WORKSPACE METHOD: ArrayOfIndexSetConstant.
Definition: m_basic_types.cc:83
Matrix1ColFromVector
void Matrix1ColFromVector(Matrix &m, const Vector &v, const Verbosity &)
WORKSPACE METHOD: Matrix1ColFromVector.
Definition: m_basic_types.cc:166
ConstTensor7View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackVII.cc:49
ConstTensor5View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackV.cc:50
VectorSet
void VectorSet(Vector &x, const Vector &values, const Verbosity &)
WORKSPACE METHOD: VectorSet.
Definition: m_basic_types.cc:1016
matpackV.h
is_increasing
bool is_increasing(ConstVectorView x)
Checks if a vector is sorted and strictly increasing.
Definition: logic.cc:258
logic.h
Header file for logic.cc.
Sparse::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackII.cc:53
ConstTensor5View::nshelves
Index nshelves() const
Returns the number of shelves.
Definition: matpackV.cc:32
ConstTensor3View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:157
matpackII.h
Header file for sparse matrices.
VectorNLogSpace
void VectorNLogSpace(Vector &x, const Index &n, const Numeric &start, const Numeric &stop, const Verbosity &verbosity)
WORKSPACE METHOD: VectorNLogSpace.
Definition: m_basic_types.cc:949
Matrix3ColFromVectors
void Matrix3ColFromVectors(Matrix &m, const Vector &v1, const Vector &v2, const Vector &v3, const Verbosity &)
WORKSPACE METHOD: Matrix3ColFromVectors.
Definition: m_basic_types.cc:200
FlagOn
void FlagOn(Index &x, const Verbosity &)
WORKSPACE METHOD: FlagOn.
Definition: m_basic_types.cc:112
VectorMatrixMultiply
void VectorMatrixMultiply(Vector &y, const Matrix &M, const Vector &x, const Verbosity &)
WORKSPACE METHOD: VectorMatrixMultiply.
Definition: m_basic_types.cc:895
IndexStep
void IndexStep(Index &xout, const Index &xin, const Verbosity &)
WORKSPACE METHOD: IndexStep.
Definition: m_basic_types.cc:127
MatrixMatrixMultiply
void MatrixMatrixMultiply(Matrix &Y, const Matrix &M, const Matrix &X, const Verbosity &)
WORKSPACE METHOD: MatrixMatrixMultiply.
Definition: m_basic_types.cc:136
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
ConstTensor7View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackVII.cc:61
linspace
void linspace(Vector &x, const Numeric start, const Numeric stop, const Numeric step)
linspace
Definition: math_funcs.cc:228
arts_exit
void arts_exit(int status)
This is the exit function of ARTS.
Definition: arts.cc:42
Tensor6
The Tensor6 class.
Definition: matpackVI.h:937
M
#define M
Definition: rng.cc:196
Vector
The Vector class.
Definition: matpackI.h:555
FlagOff
void FlagOff(Index &x, const Verbosity &)
WORKSPACE METHOD: FlagOff.
Definition: m_basic_types.cc:105
sorting.h
Contains sorting routines.
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:172
Tensor7SetConstant
void Tensor7SetConstant(Tensor7 &x, const Index &nlibraries, const Index &nvitrines, const Index &nshelves, const Index &nbooks, const Index &npages, const Index &nrows, const Index &ncols, const Numeric &value, const Verbosity &verbosity)
WORKSPACE METHOD: Tensor7SetConstant.
Definition: m_basic_types.cc:644
ConstTensor6View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackVI.cc:61
Tensor5Scale
void Tensor5Scale(Tensor5 &out, const Tensor5 &in, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: Tensor5Scale.
Definition: m_basic_types.cc:529
matpackVI.h
mystring.h
This file contains the definition of String, the ARTS string class.
Tensor7
The Tensor7 class.
Definition: matpackVII.h:1912
matpackVII.h
arts.h
The global header file for ARTS.
Tensor3Scale
void Tensor3Scale(Tensor3 &out, const Tensor3 &in, const Numeric &value, const Verbosity &)
WORKSPACE METHOD: Tensor3Scale.
Definition: m_basic_types.cc:445
VectorSetConstant
void VectorSetConstant(Vector &x, const Index &n, const Numeric &value, const Verbosity &verbosity)
WORKSPACE METHOD: VectorSetConstant.
Definition: m_basic_types.cc:998