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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2455 - (hide annotations)
Wed Jun 3 03:29:07 2009 UTC (10 years, 10 months ago) by jfenwick
File MIME type: text/plain
File size: 2136 byte(s)
Merging changes from numpy branch.

1 jfenwick 2116
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 jfenwick 2119 double getElt() const;
33 jfenwick 2116 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 jfenwick 2119 escript::DataTypes::ShapeType shape;
41     double m_scalar;
42 jfenwick 2116 };
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 jfenwick 2119 WrappedArray::getElt() const
58 jfenwick 2116 {
59 jfenwick 2119 return m_scalar;
60     }
61    
62    
63     inline double
64     WrappedArray::getElt(unsigned int i) const
65 jfenwick 2455 { // __float__ added to deal with numpy. If this causes problems we may have to register a custom converter
66     return boost::python::extract<double>(obj[i].attr("__float__")());
67 jfenwick 2116 }
68    
69     inline
70     double
71     WrappedArray::getElt(unsigned int i, unsigned int j) const
72     {
73 jfenwick 2455 return boost::python::extract<double>(obj[i][j].attr("__float__")());
74 jfenwick 2116 }
75    
76     inline
77     double
78     WrappedArray::getElt(unsigned int i, unsigned int j, unsigned int k) const
79     {
80 jfenwick 2455 return boost::python::extract<double>(obj[i][j][k].attr("__float__")());
81 jfenwick 2116 }
82    
83     inline
84     double
85     WrappedArray::getElt(unsigned int i, unsigned int j, unsigned int k, unsigned int m) const
86     {
87 jfenwick 2455 return boost::python::extract<double>(obj[i][j][k][m].attr("__float__")());
88 jfenwick 2116 }
89    
90     }
91    
92 gross 2278 #endif
93    

  ViewVC Help
Powered by ViewVC 1.1.26