ndarray: /home/runner/work/ndarray/ndarray/include/ndarray/initialization.h Source File

1

2

3

4

5

6

7

8

9

10

11#ifndef NDARRAY_initialization_h_INCLUDED

12#define NDARRAY_initialization_h_INCLUDED

13

21

22namespace ndarray {

23namespace detail {

24

26

27template <int N, typename Derived>

29public:

30

31 template <typename T, int C>

33 return static_cast<Derived const *>(this)->template apply< Array<T,N,C> >();

34 }

35

36 template <typename T, int C>

38 return static_cast<Derived const *>(this)->template apply< ArrayRef<T,N,C> >();

39 }

40

41};

42

43template <int N>

45public:

46

47 template <typename Target>

48 Target apply() const {

50 typedef typename Access::Core Core;

51 typedef typename Access::Element Element;

53 Size total = _shape.product();

55 return Access::construct(p.second, Core::create(_shape, order, p.first));

56 }

57

59

60private:

62};

63

64template <typename T, int N, typename Owner>

66public:

67

68 template <typename Target>

69 Target apply() const {

71 typedef typename Access::Core Core;

72 Manager::Ptr manager;

73 if (!boost::is_same<Owner,NullOwner>::value) {

74 manager = makeManager(_owner);

75 }

76 return Access::construct(_data, Core::create(_shape, _strides, manager));

77 }

78

80 T * data,

83 Owner const & owner

84 ) : _data(data), _owner(owner), _shape(shape), _strides(strides) {}

85

86private:

87 T * _data;

88 Owner _owner;

91};

92

93}

94

97

103template <int N, typename U>

106}

107

115}

116

124}

125

133}

134

138template <typename Derived>

139inline ArrayRef<typename boost::remove_const<typename Derived::Element>::type,

140 Derived::ND::value, Derived::ND::value>

143 Derived::ND::value,Derived::ND::value> r(

145 );

146 r = expr;

147 return r;

148}

149

151template <int N>

154 if (order == ROW_MAJOR) {

155 for (int n=N-1; n > 0; --n) r[n-1] = r[n] * shape[n];

156 } else {

157 for (int n=1; n < N; ++n) r[n] = r[n-1] * shape[n-1];

158 }

159 return r;

160}

161

175template <typename T, int N, typename U, typename V, typename Owner>

177 T * data,

180 Owner const & owner

181) {

183 data,

186 owner

187 );

188}

189

202template <typename T, int N, typename U, typename V>

204 T * data,

207) {

209 data,

213 );

214}

215

229template <typename T, int N, typename U, typename Owner>

231 T * data,

234 Owner const & owner

235) {

237 data,

240 owner

241 );

242}

243

256template <typename T, int N, typename U>

258 T * data,

261) {

263 data,

267 );

268}

269

271

272template <typename T, int N, int C>

273Array<T,N,C>::Array(Size n1, Size n2, Size n3, Size n4, Size n5, Size n6, Size n7, Size n8)

274 : Super(0, CorePtr())

275{

277 if (N > 0) shape[0] = n1;

278 if (N > 1) shape[1] = n2;

279 if (N > 2) shape[2] = n3;

280 if (N > 3) shape[3] = n4;

281 if (N > 4) shape[4] = n5;

282 if (N > 5) shape[5] = n6;

283 if (N > 6) shape[6] = n7;

284 if (N > 7) shape[7] = n8;

286}

287

288template <typename T, int N, int C>

289template <typename U>

291 : Super(0, CorePtr())

292{

294}

295

296template <typename T, int N, int C>

298 : Super(Array<T,N,C>(n1, n2, n3, n4, n5, n6, n7, n8))

299{}

300

301template <typename T, int N, int C>

302template <typename U>

305{}

306

307}

308

309#endif

Definitions for ArrayRef.

Definition of Manager, which manages the ownership of array data.

An intermediate CRTP base class for Array and ArrayRef.

Definition ArrayBaseN.h:29

A proxy class for Array with deep assignment operators.

Definition ArrayRef.h:34

A multidimensional strided array.

Definition Array.h:35

Array & operator=(Array const &other)

Non-converting shallow assignment.

Definition Array.h:102

CRTP base class for all multidimensional expressions.

Definition ExpressionBase.h:40

Index getShape() const

Return a Vector of the sizes of all dimensions.

Definition ExpressionBase.h:76

Definition ArrayAccess.h:26

static Ptr create(Vector< Size, M > const &shape, Vector< Offset, M > const &strides, Manager::Ptr const &manager=Manager::Ptr())

Create a Core::Ptr with the given shape, strides, and manager.

Definition Core.h:56

Definition initialization.h:65

Definition initialization.h:28

Definition initialization.h:44

ArrayRef< typename boost::remove_const< typename Derived::Element >::type, Derived::ND::value, Derived::ND::value > copy(ExpressionBase< Derived > const &expr)

Create a new Array by copying an Expression.

Definition initialization.h:141

detail::SimpleInitializer< N > allocate(Vector< U, N > const &shape)

Create an expression that allocates uninitialized memory for an array.

Definition initialization.h:104

detail::ExternalInitializer< T, N, Owner > external(T *data, Vector< U, N > const &shape, Vector< V, N > const &strides, Owner const &owner)

Create an expression that initializes an Array with externally allocated memory.

Definition initialization.h:176

Vector< Offset, N > computeStrides(Vector< Size, N > const &shape, DataOrderEnum order=ROW_MAJOR)

Compute row- or column-major strides for the given shape.

Definition initialization.h:152

DataOrderEnum

An enumeration for stride computation.

Definition ndarray_fwd.h:51

Traits for expressions.

Definition ExpressionTraits.h:30

A fixed-size 1D array class.

Definition Vector.h:82

Vector< T, M > first() const

Create a new Vector from the first M elements of this.

Definition Vector.h:150

T product() const

Return the product of all elements.

Definition Vector.h:214

Definition initialization.h:25