casacore
MArrayUtil.h
Go to the documentation of this file.
1 //# MArrayUtil.h: Utility functions for MArrays
2 //# Copyright (C) 2012
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: MArrayUtil.h 21262 2012-09-07 12:38:36Z gervandiepen $
27 
28 #ifndef CASA_MARRAYUTIL_H
29 #define CASA_MARRAYUTIL_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/casa/Arrays/ArrayUtil.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 // <summary>
39 // Reorder the axes of the data in an MArray object
40 // </summary>
41 
42 // <use visibility=export>
43 
44 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMArrayUtil.cc">
45 
46 // <synopsis>
47 // This function makes it possible to reorder the axes of an MArray.
48 // Both the data and the optional mask are reordered.
49 // The resulting array is a copy of the input array with its data
50 // moved around according to the new array order.
51 // If the order does not change, a copy is returned if the
52 // <src>alwaysCopy</src> is true. Otherwise a reference of the
53 // input array is returned.
54 // <p>
55 // The <src>newAxisOrder</src> defines the new axes order.
56 // Its length can be less than the dimensionality of the input array.
57 // It is appended with the non-specified axes in their natural order.
58 // <src>newAxisOrder(i)</src> gives the axis in the original array
59 // which will now get axis <src>i</src>.
60 // </synopsis>
61 
62 // <example>
63 // <srcblock>
64 // MArray<Int> result = reorderArray (someArray, IPosition(2,1,3));
65 // </srcblock>
66 // Say that someArray is a 4D array with shape [3,4,5,6].
67 // The non-specified axes get appended to the axis order
68 // specification [1,3] resulting in [1,3,0,2].
69 // <br> This means that axis 1 gets axis 0, axis 3 gets axis 1, axis 0 gets
70 // axis 2, and axis 2 gets axis 3.
71 // Thus the resulting shape is [4,6,3,5] and the data are moved accordingly.
72 // </example>
73 
74 // <group name=reorderMArray>
75 template<class T>
76 MArray<T> reorderArray (const MArray<T>& array,
77  const IPosition& newAxisOrder,
78  Bool alwaysCopy = True)
79 {
80  return (array.isNull() ?
81  MArray<T>() :
82  (array.hasMask() ?
83  MArray<T> (reorderArray(array.array(), newAxisOrder, alwaysCopy),
84  reorderArray(array.mask(), newAxisOrder, alwaysCopy)) :
85  MArray<T> (reorderArray(array.array(), newAxisOrder, alwaysCopy))));
86 }
87 // </group>
88 
89 
90 // <summary>
91 // Reverse the order of one or more axes of an MArray.
92 // </summary>
93 
94 // <use visibility=export>
95 
96 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMArrayUtil.cc">
97 
98 // <synopsis>
99 // This function makes it possible to reverse one or more axes of an MArray by
100 // swapping around the elements of each axis.
101 // Both the data and the optional mask are reversed.
102 // The resulting array is a copy of the input array with its data
103 // moved around according to the new order.
104 // If the order does not change, a copy is returned if the
105 // <src>alwaysCopy</src> is true. Otherwise a reference of the
106 // input array is returned.
107 // </synopsis>
108 
109 // <example>
110 // Reversing axis 0 of a Vector means that the Vector is reversed.
111 // Reversing axis 1 of a Matrix means that its rows are reversed.
112 // Reversing axis 0 of an N-dim array means that the elements of each Vector
113 // in that array are reversed.
114 // </example>
115 
116 // <group name=reverseMArray>
117 template<class T>
118 MArray<T> reverseArray (const MArray<T>& array,
119  const IPosition& reversedAxes,
120  Bool alwaysCopy = True)
121 {
122  return (array.isNull() ?
123  MArray<T>() :
124  (array.hasMask() ?
125  MArray<T> (reverseArray(array.array(), reversedAxes, alwaysCopy),
126  reverseArray(array.mask(), reversedAxes, alwaysCopy)) :
127  MArray<T> (reverseArray(array.array(), reversedAxes, alwaysCopy))));
128 }
129 // </group>
130 
131 
132 } //# NAMESPACE CASACORE - END
133 
134 #endif
Bool isNull() const
Does the node contain no actual node?
Definition: ExprNode.h:272
this file contains all the compiler specific defines
Definition: mainpage.dox:28
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1929
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43