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

Contents of /trunk/escript/src/WrappedArray.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2653 - (show annotations)
Tue Sep 8 04:26:30 2009 UTC (9 years, 10 months ago) by jfenwick
File size: 2038 byte(s)
Fix bug in maxGlobalDataPoint and minGlobalDataPoint.
They now give the correct answers and the datapoint ids returned are globally
correct.

Removed some #defines from before COW
Removed hasNoSamples() - I don't trust myself to use that properly let alone anybody else.


1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 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 #include <boost/python/tuple.hpp>
15 #include "WrappedArray.h"
16 #include "DataException.h"
17
18 #include <iostream>
19
20 using namespace escript;
21 using namespace boost::python;
22
23 namespace
24 {
25
26 void checkFeatures(const boost::python::object& obj)
27 {
28 using namespace std;
29 int len=0;
30 boost::python::object o2;
31 try
32 {
33 len=extract<int>(obj.attr("__len__")());
34 }
35 catch (...)
36 {
37 PyErr_Clear();
38 throw DataException("Object passed to WrappedArray must support __len__");
39 }
40 try
41 {
42 o2=obj.attr("__getitem__");
43 }
44 catch (...)
45 {
46 PyErr_Clear();
47 throw DataException("Object passed to WrappedArray must support __getitem__");
48 }
49 }
50
51 void getObjShape(const boost::python::object& obj, DataTypes::ShapeType& s)
52 {
53 int len=0;
54 try
55 {
56 len=extract<int>(obj.attr("__len__")());
57 }
58 catch(...)
59 {
60 PyErr_Clear(); // tell python the error isn't there anymore
61 return;
62 }
63 if (len<1)
64 {
65 throw DataException("Array filter - no empty components in arrays please.");
66 }
67 s.push_back(len);
68
69 if (s.size()>ESCRIPT_MAX_DATA_RANK)
70 {
71 throw DataException("Array filter - Maximum rank exceeded in array");
72 }
73 getObjShape(obj[0],s);
74 }
75
76 }
77
78 WrappedArray::WrappedArray(const boost::python::object& obj_in)
79 :obj(obj_in)
80 {
81 // First we check for scalars
82 try
83 {
84 double v=extract<double>(obj_in);
85 m_scalar=v;
86 rank=0;
87 return;
88 }
89 catch (...)
90 { // so we
91 PyErr_Clear();
92 }
93 try
94 {
95 double v=extract<double>(obj_in[make_tuple()]);
96 m_scalar=v;
97 rank=0;
98 return;
99 }
100 catch (...)
101 { // so we
102 PyErr_Clear();
103 }
104
105
106 m_scalar=0;
107 checkFeatures(obj_in);
108 getObjShape(obj,shape);
109 rank=shape.size();
110 }
111
112
113

  ViewVC Help
Powered by ViewVC 1.1.26