/[escript]/branches/arrexp_trunk2098/escript/src/WrappedArray.cpp
ViewVC logotype

Contents of /branches/arrexp_trunk2098/escript/src/WrappedArray.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2116 - (show annotations)
Tue Dec 2 01:58:34 2008 UTC (10 years, 4 months ago) by jfenwick
File size: 1623 byte(s)
Initial experiments are successful.
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 #include "WrappedArray.h"
15 #include "DataException.h"
16
17 using namespace escript;
18 using namespace boost::python;
19
20 namespace
21 {
22
23 void checkFeatures(const boost::python::object& obj)
24 {
25 int len=0;
26 boost::python::object o2;
27 try
28 {
29 len=extract<int>(obj.attr("__len__")());
30 }
31 catch (...)
32 {
33 PyErr_Clear();
34 throw DataException("Object passed to WrappedArray must support __len__");
35 }
36 try
37 {
38 o2=obj.attr("__getitem__");
39 }
40 catch (...)
41 {
42 PyErr_Clear();
43 throw DataException("Object passed to WrappedArray must support __getitem__");
44 }
45 }
46
47 void getObjShape(const boost::python::object& obj, DataTypes::ShapeType& s)
48 {
49 int len=0;
50 try
51 {
52 len=extract<int>(obj.attr("__len__")());
53 }
54 catch(...)
55 {
56 PyErr_Clear(); // tell python the error isn't there anymore
57 return;
58 }
59 if (len<1)
60 {
61 throw DataException("Array filter - no empty components in arrays please.");
62 }
63 s.push_back(len);
64
65 if (s.size()>ESCRIPT_MAX_DATA_RANK)
66 {
67 throw DataException("Array filter - Maximum rank exceeded in array");
68 }
69 getObjShape(obj[0],s);
70 }
71
72 }
73
74 WrappedArray::WrappedArray(const boost::python::object& obj_in)
75 :obj(obj_in)
76 {
77 checkFeatures(obj_in);
78 getObjShape(obj,shape);
79 rank=shape.size();
80 }
81
82
83

  ViewVC Help
Powered by ViewVC 1.1.26