/[escript]/trunk/escript/src/DataArray.cpp
ViewVC logotype

Annotation of /trunk/escript/src/DataArray.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 615 - (hide annotations)
Wed Mar 22 02:12:00 2006 UTC (13 years, 8 months ago) by elspeth
File size: 2612 byte(s)
More copyright information.

1 jgs 82 /*
2 elspeth 615 ************************************************************
3     * Copyright 2006 by ACcESS MNRF *
4     * *
5     * http://www.access.edu.au *
6     * Primary Business: Queensland, Australia *
7     * Licensed under the Open Software License version 3.0 *
8     * http://www.opensource.org/licenses/osl-3.0.php *
9     * *
10     ************************************************************
11 jgs 82 */
12    
13 jgs 474 #include "DataArray.h"
14 jgs 82
15 jgs 478 #include <boost/python/extract.hpp>
16    
17 jgs 82 using namespace boost::python;
18     using namespace std;
19    
20     namespace escript {
21    
22     DataArray::DataArray(double value)
23     {
24 jgs 151 m_data.resize(1,value,1);
25 jgs 108 // create a view with an empty shape, a scalar.
26 jgs 82 m_dataView.reset(new DataArrayView(m_data,DataArrayView::ShapeType()));
27     }
28    
29     DataArray::DataArray(const DataArrayView::ShapeType& shape,
30     double value)
31     {
32 jgs 151 int len = DataArrayView::noValues(shape);
33     m_data.resize(len,value,len);
34 jgs 82 m_dataView.reset(new DataArrayView(m_data,shape));
35     }
36    
37     DataArray::DataArray(const DataArray& value):
38     m_data(value.getData())
39     {
40     m_dataView.reset(new DataArrayView(m_data,value.getView().getShape()));
41     }
42    
43     DataArray::DataArray(const DataArrayView& value):
44     m_data(value.getData())
45     {
46     m_dataView.reset(new DataArrayView(m_data,value.getShape()));
47     }
48    
49 jgs 108 DataArray::DataArray(const object& value)
50 jgs 82 {
51     // this will throw if the value cannot be represented
52     numeric::array asNumArray(value);
53     initialise(asNumArray);
54     }
55    
56     DataArray::DataArray(const boost::python::numeric::array& value)
57     {
58     initialise(value);
59     }
60    
61     void
62     DataArray::initialise(const boost::python::numeric::array& value)
63     {
64 jgs 108 // extract the shape of the numarray
65 jgs 82 DataArrayView::ShapeType tempShape;
66 jgs 108 for (int i=0; i<value.getrank(); i++) {
67 jgs 82 tempShape.push_back(extract<int>(value.getshape()[i]));
68     }
69 jgs 108 // allocate the space for the data vector
70 jgs 151 int len = DataArrayView::noValues(tempShape);
71     m_data.resize(len,0.,len);
72 jgs 108 // create a view with the same shape
73 jgs 82 m_dataView.reset(new DataArrayView(m_data,tempShape));
74 jgs 108 // fill the data vector with the values from the numarray
75 jgs 82 m_dataView->copy(value);
76     }
77    
78     const DataArrayView&
79     DataArray::getView() const
80     {
81     return *m_dataView;
82     }
83    
84     DataArrayView&
85     DataArray::getView()
86     {
87     return *m_dataView;
88     }
89    
90     const DataArrayView::ValueType&
91     DataArray::getData() const
92     {
93     return m_data;
94     }
95    
96     DataArrayView::ValueType&
97     DataArray::getData()
98     {
99     return m_data;
100     }
101    
102     } // end of namespace

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26