casacore
Loading...
Searching...
No Matches
LatticeExprNode.h
Go to the documentation of this file.
1//# LatticeExprNode.h: LatticeExprNode.h
2//# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
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 LATTICES_LATTICEEXPRNODE_H
27#define LATTICES_LATTICEEXPRNODE_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/lattices/LEL/LELInterface.h>
33#include <casacore/lattices/LEL/LELAttribute.h>
34#include <casacore/lattices/LEL/LELBinaryEnums.h>
35#include <casacore/lattices/LEL/LELUnaryEnums.h>
36#include <casacore/lattices/LEL/LELFunctionEnums.h>
37#include <casacore/casa/Arrays/ArrayFwd.h>
38#include <casacore/casa/Arrays/IPosition.h>
39#include <casacore/casa/Utilities/DataType.h>
40#include <memory>
41
42namespace casacore { //# NAMESPACE CASACORE - BEGIN
43
44//# Forward Declarations
45template <class T> class LatticeExpr;
46template <class T> class Lattice;
47template <class T> class MaskedLattice;
48template <class T> class Block;
49class LCRegion;
50class Slicer;
51class LattRegionHolder;
52class LatticeExprNode;
53
54// Global functions operating on a LatticeExprNode.
55// <group name=GlobalLatticeExprNode>
56 // Unary functions.
57 // <group>
61 // </group>
62
63 // Numerical binary operators
64 // <group>
66 const LatticeExprNode& right);
68 const LatticeExprNode& right);
70 const LatticeExprNode& right);
72 const LatticeExprNode& right);
74 const LatticeExprNode& right);
76 const LatticeExprNode& right);
77 // </group>
78
79 // Relational binary operators
80 // <group>
82 const LatticeExprNode& right);
83 LatticeExprNode operator> (const LatticeExprNode& left,
84 const LatticeExprNode& right);
85 LatticeExprNode operator>= (const LatticeExprNode& left,
86 const LatticeExprNode& right);
87 LatticeExprNode operator< (const LatticeExprNode& left,
88 const LatticeExprNode& right);
89 LatticeExprNode operator<= (const LatticeExprNode& left,
90 const LatticeExprNode& right);
92 const LatticeExprNode& right);
93 // </group>
94
95 // Logical binary operators
96 // <group>
98 const LatticeExprNode& right);
100 const LatticeExprNode& right);
101 // </group>
102
103 // Numerical 1-argument functions
104 // <group>
123 // </group>
124
125 // Numerical 2-argument functions
126 // <group>
128 const LatticeExprNode& right);
130 const LatticeExprNode& right);
132 const LatticeExprNode& right);
134 const LatticeExprNode& right);
136 const LatticeExprNode& right);
137 // </group>
138
139 // Form a complex number from two real numbers.
141 const LatticeExprNode& right);
142
143 // Numerical 1-argument functions which result in a real number
144 // regardless of input expression type
145 // <group>
150 // </group>
151
152 // 1-argument functions operating on a numeric expression resulting
153 // in a scalar
154 // <group>
163 // </group>
164
165 // Determine the value of the element at the part <src>fraction</src>
166 // from the beginning of the given lattice.
167 // Thus <src>fraction=0.5</src> is equal to the median.
169 const LatticeExprNode& fraction);
170
171 // Determine the value range of the elements at the part <src>fraction1</src>
172 // and fraction2 from the beginning of the given lattice. Both fractions
173 // must be >=0 and <=1 and fraction1 must be <= fraction2.
174 // By default <src>fraction2</src> is equal to <src>1-fraction1</src>.
175 // Thus <src>fraction=0.25</src> gives the quartile range of the lattice.
176 // <group>
178 const LatticeExprNode& fraction1,
179 const LatticeExprNode& fraction2);
181 const LatticeExprNode& fraction);
182 // </group>
183
184 // 1-argument function to get the number of elements in a lattice.
185 // If the lattice is masked, only the True elements are counted.
186 // Results in a scalar Double.
188
189 // 1-argument function to get the dimensionality of a lattice.
190 // 0 is returned if it is a scalar.
191 // Results in a scalar Float.
193
194 // 2-argument function to get the length of an axis.
195 // Results in a scalar Float.
196 // The 2nd expression (giving the axis number) has to be a real scalar.
197 // <note role=caution>
198 // Axes start counting at 0.
199 // If the axis is a number < 0, an exception is thrown.
200 // If the axis is a number exceeding the dimensionality, 1 is returned.
201 // </note>
203 const LatticeExprNode& axis);
204
205 // 2-argument function telling per pixel if its index on the given axis
206 // is contained in the 2nd argument. The 2nd argument should be a boolean
207 // vector where True means that the index is contained.
208 // For indices >= vector_length, the 2nd argument defaults to False.
209 // Results in a Bool array.
210 // <note role=caution>
211 // Axes start counting at 0.
212 // If the axis is a number < 0 or >= ndim, an exception is thrown.
213 // </note>
215 const LatticeExprNode& indexFlags);
216
217 // 2-argument function rebinning Lattice by given factors. The 2nd argument
218 // should be a vector (preferably Float - really Int but Int not well
219 // supported in LEL yet). Results in a T array.
221 const LatticeExprNode& bin);
222
223// Test if a value is a NaN.
225
226 // Functions operating on a logical expression resulting in a scalar;
227 // Functions "any" (are any pixels "True") and "all" (are all pixels
228 // "True") result in a Bool; functions "ntrue" and "nfalse" result
229 // in a Double.
230 // <group>
235 // </group>
236
237 // This function returns the mask of the given expression.
238 // If it has no mask, the result is an array with all True values.
240
241 // This function returns the value of the expression without a mask.
243
244 // This function finds <src>sqrt(left^2+right^2)</src>. This
245 // could be used to find the (biased) polarized intensity if
246 // left and right are images of Stokes Q and U.
248 const LatticeExprNode& right);
249
250 // This function finds <src>180/pi*atan2(left,right)/2</src>. This could be
251 // used to find the position of linear polarization if left
252 // and right are images of Stokes U and Q, respectively.
254 const LatticeExprNode& right);
255
256 // This function finds the spectral index
257 // <src>alpha = log(s1/s2) / log(f1/f2)</src>.
259 const LatticeExprNode& right);
260
261 // Function resembling the ternary <src>?:</src> construct in C++.
262 // The argument "condition" has to be a Bool scalar or lattice.
263 // If an element in "condition" is True, the corresponding element from
264 // "arg1" is taken, otherwise it is taken from "arg2".
266 const LatticeExprNode& arg1,
267 const LatticeExprNode& arg2);
268
269 // This function replaces every masked-off element in the first argument
270 // with the corresponding element from the second argument.
271 // The first argument has to be a lattice (expression), the second can
272 // be a scalar or lattice. The mask of the first argument is not changed.
273 // If the first argument does not have a mask, this function does nothing.
275 const LatticeExprNode& arg2);
276
277 // Functions to convert to the given data type. These are mostly
278 // meaningful for down-conversions (e.g. double to float),
279 // since up-conversions are automatically done to get matching data types
280 // when needed. Note that some conversions are not supported, such
281 // as Complex to Double or Float.
282 // <br>The conversion to Bool is useful to convert a region to a
283 // boolean lattice, which is only possible if the region is given
284 // in world coordinates. Otherwise an exception is thrown.
285 // <group>
291 LatticeExprNode convertType (const LatticeExprNode& expr, const Float*);
293 LatticeExprNode convertType (const LatticeExprNode& expr, const Complex*);
294 LatticeExprNode convertType (const LatticeExprNode& expr, const DComplex*);
295 LatticeExprNode convertType (const LatticeExprNode& expr, const Bool*);
296 // </group>
297// </group>
298
299
300
301// <summary>
302// Bridging class to allow C++ expressions involving lattices
303// </summary>
304//
305// <use visibility=export>
306//
307// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
308// </reviewed>
309//
310// <prerequisite>
311// <li> <linkto class="Lattice"> Lattice</linkto>
312// <li> <linkto class="LatticeExpr"> LatticeExpr</linkto>
313// <li> <linkto class="LELInterface"> LELInterface</linkto>
314// </prerequisite>
315//
316// <etymology>
317// The name is derived from the fact that this class provides
318// an expression interface to the user which s/he may use to
319// write C++ expressions involving Lattices. This class actually
320// constructs the nodes of the expression tree, hence its name.
321// It is used by the envelope class LatticeExpr and provides a
322// bridge to the letter classes derived from LELInterface.
323// </etymology>
324//
325// <synopsis>
326// This class is part of the interface which allows the C++ programmer
327// to enter mathematical expressions involving Lattices. It is
328// is part of a Letter/envelope scheme. It's actually a bridge
329// between the envelope class (LatticeExpr) and the letter classes
330// (derived from LELInterface) and it exists largely to handle
331// type conversions. In a single type environment, the envelope
332// class could have directly called the letter classes.
333//
334// The envelope and bridge provide the interface which the programmer
335// sees. The letter classes do the real work and are hidden from
336// the programmer.
337//
338// All the expression manipulation functionality that the user has
339// access to is viewable in this class; it is here that the operators,
340// functions and constructors are defined. These allow the programmer
341// to write mathematical expressions which involve Lattices. The
342// letter classes take care of the optimal traversal of the Lattice
343// and the memory mangement thereof. Thus the Lattices are iterated
344// through and the expressions evaluated for each chunk (usually
345// a tile shape) of the iteration.
346//
347// A description of the implementation details of these classes can
348// be found in
349// <a href="../notes/216.html">Note 216</a>
350//
351// The available functionality is defined by the global friend functions
352// and operators, plus the public constructors. The other public members
353// functions are generally not of interest to the user of this class.
354//
355// Generally, if one writes an expression such as <src>a.copyData(sin(b))</src>,
356// the expression is automatically converted first to a LatticeExprNode and
357// then to a LatticeExpr (which is a Lattice) before evaluation occurs.
358// However, it may occur that you wish to build an expression from
359// subexpressions. To do this, you must explcitly create objects of
360// class LatticeExprNode. You cannot manipulate subexpressions of type
361// LatticeExpr<T>. See below for an example.
362// </synopsis>
363//
364// <example>
365// <srcblock>
366// ArrayLattice<Float> f1(IPosition (2,nx,ny));
367// ArrayLattice<Float> f2(IPosition (2,nx,ny));
368// f2.set(2.0);
369// f1.copyData(2*f2+f2);
370// </srcblock>
371// In this example, the values of the pixels in Lattice f1 are set
372// to the values resulting from the expression "2*f2 + f2"
373// I.e. the expression is evaluated for each pixel in the Lattices
374//
375// Note that :
376//
377// 1) the Lattice::copyData function is expecting a Lattice argument.
378// 2) LatticeExpr inherits from Lattice and therefore a LatticeExpr
379// object is a valid argument object type
380// 3) The expression in the copyData call is automatically converted to
381// a LatticeExprNode by the constructors and operators in LatticeExprNode
382// 4) The LatticeExprNode object so created is automatically converted
383// to a LatticeExpr by casting functions in LatticeExprNode.
384//
385// </example>
386//
387// <example>
388// <srcblock>
389// ArrayLattice<Float> f1(IPosition (2,nx,ny));
390// ArrayLattice<Float> f2(IPosition (2,nx,ny));
391// ArrayLattice<Double> d(IPosition (2,nx,ny));
392// ArrayLattice<Complex> c(IPosition (2,nx,ny));
393// ArrayLattice<Bool> b(IPosition (2,nx,ny));
394//
395// f2.set(1.0); d.set(2.0); c.set(Complex(2.0,3.0)); b.set(True);
396// f1.copyData( (3.5*f2) + (cos(d)) - (10/min(d,f2)*(-abs(c))*ntrue(b)) - (C::pi) );
397// </srcblock>
398//
399// In this rather silly example, we fill Lattice "f1" with the result of the
400// expression. The expression shows the use of constants, unary operations,
401// binary operations, 1D and 2D functions. It also shows how mixed types can
402// be handled. The output Lattice is a Float, whereas mixed into the
403// expression are subexpressions involving Float, Double, Complex and Bool
404// Lattices.
405//
406// </example>
407//
408// <example>
409// <srcblock>
410// ArrayLattice<Float> f1(IPosition (2,nx,ny));
411// ArrayLattice<Float> f2(IPosition (2,nx,ny));
412// f2.set(2.0);
413// LatticeExprNode exp1(sin(f2));
414// LatticeExprNode exp2(pow(f2,2.0));
415// f1.copyData(exp1+exp2);
416// </srcblock>
417// In this example, the expression is "sin(f2) + pow(f2,2.0)",
418// but we have put it together from two subexpressions contained
419// in LatticeExprNode objects exp1 and exp2. Again the LatticeExprNode
420// object formed from summing exp1 and exp2 is automatically converted
421// to a LatticeExpr for consumption by copyData
422//
423// </example>
424//
425// <motivation>
426// The Lattice expression classes enable the C++ programmer much simpler
427// handling of mathematical expressions involving lattices. In addition,
428// these classes provide the infrastructure on top of which we can build
429// an image calculator for Glish users
430// </motivation>
431//
432// <todo asof="1997/01/15">
433// <li> masks
434// <li> regions
435// </todo>
436
437
439{
440// All global functions need to be declared as friends.
441// <group>
446 const LatticeExprNode& right);
448 const LatticeExprNode& right);
450 const LatticeExprNode& right);
452 const LatticeExprNode& right);
453 friend LatticeExprNode operator% (const LatticeExprNode& left,
454 const LatticeExprNode& right);
455 friend LatticeExprNode operator^ (const LatticeExprNode& left,
456 const LatticeExprNode& right);
458 const LatticeExprNode& right);
460 const LatticeExprNode& right);
462 const LatticeExprNode& right);
464 const LatticeExprNode& right);
466 const LatticeExprNode& right);
468 const LatticeExprNode& right);
470 const LatticeExprNode& right);
472 const LatticeExprNode& right);
473 friend LatticeExprNode sin (const LatticeExprNode& expr);
476 friend LatticeExprNode cos (const LatticeExprNode& expr);
479 friend LatticeExprNode tan (const LatticeExprNode& expr);
482 friend LatticeExprNode exp (const LatticeExprNode& expr);
483 friend LatticeExprNode log (const LatticeExprNode& expr);
492 const LatticeExprNode& right);
494 const LatticeExprNode& right);
496 const LatticeExprNode& right);
498 const LatticeExprNode& right);
500 const LatticeExprNode& right);
502 const LatticeExprNode& right);
503 friend LatticeExprNode abs (const LatticeExprNode& expr);
504 friend LatticeExprNode arg (const LatticeExprNode& expr);
507 friend LatticeExprNode min (const LatticeExprNode& expr);
508 friend LatticeExprNode max (const LatticeExprNode& expr);
509 friend LatticeExprNode sum (const LatticeExprNode& expr);
516 const LatticeExprNode& fraction);
518 const LatticeExprNode& fraction1,
519 const LatticeExprNode& fraction2);
521 const LatticeExprNode& fraction);
525 const LatticeExprNode& axis);
527 const LatticeExprNode& indexFlags);
529 const LatticeExprNode& bin);
531 friend LatticeExprNode any (const LatticeExprNode& expr);
532 friend LatticeExprNode all (const LatticeExprNode& expr);
538 const LatticeExprNode& right);
539 friend LatticeExprNode pa (const LatticeExprNode& left,
540 const LatticeExprNode& right);
542 const LatticeExprNode& right);
543 friend LatticeExprNode iif (const LatticeExprNode& condition,
544 const LatticeExprNode& arg1,
545 const LatticeExprNode& arg2);
547 const LatticeExprNode& arg2);
553// </group>
554
555public:
556
557// Default constructor
559
560// Unary constant expression constructors.
561// <group>
568 LatticeExprNode (const Complex& constant);
569 LatticeExprNode (const DComplex& constant);
571// </group>
572
573// Constructor from an IPosition (containing indices or axes).
575
576// Lattice expression (gets Lattice pixels) constructors.
577// <group>
588// </group>
589
590// Create a lattice expression from a region.
591// It results in a boolean expression node.
592// <group>
593 LatticeExprNode (const LCRegion& region);
594 LatticeExprNode (const Slicer& slicer);
596// </group>
597
598// Masking operator using a condition.
599// The given boolean expression forms a mask/region for this expression node.
601
602// Copy constructor (reference semantics)
604
605// Destructor, does nothing
607
608// Assignment (reference semantics)
610
611// Get the IPosition.
612// It throws an exception if the node does not contain an IPosition.
613 const IPosition& getIPosition() const;
614
615// Convert the expression to another data type.
616// <group>
617 std::shared_ptr<LELInterface<Float>> makeFloat() const;
618 std::shared_ptr<LELInterface<Double>> makeDouble() const;
619 std::shared_ptr<LELInterface<Complex>> makeComplex() const;
620 std::shared_ptr<LELInterface<DComplex>> makeDComplex() const;
621 std::shared_ptr<LELInterface<Bool>> makeBool() const;
622// </group>
623
624// Evaluate the expression.
625// One can be sure that the result is not a reference to another array.
626// This function should be used by LatticeExpr and other users.
627// <group>
628 void eval (LELArray<Float>& result, const Slicer& section) const;
629 void eval (LELArray<Double>& result, const Slicer& section) const;
630 void eval (LELArray<Complex>& result, const Slicer& section) const;
631 void eval (LELArray<DComplex>& result, const Slicer& section) const;
632 void eval (LELArray<Bool>& result, const Slicer& section) const;
633// </group>
634
635// Evaluate the expression.
636// The result can be a reference to some internal array (in particular
637// to an array in an ArrayLattice object used as a lattice).
638// This function is meant for internal use by the LEL classes and
639// should not be used externally.
640// <group>
641 void evalRef (LELArrayRef<Float>& result, const Slicer& section) const
642 { pExprFloat_p->evalRef (result, section); }
643 void evalRef (LELArrayRef<Double>& result, const Slicer& section) const
644 { pExprDouble_p->evalRef (result, section); }
645 void evalRef (LELArrayRef<Complex>& result, const Slicer& section) const
646 { pExprComplex_p->evalRef (result, section); }
647 void evalRef (LELArrayRef<DComplex>& result, const Slicer& section) const
648 { pExprDComplex_p->evalRef (result, section); }
649 void evalRef (LELArrayRef<Bool>& result, const Slicer& section) const
650 { pExprBool_p->evalRef (result, section); }
651// </group>
652
653// Evaluate the expression (in case it is a scalar). The "eval"
654// and "get*" functions do the same thing, they just have
655// a slightly different interface.
656// <group>
657 void eval (Float& result) const;
658 void eval (Double& result) const;
659 void eval (Complex& result) const;
660 void eval (DComplex& result) const;
661 void eval (Bool& result) const;
664 Complex getComplex() const;
665 DComplex getDComplex() const;
666 Bool getBool() const;
667// </group>
668
669// Evaluate the expression (in case it is a constant array).
670// <group>
676// </group>
677
678// Get the data type of the expression.
679 DataType dataType() const
680 {return dtype_p;}
681
682// Is the expression node a region?
684 {return pAttr_p->isRegion();}
685
686// Is the result of "eval" a scalar?
688 {return pAttr_p->isScalar();}
689
690// Is the result of "eval" masked?
692 {return pAttr_p->isMasked();}
693
694// Holds the node an invalid scalar?
696 {
697 if (!donePrepare_p) doPrepare();
698 return isInvalid_p;
699 }
700
701// Return the shape of the Lattice including all degenerate axes
702// (ie. axes with a length of one)
703 const IPosition& shape() const
704 {return pAttr_p->shape();}
705
706// Get the attribute object of the expression.
708 {return *pAttr_p;}
709
710// Replace a scalar subexpression by its result.
712
713// Make the object from a std::shared_ptr<LELInterface> pointer.
714// Ideally this function is private, but alas it is needed in LELFunction1D,
715// operator==, and more (too many to make them friend).
716// <group>
717 LatticeExprNode(const std::shared_ptr<LELInterface<Float>>& expr);
718 LatticeExprNode(const std::shared_ptr<LELInterface<Double>>& expr);
719 LatticeExprNode(const std::shared_ptr<LELInterface<Complex>>& expr);
720 LatticeExprNode(const std::shared_ptr<LELInterface<DComplex>>& expr);
721 LatticeExprNode(const std::shared_ptr<LELInterface<Bool>>& expr);
722// </group>
723
724// Determine the resulting data type from the given data types.
725// An exception is thrown if they are incompatible.
726 static DataType resultDataType (DataType left, DataType right);
727
728// Check the arguments of a function and return the resulting attribute object.
729// The matchAxes argument tells if the axes have to match exactly or
730// whether it is possible that one expression is a subset of another
731// (i.e. that axes may be missing).
732// <br>The expectArray argument tells if the result should be an array
733// which is the case if one of the arguments is an array.
735 const Block<Int>& argType,
736 Bool expectArray,
737 Bool matchAxes = True);
738
739 // Handle locking of the LatticeExpr which is delegated to all of its parts.
740 // <group>
742 void unlock();
744 void resync();
745 // </group>
746
747
748private:
749// Make the object from a LELInterface* pointer.
750// <group>
756// </group>
757
758// Test if both operands represent a region.
759// An exception is thrown if only one of them is a region.
760 static Bool areRegions (const LatticeExprNode& left,
761 const LatticeExprNode& right);
762
763// Create a new node for a numerical unary operation.
764// The result has the same data type as the input.
766 const LatticeExprNode& expr);
767
768// Create a new node for a numerical function with 1 argument.
769// The result has the same data type as the input.
771 const LatticeExprNode& expr);
772
773// Create a new node for a real numerical function with 1 argument.
774// The result has the same data type as the input.
776 const LatticeExprNode& expr);
777
778// Create a new node for a complex numerical function with 1 argument.
779// The result has the same data type as the input.
781 const LatticeExprNode& expr);
782
783// Create a new node for a numerical function with 1 argument that
784// returns a real number
786 const LatticeExprNode& expr);
787
788// Create a new node for a numerical function with 2 arguments.
789// The result has the same data type as the combined input type.
791 const LatticeExprNode& left,
792 const LatticeExprNode& right);
793
794// Create a new node for a numerical binary operator.
795// The result has the same data type as the combined input type.
797 const LatticeExprNode& left,
798 const LatticeExprNode& right);
799
800// Create a new node for a logical binary operator.
801// The result has the same data type as the combined input type.
803 const LatticeExprNode& left,
804 const LatticeExprNode& right);
805
806// Create a new node for a comparison binary operator.
807// The result has the same data type as the combined input type.
809 const LatticeExprNode& left,
810 const LatticeExprNode& right);
811
812// Make (if needed and if possible) the expression nodes such that
813// the dimensionalities are equal. This is only possible if both
814// nodes have a coordinate system.
815// It is done by creating an ExtendLattice object for the node
816// with the lower dimensionality.
818 LatticeExprNode& expr1);
819
820// Do the preparation for the evaluation.
821 void doPrepare() const;
822
823
824// Member variables.
825
827 DataType dtype_p;
831 std::shared_ptr<LELInterface<Float>> pExprFloat_p;
832 std::shared_ptr<LELInterface<Double>> pExprDouble_p;
833 std::shared_ptr<LELInterface<Complex>> pExprComplex_p;
834 std::shared_ptr<LELInterface<DComplex>> pExprDComplex_p;
835 std::shared_ptr<LELInterface<Bool>> pExprBool_p;
836};
837
838
839
841 const LatticeExprNode& right)
842 { return fmod (left, right); }
844 const LatticeExprNode& right)
845 { return pow (left, right); }
846
848 { return toFloat (expr); }
850 { return toDouble (expr); }
851inline LatticeExprNode convertType(const LatticeExprNode& expr, const Complex*)
852 { return toComplex (expr); }
853inline LatticeExprNode convertType(const LatticeExprNode& expr, const DComplex*)
854 { return toDComplex (expr); }
856 { return toBool (expr); }
857
858} //# NAMESPACE CASACORE - END
859
860#endif
simple 1-D array
Definition Block.h:198
LockType
Define the possible lock types.
Definition FileLocker.h:93
This LEL class holds a possible referenced array with a mask.
Definition LELArray.h:131
Bool isRegion() const
Is expression a region?
Bool isScalar() const
Is expression a scalar?
const IPosition & shape() const
What is the shape of the expression?
Bool isMasked() const
Is the expression result masked?
std::shared_ptr< LELInterface< DComplex > > makeDComplex() const
friend LatticeExprNode avdev(const LatticeExprNode &expr)
friend LatticeExprNode tan(const LatticeExprNode &expr)
friend LatticeExprNode round(const LatticeExprNode &expr)
LatticeExprNode(const std::shared_ptr< LELInterface< Complex > > &expr)
Array< Complex > getArrayComplex() const
LatticeExprNode(LELInterface< Double > *expr)
void evalRef(LELArrayRef< Double > &result, const Slicer &section) const
void evalRef(LELArrayRef< Float > &result, const Slicer &section) const
Evaluate the expression.
void eval(LELArray< Complex > &result, const Slicer &section) const
void evalRef(LELArrayRef< DComplex > &result, const Slicer &section) const
friend LatticeExprNode operator>(const LatticeExprNode &left, const LatticeExprNode &right)
friend LatticeExprNode formComplex(const LatticeExprNode &left, const LatticeExprNode &right)
Form a complex number from two real numbers.
std::shared_ptr< LELInterface< Bool > > makeBool() const
void eval(Bool &result) const
LatticeExprNode operator[](const LatticeExprNode &cond) const
Masking operator using a condition.
friend LatticeExprNode max(const LatticeExprNode &expr)
LatticeExprNode(const std::shared_ptr< LELInterface< Double > > &expr)
LatticeExprNode(const DComplex &constant)
friend LatticeExprNode asin(const LatticeExprNode &expr)
friend LatticeExprNode toComplex(const LatticeExprNode &expr)
friend LatticeExprNode log10(const LatticeExprNode &expr)
static LatticeExprNode newBinaryCmp(LELBinaryEnums::Operation oper, const LatticeExprNode &left, const LatticeExprNode &right)
Create a new node for a comparison binary operator.
void evalRef(LELArrayRef< Complex > &result, const Slicer &section) const
LatticeExprNode(const Lattice< Float > &lattice)
Lattice expression (gets Lattice pixels) constructors.
friend LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
void eval(Double &result) const
Double getDouble() const
friend LatticeExprNode exp(const LatticeExprNode &expr)
const IPosition & shape() const
Return the shape of the Lattice including all degenerate axes (ie.
friend LatticeExprNode median(const LatticeExprNode &expr)
LatticeExprNode(const LCRegion &region)
Create a lattice expression from a region.
LatticeExprNode(const std::shared_ptr< LELInterface< Bool > > &expr)
friend LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
DComplex getDComplex() const
friend LatticeExprNode ceil(const LatticeExprNode &expr)
friend LatticeExprNode operator-(const LatticeExprNode &expr)
friend LatticeExprNode fractileRange(const LatticeExprNode &expr, const LatticeExprNode &fraction1, const LatticeExprNode &fraction2)
Determine the value range of the elements at the part fraction1 and fraction2 from the beginning of t...
LatticeExprNode(const MaskedLattice< Bool > &lattice)
friend LatticeExprNode tanh(const LatticeExprNode &expr)
Array< DComplex > getArrayDComplex() const
friend LatticeExprNode operator+(const LatticeExprNode &expr)
All global functions need to be declared as friends.
void doPrepare() const
Do the preparation for the evaluation.
std::shared_ptr< LELInterface< Bool > > pExprBool_p
friend LatticeExprNode rebin(const LatticeExprNode &expr, const LatticeExprNode &bin)
2-argument function rebinning Lattice by given factors.
std::shared_ptr< LELInterface< Double > > makeDouble() const
void eval(LELArray< Float > &result, const Slicer &section) const
Evaluate the expression.
friend LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
friend LatticeExprNode real(const LatticeExprNode &expr)
friend LatticeExprNode floor(const LatticeExprNode &expr)
Bool replaceScalarExpr()
Replace a scalar subexpression by its result.
friend LatticeExprNode arg(const LatticeExprNode &expr)
static LatticeExprNode newRealFunc1D(LELFunctionEnums::Function func, const LatticeExprNode &expr)
Create a new node for a real numerical function with 1 argument.
friend LatticeExprNode operator^(const LatticeExprNode &left, const LatticeExprNode &right)
friend LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
friend LatticeExprNode toDouble(const LatticeExprNode &expr)
static LatticeExprNode newLogBinary(LELBinaryEnums::Operation oper, const LatticeExprNode &left, const LatticeExprNode &right)
Create a new node for a logical binary operator.
void eval(Complex &result) const
void eval(LELArray< Double > &result, const Slicer &section) const
friend LatticeExprNode sign(const LatticeExprNode &expr)
LatticeExprNode(const Lattice< Bool > &lattice)
friend LatticeExprNode operator<(const LatticeExprNode &left, const LatticeExprNode &right)
static LatticeExprNode newNumFunc1D(LELFunctionEnums::Function func, const LatticeExprNode &expr)
Create a new node for a numerical function with 1 argument.
Bool hasLock(FileLocker::LockType) const
Array< Double > getArrayDouble() const
LatticeExprNode(const LattRegionHolder &region)
friend LatticeExprNode fractile(const LatticeExprNode &expr, const LatticeExprNode &fraction)
Determine the value of the element at the part fraction from the beginning of the given lattice.
LatticeExprNode & operator=(const LatticeExprNode &other)
Assignment (reference semantics)
friend LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
LatticeExprNode(LELInterface< Bool > *expr)
friend LatticeExprNode nfalse(const LatticeExprNode &expr)
friend LatticeExprNode stddev(const LatticeExprNode &expr)
const LELAttribute * pAttr_p
friend LatticeExprNode amp(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds sqrt(left^2+right^2).
friend LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode(Long constant)
friend LatticeExprNode operator!=(const LatticeExprNode &left, const LatticeExprNode &right)
Array< Float > getArrayFloat() const
Evaluate the expression (in case it is a constant array).
LatticeExprNode(uInt constant)
friend LatticeExprNode conj(const LatticeExprNode &expr)
LatticeExprNode(const Complex &constant)
friend LatticeExprNode ntrue(const LatticeExprNode &expr)
friend LatticeExprNode fractileRange(const LatticeExprNode &expr, const LatticeExprNode &fraction)
LatticeExprNode(const Lattice< Complex > &lattice)
static LatticeExprNode newNumFunc2D(LELFunctionEnums::Function func, const LatticeExprNode &left, const LatticeExprNode &right)
Create a new node for a numerical function with 2 arguments.
LatticeExprNode(const Slicer &slicer)
friend LatticeExprNode atan(const LatticeExprNode &expr)
std::shared_ptr< LELInterface< Complex > > makeComplex() const
LatticeExprNode(const Lattice< Double > &lattice)
Bool isScalar() const
Is the result of "eval" a scalar?
std::shared_ptr< LELInterface< DComplex > > pExprDComplex_p
LatticeExprNode(const MaskedLattice< Double > &lattice)
LatticeExprNode(LELInterface< Complex > *expr)
friend LatticeExprNode toBool(const LatticeExprNode &expr)
friend LatticeExprNode operator<=(const LatticeExprNode &left, const LatticeExprNode &right)
void evalRef(LELArrayRef< Bool > &result, const Slicer &section) const
const IPosition & getIPosition() const
Get the IPosition.
const LELAttribute & getAttribute() const
Get the attribute object of the expression.
friend LatticeExprNode min(const LatticeExprNode &expr)
1-argument functions operating on a numeric expression resulting in a scalar
friend LatticeExprNode all(const LatticeExprNode &expr)
LatticeExprNode(const std::shared_ptr< LELInterface< Float > > &expr)
Make the object from a std::shared_ptr<LELInterface> pointer.
friend LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
friend LatticeExprNode abs(const LatticeExprNode &expr)
Numerical 1-argument functions which result in a real number regardless of input expression type.
LatticeExprNode(const MaskedLattice< Complex > &lattice)
friend LatticeExprNode replace(const LatticeExprNode &arg1, const LatticeExprNode &arg2)
This function replaces every masked-off element in the first argument with the corresponding element ...
LatticeExprNode(const MaskedLattice< Float > &lattice)
Bool isRegion() const
Is the expression node a region?
std::shared_ptr< LELInterface< Float > > makeFloat() const
Convert the expression to another data type.
Bool isMasked() const
Is the result of "eval" masked?
void eval(LELArray< Bool > &result, const Slicer &section) const
friend LatticeExprNode log(const LatticeExprNode &expr)
friend LatticeExprNode variance(const LatticeExprNode &expr)
Array< Bool > getArrayBool() const
static Int makeEqualDim(LatticeExprNode &expr0, LatticeExprNode &expr1)
Make (if needed and if possible) the expression nodes such that the dimensionalities are equal.
void eval(LELArray< DComplex > &result, const Slicer &section) const
LatticeExprNode()
Default constructor.
LatticeExprNode(Bool constant)
friend LatticeExprNode cosh(const LatticeExprNode &expr)
static LELAttribute checkArg(const Block< LatticeExprNode > &arg, const Block< Int > &argType, Bool expectArray, Bool matchAxes=True)
Check the arguments of a function and return the resulting attribute object.
friend LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
friend LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
friend LatticeExprNode operator*(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode(Int constant)
friend LatticeExprNode toFloat(const LatticeExprNode &expr)
Functions to convert to the given data type.
friend LatticeExprNode any(const LatticeExprNode &expr)
Functions operating on a logical expression resulting in a scalar; Functions "any" (are any pixels "T...
friend LatticeExprNode operator||(const LatticeExprNode &left, const LatticeExprNode &right)
std::shared_ptr< LELInterface< Complex > > pExprComplex_p
LatticeExprNode(Float constant)
std::shared_ptr< LELInterface< Float > > pExprFloat_p
Bool isInvalidScalar() const
Holds the node an invalid scalar?
friend LatticeExprNode cos(const LatticeExprNode &expr)
static Bool areRegions(const LatticeExprNode &left, const LatticeExprNode &right)
Test if both operands represent a region.
LatticeExprNode(const LatticeExprNode &other)
Copy constructor (reference semantics)
void eval(DComplex &result) const
LatticeExprNode(Int64 constant)
Unary constant expression constructors.
virtual ~LatticeExprNode()
Destructor, does nothing.
std::shared_ptr< LELInterface< Double > > pExprDouble_p
friend LatticeExprNode sinh(const LatticeExprNode &expr)
friend LatticeExprNode sum(const LatticeExprNode &expr)
friend LatticeExprNode isNaN(const LatticeExprNode &expr)
Test if a value is a NaN.
friend LatticeExprNode fmod(const LatticeExprNode &left, const LatticeExprNode &right)
static LatticeExprNode newNumUnary(LELUnaryEnums::Operation oper, const LatticeExprNode &expr)
Create a new node for a numerical unary operation.
friend LatticeExprNode spectralindex(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds the spectral index alpha = log(s1/s2) / log(f1/f2).
LatticeExprNode(Double constant)
Bool lock(FileLocker::LockType, uInt nattempts)
Handle locking of the LatticeExpr which is delegated to all of its parts.
friend LatticeExprNode operator!(const LatticeExprNode &expr)
LatticeExprNode(LELInterface< Float > *expr)
Make the object from a LELInterface* pointer.
friend LatticeExprNode acos(const LatticeExprNode &expr)
void eval(Float &result) const
Evaluate the expression (in case it is a scalar).
friend LatticeExprNode operator>=(const LatticeExprNode &left, const LatticeExprNode &right)
friend LatticeExprNode sqrt(const LatticeExprNode &expr)
LatticeExprNode(const IPosition &)
Constructor from an IPosition (containing indices or axes).
friend LatticeExprNode operator%(const LatticeExprNode &left, const LatticeExprNode &right)
Bool donePrepare_p
Member variables.
LatticeExprNode(LELInterface< DComplex > *expr)
friend LatticeExprNode indexin(const LatticeExprNode &axis, const LatticeExprNode &indexFlags)
2-argument function telling per pixel if its index on the given axis is contained in the 2nd argument...
friend LatticeExprNode toDComplex(const LatticeExprNode &expr)
friend LatticeExprNode operator&&(const LatticeExprNode &left, const LatticeExprNode &right)
Logical binary operators.
Complex getComplex() const
friend LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
DataType dataType() const
Get the data type of the expression.
friend LatticeExprNode mean(const LatticeExprNode &expr)
friend LatticeExprNode nelements(const LatticeExprNode &expr)
1-argument function to get the number of elements in a lattice.
LatticeExprNode(const MaskedLattice< DComplex > &lattice)
friend LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
static LatticeExprNode newNumBinary(LELBinaryEnums::Operation oper, const LatticeExprNode &left, const LatticeExprNode &right)
Create a new node for a numerical binary operator.
LatticeExprNode(const Lattice< DComplex > &lattice)
static DataType resultDataType(DataType left, DataType right)
Determine the resulting data type from the given data types.
friend LatticeExprNode imag(const LatticeExprNode &expr)
static LatticeExprNode newComplexFunc1D(LELFunctionEnums::Function func, const LatticeExprNode &expr)
Create a new node for a complex numerical function with 1 argument.
LatticeExprNode(const std::shared_ptr< LELInterface< DComplex > > &expr)
friend LatticeExprNode iif(const LatticeExprNode &condition, const LatticeExprNode &arg1, const LatticeExprNode &arg2)
Function resembling the ternary ?: construct in C++.
static LatticeExprNode newNumReal1D(LELFunctionEnums::Function func, const LatticeExprNode &expr)
Create a new node for a numerical function with 1 argument that returns a real number.
friend LatticeExprNode operator==(const LatticeExprNode &left, const LatticeExprNode &right)
Relational binary operators.
this file contains all the compiler specific defines
Definition mainpage.dox:28
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
LatticeExprNode fractile(const LatticeExprNode &expr, const LatticeExprNode &fraction)
Determine the value of the element at the part fraction from the beginning of the given lattice.
LatticeExprNode exp(const LatticeExprNode &expr)
LatticeExprNode isNaN(const LatticeExprNode &expr)
Test if a value is a NaN.
LatticeExprNode operator&&(const LatticeExprNode &left, const LatticeExprNode &right)
Logical binary operators.
LatticeExprNode fractileRange(const LatticeExprNode &expr, const LatticeExprNode &fraction1, const LatticeExprNode &fraction2)
Determine the value range of the elements at the part fraction1 and fraction2 from the beginning of t...
LatticeExprNode asin(const LatticeExprNode &expr)
LatticeExprNode fmod(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode acos(const LatticeExprNode &expr)
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
LatticeExprNode replace(const LatticeExprNode &arg1, const LatticeExprNode &arg2)
This function replaces every masked-off element in the first argument with the corresponding element ...
LatticeExprNode mean(const LatticeExprNode &expr)
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
long Long
Definition aipstype.h:50
LatticeExprNode cosh(const LatticeExprNode &expr)
LatticeExprNode atan(const LatticeExprNode &expr)
LatticeExprNode indexin(const LatticeExprNode &axis, const LatticeExprNode &indexFlags)
2-argument function telling per pixel if its index on the given axis is contained in the 2nd argument...
LatticeExprNode tanh(const LatticeExprNode &expr)
LatticeExprNode sign(const LatticeExprNode &expr)
LatticeExprNode arg(const LatticeExprNode &expr)
LatticeExprNode log10(const LatticeExprNode &expr)
LatticeExprNode toFloat(const LatticeExprNode &expr)
Functions to convert to the given data type.
LatticeExprNode conj(const LatticeExprNode &expr)
LatticeExprNode formComplex(const LatticeExprNode &left, const LatticeExprNode &right)
Form a complex number from two real numbers.
LatticeExprNode operator%(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode sinh(const LatticeExprNode &expr)
LatticeExprNode sum(const LatticeExprNode &expr)
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
MVBaseline operator*(const RotMatrix &left, const MVBaseline &right)
Rotate a Baseline vector with rotation matrix and other multiplications.
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode stddev(const LatticeExprNode &expr)
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode abs(const LatticeExprNode &expr)
Numerical 1-argument functions which result in a real number regardless of input expression type.
LatticeExprNode operator-(const LatticeExprNode &expr)
LatticeExprNode tan(const LatticeExprNode &expr)
bool operator==(const casacore_allocator< T, ALIGNMENT > &, const casacore_allocator< T, ALIGNMENT > &)
Definition Allocator.h:127
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
bool operator!=(const casacore_allocator< T, ALIGNMENT > &, const casacore_allocator< T, ALIGNMENT > &)
Definition Allocator.h:133
LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
LatticeExprNode variance(const LatticeExprNode &expr)
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
LatticeExprNode toDouble(const LatticeExprNode &expr)
LatticeExprNode any(const LatticeExprNode &expr)
Functions operating on a logical expression resulting in a scalar; Functions "any" (are any pixels "T...
LatticeExprNode sqrt(const LatticeExprNode &expr)
float Float
Definition aipstype.h:52
LatticeExprNode ntrue(const LatticeExprNode &expr)
LatticeExprNode amp(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds sqrt(left^2+right^2).
LatticeExprNode toBool(const LatticeExprNode &expr)
LatticeExprNode avdev(const LatticeExprNode &expr)
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
LatticeExprNode convertType(const LatticeExprNode &expr, const Float *)
LatticeExprNode toComplex(const LatticeExprNode &expr)
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode toDComplex(const LatticeExprNode &expr)
LatticeExprNode log(const LatticeExprNode &expr)
LatticeExprNode iif(const LatticeExprNode &condition, const LatticeExprNode &arg1, const LatticeExprNode &arg2)
Function resembling the ternary ?: construct in C++.
LatticeExprNode spectralindex(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds the spectral index alpha = log(s1/s2) / log(f1/f2).
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode operator^(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
LatticeExprNode cos(const LatticeExprNode &expr)
LatticeExprNode operator!(const LatticeExprNode &expr)
LatticeExprNode floor(const LatticeExprNode &expr)
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53
LatticeExprNode median(const LatticeExprNode &expr)
LatticeExprNode all(const LatticeExprNode &expr)
LatticeExprNode nelements(const LatticeExprNode &expr)
1-argument function to get the number of elements in a lattice.
LatticeExprNode round(const LatticeExprNode &expr)
LatticeExprNode ceil(const LatticeExprNode &expr)
LatticeExprNode real(const LatticeExprNode &expr)
LatticeExprNode operator||(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode nfalse(const LatticeExprNode &expr)
LatticeExprNode imag(const LatticeExprNode &expr)
LatticeExprNode rebin(const LatticeExprNode &expr, const LatticeExprNode &bin)
2-argument function rebinning Lattice by given factors.