/[escript]/branches/schroedinger/escript/src/DataLazy.cpp
ViewVC logotype

Contents of /branches/schroedinger/escript/src/DataLazy.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1865 - (show annotations)
Thu Oct 9 03:53:57 2008 UTC (10 years, 11 months ago) by jfenwick
File size: 3525 byte(s)
Branch commit
Added some missing files.

In python can ask a data object if it-  isReady(), isConstant(), 
isLazy().



1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #include "DataLazy.h"
16 #ifdef USE_NETCDF
17 #include <netcdfcpp.h>
18 #endif
19 #ifdef PASO_MPI
20 #include <mpi.h>
21 #endif
22 #include "FunctionSpace.h"
23 #include "DataTypes.h"
24
25 using namespace std;
26
27 namespace escript
28 {
29
30 const std::string&
31 opToString(ES_optype op);
32
33 namespace
34 {
35
36 // return the FunctionSpace of the result of "left op right"
37 FunctionSpace
38 resultFS(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op)
39 {
40 // perhaps this should call interpolate and throw or something?
41 // maybe we need an interpolate node -
42 // that way, if interpolate is required in any other op we can just throw a
43 // programming error exception.
44 return left->getFunctionSpace();
45 }
46
47 // return the shape of the result of "left op right"
48 DataTypes::ShapeType
49 resultShape(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op)
50 {
51 return DataTypes::scalarShape;
52 }
53
54 size_t
55 resultLength(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op)
56 {
57 switch(op)
58 {
59 case IDENTITY: return left->getLength();
60 default:
61 throw DataException("Programmer Error - attempt to getLength() for operator "+opToString(op)+".");
62
63 }
64 }
65
66 string ES_opstrings[]={"UNKNOWN","IDENTITY"};
67 int ES_opcount=2;
68
69 } // end anonymous namespace
70
71
72 const std::string&
73 opToString(ES_optype op)
74 {
75 if (op<0 || op>=ES_opcount)
76 {
77 op=UNKNOWNOP;
78 }
79 return ES_opstrings[op];
80 }
81
82
83 DataLazy::DataLazy(DataAbstract_ptr p)
84 : parent(p->getFunctionSpace(),p->getShape()),
85 m_left(p),
86 m_op(IDENTITY)
87 {
88 length=resultLength(m_left,m_right,m_op);
89 }
90
91 DataLazy::DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op)
92 : parent(resultFS(left,right,op), resultShape(left,right,op)),
93 m_left(left),
94 m_right(right),
95 m_op(op)
96 {
97 length=resultLength(m_left,m_right,m_op);
98 }
99
100
101 DataLazy::~DataLazy()
102 {
103 }
104
105 // If resolving records a pointer to the resolved Data we may need to rethink the const on this method
106 DataReady_ptr
107 DataLazy::resolve()
108 {
109 if (m_op==IDENTITY)
110 {
111 return m_left->resolve();
112 }
113 else
114 {
115 throw DataException("Programmer error - do not know how to resolve operator "+opToString(m_op)+".");
116 }
117 }
118
119 std::string
120 DataLazy::toString() const
121 {
122 return "Lazy evaluation object. No details available.";
123 }
124
125 // Note that in this case, deepCopy does not make copies of the leaves.
126 // Hopefully copy on write (or whatever we end up using) will take care of this.
127 DataAbstract*
128 DataLazy::deepCopy()
129 {
130 if (m_op==IDENTITY)
131 {
132 return new DataLazy(m_left); // we don't need to copy the child here
133 }
134 return new DataLazy(m_left->deepCopy()->getPtr(),m_right->deepCopy()->getPtr(),m_op);
135 }
136
137
138 DataTypes::ValueType::size_type
139 DataLazy::getLength() const
140 {
141 return length;
142 }
143
144
145 DataAbstract*
146 DataLazy::getSlice(const DataTypes::RegionType& region) const
147 {
148 // this seems like a really good one to include I just haven't added it yet
149 throw DataException("getSlice - not implemented for Lazy objects - yet.");
150 }
151
152 DataTypes::ValueType::size_type
153 DataLazy::getPointOffset(int sampleNo,
154 int dataPointNo) const
155 {
156 throw DataException("getPointOffset - not implemented for Lazy objects - yet.");
157 }
158
159 } // end namespace

  ViewVC Help
Powered by ViewVC 1.1.26