casacore
ExprFuncNodeArray.h
Go to the documentation of this file.
1 //# ExprFuncNodeArray.h: Class representing an array function in table select expression
2 //# Copyright (C) 2001,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: aips2-request@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 //# $Id: ExprFuncNodeArray.h 21277 2012-10-31 16:07:31Z gervandiepen $
27 
28 #ifndef TABLES_EXPRFUNCNODEARRAY_H
29 #define TABLES_EXPRFUNCNODEARRAY_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/tables/TaQL/ExprNodeArray.h>
34 #include <casacore/tables/TaQL/ExprFuncNode.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward Declarations
39 
40 
41 // <summary>
42 // Class representing an array function in table select expression
43 // </summary>
44 
45 // <use visibility=local>
46 
47 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
48 // </reviewed>
49 // <prerequisite>
50 //# Classes you should understand before using this one.
51 // <li> <linkto class=TableExprFuncNode>TableExprFuncNode</linkto>
52 // <li> <linkto class=TableExprNodeArray>TableExprNodeArray</linkto>
53 // </prerequisite>
54 
55 // <synopsis>
56 // This class can be seen as a specialization of TableExprFuncNode
57 // for functions returning arrays.
58 // However, it is derived from TableExprNodeArray to make it possible
59 // that the ExprNode classes use all array functionality offered by
60 // that base class.
61 // <br>Internally an TableExprFuncNode object is used.
62 // <p>
63 // When a TaQL function is used, TableExprFuncNode::checkOperands
64 // determines whether the result is a scalar or an array.
65 // Thereafter TableExprNode::newFunctionNode creates a TableExprFuncNode
66 // for scalars or a TableExprFuncNodeArray for arrays.
67 // </synopsis>
68 
69 
71 {
72 public:
73  // Constructor
76  const TableExprNodeSet& source,
77  const vector<TENShPtr>& nodes,
78  const Block<Int>& dtypeOper,
79  const TaQLStyle&);
80 
81  // Destructor
83 
84  // Get the nodes representing an aggregate function.
85  virtual void getAggrNodes (std::vector<TableExprNodeRep*>& aggr);
86 
87  // Get the nodes representing a table column.
88  virtual void getColumnNodes (std::vector<TableExprNodeRep*>& cols);
89 
90  // 'get' Functions to get the desired result of a function
91  // <group>
92  virtual MArray<Bool> getArrayBool (const TableExprId& id);
93  virtual MArray<Int64> getArrayInt (const TableExprId& id);
98  // </group>
99 
100  // Get the function node.
102  { return &node_p; }
104  { return &node_p; }
105 
106 protected:
107  // Try if the function gives a constant result.
108  // If so, set the expression type to Constant.
109  // Get possible constant arguments like axes.
110  void tryToConst();
111 
112  // Some functions to be used by TableExprNodeFuncArray.
113  // <group>
114  const std::vector<TENShPtr>& operands() const
115  { return node_p.operands(); }
116  std::vector<TENShPtr>& rwOperands()
117  { return node_p.rwOperands(); }
119  { return node_p.funcType(); }
121  { return node_p.argDataType(); }
122  // </group>
123 
124 private:
125  // Get the collapse axes for the partial functions.
126  // It compares the values with the #dim and removes them if too high.
127  // axarg gives the argument nr of the axes.
129  Int ndim, uInt axarg=1, Bool swapRemove=True);
130 
131  // Remove axes exceeding ndim.
132  IPosition removeAxes (const IPosition& axes, Int ndim) const;
133 
134  // Get the shape for the array, boxed and running functions.
135  // If an axis length < 0, the corresponding main shape axis (if present)
136  // is used.
137  // axarg gives the argument nr of the shape.
139  uInt axarg=1);
140 
141  // Get the transpose order of the array axes.
143 
144  // Get the axes for the reverse function.
146 
147  // Get the arguments for the diagonals function.
148  // They are checked and if needed adapted if the shape is not empty.
150  const IPosition& shp);
151 
152  // Set the alternate value expandAlt_p for array expand and return it.
153  const IPosition& getAlternate (const TableExprId& id);
154 
155  // Adjust the resize shape by replacing negative axes with the
156  // original axis (if present) or 1.
158  const IPosition& origShape) const;
159 
160  // Templated function to resize/expand an array.
161  template<typename T>
162  MArray<T> TEFResize (const MArray<T>& arr, const TableExprId& id);
163 
164  // The angular distance between each pair of the arguments.
166  const MArray<Double>& a2) const;
167 
168 
169  //# Data members
171  Int origin_p; //# axes origin
172  Bool isCOrder_p; //# axes order
173  Bool constAxes_p; //# True = collapse axes are constant
174  Bool constAlt_p; //# True = expandAlt_p is constant
175  IPosition ipos_p; //# the (maybe constant) axes or shape
176  IPosition iposN_p; //# the non-reversed axes or shape
177  IPosition expandAlt_p; //# alternate for expand/resize
178 };
179 
180 
181 
182 
183 } //# NAMESPACE CASACORE - END
184 
185 #endif
const IPosition & getDiagonalArg(const TableExprId &id, const IPosition &shp)
Get the arguments for the diagonals function.
IPosition getOrder(const TableExprId &id, Int ndim)
Get the transpose order of the array axes.
IPosition removeAxes(const IPosition &axes, Int ndim) const
Remove axes exceeding ndim.
TableExprFuncNode::FunctionType funcType() const
virtual MArray< Bool > getArrayBool(const TableExprId &id)
'get' Functions to get the desired result of a function
virtual void getColumnNodes(std::vector< TableExprNodeRep * > &cols)
Get the nodes representing a table column.
MArray< Double > angdistx(const MArray< Double > &a1, const MArray< Double > &a2) const
The angular distance between each pair of the arguments.
virtual MArray< MVTime > getArrayDate(const TableExprId &id)
std::vector< TENShPtr > & rwOperands()
const std::vector< TENShPtr > & operands() const
Some functions to be used by TableExprNodeFuncArray.
IPosition getReverseAxes(const TableExprId &id, uInt ndim)
Get the axes for the reverse function.
IPosition getAxes(const TableExprId &id, Int ndim, uInt axarg=1, Bool swapRemove=True)
Get the collapse axes for the partial functions.
const IPosition & getArrayShape(const TableExprId &id, uInt axarg=1)
Get the shape for the array, boxed and running functions.
virtual MArray< Int64 > getArrayInt(const TableExprId &id)
TableExprFuncNodeArray(TableExprFuncNode::FunctionType, NodeDataType, ValueType, const TableExprNodeSet &source, const vector< TENShPtr > &nodes, const Block< Int > &dtypeOper, const TaQLStyle &)
Constructor.
TableExprFuncNode * getChild()
Get the function node.
const IPosition & getAlternate(const TableExprId &id)
Set the alternate value expandAlt_p for array expand and return it.
virtual MArray< String > getArrayString(const TableExprId &id)
IPosition adjustShape(const IPosition &shape, const IPosition &origShape) const
Adjust the resize shape by replacing negative axes with the original axis (if present) or 1.
virtual MArray< DComplex > getArrayDComplex(const TableExprId &id)
The default implementation of getArrayDComplex does getArrayDouble and converts the result.
const TableExprFuncNode * getChild() const
virtual MArray< Double > getArrayDouble(const TableExprId &id)
The default implementation of getArrayDouble does getArrayInt and converts the result.
MArray< T > TEFResize(const MArray< T > &arr, const TableExprId &id)
Templated function to resize/expand an array.
void tryToConst()
Try if the function gives a constant result.
virtual void getAggrNodes(std::vector< TableExprNodeRep * > &aggr)
Get the nodes representing an aggregate function.
NodeDataType argDataType() const
Definition: ExprFuncNode.h:402
const std::vector< TENShPtr > & operands() const
Some functions to be used by TableExprNodeFuncArray.
Definition: ExprFuncNode.h:396
FunctionType funcType() const
Definition: ExprFuncNode.h:400
std::vector< TENShPtr > & rwOperands()
Definition: ExprFuncNode.h:398
NodeDataType
Define the data types of a node.
Definition: ExprNodeRep.h:161
const IPosition & shape() const
Get the fixed shape (same for all rows).
Definition: ExprNodeRep.h:745
Int ndim() const
Get the fixed dimensionality (same for all rows).
Definition: ExprNodeRep.h:741
ValueType
Define the value types.
Definition: ExprNodeRep.h:176
Class to hold multiple table expression nodes.
Definition: ExprNodeSet.h:311
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43