DataLazy.h
Go to the documentation of this file.
/*****************************************************************************
*
* Copyright (c) 2003-2020 by The University of Queensland
* http://www.uq.edu.au
*
* Primary Business: Queensland, Australia
* Licensed under the Apache License, version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Development until 2012 by Earth Systems Science Computational Center (ESSCC)
* Development 2012-2013 by School of Earth Sciences
* Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
* Development from 2019 by School of Earth and Environmental Sciences
**
*****************************************************************************/
#ifndef __ESCRIPT_DATALAZY_H__
#define __ESCRIPT_DATALAZY_H__
#include "system_dep.h"
#include "DataAbstract.h"
#include "ArrayOps.h" // for tensor_binary_op
#include "DataVector.h" // for ElementType
#include "ES_optype.h"
#include <string>
//#define LAZY_NODE_STORAGE
namespace escript {
class DataLazy;
typedef POINTER_WRAPPER_CLASS(DataLazy) DataLazy_ptr;
typedef POINTER_WRAPPER_CLASS(const DataLazy) const_DataLazy_ptr;
class DataLazy : public DataAbstract
{
typedef DataAbstract parent;
typedef DataTypes::ShapeType ShapeType;
public:
ESCRIPT_DLL_API
DataLazy(DataAbstract_ptr p);
ESCRIPT_DLL_API
DataLazy(DataAbstract_ptr left, ES_optype op);
ESCRIPT_DLL_API
DataLazy(DataAbstract_ptr left, ES_optype op, double tol);
ESCRIPT_DLL_API
DataLazy(DataAbstract_ptr left, ES_optype op, int axis_offset);
ESCRIPT_DLL_API
DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op);
ESCRIPT_DLL_API
DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op, int axis_offset, int transpose);
ESCRIPT_DLL_API
DataLazy(DataAbstract_ptr left, ES_optype op, const int axis0, const int axis1);
ESCRIPT_DLL_API
DataLazy(DataAbstract_ptr mask, DataAbstract_ptr left, DataAbstract_ptr right/*, double tol*/);
ESCRIPT_DLL_API
~DataLazy();
ESCRIPT_DLL_API
DataReady_ptr
resolve();
ESCRIPT_DLL_API
std::string
toString() const;
ESCRIPT_DLL_API
DataAbstract*
deepCopy() const;
ESCRIPT_DLL_API
DataAbstract*
zeroedCopy() const;
ESCRIPT_DLL_API
DataTypes::RealVectorType::size_type
getLength() const;
ESCRIPT_DLL_API
DataAbstract*
getSlice(const DataTypes::RegionType& region) const;
DataTypes::RealVectorType::size_type
getPointOffset(int sampleNo,
int dataPointNo) const;
DataTypes::RealVectorType::size_type
getPointOffset(int sampleNo,
int dataPointNo);
ESCRIPT_DLL_API
size_t
getMaxSampleSize() const;
ESCRIPT_DLL_API
const DataTypes::RealVectorType*
resolveSample(int sampleNo, size_t& roffset) const;
ESCRIPT_DLL_API
const DataTypes::CplxVectorType*
resolveTypedSample(int sampleNo, size_t& roffset, DataTypes::cplx_t dummy) const;
ESCRIPT_DLL_API
const DataTypes::RealVectorType*
resolveTypedSample(int sampleNo, size_t& roffset, DataTypes::real_t dummy) const;
ESCRIPT_DLL_API
bool
actsExpanded() const;
ESCRIPT_DLL_API
virtual void
setToZero();
ESCRIPT_DLL_API
void
resolveGroupWorker(std::vector<DataLazy*>& dats);
private:
int* m_sampleids; // may be NULL
mutable DataTypes::RealVectorType m_samples_r;
mutable DataTypes::CplxVectorType m_samples_c;
mutable DataReady_ptr m_id; // For IDENTITY nodes, stores a wrapped value.
mutable DataLazy_ptr m_left, m_right, m_mask; // operands for operation.
mutable ES_optype m_op; // operation to perform.
mutable ES_opgroup m_opgroup; // type of operation to perform
size_t m_samplesize; // number of values required to store a sample
char m_readytype; // E for expanded, T for tagged, C for constant
int m_axis_offset; // required extra info for general tensor product
int m_transpose; // offset and transpose are used for swapaxes as well
int m_SL, m_SM, m_SR; // computed properties used in general tensor product
double m_tol; // required extra info for <>0 and ==0
mutable size_t m_children;
mutable size_t m_height;
void LazyNodeSetup();
const DataTypes::RealVectorType*
resolveNodeUnary(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::CplxVectorType*
resolveNodeUnaryCplx(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::RealVectorType*
resolveNodeReduction(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::CplxVectorType*
resolveNodeReductionCplx(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::RealVectorType*
resolveNodeSample(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::CplxVectorType*
resolveNodeSampleCplx(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::RealVectorType*
resolveNodeBinary(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::CplxVectorType*
resolveNodeBinaryCplx(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::RealVectorType*
resolveNodeNP1OUT(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::CplxVectorType*
resolveNodeNP1OUTCplx(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::RealVectorType*
resolveNodeNP1OUT_P(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::CplxVectorType*
resolveNodeNP1OUT_PCplx(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::RealVectorType*
resolveNodeTProd(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::CplxVectorType*
resolveNodeTProdCplx(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::RealVectorType*
resolveNodeNP1OUT_2P(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::CplxVectorType*
resolveNodeNP1OUT_2PCplx(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::RealVectorType*
resolveNodeCondEval(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::CplxVectorType*
resolveNodeCondEvalCplx(int tid, int sampleNo, size_t& roffset) const;
const DataTypes::CplxVectorType*
resolveNodeUnary_C(int tid, int sampleNo, size_t& roffset) const;
void
intoString(std::ostringstream& oss) const;
void
intoTreeString(std::ostringstream& oss,std::string indent) const;
void
collapse() const; // converts the node into an IDENTITY node
DataReady_ptr
collapseToReady() const;
void
resolveToIdentity();
void
makeIdentity(const DataReady_ptr& p);
DataReady_ptr
resolveNodeWorker();
DataReady_ptr
resolveNodeWorkerCplx();
};
// If an expression is already complex, return the same expression.
// Otherwise, return the old expression with a promote operation
// above it
DataLazy_ptr makePromote(DataLazy_ptr p);
}
#endif // __ESCRIPT_DATALAZY_H__
ArrayOps.h
DataAbstract.h
DataVector.h
ES_optype.h
POINTER_WRAPPER_CLASS
#define POINTER_WRAPPER_CLASS(x)
Definition: Pointers.h:33
escript::DataAbstract
Definition: DataAbstract.h:63
escript::DataAbstract::DataLazy
friend class DataLazy
Definition: DataAbstract.h:550
escript::DataAbstract::transpose
virtual void transpose(DataAbstract *ev, int axis_offset)
Transpose each data point of this Data object around the given axis.
Definition: DataAbstract.cpp:246
escript::DataLazy
Wraps an expression tree of other DataObjects. The data will be evaluated when required.
Definition: DataLazy.h:49
escript::DataLazy::collapseToReady
DataReady_ptr collapseToReady() const
Evaluates the expression using methods on Data. This does the work for the collapse method....
Definition: DataLazy.cpp:931
escript::DataLazy::makeIdentity
void makeIdentity(const DataReady_ptr &p)
helper method for resolveToIdentity and the identity constructor
Definition: DataLazy.cpp:2434
escript::DataLazy::resolveNodeBinary
const DataTypes::RealVectorType * resolveNodeBinary(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1774
escript::DataLazy::zeroedCopy
DataAbstract * zeroedCopy() const
Return an object with the same type, domain (and tags if appropriate) as this, but all values are zer...
Definition: DataLazy.cpp:2903
escript::DataLazy::resolveNodeWorkerCplx
DataReady_ptr resolveNodeWorkerCplx()
Definition: DataLazy.cpp:2602
escript::DataLazy::m_right
DataLazy_ptr m_right
Definition: DataLazy.h:240
escript::DataLazy::deepCopy
DataAbstract * deepCopy() const
Return a deep copy of the current object.
Definition: DataLazy.cpp:2879
escript::DataLazy::~DataLazy
~DataLazy()
Definition: DataLazy.cpp:919
escript::DataLazy::resolveToIdentity
void resolveToIdentity()
resolve the expression can store it in the current node The current node will be converted to an iden...
Definition: DataLazy.cpp:2418
escript::DataLazy::m_readytype
char m_readytype
Definition: DataLazy.h:246
escript::DataLazy::resolveNodeCondEvalCplx
const DataTypes::CplxVectorType * resolveNodeCondEvalCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1729
escript::DataLazy::resolveNodeReductionCplx
const DataTypes::CplxVectorType * resolveNodeReductionCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1372
escript::DataLazy::actsExpanded
bool actsExpanded() const
if resolve() was called would it produce expanded data.
Definition: DataLazy.cpp:3001
escript::DataLazy::ShapeType
DataTypes::ShapeType ShapeType
Definition: DataLazy.h:52
escript::DataLazy::intoTreeString
void intoTreeString(std::ostringstream &oss, std::string indent) const
Definition: DataLazy.cpp:2789
escript::DataLazy::m_left
DataLazy_ptr m_left
Definition: DataLazy.h:240
escript::DataLazy::m_height
size_t m_height
Definition: DataLazy.h:256
escript::DataLazy::resolveNodeNP1OUT_PCplx
const DataTypes::CplxVectorType * resolveNodeNP1OUT_PCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1574
escript::DataLazy::parent
DataAbstract parent
Definition: DataLazy.h:51
escript::DataLazy::m_opgroup
ES_opgroup m_opgroup
Definition: DataLazy.h:242
escript::DataLazy::resolveNodeNP1OUT_2PCplx
const DataTypes::CplxVectorType * resolveNodeNP1OUT_2PCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1658
escript::DataLazy::resolveNodeBinaryCplx
const DataTypes::CplxVectorType * resolveNodeBinaryCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1997
escript::DataLazy::intoString
void intoString(std::ostringstream &oss) const
Definition: DataLazy.cpp:2681
escript::DataLazy::resolveNodeUnaryCplx
const DataTypes::CplxVectorType * resolveNodeUnaryCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1274
escript::DataLazy::resolveNodeSampleCplx
const DataTypes::CplxVectorType * resolveNodeSampleCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1175
escript::DataLazy::resolveTypedSample
const DataTypes::CplxVectorType * resolveTypedSample(int sampleNo, size_t &roffset, DataTypes::cplx_t dummy) const
Definition: DataLazy.cpp:2389
escript::DataLazy::m_mask
DataLazy_ptr m_mask
Definition: DataLazy.h:240
escript::DataLazy::resolveNodeCondEval
const DataTypes::RealVectorType * resolveNodeCondEval(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1694
escript::DataLazy::resolveNodeTProd
const DataTypes::RealVectorType * resolveNodeTProd(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:2224
escript::DataLazy::getLength
DataTypes::RealVectorType::size_type getLength() const
This method throws an exception. It does not really make sense to ask this question of lazy data.
Definition: DataLazy.cpp:2915
escript::DataLazy::m_op
ES_optype m_op
Definition: DataLazy.h:241
escript::DataLazy::resolveGroupWorker
void resolveGroupWorker(std::vector< DataLazy * > &dats)
Definition: DataLazy.cpp:2464
escript::DataLazy::m_tol
double m_tol
Definition: DataLazy.h:253
escript::DataLazy::m_sampleids
int * m_sampleids
Definition: DataLazy.h:235
escript::DataLazy::resolveNodeSample
const DataTypes::RealVectorType * resolveNodeSample(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1119
escript::DataLazy::resolveNodeNP1OUTCplx
const DataTypes::CplxVectorType * resolveNodeNP1OUTCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1466
escript::DataLazy::collapse
void collapse() const
Converts the DataLazy into an IDENTITY storing the value of the expression. This method uses the orig...
Definition: DataLazy.cpp:1100
escript::DataLazy::resolveNodeNP1OUT_P
const DataTypes::RealVectorType * resolveNodeNP1OUT_P(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1527
escript::DataLazy::resolveNodeNP1OUT
const DataTypes::RealVectorType * resolveNodeNP1OUT(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1391
escript::DataLazy::m_transpose
int m_transpose
Definition: DataLazy.h:249
escript::DataLazy::resolveSample
const DataTypes::RealVectorType * resolveSample(int sampleNo, size_t &roffset) const
Compute the value of the expression for the given sample.
Definition: DataLazy.cpp:2336
escript::DataLazy::m_samplesize
size_t m_samplesize
Definition: DataLazy.h:244
escript::DataLazy::setToZero
virtual void setToZero()
Produces an IDENTITY DataLazy containing zero. The result will have the same shape and functionspace ...
Definition: DataLazy.cpp:2986
escript::DataLazy::m_id
DataReady_ptr m_id
Definition: DataLazy.h:239
escript::DataLazy::m_axis_offset
int m_axis_offset
Definition: DataLazy.h:248
escript::DataLazy::resolveNodeTProdCplx
const DataTypes::CplxVectorType * resolveNodeTProdCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:2278
escript::DataLazy::m_SM
int m_SM
Definition: DataLazy.h:250
escript::DataLazy::m_SR
int m_SR
Definition: DataLazy.h:250
escript::DataLazy::resolveNodeNP1OUT_2P
const DataTypes::RealVectorType * resolveNodeNP1OUT_2P(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1621
escript::DataLazy::getMaxSampleSize
size_t getMaxSampleSize() const
escript::DataLazy::LazyNodeSetup
void LazyNodeSetup()
Definition: DataLazy.cpp:408
escript::DataLazy::getSlice
DataAbstract * getSlice(const DataTypes::RegionType &region) const
Return the given slice from this object.
Definition: DataLazy.cpp:2922
escript::DataLazy::m_samples_c
DataTypes::CplxVectorType m_samples_c
Definition: DataLazy.h:237
escript::DataLazy::m_children
size_t m_children
Definition: DataLazy.h:255
escript::DataLazy::toString
std::string toString() const
Write the data as a string.
Definition: DataLazy.cpp:2660
escript::DataLazy::m_SL
int m_SL
Definition: DataLazy.h:250
escript::DataLazy::m_samples_r
DataTypes::RealVectorType m_samples_r
Definition: DataLazy.h:236
escript::DataLazy::getPointOffset
DataTypes::RealVectorType::size_type getPointOffset(int sampleNo, int dataPointNo) const
Return the offset for the given sample. This returns the offset for the given point into the containe...
Definition: DataLazy.cpp:2956
escript::DataLazy::resolveNodeUnary
const DataTypes::RealVectorType * resolveNodeUnary(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1225
escript::DataLazy::resolve
DataReady_ptr resolve()
Evaluate the lazy expression.
Definition: DataLazy.cpp:2455
escript::DataLazy::resolveNodeReduction
const DataTypes::RealVectorType * resolveNodeReduction(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1320
escript::DataLazy::resolveNodeWorker
DataReady_ptr resolveNodeWorker()
resolve to a ReadyData object using storage at nodes
Definition: DataLazy.cpp:2544
escript::DataLazy::resolveNodeUnary_C
const DataTypes::CplxVectorType * resolveNodeUnary_C(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1437
escript::DataTypes::DataVectorAlt< real_t >
escript::DataTypes::DataVectorAlt< real_t >::size_type
DataTypes::vec_size_type size_type
Definition: DataVectorAlt.h:50
ESCRIPT_DLL_API
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:30
escript::DataTypes::cplx_t
std::complex< real_t > cplx_t
complex data type
Definition: DataTypes.h:55
escript::DataTypes::RegionType
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:45
escript::DataTypes::real_t
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:52
escript::DataTypes::ShapeType
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:44
escript
Definition: AbstractContinuousDomain.cpp:23
escript::makePromote
DataLazy_ptr makePromote(DataLazy_ptr p)
Definition: DataLazy.cpp:115
escript::DataAbstract_ptr
boost::shared_ptr< DataAbstract > DataAbstract_ptr
Definition: DataAbstract.h:52
escript::DataLazy_ptr
boost::shared_ptr< DataLazy > DataLazy_ptr
Definition: DataLazy.h:43
escript::ES_optype
ES_optype
Definition: ES_optype.h:30
escript::const_DataLazy_ptr
boost::shared_ptr< const DataLazy > const_DataLazy_ptr
Definition: DataLazy.h:46
escript::ES_opgroup
ES_opgroup
Definition: ES_optype.h:93
escript::DataReady_ptr
boost::shared_ptr< DataReady > DataReady_ptr
Definition: DataAbstract.h:57
system_dep.h