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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 155 - (hide annotations)
Wed Nov 9 02:02:19 2005 UTC (14 years, 1 month ago) by jgs
Original Path: trunk/escript/src/Data/DataArray.cpp
File size: 2983 byte(s)
move all directories from trunk/esys2 into trunk and remove esys2

1 jgs 82 /*
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 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