/[escript]/trunk/escript/src/DataLazy.h
ViewVC logotype

Diff of /trunk/escript/src/DataLazy.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2147 by jfenwick, Wed Dec 10 04:41:26 2008 UTC revision 2521 by jfenwick, Tue Jul 7 00:08:58 2009 UTC
# Line 22  Line 22 
22  #include <functional>  #include <functional>
23    
24  #include "LocalOps.h"       // for tensor_binary_op  #include "LocalOps.h"       // for tensor_binary_op
25    #include "BufferGroup.h"
26    #include "DataVector.h"     // for ElementType
27    
28    
29    #define LAZY_NODE_STORAGE
30    
31  namespace escript {  namespace escript {
32    
# Line 67  enum ES_optype Line 72  enum ES_optype
72      NSYM=SYM+1,      NSYM=SYM+1,
73      PROD=NSYM+1,      PROD=NSYM+1,
74      TRANS=PROD+1,      TRANS=PROD+1,
75      TRACE=TRANS+1      TRACE=TRANS+1,
76        SWAP=TRACE+1
77  };  };
78    
79  ESCRIPT_DLL_API  ESCRIPT_DLL_API
# Line 160  public: Line 166  public:
166    ESCRIPT_DLL_API    ESCRIPT_DLL_API
167    DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op, int axis_offset, int transpose);    DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op, int axis_offset, int transpose);
168    
169      /**
170      \brief Produce a DataLazy for a unary operation which requires two integer parameters.
171      \param left DataAbstract to be operated on.
172      \param op unary operation to perform.
173      \param axis0 the first parameter for the operation
174      \param axis1 the second parameter for the operation
175      \throws DataException if op is not a unary operation or if p cannot be converted to a DataLazy.
176      Note that IDENTITY is not considered a unary operation.
177      */
178      ESCRIPT_DLL_API
179      DataLazy(DataAbstract_ptr left, ES_optype op, const int axis0, const int axis1);
180    
181    ESCRIPT_DLL_API    ESCRIPT_DLL_API
182    ~DataLazy();    ~DataLazy();
183    
# Line 217  public: Line 235  public:
235    size_t    size_t
236    getMaxSampleSize() const;    getMaxSampleSize() const;
237    
238      /**
239        \return the size of the buffer required to evaulate a sample for this object
240      */
241      ESCRIPT_DLL_API
242      size_t
243      getSampleBufferSize() const;
244    
245       /**
246      \brief Compute the value of the expression for the given sample.
247      \return Vector which stores the value of the subexpression for the given sample.
248      \param bg A BufferGroup to store intermediate results.
249      \param sampleNo Sample number to evaluate.
250      \param roffset (output parameter) the offset in the return vector where the result begins.
251    
252      The return value will be an existing vector so do not deallocate it.
253      */
254      ESCRIPT_DLL_API
255      const ValueType*
256      resolveSample(BufferGroup& bg, int sampleNo, size_t& roffset);
257    
258      /**
259      \brief if resolve() was called would it produce expanded data.
260      */
261      ESCRIPT_DLL_API
262      bool
263      actsExpanded() const;
264    
265    /**    /**
266       \brief Produces an IDENTITY DataLazy containing zero.       \brief Produces an IDENTITY DataLazy containing zero.
# Line 237  private: Line 281  private:
281    char m_readytype; // E for expanded, T for tagged, C for constant    char m_readytype; // E for expanded, T for tagged, C for constant
282    
283    int m_axis_offset;    // required extra info for general tensor product    int m_axis_offset;    // required extra info for general tensor product
284    int m_transpose;    int m_transpose;  // offset and transpose are used for swapaxes as well
285    int m_SL, m_SM, m_SR; // computed properties used in general tensor product    int m_SL, m_SM, m_SR; // computed properties used in general tensor product
286    
287    
288    double m_tol;     // required extra info for <>0 and ==0    double m_tol;     // required extra info for <>0 and ==0
289    
290    unsigned int m_maxsamplesize; // largest samplesize required by any node in the expression    size_t m_maxsamplesize;   // largest samplesize required by any node in the expression
291      size_t m_children;
292      size_t m_height;
293    
294    #ifdef LAZY_NODE_STORAGE
295    
296      int* m_sampleids;     // may be NULL
297      DataVector m_samples;  
298    
299    #endif // LAZY_NODE_STORAGE
300    
301    
302    #ifdef LAZY_NODE_STORAGE
303      /**
304      Allocates sample storage at each node
305      */
306      void LazyNodeSetup();
307    
308    
309      const DataTypes::ValueType*
310      resolveNodeUnary(int tid, int sampleNo, size_t& roffset);
311    
312      const DataTypes::ValueType*
313      resolveNodeSample(int tid, int sampleNo, size_t& roffset);
314    
315      const DataTypes::ValueType*
316      resolveNodeBinary(int tid, int sampleNo, size_t& roffset);
317    
318      const DataTypes::ValueType*
319      resolveNodeNP1OUT(int tid, int sampleNo, size_t& roffset);
320    
321      const DataTypes::ValueType*
322      resolveNodeNP1OUT_P(int tid, int sampleNo, size_t& roffset);
323    
324      const DataTypes::ValueType*
325      resolveNodeTProd(int tid, int sampleNo, size_t& roffset);
326    
327      const DataTypes::ValueType*
328      resolveNodeNP1OUT_2P(int tid, int sampleNo, size_t& roffset);
329      
330    #endif
331    
332    /**    /**
333    Does the work for toString.    Does the work for toString.
# Line 270  private: Line 354  private:
354    collapseToReady();    collapseToReady();
355    
356    /**    /**
357    \brief Compute the value of the expression for the given sample.    \brief resolve the expression can store it in the current node
358      The current node will be converted to an identity node.
359      */
360      void
361      resolveToIdentity();
362    
363      /**
364      \brief helper method for resolveToIdentity and the identity constructor
365      */
366      void
367      makeIdentity(const DataReady_ptr& p);
368    
369      /**
370      \brief resolve to a ReadyData object using a vector buffer.
371      */
372      DataReady_ptr
373      resolveVectorWorker();
374    
375    #ifdef LAZY_NODE_STORAGE
376      /**
377      \brief resolve to a ReadyData object using storage at nodes
378      */
379      DataReady_ptr
380      resolveNodeWorker();
381    #endif
382    
383      /**
384      \brief Compute the value of the expression for the given sample - using the vector buffer approach.
385    \return Vector which stores the value of the subexpression for the given sample.    \return Vector which stores the value of the subexpression for the given sample.
386    \param v A vector to store intermediate results.    \param v A vector to store intermediate results.
387    \param offset Index in v to begin storing results.    \param offset Index in v to begin storing results.
# Line 279  private: Line 390  private:
390    
391    The return value will be an existing vector so do not deallocate it.    The return value will be an existing vector so do not deallocate it.
392    */    */
393      ESCRIPT_DLL_API
394    const ValueType*    const ValueType*
395    resolveSample(ValueType& v,  size_t offset ,int sampleNo, size_t& roffset);    resolveVectorSample(ValueType& v,  size_t offset, int sampleNo, size_t& roffset);
396    
397    
398    /**    /**
399    \brief Compute the value of the expression (unary operation) for the given sample.    \brief Compute the value of the expression (unary operation) for the given sample.
# Line 332  private: Line 445  private:
445  DataTypes::ValueType*  DataTypes::ValueType*
446  resolveNP1OUT_P(ValueType& v, size_t offset, int sampleNo, size_t& roffset) const;  resolveNP1OUT_P(ValueType& v, size_t offset, int sampleNo, size_t& roffset) const;
447    
448    /**
449      \brief Compute the value of the expression (unary operation with int params) for the given sample.
450      \return Vector which stores the value of the subexpression for the given sample.
451      \param v A vector to store intermediate results.
452      \param offset Index in v to begin storing results.
453      \param sampleNo Sample number to evaluate.
454      \param roffset (output parameter) the offset in the return vector where the result begins.
455    
456      The return value will be an existing vector so do not deallocate it.
457      If the result is stored in v it should be stored at the offset given.
458      Everything from offset to the end of v should be considered available for this method to use.
459    */
460    DataTypes::ValueType*
461    resolveNP1OUT_2P(ValueType& v, size_t offset, int sampleNo, size_t& roffset) const;
462    
463    
464    /**    /**
465    \brief Compute the value of the expression (binary operation) for the given sample.    \brief Compute the value of the expression (binary operation) for the given sample.

Legend:
Removed from v.2147  
changed lines
  Added in v.2521

  ViewVC Help
Powered by ViewVC 1.1.26