NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
asarray.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <array>
31#include <deque>
32#include <initializer_list>
33#include <iterator>
34#include <list>
35#include <set>
36#include <type_traits>
37#include <vector>
38
39#include "NumCpp/Core/Enums.hpp"
41#include "NumCpp/NdArray.hpp"
42
43namespace nc
44{
45 //============================================================================
46 // Method Description:
55 template<typename dtype, std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
56 NdArray<dtype> asarray(std::initializer_list<dtype> inList)
57 {
58 return NdArray<dtype>(inList);
59 }
60
61 //============================================================================
62 // Method Description:
71 template<typename dtype>
72 NdArray<dtype> asarray(std::initializer_list<std::initializer_list<dtype>> inList)
73 {
74 return NdArray<dtype>(inList);
75 }
76
77 //============================================================================
78 // Method Description:
88 template<typename dtype, size_t ArraySize, std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
89 NdArray<dtype> asarray(std::array<dtype, ArraySize>& inArray, PointerPolicy pointerPolicy = PointerPolicy::COPY)
90 {
91 return NdArray<dtype>(inArray, pointerPolicy);
92 }
93
94 //============================================================================
95 // Method Description:
105 template<typename dtype, size_t Dim0Size, size_t Dim1Size>
106 NdArray<dtype> asarray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& inArray,
107 PointerPolicy pointerPolicy = PointerPolicy::COPY)
108 {
109 return NdArray<dtype>(inArray, pointerPolicy);
110 }
111
112 //============================================================================
113 // Method Description:
123 template<typename dtype, std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
124 NdArray<dtype> asarray(std::vector<dtype>& inVector, PointerPolicy pointerPolicy = PointerPolicy::COPY)
125 {
126 return NdArray<dtype>(inVector, pointerPolicy);
127 }
128
129 //============================================================================
130 // Method Description:
138 template<typename dtype>
139 NdArray<dtype> asarray(const std::vector<std::vector<dtype>>& inVector)
140 {
141 return NdArray<dtype>(inVector);
142 }
143
144 //============================================================================
145 // Method Description:
155 template<typename dtype, size_t Dim1Size>
156 NdArray<dtype> asarray(std::vector<std::array<dtype, Dim1Size>>& inVector,
157 PointerPolicy pointerPolicy = PointerPolicy::COPY)
158 {
159 return NdArray<dtype>(inVector, pointerPolicy);
160 }
161
162 //============================================================================
163 // Method Description:
171 template<typename dtype, std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
172 NdArray<dtype> asarray(const std::deque<dtype>& inDeque)
173 {
174 return NdArray<dtype>(inDeque);
175 }
176
177 //============================================================================
178 // Method Description:
186 template<typename dtype>
187 NdArray<dtype> asarray(const std::deque<std::deque<dtype>>& inDeque)
188 {
189 return NdArray<dtype>(inDeque);
190 }
191
192 //============================================================================
193 // Method Description:
201 template<typename dtype, typename dtypeComp>
202 NdArray<dtype> asarray(const std::set<dtype, dtypeComp>& inSet)
203 {
204 return NdArray<dtype>(inSet);
205 }
206
207 //============================================================================
208 // Method Description:
216 template<typename dtype>
217 NdArray<dtype> asarray(const std::list<dtype>& inList)
218 {
219 return NdArray<dtype>(inList);
220 }
221
222 //============================================================================
223 // Method Description:
232 template<typename Iterator>
233 auto asarray(Iterator iterBegin, Iterator iterEnd)
234 {
236 }
237
238 //============================================================================
239 // Method Description:
248 template<typename dtype>
249 NdArray<dtype> asarray(const dtype* iterBegin, const dtype* iterEnd)
250 {
251 return NdArray<dtype>(iterBegin, iterEnd);
252 }
253
254 //============================================================================
255 // Method Description:
264 template<typename dtype>
266 {
267 return NdArray<dtype>(ptr, size);
268 }
269
270 //============================================================================
271 // Method Description:
281 template<typename dtype>
282 NdArray<dtype> asarray(const dtype* ptr, uint32 numRows, uint32 numCols)
283 {
284 return NdArray<dtype>(ptr, numRows, numCols);
285 }
286
287 //============================================================================
288 // Method Description:
299 template<typename dtype,
300 typename UIntType,
301 std::enable_if_t<std::is_integral_v<UIntType> && !std::is_same_v<UIntType, bool>, int> = 0>
302 NdArray<dtype> asarray(dtype* ptr, UIntType size, PointerPolicy pointerPolicy = PointerPolicy::COPY) noexcept
303 {
304 return NdArray<dtype>(ptr, size, pointerPolicy);
305 }
306
307 //============================================================================
308 // Method Description:
320 template<typename dtype,
321 typename UIntType1,
322 typename UIntType2,
323 std::enable_if_t<std::is_integral_v<UIntType1> && !std::is_same_v<UIntType1, bool>, int> = 0,
324 std::enable_if_t<std::is_integral_v<UIntType2> && !std::is_same_v<UIntType2, bool>, int> = 0>
326 UIntType1 numRows,
327 UIntType2 numCols,
328 PointerPolicy pointerPolicy = PointerPolicy::COPY) noexcept
329 {
330 return NdArray<dtype>(ptr, numRows, numCols, pointerPolicy);
331 }
332} // namespace nc
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
Definition Cartesian.hpp:39
uint32 size(const NdArray< dtype > &inArray) noexcept
Definition size.hpp:43
NdArray< dtype > asarray(std::initializer_list< dtype > inList)
Definition asarray.hpp:56
PointerPolicy
Policy for NdArray constructor that takes in a pointer to data.
Definition Enums.hpp:56
@ COPY
Definition Enums.hpp:57
std::uint32_t uint32
Definition Types.hpp:40