00001 //# MArrayUtil.h: Utility functions for MArrays 00002 //# Copyright (C) 2012 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: MArrayUtil.h 21262 2012-09-07 12:38:36Z gervandiepen $ 00027 00028 #ifndef CASA_MARRAYUTIL_H 00029 #define CASA_MARRAYUTIL_H 00030 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/casa/Arrays/ArrayUtil.h> 00035 00036 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00037 00038 // <summary> 00039 // Reorder the axes of the data in an MArray object 00040 // </summary> 00041 00042 // <use visibility=export> 00043 00044 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tArrayUtil2.cc"> 00045 00046 // <synopsis> 00047 // This function makes it possible to reorder the axes of an MArray. 00048 // Both the data and the optional mask are reordered. 00049 // The resulting array is a copy of the input array with its data 00050 // moved around according to the new array order. 00051 // If the order does not change, a copy is returned if the 00052 // <src>alwaysCopy</src> is true. Otherwise a reference of the 00053 // input array is returned. 00054 // <p> 00055 // The <src>newAxisOrder</src> defines the new axes order. 00056 // Its length can be less than the dimensionality of the input array. 00057 // It is appended with the non-specified axes in their natural order. 00058 // <src>newAxisOrder(i)</src> gives the axis in the original array 00059 // which will now get axis <src>i</src>. 00060 // </synopsis> 00061 00062 // <example> 00063 // <srcblock> 00064 // MArray<Int> result = reorderArray (someArray, IPosition(2,1,3)); 00065 // </srcblock> 00066 // Say that someArray is a 4D array with shape [3,4,5,6]. 00067 // The non-specified axes get appended to the axis order 00068 // specification [1,3] resulting in [1,3,0,2]. 00069 // <br> This means that axis 1 gets axis 0, axis 3 gets axis 1, axis 0 gets 00070 // axis 2, and axis 2 gets axis 3. 00071 // Thus the resulting shape is [4,6,3,5] and the data are moved accordingly. 00072 // </example> 00073 00074 // <group name=reorderMArray> 00075 template<class T> 00076 MArray<T> reorderArray (const MArray<T>& array, 00077 const IPosition& newAxisOrder, 00078 Bool alwaysCopy = True) 00079 { 00080 return (array.isNull() ? 00081 MArray<T>() : 00082 (array.hasMask() ? 00083 MArray<T> (reorderArray(array.array(), newAxisOrder, alwaysCopy), 00084 reorderArray(array.mask(), newAxisOrder, alwaysCopy)) : 00085 MArray<T> (reorderArray(array.array(), newAxisOrder, alwaysCopy)))); 00086 } 00087 // </group> 00088 00089 } //# NAMESPACE CASACORE - END 00090 00091 #endif