1#ifndef __FIBER_MULTIARRAY_HPP
2#define __FIBER_MULTIARRAY_HPP "Created 3.07.2004 21:42:21 by bzfbenge"
4#include "MultiIndex.hpp"
6#include "Expression.hpp"
7#include "CreativeIterator.hpp"
9#include <memcore/breakpoint.hpp>
28template <Dims_t N,
class T>
85 , dimensions(
MAB.dimensions)
91 return dimensions.size() *
sizeof(T);
109 this->dimensions = D;
118 return dimensions.size();
127#ifdef __cpp_multidimensional_subscript
128 template<
typename I0,
typename I1,
typename...
I>
131 static_assert( N ==
sizeof...(I)+2,
"Wrong number of multidimensional arguments." );
143 Assertion( myDataCreator,
"Accessing MultiArray without storage!" );
146 Slice_t mySlice( myDataCreator->slice(
Dims-1, i), dimensions.subidx(), myDataCreator);
149 return mySlice[
sI ];
165 assert(i>=0 && i < dimensions.maxidx() );
184 reference_t first()
const
187 for(std::size_t i=0; i<N; i++)
194 reference_t last()
const
197 for(std::size_t i=0; i<N; i++)
202 I[i] = dimensions[i] - 1;
252 if (
count() > dimensions.size() )
253 this->
setCount( dimensions.size() );
271 this->dimensions = D;
284 return dimensions.size() *
sizeof(T);
302 return dimensions.size();
335 return (*
this)[
I.maxidx() ];
354 I = dimensions[0] - 1;
362#warning CLANG HAS BUG https:
363#define INDEX_SEQUENCE_BUG
366#ifdef INDEX_SEQUENCE_BUG
367template <Dims_t N,
class T>
370template <Dims_t N,
class T,
class = std::make_index_sequence<N>>
386#ifdef INDEX_SEQUENCE_BUG
387template <Dims_t N,
class T>
390template <Dims_t N, class T, std::size_t... Is>
403 using Base_t::operator[];
407 typedef typename Base_t::component_t component_t;
441 MultiArray(
const Base_t&MA)
445 MultiArrayBase_t arraybase()
const
447 return MultiArrayBase_t( this->getArrayIterator(), Size() );
462 MultiArrayComponent_t component(
int i)
const
464 return MultiArrayComponent_t(this->getComponent(i),
Size() );
470 typedef typename MultiArray<N-1,T>::MultiArray_t Hyperslab_t;
486 return Hyperslab_t(
slice(i) );
489#ifndef INDEX_SEQUENCE_BUG
490 T&operator()(
decltype(
Is,
index_t{})... args)
492 return this->getElement( Fiber::MIndex(args...) );
495 const T&operator()(
decltype(Is, index_t{})... args)
const
497 return this->getElement( Fiber::MIndex(args...) );
507 typedef T MultiArray_t;
522 void *ptr()
const {
return 0; }
528 enum { begin =
'{', end =
'}' };
533 enum { begin = 0, end =
' ' };
538 enum { begin =
'(', end =
')' };
543 enum { begin = 0, end =
'\n' };
547#if defined(_IOSTREAM_) || defined(_GLIBCXX_OSTREAM) || _CPP_IOSTREAM || defined(__SGI_STL_IOSTREAM) || defined(__clang__)
549template <
int N,
class T>
552 for(
index_t k=0; k<M.Size()[N-1]; k++)
566template <
class Operator>
570 template <
int D,
class Data,
class Data1,
class Data2>
584template <
int N,
class T>
594template <
int N,
class T>
595[[deprecated(
"Warning: Converting an entire MultiArray to a string!")]]
600 for(
auto I : M.
Size())
619template <
int N,
class T>
620[[deprecated(
"Warning: Converting an entire MultiArray to a string!")]]
625 for(
auto I : M.Size())
627 retval +=
" " + to_string(I) +
": " + to_string(M[I]) +
"\n";
basic_ostream< char > ostream
valarray< size_t > size() const
basic_string< char > string
constexpr const_iterator begin() const noexcept
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
void SetNewData(T *newData, index_t newLength)
Change the stored data chunk to a new location and length.
Definition vector/Iterator.hpp:233
T & getElement(index_t i, int c) const
Element access (no range check!).
Definition vector/Iterator.hpp:285
T * ptr(int c=0) const
Return pointer to data, which is good for C interface, but otherwise, avoid that.
Definition vector/Iterator.hpp:266
void setCount(index_t size)
Set the maximally allowed count, i.e.
Definition HyperslabParameters.hpp:156
index_t count() const
Return the number of steps which can be traversed through this ElementIterator.
Definition HyperslabParameters.hpp:147
Implementation of an Iterator to a sequence of elements, which might be contiguous or a projection of...
Definition vector/Iterator.hpp:525
T & operator[](index_t i) const
Access an element of the array, writeable.
Definition vector/Iterator.hpp:712
const reference_t first() const
Return reference to the first element.
Definition MultiArray.hpp:344
const MultiIndex< Dims > & Size() const
Return the number of elements in each direction, a multidimensional index.
Definition MultiArray.hpp:293
unsigned long memsize() const
Return the number of bytes occupied by this MultiArray.
Definition MultiArray.hpp:282
const Storage_t & storage() const
Reference to the stored data.
Definition MultiArray.hpp:263
MultiArrayBase(const Iterator< T > &data, const MultiIndex< Dims > &Extension, DataCreator< T > *Crec)
One-dimensional constructor.
Definition MultiArray.hpp:248
void Resize(T *newData, const index_t &D)
Change internally stored memory layout, shortcut for 1D.
Definition MultiArray.hpp:276
const reference_t operator[](const MultiIndex< 1 > &I) const
Index via multidimensional index, readonly.
Definition MultiArray.hpp:326
index_t nElements() const
Return the total number of elements This is equivalent to calling Size().size()
Definition MultiArray.hpp:300
MultiArrayBase(T *data, const MultiIndex< 1 > &Extension, DataCreator< T > *Crec)
Constructor.
Definition MultiArray.hpp:257
const reference_t operator[](index_t i) const
Return a stored element accessed by a linear index possible invoking the local creator if such exists...
Definition MultiArray.hpp:307
reference_t operator[](const MultiIndex< 1 > &I)
Access via multidimensional index, modifyable.
Definition MultiArray.hpp:333
Iterator< T > Storage_t
The layout of the stored data.
Definition MultiArray.hpp:243
const reference_t last() const
Return last element in the array.
Definition MultiArray.hpp:350
void Resize(T *newData, const MultiIndex< 1 > &D)
Change internally stored memory layout.
Definition MultiArray.hpp:269
reference_t operator[](index_t i)
Return a reference to a stored element via a linear index, possible invoking the local creator if suc...
Definition MultiArray.hpp:317
A generic multidimensional array is a one-dimensional pointer together with a specification of the ex...
Definition MultiArray.hpp:30
Slice_t slice(index_t i) const
Extract an N-1 dimensional slice of the current data set for read-only access.
Definition MultiArray.hpp:162
constexpr const Storage_t & storage() const
Reference to the stored data.
Definition MultiArray.hpp:95
void Resize(T *data, const MultiIndex< N > &D)
Change stored dimensionality, use with care.
Definition MultiArray.hpp:107
static constexpr Dims_t Dims
The dimensions of this array.
Definition MultiArray.hpp:46
Iterator< T > SliceStorge_t
The storage type of a subslice.
Definition MultiArray.hpp:57
Iterator< T > Storage_t
The layout of the stored data.
Definition MultiArray.hpp:54
T value_type
The type of each element in this array.
Definition MultiArray.hpp:51
MultiArrayBase(const MultiArrayBase &MAB)
Copy Constructor.
Definition MultiArray.hpp:83
reference_t operator[](const MultiIndex< N > &I) const
multidimensional element access
Definition MultiArray.hpp:122
index_t nElements() const
number of elements in here
Definition MultiArray.hpp:116
MultiArrayBase(T *data, const MultiIndex< Dims > &Extension, DataCreator< T > *Crec)
Constructor.
Definition MultiArray.hpp:66
constexpr unsigned long memsize() const
Return the number of bytes occupied by this MultiArray.
Definition MultiArray.hpp:89
reference_t getElement(const MultiIndex< N > &I) const
Element access.
Definition MultiArray.hpp:139
MultiArrayBase(const Iterator< T > &data, const MultiIndex< Dims > &Extension, DataCreator< T > *TheCreator=0)
Constructor.
Definition MultiArray.hpp:72
MultiArrayBase< N-1, T > Slice_t
The type of a slice of this array All data in this slice are still contiguous.
Definition MultiArray.hpp:61
constexpr const MultiIndex< Dims > & Size() const
Dimensionality.
Definition MultiArray.hpp:101
Iterator< T > SliceStorage_t
The layout of the stored data within a slice.
Definition MultiArray.hpp:468
MultiArray(const MultiIndex< N > &Sz, DataCreator< T > *Crec)
Construct multidimensional array with callback for data creation when a certain slice is accessed (de...
Definition MultiArray.hpp:425
MultiArray(T *data, const MultiIndex< N > &Sz)
Construct a multidimensional array from a data pointer and size specification.
Definition MultiArray.hpp:417
MultiArray(const Iterator< T > &data, const MultiIndex< N > &Sz)
Construct multidimensional array from iterator object and dimensionality.
Definition MultiArray.hpp:433
Hyperslab_t hyperslab(index_t i) const
Extract an N-1 dimensional hyperslab of the current data set.
Definition MultiArray.hpp:484
Definition MultiArray.hpp:371
A recursively defined multidimensional index.
Definition MultiIndex.hpp:331
Anemone_Context_t operator<<(Anemone &A, VRenderContext &VC)
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
Iterator< Type > array_iterator(const Iterator< Type > &It)
Specialization of the array_iterator() function for Iterators on what is already a FixedArray.
Definition vector/Iterator.hpp:1268
IndexTypeConfig< sizeof(void *)>::index_t index_t
Define the index type as according to the size of a pointer, i.e.
Definition Index.hpp:22
std::string to_string(const span< char > &s)
static void ternary(const Iterator< Data > &p, const Iterator< Data1 > &q, const Iterator< Data2 > &r)
Definition Expression.hpp:76
Definition MultiArray.hpp:568
Definition MultiArray.hpp:527
A multidimensional array for data that are stored in an STL vector<>.
Definition MultiArray.hpp:586