/[escript]/trunk/escript/test/python/test_shared.py
ViewVC logotype

Contents of /trunk/escript/test/python/test_shared.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2212 - (show annotations)
Wed Jan 14 00:15:00 2009 UTC (10 years, 9 months ago) by jfenwick
Original Path: branches/arrexp_2137_win/escript/test/python/test_shared.py
File MIME type: text/x-python
File size: 2011 byte(s)
Executive summary:

This commit adds copy on write checks to operations involving shared data. 

Changes:

new #defines:
~~~~~~~~~~~~~
Data.cpp has ASSIGNMENT_MEANS_DEEPCOPY (defaults to undefined).
Defining this will put the data = operator back to making deep copies instead
of sharing data (now the default.)

Data:
~~~~~
. Added exclusiveWrite method to copy the underlying data if it is shared.
. Some operators which took python objects now call the c++ versions intead of duplicating code.

DataAbstract and offspring:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
. Added method to determine whether the data is currently shared.
. Added getVectorRO to children of DataReady.
. Added getTagRO.

. Operations which modify values in place (or return modifiable pointers) now use
a macro to check for sharing. In the case where a modification attempt is detected, it throws an exception. In the future, I will enable this only for debugging.

. This shold not really have been required but the compiler was not choosing the use the const version as I would have liked. Besides, this makes things explict.

. Moved (and de-inlined) getVector in DataConstant (It was virtual in a parent class).

Unit tests:
~~~~~~~~~~~
Added both python and c++ unit tests to check known cases of sharing and "inplace"
modification operations.

General:
~~~~~~~~
Removed some commented out code.

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 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="http://www.uq.edu.au/esscc/escript-finley"
21
22 """
23 Test to ensure that modification of shared Data does not occur
24 """
25
26 import unittest
27 from esys.escript import *
28
29 class Test_Shared(unittest.TestCase):
30 def test_setToZero(self):
31 d=Data(42)
32 e=d.delay()
33 d.setToZero()
34 self.failUnless(Lsup(e-42)<=self.tol)
35
36 def test_copyConstr(self):
37 d=Data(42)
38 e=Data(d)
39 d+=17
40 self.failUnless(Lsup(e-42)<=self.tol)
41
42 # This should not fail (even in the old code) but it doesn't hurt to check
43 def test_Copy(self):
44 d=Data(42)
45 e=d.copy()
46 d+=17
47 self.failUnless(Lsup(e-42)<=self.tol)
48
49 def test_eqops(self):
50 d=Data(42)
51 e=d.delay()
52 d+=17
53 self.failUnless(Lsup(e-42)<=self.tol)
54 d=Data(42)
55 e=d.delay()
56 d-=1
57 self.failUnless(Lsup(e-42)<=self.tol)
58 d*=3
59 d=Data(42)
60 e=d.delay()
61 d/=2
62 self.failUnless(Lsup(e-42)<=self.tol)
63
64 def test_setItem(self):
65 d=Data(42)
66 e=d.delay()
67 d[tuple()]=17
68 self.failUnless(Lsup(e-42)<=self.tol)
69
70
71 def test_setTaggedValue(self):
72 d=Data(42,self.domain.getX().getFunctionSpace()) # doesn't really matter which non-NULL FS we use
73 d.tag()
74 self.domain.setTagMap("TestTag",2)
75 e=d.delay()
76 d.setTaggedValue("TestTag",17)
77 e.resolve()
78 self.failUnless(str(e)!=str(d))
79 e=d.delay()
80 d.setTaggedValue(1,12)
81 e.resolve()
82 self.failUnless(str(e)!=str(d))
83
84
85
86

  ViewVC Help
Powered by ViewVC 1.1.26