/[escript]/branches/symbolic_from_3470/escript/src/WrappedArray.h
ViewVC logotype

Contents of /branches/symbolic_from_3470/escript/src/WrappedArray.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3868 - (show annotations)
Thu Mar 15 06:07:08 2012 UTC (7 years, 1 month ago) by caltinay
File MIME type: text/plain
File size: 2479 byte(s)
Update to latest trunk

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 template<typename T> void convertNumpyArray(const T* array, const std::vector<int>& strides) const;
41 const boost::python::object& obj;
42 int rank;
43 escript::DataTypes::ShapeType shape;
44 double m_scalar;
45 mutable double* dat;
46 };
47
48 inline unsigned int
49 WrappedArray::getRank() const
50 {
51 return rank;
52 }
53
54 inline const DataTypes::ShapeType&
55 WrappedArray::getShape() const
56 {
57 return shape;
58 }
59
60 inline double
61 WrappedArray::getElt() const
62 {
63 return m_scalar;
64 }
65
66
67 inline double
68 WrappedArray::getElt(unsigned int i) const
69 { // __float__ added to deal with numpy. If this causes problems we may have to register a custom converter
70 return (dat!=0)?dat[i]:(boost::python::extract<double>(obj[i].attr("__float__")()));
71 }
72
73 inline
74 double
75 WrappedArray::getElt(unsigned int i, unsigned int j) const
76 {
77 return (dat!=0)?dat[DataTypes::getRelIndex(shape,i,j)]:(boost::python::extract<double>(obj[i][j].attr("__float__")()));
78 }
79
80 inline
81 double
82 WrappedArray::getElt(unsigned int i, unsigned int j, unsigned int k) const
83 {
84 return (dat!=0)?dat[DataTypes::getRelIndex(shape,i,j,k)]:(boost::python::extract<double>(obj[i][j][k].attr("__float__")()));
85 }
86
87 inline
88 double
89 WrappedArray::getElt(unsigned int i, unsigned int j, unsigned int k, unsigned int m) const
90 {
91 return (dat!=0)?dat[DataTypes::getRelIndex(shape,i,j,k,m)]:(boost::python::extract<double>(obj[i][j][k][m].attr("__float__")()));
92 }
93
94 }
95
96 #endif
97

  ViewVC Help
Powered by ViewVC 1.1.26