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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (hide annotations)
Mon Sep 24 06:18:44 2007 UTC (13 years, 7 months ago) by ksteube
File size: 2487 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

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