18 #ifndef __ESCRIPT_DATAVECTORALT_H__
19 #define __ESCRIPT_DATAVECTORALT_H__
42 typedef T ElementType;
47 typedef const ElementType * const_pointer;
48 typedef ElementType value_type;
50 typedef ElementType & reference;
51 typedef const ElementType & const_reference;
70 DataVectorAlt(
const DataVectorAlt<T>& other);
90 DataVectorAlt(
const size_type size,
91 const value_type val=0.0,
92 const size_type blockSize=1);
114 resize(
const size_type newSize,
115 const value_type newVal=0.0,
116 const size_type newBlockSize=1);
125 copyFromArray(
const WrappedArray& value, size_type copies);
131 copyFromArrayToOffset(
const WrappedArray& value, size_type offset, size_type copies);
148 operator=(
const DataVectorAlt<T>& other);
156 operator==(
const DataVectorAlt<T>& other)
const;
164 operator!=(
const DataVectorAlt<T>& other)
const;
176 operator[](
const size_type i);
180 operator[](
const size_type i)
const;
184 const ElementType* data()
const;
194 ElementType* m_array_data;
224 ESYS_ASSERT(i<size(),
"DataVectorAlt: invalid index specified, " << i <<
" of " << size());
225 return m_array_data[i];
233 ESYS_ASSERT(i<size(),
"DataVectorAlt: invalid index specified. " << i <<
" of " << size());
234 return m_array_data[i];
250 m_size(other.m_size),
255 m_array_data=reinterpret_cast<T*>(malloc(
sizeof(T)*m_size));
257 #pragma omp parallel for private(i) schedule(static)
258 for (i=0; i<m_size; i++) {
271 resize(size, val, blockSize);
290 DataVectorAlt<T>::resize(
const DataVectorAlt<T>::size_type newSize,
291 const DataVectorAlt<T>::value_type newValue,
292 const DataVectorAlt<T>::size_type newBlockSize)
295 if ( newBlockSize < 1) {
296 std::ostringstream oss;
297 oss <<
"DataVectorAlt: invalid blockSize specified (" << newBlockSize <<
')';
302 std::ostringstream oss;
303 oss <<
"DataVectorAlt: invalid new size specified (" << newSize <<
')';
306 if ( (newSize % newBlockSize) != 0) {
307 std::ostringstream oss;
308 oss <<
"DataVectorAlt: newSize is not a multiple of blockSize: (" << newSize <<
", " << newBlockSize<<
')';
313 m_dim = newBlockSize;
314 m_N = newSize / newBlockSize;
320 m_array_data=reinterpret_cast<T*>(malloc(
sizeof(T)*m_size));
322 #pragma omp parallel for private(i) schedule(static)
323 for (i=0; i<m_size; i++) {
324 m_array_data[i] = newValue;
330 DataVectorAlt<T>::operator=(
const DataVectorAlt& other)
335 m_size = other.m_size;
343 m_array_data=reinterpret_cast<T*>(malloc(
sizeof(T)*m_size));
345 #pragma omp parallel for private(i) schedule(static)
346 for (i=0; i<m_size; i++) {
347 m_array_data[i] = other.m_array_data[i];
359 if (m_size!=other.
m_size) {
362 if (m_dim!=other.
m_dim) {
365 if (m_N!=other.
m_N) {
368 for (
int i=0; i<m_size; i++) {
380 return !(*
this==other);
389 if (offset+len*copies>size())
391 std::ostringstream ss;
392 ss <<
"Error - not enough room for that DataPoint at that offset. (";
393 ss <<
"offset=" << offset <<
" + " <<
" len=" << len <<
" >= " << size();
396 size_type si=0,sj=0,sk=0,sl=0;
400 for (size_type z=0;z<copies;++z)
402 m_array_data[offset+z]=value.
getElt();
406 for (size_type z=0;z<copies;++z)
408 for (
size_t i=0;i<tempShape[0];++i)
410 m_array_data[offset+i]=value.
getElt(i);
418 for (size_type z=0;z<copies;++z)
420 for (size_type i=0;i<si;i++)
422 for (size_type j=0;j<sj;j++)
434 for (size_type z=0;z<copies;++z)
436 for (size_type i=0;i<si;i++)
438 for (size_type j=0;j<sj;j++)
440 for (size_type k=0;k<sk;k++)
454 for (size_type z=0;z<copies;++z)
456 for (size_type i=0;i<si;i++)
458 for (size_type j=0;j<sj;j++)
460 for (size_type k=0;k<sk;k++)
462 for (size_type l=0;l<sl;l++)
473 std::ostringstream oss;
474 oss <<
"Error - unknown rank. Rank=" << value.
getRank();
475 throw DataException(oss.str());
481 DataVectorAlt<T>::copyFromArray(
const WrappedArray& value, size_type copies)
489 m_array_data=reinterpret_cast<T*>(malloc(
sizeof(T)*nelements));
493 copyFromArrayToOffset(value,0,copies);
501 #endif // __ESCRIPT_DATAVECTORALT_H__