# Contents of /branches/numpy/escript/src/WrappedArray.h

Revision 2437 - (show annotations)
Tue May 26 01:48:35 2009 UTC (9 years, 10 months ago) by jfenwick
File MIME type: text/plain
File size: 2136 byte(s)
```Modified WrappedArray to cope with numpy types.
Numpy branch passes utest.sh but has not had the latest trunk changes pulled over yet.

```
 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 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 unsigned int getRank() const; 31 const DataTypes::ShapeType& getShape() const; 32 double getElt() const; 33 double getElt(unsigned int i) const; 34 double getElt(unsigned int i, unsigned int j) const; 35 double getElt(unsigned int i, unsigned int j, unsigned int k) const; 36 double getElt(unsigned int i, unsigned int j, unsigned int k, unsigned int m) const; 37 private: 38 const boost::python::object& obj; 39 int rank; 40 escript::DataTypes::ShapeType shape; 41 double m_scalar; 42 }; 43 44 inline unsigned int 45 WrappedArray::getRank() const 46 { 47 return rank; 48 } 49 50 inline const DataTypes::ShapeType& 51 WrappedArray::getShape() const 52 { 53 return shape; 54 } 55 56 inline double 57 WrappedArray::getElt() const 58 { 59 return m_scalar; 60 } 61 62 63 inline double 64 WrappedArray::getElt(unsigned int i) const 65 { // __float__ added to deal with numpy. If this causes problems we may have to register a custom converter 66 return boost::python::extract(obj[i].attr("__float__")()); 67 } 68 69 inline 70 double 71 WrappedArray::getElt(unsigned int i, unsigned int j) const 72 { 73 return boost::python::extract(obj[i][j].attr("__float__")()); 74 } 75 76 inline 77 double 78 WrappedArray::getElt(unsigned int i, unsigned int j, unsigned int k) const 79 { 80 return boost::python::extract(obj[i][j][k].attr("__float__")()); 81 } 82 83 inline 84 double 85 WrappedArray::getElt(unsigned int i, unsigned int j, unsigned int k, unsigned int m) const 86 { 87 return boost::python::extract(obj[i][j][k][m].attr("__float__")()); 88 } 89 90 } 91 92 #endif 93

 ViewVC Help Powered by ViewVC 1.1.26