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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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