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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 474 - (hide annotations)
Mon Jan 30 04:23:44 2006 UTC (15 years, 2 months ago) by jgs
File size: 2897 byte(s)
restructure escript source tree
move src/Data/* -> src
remove inc
modify #includes and cpppath settings accordingly

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