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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 121 - (show annotations)
Fri May 6 04:26:16 2005 UTC (14 years, 7 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataArray.cpp
File size: 2932 byte(s)
Merge of development branch back to main trunk on 2005-05-06

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 "escript/Data/DataArray.h"
16
17 #include <boost/python/numeric.hpp>
18 #include <boost/python/extract.hpp>
19
20 using namespace boost::python;
21 using namespace std;
22
23 namespace escript {
24
25 DataArray::DataArray(double value)
26 {
27 m_data.resize(1,value);
28 // create a view with an empty shape, a scalar.
29 m_dataView.reset(new DataArrayView(m_data,DataArrayView::ShapeType()));
30 }
31
32 DataArray::DataArray(const DataArrayView::ShapeType& shape,
33 double value)
34 {
35 m_data.resize(DataArrayView::noValues(shape),value);
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 m_data.resize(DataArrayView::noValues(tempShape));
73 // create a view with the same shape
74 m_dataView.reset(new DataArrayView(m_data,tempShape));
75 // fill the data vector with the values from the numarray
76 m_dataView->copy(value);
77 }
78
79 const DataArrayView&
80 DataArray::getView() const
81 {
82 return *m_dataView;
83 }
84
85 DataArrayView&
86 DataArray::getView()
87 {
88 return *m_dataView;
89 }
90
91 const DataArrayView::ValueType&
92 DataArray::getData() const
93 {
94 return m_data;
95 }
96
97 DataArrayView::ValueType&
98 DataArray::getData()
99 {
100 return m_data;
101 }
102
103 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26