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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 82 - (show annotations)
Tue Oct 26 06:53:54 2004 UTC (15 years, 1 month ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataArray.cpp
File size: 2931 byte(s)
Initial revision

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 //
28 // The default is a scalar, an empty shape vector is interpreted
29 // as a scalar.
30 m_data.push_back(value);
31 //
32 // create a view with an empty shape type
33 m_dataView.reset(new DataArrayView(m_data,DataArrayView::ShapeType()));
34 }
35
36 DataArray::DataArray(const DataArrayView::ShapeType& shape,
37 double value)
38 {
39 m_data.resize(DataArrayView::noValues(shape),value);
40 m_dataView.reset(new DataArrayView(m_data,shape));
41 }
42
43 DataArray::DataArray(const DataArray& value):
44 m_data(value.getData())
45 {
46 m_dataView.reset(new DataArrayView(m_data,value.getView().getShape()));
47 }
48
49 DataArray::DataArray(const DataArrayView& value):
50 m_data(value.getData())
51 {
52 m_dataView.reset(new DataArrayView(m_data,value.getShape()));
53 }
54
55 DataArray::DataArray(const object& value)
56 {
57 //
58 // this will throw if the value cannot be represented
59 numeric::array asNumArray(value);
60 initialise(asNumArray);
61 }
62
63 DataArray::DataArray(const boost::python::numeric::array& value)
64 {
65 initialise(value);
66 }
67
68 void
69 DataArray::initialise(const boost::python::numeric::array& value)
70 {
71 //
72 // extract the shape from the numarray
73 DataArrayView::ShapeType tempShape;
74 for (int i=0; i<value.getrank(); ++i) {
75 tempShape.push_back(extract<int>(value.getshape()[i]));
76 }
77 //
78 // allocate the space
79 m_data.resize(DataArrayView::noValues(tempShape));
80 m_dataView.reset(new DataArrayView(m_data,tempShape));
81 m_dataView->copy(value);
82 }
83
84 const DataArrayView&
85 DataArray::getView() const
86 {
87 return *m_dataView;
88 }
89
90 DataArrayView&
91 DataArray::getView()
92 {
93 return *m_dataView;
94 }
95
96 const DataArrayView::ValueType&
97 DataArray::getData() const
98 {
99 return m_data;
100 }
101
102 DataArrayView::ValueType&
103 DataArray::getData()
104 {
105 return m_data;
106 }
107
108 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26