ndarray
NumPy-friendly multidimensional arrays in C++
Loading...
Searching...
No Matches
Array.h
Go to the documentation of this file.
1// -*- c++ -*-
2/*
3 * Copyright (c) 2010-2012, Jim Bosch
4 * All rights reserved.
5 *
6 * ndarray is distributed under a simple BSD-like license;
7 * see the LICENSE file that should be present in the root
8 * of the source distribution, or alternately available at:
9 * https://github.com/ndarray/ndarray
10 */
11#ifndef NDARRAY_Array_h_INCLUDED
12#define NDARRAY_Array_h_INCLUDED
13
20#include "ndarray_fwd.h"
21#include "ndarray/ArrayTraits.h"
22#include "ndarray/ArrayBaseN.h"
23#include "ndarray/Vector.h"
24#include "ndarray/detail/Core.h"
25#include "ndarray/views.h"
26
27namespace ndarray {
28
34template <typename T, int N, int C>
35class Array : public ArrayBaseN< Array<T,N,C> > {
37 typedef typename Super::Core Core;
38 typedef typename Super::CorePtr CorePtr;
39public:
40
46 Array() : Super(0, Core::create()) {}
47
51 Array(Array const & other) : Super(other._data, other._core) {}
52
59 template <typename T_, int C_>
61 Array<T_,N,C_> const & other
62#ifndef DOXYGEN
63 , typename boost::enable_if<detail::Convertible<N,T_,C_,T,C>,void*>::type=0
64#endif
65 ) : Super(other._data, other._core) {}
66
73 template <typename T_, int C_>
75 ArrayRef<T_,N,C_> const & other
76#ifndef DOXYGEN
77 , typename boost::enable_if<detail::Convertible<N,T_,C_,T,C>,void*>::type=0
78#endif
79 ) : Super(other._data, other._core) {}
80
89 explicit Array(Size n1, Size n2=1, Size n3=1, Size n4=1, Size n5=1, Size n6=1, Size n7=1, Size n8=1);
90
96 template <typename U>
97 explicit Array(Vector<U,N> const & shape);
98
102 Array & operator=(Array const & other) {
103 if (&other != this) {
104 this->_data = other._data;
105 this->_core = other._core;
106 }
107 return *this;
108 }
109
116 template <typename T_, int C_>
117#ifndef DOXYGEN
118 typename boost::enable_if<detail::Convertible<N,T_,C_,T,C>, Array &>::type
119#else
120 Array &
121#endif
122 operator=(Array<T_,N,C_> const & other) {
123 this->_data = other._data;
124 this->_core = other._core;
125 return *this;
126 }
127
134 template <typename T_, int C_>
135#ifndef DOXYGEN
136 typename boost::enable_if<detail::Convertible<N,T_,C_,T,C>, Array &>::type
137#else
138 Array &
139#endif
141 this->_data = other._data;
142 this->_core = other._core;
143 return *this;
144 }
145
150 template <typename T_, int N_, int C_>
151 bool operator==(Array<T_,N_,C_> const & other) const {
152 return this->getData() == other.getData()
153 && this->getShape() == other.getShape()
154 && this->getStrides() == other.getStrides();
155 }
156
160 template <typename T_, int N_, int C_>
161 bool operator!=(Array<T_,N_,C_> const & other) const {
162 return !this->operator==(other);
163 }
164
166 void swap(Array & other) {
167 std::swap(this->_data, other._data);
168 this->_core.swap(other._core);
169 }
170
178 bool isUnique() const { return this->_core->isUnique(); }
179
180private:
181 template <typename T_, int N_, int C_> friend class Array;
182 template <typename T_, int N_, int C_> friend class ArrayRef;
183 template <typename T_, int N_, int C_> friend struct ArrayTraits;
184 template <typename Derived> friend class ArrayBase;
185 template <typename Array_> friend class detail::ArrayAccess;
186
188 Array(T * data, CorePtr const & core) : Super(data, core) {}
189};
190
191} // namespace ndarray
192
193#endif // !NDARRAY_Array_h_INCLUDED
Definition of ArrayBaseN, a dimension-specialized CRTP base class for Array and ArrayRef.
Traits for Array.
Definitions for Core.
Definition for Vector.
An intermediate CRTP base class for Array and ArrayRef.
Definition ArrayBaseN.h:29
CRTP implementation for Array and ArrayRef.
Definition ArrayBase.h:43
Element * getData() const
Return a raw pointer to the first element of the array.
Definition ArrayBase.h:130
Strides getStrides() const
Return a Vector of the strides of all dimensions.
Definition ArrayBase.h:152
Index getShape() const
Return a Vector of the sizes of all dimensions.
Definition ArrayBase.h:149
A proxy class for Array with deep assignment operators.
Definition ArrayRef.h:34
A multidimensional strided array.
Definition Array.h:35
bool operator==(Array< T_, N_, C_ > const &other) const
Shallow equality comparison: return true if the arrays share data and have the same shape and strides...
Definition Array.h:151
Array(Array< T_, N, C_ > const &other, typename boost::enable_if< detail::Convertible< N, T_, C_, T, C >, void * >::type=0)
Converting copy constructor.
Definition Array.h:60
Array(ArrayRef< T_, N, C_ > const &other, typename boost::enable_if< detail::Convertible< N, T_, C_, T, C >, void * >::type=0)
Converting copy constructor.
Definition Array.h:74
Array(Array const &other)
Non-converting copy constructor.
Definition Array.h:51
Array()
Default constructor.
Definition Array.h:46
Array & operator=(Array const &other)
Non-converting shallow assignment.
Definition Array.h:102
boost::enable_if< detail::Convertible< N, T_, C_, T, C >, Array & >::type operator=(ArrayRef< T_, N, C_ > const &other)
Converting shallow assignment.
Definition Array.h:140
bool isUnique() const
Return true if the Array is definitely unique.
Definition Array.h:178
void swap(Array &other)
Lightweight shallow swap.
Definition Array.h:166
boost::enable_if< detail::Convertible< N, T_, C_, T, C >, Array & >::type operator=(Array< T_, N, C_ > const &other)
Converting shallow assignment.
Definition Array.h:122
bool operator!=(Array< T_, N_, C_ > const &other) const
Shallow inequality comparison.
Definition Array.h:161
Definition ArrayAccess.h:26
Forward declarations and default template parameters for ndarray.
Dimension-specialized traits shared by Array and ArrayRef.
Definition ArrayTraits.h:44
A fixed-size 1D array class.
Definition Vector.h:82
Definition ArrayTraits.h:33
Public interface for arbitrary views into arrays.