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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 /*
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 #include "DataArray.h"
16
17 #include <boost/python/extract.hpp>
18
19 using namespace boost::python;
20 using namespace std;
21
22 namespace escript {
23
24 DataArray::DataArray(double value)
25 {
26 m_data.resize(1,value,1);
27 // create a view with an empty shape, a scalar.
28 m_dataView.reset(new DataArrayView(m_data,DataArrayView::ShapeType()));
29 }
30
31 DataArray::DataArray(const DataArrayView::ShapeType& shape,
32 double value)
33 {
34 int len = DataArrayView::noValues(shape);
35 m_data.resize(len,value,len);
36 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 DataArray::DataArray(const object& value)
52 {
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 // extract the shape of the numarray
67 DataArrayView::ShapeType tempShape;
68 for (int i=0; i<value.getrank(); i++) {
69 tempShape.push_back(extract<int>(value.getshape()[i]));
70 }
71 // allocate the space for the data vector
72 int len = DataArrayView::noValues(tempShape);
73 m_data.resize(len,0.,len);
74 // create a view with the same shape
75 m_dataView.reset(new DataArrayView(m_data,tempShape));
76 // fill the data vector with the values from the numarray
77 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