/[escript]/trunk/escript/src/DataAbstract.cpp
ViewVC logotype

Annotation of /trunk/escript/src/DataAbstract.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2271 - (hide annotations)
Mon Feb 16 05:08:29 2009 UTC (10 years, 7 months ago) by jfenwick
File size: 7112 byte(s)
Merging version 2269 to trunk

1 jgs 82
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
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 ksteube 1312
14 ksteube 1811
15 jgs 474 #include "DataAbstract.h"
16     #include "DataException.h"
17 jfenwick 2005 #include "DataLazy.h"
18 jgs 82
19 jfenwick 2271 #include "Data.h" // So we can update the shared status when things change
20    
21 jgs 82 using namespace std;
22    
23     namespace escript {
24    
25 jfenwick 1872 DataAbstract_ptr DataAbstract::getPtr()
26     {
27     if (_internal_weak_this.expired())
28     {
29     return DataAbstract_ptr(this);
30     }
31     else
32     {
33     return shared_from_this();
34     }
35     }
36    
37     const_DataAbstract_ptr DataAbstract::getPtr() const
38     {
39     if (_internal_weak_this.expired())
40     {
41     return const_DataAbstract_ptr(this);
42     }
43     else
44     {
45     return shared_from_this();
46     }
47     }
48    
49 jfenwick 2271
50     // Warning - this method uses .use_count() which the boost doco labels inefficient.
51     // If this method needs to be called in debug contexts, we may need to do some
52     // timing experiments to determine how inefficient and possibly switch over to
53     // invasive pointers which can answer these questions faster
54     bool DataAbstract::checkNoSharing() const
55     {
56    
57     return !m_lazyshared && (m_owners.size()<2);
58    
59     /* if (_internal_weak_this.expired()) // there is no shared_ptr for this object yet
60     {
61     return true;
62     }
63     if (shared_from_this().use_count()==2) // shared_from_this will increase the ref count
64     { // which is the reason .unique is no use.
65     return true;
66     }
67     std::cerr << "-<"<<shared_from_this().use_count() << ">-" << endl;
68     return false;*/
69     }
70    
71 jfenwick 2005 bool
72     DataAbstract::isLazy() const
73     {
74     return (dynamic_cast<const DataLazy*>(this)!=0);
75     }
76 jfenwick 1872
77    
78 jfenwick 2005
79 jfenwick 1803 DataAbstract::DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty):
80 jfenwick 1946 m_noSamples(what.getNumSamples()),
81 jgs 82 m_noDataPointsPerSample(what.getNumDPPSample()),
82 jfenwick 1796 m_functionSpace(what),
83     m_shape(shape),
84 jfenwick 1946 m_novalues(DataTypes::noValues(shape)),
85 jfenwick 2271 m_rank(DataTypes::getRank(shape)),
86     m_lazyshared(false)
87 jfenwick 1946
88 jgs 82 {
89 jfenwick 1803 m_isempty=isDataEmpty;
90 jfenwick 2086 if (m_rank>ESCRIPT_MAX_DATA_RANK)
91     {
92     ostringstream os;
93     os << "Error - Attempt to create a rank " << m_rank
94     << " object. The maximum rank is " << ESCRIPT_MAX_DATA_RANK << ".";
95     throw DataException(os.str());
96     }
97 jgs 82 }
98    
99     DataAbstract::~DataAbstract()
100     {
101     }
102    
103    
104 jgs 119 void
105 jgs 82 DataAbstract::operandCheck(const DataAbstract& right) const
106     {
107     if ((right.getNumDPPSample()!=getNumDPPSample()) ||
108     (right.getNumSamples()!=getNumSamples()) ||
109     (right.getFunctionSpace()!=getFunctionSpace())) {
110     stringstream temp;
111     temp << "Error - Right hand argument sample shape or function space "
112     << "incompatible with left." << endl
113     << "LHS: (" << getNumSamples() << ","
114     << getNumDPPSample() << ") " << getFunctionSpace().toString()
115     << endl
116     << "RHS: (" << right.getNumSamples() << ","
117     << right.getNumDPPSample() << ") "
118     << right.getFunctionSpace().toString();
119     throw DataException(temp.str());
120     }
121    
122     //
123     // Check the shape of the point data, a rank of 0(scalar) is okay
124 jfenwick 2084 if (!((right.getRank()==0) || (getRank()==0) ||
125 jfenwick 1796 (right.getShape()==getShape())))
126 jgs 82 {
127     stringstream temp;
128     temp << "Error - Right hand argument point data shape: "
129 jfenwick 1796 << DataTypes::shapeToString(right.getShape())
130 jgs 82 << " doesn't match left: "
131 jfenwick 1796 << DataTypes::shapeToString(getShape());
132 jgs 82 throw DataException(temp.str());
133     }
134     }
135    
136 gross 950 void
137     DataAbstract::dump(const std::string fileName) const
138     {
139 jfenwick 1803 throw DataException("Error - DataAbstract::dump: not implemented.");
140 gross 950 }
141    
142    
143    
144 jgs 82 DataAbstract::ValueType::value_type*
145     DataAbstract::getSampleDataByTag(int tag)
146     {
147 jgs 110 throw DataException("Error - DataAbstract::getSampleDataByTag: Data type does not have tag values.");
148 jgs 82 }
149    
150 jfenwick 1796
151     void
152 jgs 82 DataAbstract::setTaggedValue(int tagKey,
153 jfenwick 1796 const DataTypes::ShapeType& pointshape,
154     const DataTypes::ValueType& value,
155     int dataOffset)
156 jgs 82 {
157 jgs 110 throw DataException("Error - DataAbstract::setTaggedValue: Data type does not have tag values.");
158 jgs 82 }
159    
160 jfenwick 1796
161 jgs 149 int
162     DataAbstract::getTagNumber(int dpno)
163     {
164     throw DataException("Error - DataAbstract::getTagNumber: Data type cannot be accessed by tag values.");
165     return (0);
166     }
167    
168 jgs 126 void
169 gross 922 DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const double value)
170     {
171     throw DataException("Error - DataAbstract::copying data from double value to a single data point is not supported.");
172     }
173 jfenwick 2271
174    
175 gross 922 void
176 jfenwick 2271 DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value)
177 gross 921 {
178 jfenwick 2271 throw DataException("Error - DataAbstract::copying data from WrappedArray objects to a single data point is not supported.");
179 gross 921 }
180 jgs 126
181 jfenwick 2271
182 gross 576 void
183 ksteube 775 DataAbstract::symmetric(DataAbstract* ev)
184     {
185     throw DataException("Error - DataAbstract::symmetric is not supported.");
186     }
187    
188     void
189     DataAbstract::nonsymmetric(DataAbstract* ev)
190     {
191     throw DataException("Error - DataAbstract::nonsymmetric is not supported.");
192     }
193    
194     void
195 gross 800 DataAbstract::trace(DataAbstract* ev, int axis_offset)
196 ksteube 775 {
197 gross 800 throw DataException("Error - DataAbstract::trace is not supported.");
198 ksteube 775 }
199    
200     void
201 gross 804 DataAbstract::swapaxes(DataAbstract* ev, int axis0, int axis1)
202 gross 800 {
203 gross 804 throw DataException("Error - DataAbstract::component swapaxes is not supported.");
204 gross 800 }
205     void
206 ksteube 775 DataAbstract::transpose(DataAbstract* ev, int axis_offset)
207     {
208     throw DataException("Error - DataAbstract::transpose is not supported.");
209     }
210    
211     void
212 gross 576 DataAbstract::eigenvalues(DataAbstract* ev)
213     {
214     throw DataException("Error - DataAbstract::eigenvalues is not supported.");
215     }
216     void
217     DataAbstract::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
218     {
219     throw DataException("Error - DataAbstract::eigenvalues_and_eigenvectors is not supported.");
220    
221     }
222 gross 1118 void
223     DataAbstract::setToZero()
224     {
225     throw DataException("Error - DataAbstract:: cannot set values to zero.");
226     }
227 gross 576
228 gross 1487 void
229     DataAbstract::reorderByReferenceIDs(int *reference_ids)
230     {
231 jfenwick 1803 throw DataException("Error - DataAbstract:: cannot reorder by reference ids.");
232 gross 1487 }
233 gross 576
234    
235 jfenwick 2271 void DataAbstract::addOwner(Data* d)
236     {
237     for (size_t i=0;i<m_owners.size();++i)
238     {
239     if (m_owners[i]==d)
240     {
241     return;
242     }
243     }
244     m_owners.push_back(d);
245     // cerr << "Adding " << d << " as an owner of " << this << " now O=" << m_owners.size() << endl;
246     if (m_owners.size()==2) // Means it used to be 1 so we need to tell people
247     {
248     for (size_t i=0;i<m_owners.size();++i)
249     {
250     m_owners[i]->updateShareStatus(true);
251     }
252     }
253     }
254 gross 1487
255 jfenwick 2271 void DataAbstract::removeOwner(Data* d)
256     {
257     for (size_t i=0;i<m_owners.size();++i)
258     {
259     if (m_owners[i]==d)
260     {
261     m_owners.erase(m_owners.begin()+i,m_owners.begin()+(i+1)); // remove the element
262     break;
263     }
264     }
265     if (m_owners.size()==1) // Means it used to be 2 so we need to tell people
266     {
267     m_owners[0]->updateShareStatus(isShared()); // could still be lazy shared
268     }
269     }
270 gross 1487
271 jfenwick 1796
272 jfenwick 2271 void DataAbstract::makeLazyShared()
273     {
274     m_lazyshared=true; // now we need to inform all the owners
275     for (size_t i=0;i<m_owners.size();++i)
276     {
277     m_owners[i]->updateShareStatus(true);
278     }
279     }
280 jfenwick 1796
281 jfenwick 2271
282 jgs 82 } // end of namespace

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26