casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ArrayOpsDiffShapes.h
Go to the documentation of this file.
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: ArrayOpsDiffShapes.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $
00027 
00028 #ifndef CASA_ARRAYOPSDIFFSHAPES_H
00029 #define CASA_ARRAYOPSDIFFSHAPES_H
00030 
00031 #include <casa/Arrays/ArrayMath.h>
00032 #include <casa/Arrays/ArrayLogical.h>
00033 //#include <casa/Arrays/ArrayUtil.h>
00034 #include <casa/Arrays/IPosition.h>
00035 //#include <casa/Arrays/Slice.h>
00036 //#include <casa/BasicSL/String.h>
00037 
00038 // Don't forget a .tcc file is included at the end!
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 // <summary>
00043 //    Operations for 2 Arrays with possibly different shapes.
00044 // </summary>
00045 // <!-- <reviewed reviewer="UNKNOWN" date="" tests=""> -->
00046 //
00047 // <prerequisite>
00048 //   <li> <linkto class=Array>Array</linkto>
00049 //   <li> <linkto>ArrayMath</linkto>
00050 // </prerequisite>
00051 //
00052 // <etymology>
00053 // This file contains global functions that attempt binary operations with
00054 // arrays that have possibly differing shapes.
00055 // </etymology>
00056 //
00057 // <synopsis>
00058 // These functions perform operations on two arrays, left and right, which go
00059 // chunk by chunk in left and element by element in right, as long as right
00060 // spans a subspace of left.  If left's shape has more dimensions than right's,
00061 // each entry in right will effectively be replicated as necessary to act on
00062 // each entry in the corresponding chunk of left.
00063 // e.g. if left's shape is (256, 256, 1, 4), and right's is (256, 256), 
00064 // left(i, j, 1, l) will be operated on with right(i, j) for i & j from 0 to
00065 // 255 and l from 0 to 3.  Note that right must be either reformable to left's
00066 // shape (same # of elements) or its shape must equal left's shape "as far as
00067 // it goes", i.e. where right's dimensions are defined.
00068 // </synopsis>
00069 //
00070 // <example>
00071 // <srcblock>
00072 //   Array<Complex> a(10, 6);
00073 //   Vector<Int>    b(10);
00074 //   Array<Complex> c(10, 6);
00075 //   
00076 //   c = binOpExpandR(a, b, std::plus<Complex>());
00077 // </srcblock>
00078 // This example sets c(i, j) to a(i, j) + b(i).  It checks that either b's
00079 // shape can be reformed to a's (same # of elements) or that a's shape is the
00080 // same as b's where b's dimensions are defined.
00081 // The result of this operation is an Array.
00082 // </example>
00083 
00084 // <group name=OpsDiff_functions>
00085 
00086 // Returns a LogicalArray with elements (at pos) set to (data(pos) ==
00087 // truthvalue).  data is effectively collapsed using anyEQ if necessary to
00088 // fit desiredform.  Throws an exception if that does not work.
00089 template<typename T>
00090 LogicalArray reformedMask(const Array<T>& data, const T truthvalue,
00091                           const IPosition& desiredform);
00092 
00093 // Can arrays left and right with respective shapes leftShape and rightShape be
00094 // used in function(left, right, ...) for the other functions declared here?
00095 Bool rightExpandableToLeft(const IPosition& leftShape, const IPosition& rightShape);
00096 
00097 // Apply op elementwise to left and right, replicating elements of right as
00098 // necessary (see example above).  Throws an ArrayConformanceError exception if
00099 // that cannot be done.
00100 //
00101 // Currently assumes that it is the trailing axes of left that right will be
00102 // replicated along.  e.g. if left's shape is (1, 2, 4) and right's is (1, 2),
00103 // the result will be left(i, j, k) op right(i, j) for all (i, j, k).
00104 //
00105 //# template<typename L, typename R, typename BinaryOperator, typename RES>
00106 //# Array<RES> binOpExpandR(const Array<L>& left, const Array<R>& right,
00107 //#                     BinaryOperator op);
00108 
00109 // Like binOpExpandR(left, right, res, op), but work on left in place.
00110 template<typename L, typename R, typename BinaryOperator>
00111 void binOpExpandInPlace(Array<L>& left, const Array<R>& right, BinaryOperator op);
00112 
00113 // </group>
00114 
00115 } //#End casa namespace
00116 
00117 #ifndef CASACORE_NO_AUTO_TEMPLATES
00118 #include <casa/Arrays/ArrayOpsDiffShapes.tcc>
00119 #endif //# CASACORE_NO_AUTO_TEMPLATES
00120 #endif