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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 6 months ago) by jfenwick
File MIME type: text/plain
File size: 2378 byte(s)
Don't panic.
Updating copyright stamps

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 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 /** \file WrappedArray.h */
16
17 #ifndef WrappedArray_20081202_H
18 #define WrappedArray_20081202_H
19 #include "system_dep.h"
20 #include "DataTypes.h"
21 #include "boost/python/extract.hpp"
22
23 namespace escript
24 {
25
26 class WrappedArray
27 {
28 public:
29 WrappedArray(const boost::python::object& obj_in);
30 ~WrappedArray();
31 unsigned int getRank() const;
32 const DataTypes::ShapeType& getShape() const;
33 double getElt() const;
34 double getElt(unsigned int i) const;
35 double getElt(unsigned int i, unsigned int j) const;
36 double getElt(unsigned int i, unsigned int j, unsigned int k) const;
37 double getElt(unsigned int i, unsigned int j, unsigned int k, unsigned int m) const;
38 void convertArray() const;
39 private:
40 const boost::python::object& obj;
41 int rank;
42 escript::DataTypes::ShapeType shape;
43 double m_scalar;
44 mutable double* dat;
45 };
46
47 inline unsigned int
48 WrappedArray::getRank() const
49 {
50 return rank;
51 }
52
53 inline const DataTypes::ShapeType&
54 WrappedArray::getShape() const
55 {
56 return shape;
57 }
58
59 inline double
60 WrappedArray::getElt() const
61 {
62 return m_scalar;
63 }
64
65
66 inline double
67 WrappedArray::getElt(unsigned int i) const
68 { // __float__ added to deal with numpy. If this causes problems we may have to register a custom converter
69 return (dat!=0)?dat[i]:(boost::python::extract<double>(obj[i].attr("__float__")()));
70 }
71
72 inline
73 double
74 WrappedArray::getElt(unsigned int i, unsigned int j) const
75 {
76 return (dat!=0)?dat[DataTypes::getRelIndex(shape,i,j)]:(boost::python::extract<double>(obj[i][j].attr("__float__")()));
77 }
78
79 inline
80 double
81 WrappedArray::getElt(unsigned int i, unsigned int j, unsigned int k) const
82 {
83 return (dat!=0)?dat[DataTypes::getRelIndex(shape,i,j,k)]:(boost::python::extract<double>(obj[i][j][k].attr("__float__")()));
84 }
85
86 inline
87 double
88 WrappedArray::getElt(unsigned int i, unsigned int j, unsigned int k, unsigned int m) const
89 {
90 return (dat!=0)?dat[DataTypes::getRelIndex(shape,i,j,k,m)]:(boost::python::extract<double>(obj[i][j][k][m].attr("__float__")()));
91 }
92
93 }
94
95 #endif
96

  ViewVC Help
Powered by ViewVC 1.1.26