/[escript]/trunk-mpi-branch/escript/src/DataArray.cpp
ViewVC logotype

Contents of /trunk-mpi-branch/escript/src/DataArray.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1306 - (show annotations)
Tue Sep 18 05:51:09 2007 UTC (11 years, 11 months ago) by ksteube
File size: 2487 byte(s)
New Copyright in each .c .h .cpp and .py file

1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #include "DataArray.h"
17
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,1);
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 int len = DataArrayView::noValues(shape);
36 m_data.resize(len,value,len);
37 m_dataView.reset(new DataArrayView(m_data,shape));
38 }
39
40 DataArray::DataArray(const DataArray& value):
41 m_data(value.getData())
42 {
43 m_dataView.reset(new DataArrayView(m_data,value.getView().getShape()));
44 }
45
46 DataArray::DataArray(const DataArrayView& value):
47 m_data(value.getData())
48 {
49 m_dataView.reset(new DataArrayView(m_data,value.getShape()));
50 }
51
52 DataArray::DataArray(const object& value)
53 {
54 // this will throw if the value cannot be represented
55 numeric::array asNumArray(value);
56 initialise(asNumArray);
57 }
58
59 DataArray::DataArray(const boost::python::numeric::array& value)
60 {
61 initialise(value);
62 }
63
64 void
65 DataArray::initialise(const boost::python::numeric::array& value)
66 {
67 // extract the shape of the numarray
68 DataArrayView::ShapeType tempShape;
69 for (int i=0; i<value.getrank(); i++) {
70 tempShape.push_back(extract<int>(value.getshape()[i]));
71 }
72 // allocate the space for the data vector
73 int len = DataArrayView::noValues(tempShape);
74 m_data.resize(len,0.,len);
75 // create a view with the same shape
76 m_dataView.reset(new DataArrayView(m_data,tempShape));
77 // fill the data vector with the values from the numarray
78 m_dataView->copy(value);
79 }
80
81 const DataArrayView&
82 DataArray::getView() const
83 {
84 return *m_dataView;
85 }
86
87 DataArrayView&
88 DataArray::getView()
89 {
90 return *m_dataView;
91 }
92
93 const DataArrayView::ValueType&
94 DataArray::getData() const
95 {
96 return m_data;
97 }
98
99 DataArrayView::ValueType&
100 DataArray::getData()
101 {
102 return m_data;
103 }
104
105 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26