ESYS13  Revision_
Public Member Functions | Private Types | Private Member Functions | Private Attributes
escript::DataLazy Class Reference

Wraps an expression tree of other DataObjects. The data will be evaluated when required. More...

#include <DataLazy.h>

Inheritance diagram for escript::DataLazy:
escript::DataAbstract

List of all members.

Public Member Functions

 DataLazy (DataAbstract_ptr p)
 Create an IDENTITY DataLazy for the given DataAbstract.
 DataLazy (DataAbstract_ptr left, ES_optype op)
 Produce a DataLazy for a unary operation.
 DataLazy (DataAbstract_ptr left, ES_optype op, double tol)
 Produce a DataLazy for a unary operation.
 DataLazy (DataAbstract_ptr left, ES_optype op, int axis_offset)
 Produce a DataLazy for a unary operation which requires a parameter.
 DataLazy (DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op)
 Produce a DataLazy for a binary operation.
 DataLazy (DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op, int axis_offset, int transpose)
 Produce a DataLazy for a binary operation with additional paramters.
 DataLazy (DataAbstract_ptr left, ES_optype op, const int axis0, const int axis1)
 Produce a DataLazy for a unary operation which requires two integer parameters.
 DataLazy (DataAbstract_ptr mask, DataAbstract_ptr left, DataAbstract_ptr right)
 Produce a DataLazy for a unary operation which requires two integer parameters.
 ~DataLazy ()
DataReady_ptr resolve ()
 Evaluate the lazy expression.
std::string toString () const
 Write the data as a string.
DataAbstractdeepCopy ()
 Return a deep copy of the current object.
ValueType::size_type getLength () const
 This method throws an exception. It does not really make sense to ask this question of lazy data.
DataAbstractgetSlice (const DataTypes::RegionType &region) const
 Return the given slice from this object.
DataTypes::ValueType::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 container holding the point data.
DataTypes::ValueType::size_type getPointOffset (int sampleNo, int dataPointNo)
size_t getMaxSampleSize () const
const ValueTyperesolveSample (int sampleNo, size_t &roffset)
 Compute the value of the expression for the given sample.
bool actsExpanded () const
 if resolve() was called would it produce expanded data.
virtual void setToZero ()
 Produces an IDENTITY DataLazy containing zero. The result will have the same shape and functionspace as before.
void resolveGroupWorker (std::vector< DataLazy * > &dats)

Private Types

typedef DataAbstract parent
typedef DataTypes::ValueType ValueType
typedef DataTypes::ShapeType ShapeType

Private Member Functions

void LazyNodeSetup ()
const DataTypes::ValueTyperesolveNodeUnary (int tid, int sampleNo, size_t &roffset)
const DataTypes::ValueTyperesolveNodeReduction (int tid, int sampleNo, size_t &roffset)
const DataTypes::ValueTyperesolveNodeSample (int tid, int sampleNo, size_t &roffset)
const DataTypes::ValueTyperesolveNodeBinary (int tid, int sampleNo, size_t &roffset)
const DataTypes::ValueTyperesolveNodeNP1OUT (int tid, int sampleNo, size_t &roffset)
const DataTypes::ValueTyperesolveNodeNP1OUT_P (int tid, int sampleNo, size_t &roffset)
const DataTypes::ValueTyperesolveNodeTProd (int tid, int sampleNo, size_t &roffset)
const DataTypes::ValueTyperesolveNodeNP1OUT_2P (int tid, int sampleNo, size_t &roffset)
const DataTypes::ValueTyperesolveNodeCondEval (int tid, int sampleNo, size_t &roffset)
void intoString (std::ostringstream &oss) const
void intoTreeString (std::ostringstream &oss, std::string indent) const
void collapse ()
 Converts the DataLazy into an IDENTITY storing the value of the expression. This method uses the original methods on the Data class to evaluate the expressions. For this reason, it should not be used on DataExpanded instances. (To do so would defeat the purpose of using DataLazy in the first place).
DataReady_ptr collapseToReady ()
 Evaluates the expression using methods on Data. This does the work for the collapse method. For reasons of efficiency do not call this method on DataExpanded nodes.
void resolveToIdentity ()
 resolve the expression can store it in the current node The current node will be converted to an identity node.
void makeIdentity (const DataReady_ptr &p)
 helper method for resolveToIdentity and the identity constructor
DataReady_ptr resolveNodeWorker ()
 resolve to a ReadyData object using storage at nodes

Private Attributes

DataReady_ptr m_id
DataLazy_ptr m_left
DataLazy_ptr m_right
DataLazy_ptr m_mask
ES_optype m_op
size_t m_samplesize
char m_readytype
int m_axis_offset
int m_transpose
int m_SL
int m_SM
int m_SR
double m_tol
size_t m_children
size_t m_height
int * m_sampleids
DataVector m_samples

Detailed Description

Wraps an expression tree of other DataObjects. The data will be evaluated when required.

NOTE: This class assumes that the Data being pointed at are immutable.


Member Typedef Documentation

Reimplemented from escript::DataAbstract.

Reimplemented from escript::DataAbstract.


Constructor & Destructor Documentation

Create an IDENTITY DataLazy for the given DataAbstract.

Parameters:
pDataAbstract to be wrapped.
Exceptions:
DataExceptionif p is lazy data or it is not constant, tagged or expanded.

References LAZYDEBUG, m_id, m_samplesize, and makeIdentity().

Referenced by DataLazy(), and deepCopy().

Produce a DataLazy for a unary operation.

Parameters:
leftDataAbstract to be operated on.
opunary operation to perform.
Exceptions:
DataExceptionif op is not a unary operation or if p cannot be converted to a DataLazy. Note that IDENTITY is not considered a unary operation.

References DataLazy(), escript::DataAbstract::getNoValues(), escript::DataAbstract::getNumDPPSample(), LazyNodeSetup(), m_children, m_height, m_left, m_readytype, m_samplesize, and SIZELIMIT.

escript::DataLazy::DataLazy ( DataAbstract_ptr  left,
ES_optype  op,
double  tol 
)

Produce a DataLazy for a unary operation.

Parameters:
leftDataAbstract to be operated on.
opunary operation to perform.
toltolerance for operation
Exceptions:
DataExceptionif op is not a unary operation or if p cannot be converted to a DataLazy. Note that IDENTITY is not considered a unary operation.

References DataLazy(), escript::DataAbstract::getNoValues(), escript::DataAbstract::getNumDPPSample(), LAZYDEBUG, LazyNodeSetup(), m_children, m_height, m_left, m_readytype, m_samplesize, and SIZELIMIT.

escript::DataLazy::DataLazy ( DataAbstract_ptr  left,
ES_optype  op,
int  axis_offset 
)

Produce a DataLazy for a unary operation which requires a parameter.

Parameters:
leftDataAbstract to be operated on.
opunary operation to perform.
axis_offsetthe parameter for the operation
Exceptions:
DataExceptionif op is not a unary operation or if p cannot be converted to a DataLazy. Note that IDENTITY is not considered a unary operation.

References DataLazy(), escript::DataAbstract::getNoValues(), escript::DataAbstract::getNumDPPSample(), LAZYDEBUG, LazyNodeSetup(), m_children, m_height, m_left, m_readytype, m_samplesize, and SIZELIMIT.

Produce a DataLazy for a binary operation.

Parameters:
leftleft operand
rightright operand
opunary operation to perform.
Exceptions:
DataExceptionif op is not a binary operation or if left or right cannot be converted to a DataLazy.

References escript::Data::borrowDataPtr(), DataLazy(), escript::DataAbstract::getFunctionSpace(), escript::DataAbstract::getNoValues(), escript::DataAbstract::getNumDPPSample(), LAZYDEBUG, LazyNodeSetup(), m_children, m_height, m_left, m_readytype, m_right, m_samplesize, and SIZELIMIT.

escript::DataLazy::DataLazy ( DataAbstract_ptr  left,
DataAbstract_ptr  right,
ES_optype  op,
int  axis_offset,
int  transpose 
)

Produce a DataLazy for a binary operation with additional paramters.

Parameters:
leftleft operand
rightright operand
opunary operation to perform.
axis_offset
transpose
Exceptions:
DataExceptionif op is not a binary operation requiring parameters or if left or right cannot be converted to a DataLazy.

References escript::Data::borrowDataPtr(), DataLazy(), escript::DataAbstract::getFunctionSpace(), escript::DataAbstract::getNoValues(), escript::DataAbstract::getNumDPPSample(), LAZYDEBUG, LazyNodeSetup(), m_children, m_height, m_left, m_readytype, m_right, m_samplesize, and SIZELIMIT.

escript::DataLazy::DataLazy ( DataAbstract_ptr  left,
ES_optype  op,
const int  axis0,
const int  axis1 
)

Produce a DataLazy for a unary operation which requires two integer parameters.

Parameters:
leftDataAbstract to be operated on.
opunary operation to perform.
axis0the first parameter for the operation
axis1the second parameter for the operation
Exceptions:
DataExceptionif op is not a unary operation or if p cannot be converted to a DataLazy. Note that IDENTITY is not considered a unary operation.

References DataLazy(), escript::DataAbstract::getNoValues(), escript::DataAbstract::getNumDPPSample(), LAZYDEBUG, LazyNodeSetup(), m_children, m_height, m_left, m_readytype, m_samplesize, and SIZELIMIT.

Produce a DataLazy for a unary operation which requires two integer parameters.

Parameters:
maskscalar mask to select values.
leftDataAbstract to use for true mask.
rightDataAbstract to use for false mask.

References DataLazy(), escript::DataAbstract::getNoValues(), escript::DataAbstract::getNumDPPSample(), LAZYDEBUG, LazyNodeSetup(), m_children, m_height, m_left, m_mask, m_readytype, m_right, m_samplesize, and SIZELIMIT.

References m_sampleids.


Member Function Documentation

bool escript::DataLazy::actsExpanded ( ) const [virtual]

if resolve() was called would it produce expanded data.

Reimplemented from escript::DataAbstract.

References m_readytype.

void escript::DataLazy::collapse ( ) [private]

Converts the DataLazy into an IDENTITY storing the value of the expression. This method uses the original methods on the Data class to evaluate the expressions. For this reason, it should not be used on DataExpanded instances. (To do so would defeat the purpose of using DataLazy in the first place).

References collapseToReady(), escript::IDENTITY, m_id, m_op, and m_readytype.

Referenced by getPointOffset(), resolveNodeSample(), and resolveNodeWorker().

Evaluates the expression using methods on Data. This does the work for the collapse method. For reasons of efficiency do not call this method on DataExpanded nodes.

References escript::ABS, escript::Data::abs(), escript::ACOS, escript::Data::acos(), escript::ACOSH, escript::Data::acosh(), escript::ADD, escript::ASIN, escript::Data::asin(), escript::ASINH, escript::Data::asinh(), escript::ATAN, escript::Data::atan(), escript::ATANH, escript::Data::atanh(), escript::Data::borrowReadyPtr(), escript::C_GeneralTensorProduct(), escript::COS, escript::Data::cos(), escript::COSH, escript::Data::cosh(), escript::DIV, escript::ERF, escript::Data::erf(), escript::EXP, escript::Data::exp(), escript::EZ, escript::GEZ, escript::GZ, escript::IDENTITY, escript::LEZ, escript::LOG, escript::Data::log(), escript::LOG10, escript::Data::log10(), escript::LZ, m_axis_offset, m_id, m_left, m_op, m_readytype, m_right, m_tol, m_transpose, escript::MAXVAL, escript::MINVAL, escript::Data::minval(), escript::MUL, escript::NEG, escript::Data::neg(), escript::NEZ, escript::Data::nonsymmetric(), escript::NSYM, escript::Data::oneOver(), escript::opToString(), escript::POS, escript::PROD, escript::RECIP, escript::SIGN, escript::Data::sign(), escript::SIN, escript::Data::sin(), escript::SINH, escript::Data::sinh(), escript::SQRT, escript::Data::sqrt(), escript::SUB, escript::SWAP, escript::Data::swapaxes(), escript::SYM, escript::Data::symmetric(), escript::TAN, escript::Data::tan(), escript::TANH, escript::Data::tanh(), escript::TRACE, escript::Data::trace(), escript::TRANS, escript::Data::transpose(), escript::Data::whereNegative(), escript::Data::whereNonNegative(), escript::Data::whereNonPositive(), escript::Data::whereNonZero(), escript::Data::wherePositive(), and escript::Data::whereZero().

Referenced by collapse().

Return a deep copy of the current object.

Implements escript::DataAbstract.

References DataLazy(), m_axis_offset, m_id, m_left, m_op, m_right, m_tol, m_transpose, and escript::opToString().

This method throws an exception. It does not really make sense to ask this question of lazy data.

Implements escript::DataAbstract.

Returns:
the largest samplesize required to evaluate the expression.
DataTypes::ValueType::size_type escript::DataLazy::getPointOffset ( int  sampleNo,
int  dataPointNo 
) const [virtual]

Return the offset for the given sample. This returns the offset for the given point into the container holding the point data.

Parameters:
sampleNo- Input - sample number.
dataPointNo- Input - data point number.

Implements escript::DataAbstract.

References escript::IDENTITY, m_id, m_left, m_op, m_readytype, and m_right.

DataTypes::ValueType::size_type escript::DataLazy::getPointOffset ( int  sampleNo,
int  dataPointNo 
) [virtual]
DataAbstract * escript::DataLazy::getSlice ( const DataTypes::RegionType region) const [virtual]

Return the given slice from this object.

NB: The caller is responsible for managing the object created.

Implements escript::DataAbstract.

void escript::DataLazy::intoString ( std::ostringstream &  oss) const [private]

Does the work for toString.

References m_axis_offset, m_id, m_left, m_mask, m_op, m_right, m_transpose, and escript::opToString().

Referenced by toString().

void escript::DataLazy::intoTreeString ( std::ostringstream &  oss,
std::string  indent 
) const [private]
Warning:
internal use only!!

References m_axis_offset, m_id, m_left, m_op, escript::DataAbstract::m_rank, m_right, m_samplesize, m_transpose, and escript::opToString().

Referenced by toString().

Allocates sample storage at each node

References omp_get_max_threads.

Referenced by DataLazy().

void escript::DataLazy::makeIdentity ( const DataReady_ptr p) [private]

helper method for resolveToIdentity and the identity constructor

References escript::IDENTITY, m_axis_offset, m_children, m_height, m_id, m_left, m_op, m_readytype, m_right, m_samplesize, m_SL, m_SM, m_SR, and m_transpose.

Referenced by DataLazy(), and resolveToIdentity().

Evaluate the lazy expression.

Returns:
A DataReady with the value of the lazy expresion.

Implements escript::DataAbstract.

References m_id, and resolveToIdentity().

void escript::DataLazy::resolveGroupWorker ( std::vector< DataLazy * > &  dats)
const DataTypes::ValueType * escript::DataLazy::resolveNodeBinary ( int  tid,
int  sampleNo,
size_t &  roffset 
) [private]
const DataTypes::ValueType * escript::DataLazy::resolveNodeCondEval ( int  tid,
int  sampleNo,
size_t &  roffset 
) [private]
const DataTypes::ValueType * escript::DataLazy::resolveNodeNP1OUT ( int  tid,
int  sampleNo,
size_t &  roffset 
) [private]
const DataTypes::ValueType * escript::DataLazy::resolveNodeNP1OUT_2P ( int  tid,
int  sampleNo,
size_t &  roffset 
) [private]
const DataTypes::ValueType * escript::DataLazy::resolveNodeNP1OUT_P ( int  tid,
int  sampleNo,
size_t &  roffset 
) [private]
const DataTypes::ValueType * escript::DataLazy::resolveNodeReduction ( int  tid,
int  sampleNo,
size_t &  roffset 
) [private]
const DataTypes::ValueType * escript::DataLazy::resolveNodeSample ( int  tid,
int  sampleNo,
size_t &  roffset 
) [private]
const DataTypes::ValueType * escript::DataLazy::resolveNodeTProd ( int  tid,
int  sampleNo,
size_t &  roffset 
) [private]
const DataTypes::ValueType * escript::DataLazy::resolveNodeUnary ( int  tid,
int  sampleNo,
size_t &  roffset 
) [private]
const DataTypes::ValueType * escript::DataLazy::resolveSample ( int  sampleNo,
size_t &  roffset 
)

Compute the value of the expression for the given sample.

Returns:
Vector which stores the value of the subexpression for the given sample.
Parameters:
sampleNoSample number to evaluate.
roffset(output parameter) the offset in the return vector where the result begins.

The return value will be an existing vector so do not deallocate it.

References omp_get_thread_num, and resolveNodeSample().

Referenced by escript::Data::getSampleDataRO(), and escript::Data::lazyAlgWorker().

resolve the expression can store it in the current node The current node will be converted to an identity node.

References escript::IDENTITY, m_op, makeIdentity(), and resolveNodeWorker().

Referenced by resolve().

void escript::DataLazy::setToZero ( ) [virtual]

Produces an IDENTITY DataLazy containing zero. The result will have the same shape and functionspace as before.

Reimplemented from escript::DataAbstract.

std::string escript::DataLazy::toString ( ) const [virtual]

Member Data Documentation

Referenced by DataLazy(), and makeIdentity().

size_t escript::DataLazy::m_height [private]

Referenced by DataLazy(), makeIdentity(), and toString().

Referenced by resolveNodeSample(), and ~DataLazy().

int escript::DataLazy::m_SL [private]

Referenced by makeIdentity(), and resolveNodeTProd().

int escript::DataLazy::m_SM [private]

Referenced by makeIdentity(), and resolveNodeTProd().

int escript::DataLazy::m_SR [private]

Referenced by makeIdentity(), and resolveNodeTProd().

double escript::DataLazy::m_tol [private]

The documentation for this class was generated from the following files: