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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 478 - (hide annotations)
Tue Jan 31 02:21:49 2006 UTC (15 years, 2 months ago) by jgs
File size: 2934 byte(s)
rationalise #includes

1 jgs 82 /*
2     ******************************************************************************
3     * *
4     * COPYRIGHT ACcESS 2004 - All Rights Reserved *
5     * *
6     * This software is the property of ACcESS. No part of this code *
7     * may be copied in any form or by any means without the expressed written *
8     * consent of ACcESS. Copying, use or modification of this software *
9     * by any unauthorised person is illegal unless that person has a software *
10     * license agreement with ACcESS. *
11     * *
12     ******************************************************************************
13     */
14    
15 jgs 474 #include "DataArray.h"
16 jgs 82
17 jgs 478 #include <boost/python/extract.hpp>
18    
19 jgs 82 using namespace boost::python;
20     using namespace std;
21    
22     namespace escript {
23    
24     DataArray::DataArray(double value)
25     {
26 jgs 151 m_data.resize(1,value,1);
27 jgs 108 // create a view with an empty shape, a scalar.
28 jgs 82 m_dataView.reset(new DataArrayView(m_data,DataArrayView::ShapeType()));
29     }
30    
31     DataArray::DataArray(const DataArrayView::ShapeType& shape,
32     double value)
33     {
34 jgs 151 int len = DataArrayView::noValues(shape);
35     m_data.resize(len,value,len);
36 jgs 82 m_dataView.reset(new DataArrayView(m_data,shape));
37     }
38    
39     DataArray::DataArray(const DataArray& value):
40     m_data(value.getData())
41     {
42     m_dataView.reset(new DataArrayView(m_data,value.getView().getShape()));
43     }
44    
45     DataArray::DataArray(const DataArrayView& value):
46     m_data(value.getData())
47     {
48     m_dataView.reset(new DataArrayView(m_data,value.getShape()));
49     }
50    
51 jgs 108 DataArray::DataArray(const object& value)
52 jgs 82 {
53     // this will throw if the value cannot be represented
54     numeric::array asNumArray(value);
55     initialise(asNumArray);
56     }
57    
58     DataArray::DataArray(const boost::python::numeric::array& value)
59     {
60     initialise(value);
61     }
62    
63     void
64     DataArray::initialise(const boost::python::numeric::array& value)
65     {
66 jgs 108 // extract the shape of the numarray
67 jgs 82 DataArrayView::ShapeType tempShape;
68 jgs 108 for (int i=0; i<value.getrank(); i++) {
69 jgs 82 tempShape.push_back(extract<int>(value.getshape()[i]));
70     }
71 jgs 108 // allocate the space for the data vector
72 jgs 151 int len = DataArrayView::noValues(tempShape);
73     m_data.resize(len,0.,len);
74 jgs 108 // create a view with the same shape
75 jgs 82 m_dataView.reset(new DataArrayView(m_data,tempShape));
76 jgs 108 // fill the data vector with the values from the numarray
77 jgs 82 m_dataView->copy(value);
78     }
79    
80     const DataArrayView&
81     DataArray::getView() const
82     {
83     return *m_dataView;
84     }
85    
86     DataArrayView&
87     DataArray::getView()
88     {
89     return *m_dataView;
90     }
91    
92     const DataArrayView::ValueType&
93     DataArray::getData() const
94     {
95     return m_data;
96     }
97    
98     DataArrayView::ValueType&
99     DataArray::getData()
100     {
101     return m_data;
102     }
103    
104     } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26