24 |
|
|
25 |
DataArray::DataArray(double value) |
DataArray::DataArray(double value) |
26 |
{ |
{ |
|
// |
|
|
// The default is a scalar, an empty shape vector is interpreted |
|
|
// as a scalar. |
|
27 |
m_data.push_back(value); |
m_data.push_back(value); |
28 |
// |
// create a view with an empty shape, a scalar. |
|
// create a view with an empty shape type |
|
29 |
m_dataView.reset(new DataArrayView(m_data,DataArrayView::ShapeType())); |
m_dataView.reset(new DataArrayView(m_data,DataArrayView::ShapeType())); |
30 |
} |
} |
31 |
|
|
48 |
m_dataView.reset(new DataArrayView(m_data,value.getShape())); |
m_dataView.reset(new DataArrayView(m_data,value.getShape())); |
49 |
} |
} |
50 |
|
|
51 |
DataArray::DataArray(const object& value) |
DataArray::DataArray(const object& value) |
52 |
{ |
{ |
|
// |
|
53 |
// this will throw if the value cannot be represented |
// this will throw if the value cannot be represented |
54 |
numeric::array asNumArray(value); |
numeric::array asNumArray(value); |
55 |
initialise(asNumArray); |
initialise(asNumArray); |
63 |
void |
void |
64 |
DataArray::initialise(const boost::python::numeric::array& value) |
DataArray::initialise(const boost::python::numeric::array& value) |
65 |
{ |
{ |
66 |
// |
// extract the shape of the numarray |
|
// extract the shape from the numarray |
|
67 |
DataArrayView::ShapeType tempShape; |
DataArrayView::ShapeType tempShape; |
68 |
for (int i=0; i<value.getrank(); ++i) { |
for (int i=0; i<value.getrank(); i++) { |
69 |
tempShape.push_back(extract<int>(value.getshape()[i])); |
tempShape.push_back(extract<int>(value.getshape()[i])); |
70 |
} |
} |
71 |
// |
// allocate the space for the data vector |
|
// allocate the space |
|
72 |
m_data.resize(DataArrayView::noValues(tempShape)); |
m_data.resize(DataArrayView::noValues(tempShape)); |
73 |
|
// create a view with the same shape |
74 |
m_dataView.reset(new DataArrayView(m_data,tempShape)); |
m_dataView.reset(new DataArrayView(m_data,tempShape)); |
75 |
|
// fill the data vector with the values from the numarray |
76 |
m_dataView->copy(value); |
m_dataView->copy(value); |
77 |
} |
} |
78 |
|
|