casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef CASA_MARRAYUTIL_H
27#define CASA_MARRAYUTIL_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/Arrays/ArrayUtil.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Reorder the axes of the data in an MArray object
38// </summary>
39
40// <use visibility=export>
41
42// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMArrayUtil.cc">
43
44// <synopsis>
45// This function makes it possible to reorder the axes of an MArray.
46// Both the data and the optional mask are reordered.
47// The resulting array is a copy of the input array with its data
48// moved around according to the new array order.
49// If the order does not change, a copy is returned if the
50// <src>alwaysCopy</src> is true. Otherwise a reference of the
51// input array is returned.
52// <p>
53// The <src>newAxisOrder</src> defines the new axes order.
54// Its length can be less than the dimensionality of the input array.
55// It is appended with the non-specified axes in their natural order.
56// <src>newAxisOrder(i)</src> gives the axis in the original array
57// which will now get axis <src>i</src>.
58// </synopsis>
59
60// <example>
61// <srcblock>
62// MArray<Int> result = reorderArray (someArray, IPosition(2,1,3));
63// </srcblock>
64// Say that someArray is a 4D array with shape [3,4,5,6].
65// The non-specified axes get appended to the axis order
66// specification [1,3] resulting in [1,3,0,2].
67// <br> This means that axis 1 gets axis 0, axis 3 gets axis 1, axis 0 gets
68// axis 2, and axis 2 gets axis 3.
69// Thus the resulting shape is [4,6,3,5] and the data are moved accordingly.
70// </example>
71
72// <group name=reorderMArray>
73template<class T>
74MArray<T> reorderArray (const MArray<T>& array,
75 const IPosition& newAxisOrder,
76 Bool alwaysCopy = True)
77{
78 return (array.isNull() ?
79 MArray<T>() :
80 (array.hasMask() ?
81 MArray<T> (reorderArray(array.array(), newAxisOrder, alwaysCopy),
82 reorderArray(array.mask(), newAxisOrder, alwaysCopy)) :
83 MArray<T> (reorderArray(array.array(), newAxisOrder, alwaysCopy))));
84}
85// </group>
86
87
88// <summary>
89// Reverse the order of one or more axes of an MArray.
90// </summary>
91
92// <use visibility=export>
93
94// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMArrayUtil.cc">
95
96// <synopsis>
97// This function makes it possible to reverse one or more axes of an MArray by
98// swapping around the elements of each axis.
99// Both the data and the optional mask are reversed.
100// The resulting array is a copy of the input array with its data
101// moved around according to the new order.
102// If the order does not change, a copy is returned if the
103// <src>alwaysCopy</src> is true. Otherwise a reference of the
104// input array is returned.
105// </synopsis>
106
107// <example>
108// Reversing axis 0 of a Vector means that the Vector is reversed.
109// Reversing axis 1 of a Matrix means that its rows are reversed.
110// Reversing axis 0 of an N-dim array means that the elements of each Vector
111// in that array are reversed.
112// </example>
113
114// <group name=reverseMArray>
115template<class T>
116MArray<T> reverseArray (const MArray<T>& array,
117 const IPosition& reversedAxes,
118 Bool alwaysCopy = True)
119{
120 return (array.isNull() ?
121 MArray<T>() :
122 (array.hasMask() ?
123 MArray<T> (reverseArray(array.array(), reversedAxes, alwaysCopy),
124 reverseArray(array.mask(), reversedAxes, alwaysCopy)) :
125 MArray<T> (reverseArray(array.array(), reversedAxes, alwaysCopy))));
126}
127// </group>
128
129
130} //# NAMESPACE CASACORE - END
131
132#endif
Bool isNull() const
Does the node contain no actual node?
Definition ExprNode.h:269
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:1933
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
MArray< T > reorderArray(const MArray< T > &array, const IPosition &newAxisOrder, Bool alwaysCopy=True)
Definition MArrayUtil.h:75
Reverse the order of one or more axes of an MArray.
Definition MArrayUtil.h:115
MArray< T > reverseArray(const MArray< T > &array, const IPosition &reversedAxes, Bool alwaysCopy=True)
Definition MArrayUtil.h:117