00001 //# ArrayOpsDiffShapes.h: Operations for 2 Arrays with possibly different shapes. 00002 //# Copyright (C) 2009 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This program is free software; you can redistribute it and/or modify 00006 //# it under the terms of the GNU General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or 00008 //# (at your option) any later version. 00009 //# 00010 //# This program is distributed in the hope that it will be useful, 00011 //# but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 //# GNU General Public License for more details. 00014 //# 00015 //# You should have received a copy of the GNU General Public License 00016 //# along with this program; if not, write to the Free Software 00017 //# Foundation, Inc., 675 Mass 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$ 00027 00028 #ifndef CASA_ARRAYOPSDIFFSHAPES_H 00029 #define CASA_ARRAYOPSDIFFSHAPES_H 00030 00031 #include <casacore/casa/aips.h> 00032 #include <casacore/casa/Arrays/ArrayMath.h> 00033 #include <casacore/casa/Arrays/ArrayLogical.h> 00034 //#include <casacore/casa/Arrays/ArrayUtil.h> 00035 #include <casacore/casa/Arrays/IPosition.h> 00036 //#include <casacore/casa/Arrays/Slice.h> 00037 //#include <casacore/casa/BasicSL/String.h> 00038 00039 // Don't forget a .tcc file is included at the end! 00040 00041 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00042 00043 // <summary> 00044 // Operations for 2 Arrays with possibly different shapes. 00045 // </summary> 00046 // <!-- <reviewed reviewer="UNKNOWN" date="" tests=""> --> 00047 // 00048 // <prerequisite> 00049 // <li> <linkto class=Array>Array</linkto> 00050 // <li> <linkto>ArrayMath</linkto> 00051 // </prerequisite> 00052 // 00053 // <etymology> 00054 // This file contains global functions that attempt binary operations with 00055 // arrays that have possibly differing shapes. 00056 // </etymology> 00057 // 00058 // <synopsis> 00059 // These functions perform operations on two arrays, left and right, which go 00060 // chunk by chunk in left and element by element in right, as long as right 00061 // spans a subspace of left. If left's shape has more dimensions than right's, 00062 // each entry in right will effectively be replicated as necessary to act on 00063 // each entry in the corresponding chunk of left. 00064 // e.g. if left's shape is (256, 256, 1, 4), and right's is (256, 256), 00065 // left(i, j, 1, l) will be operated on with right(i, j) for i & j from 0 to 00066 // 255 and l from 0 to 3. Note that right must be either reformable to left's 00067 // shape (same # of elements) or its shape must equal left's shape "as far as 00068 // it goes", i.e. where right's dimensions are defined. 00069 // </synopsis> 00070 // 00071 // <example> 00072 // <srcblock> 00073 // Array<Complex> a(10, 6); 00074 // Vector<Int> b(10); 00075 // Array<Complex> c(10, 6); 00076 // 00077 // c = binOpExpandR(a, b, std::plus<Complex>()); 00078 // </srcblock> 00079 // This example sets c(i, j) to a(i, j) + b(i). It checks that either b's 00080 // shape can be reformed to a's (same # of elements) or that a's shape is the 00081 // same as b's where b's dimensions are defined. 00082 // The result of this operation is an Array. 00083 // </example> 00084 00085 // <group name=OpsDiff_functions> 00086 00087 // Returns a LogicalArray with elements (at pos) set to (data(pos) == 00088 // truthvalue). data is effectively collapsed using anyEQ if necessary to 00089 // fit desiredform. Throws an exception if that does not work. 00090 template<typename T> 00091 LogicalArray reformedMask(const Array<T>& data, const T truthvalue, 00092 const IPosition& desiredform); 00093 00094 // Can arrays left and right with respective shapes leftShape and rightShape be 00095 // used in function(left, right, ...) for the other functions declared here? 00096 Bool rightExpandableToLeft(const IPosition& leftShape, const IPosition& rightShape); 00097 00098 // Apply op elementwise to left and right, replicating elements of right as 00099 // necessary (see example above). Throws an ArrayConformanceError exception if 00100 // that cannot be done. 00101 // 00102 // Currently assumes that it is the trailing axes of left that right will be 00103 // replicated along. e.g. if left's shape is (1, 2, 4) and right's is (1, 2), 00104 // the result will be left(i, j, k) op right(i, j) for all (i, j, k). 00105 // 00106 //# template<typename L, typename R, typename BinaryOperator, typename RES> 00107 //# Array<RES> binOpExpandR(const Array<L>& left, const Array<R>& right, 00108 //# BinaryOperator op); 00109 00110 // Like binOpExpandR(left, right, res, op), but work on left in place. 00111 template<typename L, typename R, typename BinaryOperator> 00112 void binOpExpandInPlace(Array<L>& left, const Array<R>& right, BinaryOperator op); 00113 00114 // </group> 00115 00116 } //#End casa namespace 00117 00118 #ifndef CASACORE_NO_AUTO_TEMPLATES 00119 #include <casacore/casa/Arrays/ArrayOpsDiffShapes.tcc> 00120 #endif //# CASACORE_NO_AUTO_TEMPLATES 00121 #endif