NumCpp  2.6.2
A Templatized Header Only C++ Implementation of the Python NumPy Library
asarray.hpp
Go to the documentation of this file.
1 
28 #pragma once
29 
31 #include "NumCpp/NdArray.hpp"
32 
33 #include <array>
34 #include <deque>
35 #include <forward_list>
36 #include <initializer_list>
37 #include <iterator>
38 #include <list>
39 #include <set>
40 #include <vector>
41 
42 namespace nc
43 {
44  //============================================================================
45  // Method Description:
56  template<typename dtype,
57  std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
58  NdArray<dtype> asarray(std::initializer_list<dtype> inList)
59  {
60  return NdArray<dtype>(inList);
61  }
62 
63  //============================================================================
64  // Method Description:
75  template<typename dtype>
76  NdArray<dtype> asarray(std::initializer_list<std::initializer_list<dtype> > inList)
77  {
78  return NdArray<dtype>(inList);
79  }
80 
81  //============================================================================
82  // Method Description:
93  template<typename dtype, size_t ArraySize,
94  std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
95  NdArray<dtype> asarray(std::array<dtype, ArraySize>& inArray, bool copy = true)
96  {
97  return NdArray<dtype>(inArray, copy);
98  }
99 
100  //============================================================================
101  // Method Description:
112  template<typename dtype, size_t Dim0Size, size_t Dim1Size>
113  NdArray<dtype> asarray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& inArray, bool copy = true)
114  {
115  return NdArray<dtype>(inArray, copy);
116  }
117 
118  //============================================================================
119  // Method Description:
130  template<typename dtype,
131  std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
132  NdArray<dtype> asarray(std::vector<dtype>& inVector, bool copy = true)
133  {
134  return NdArray<dtype>(inVector, copy);
135  }
136 
137  //============================================================================
138  // Method Description:
147  template<typename dtype>
148  NdArray<dtype> asarray(const std::vector<std::vector<dtype>>& inVector)
149  {
150  return NdArray<dtype>(inVector);
151  }
152 
153  //============================================================================
154  // Method Description:
165  template<typename dtype, size_t Dim1Size>
166  NdArray<dtype> asarray(std::vector<std::array<dtype, Dim1Size>>& inVector, bool copy = true)
167  {
168  return NdArray<dtype>(inVector, copy);
169  }
170 
171  //============================================================================
172  // Method Description:
181  template<typename dtype,
182  std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
183  NdArray<dtype> asarray(const std::deque<dtype>& inDeque)
184  {
185  return NdArray<dtype>(inDeque);
186  }
187 
188  //============================================================================
189  // Method Description:
198  template<typename dtype>
199  NdArray<dtype> asarray(const std::deque<std::deque<dtype>>& inDeque)
200  {
201  return NdArray<dtype>(inDeque);
202  }
203 
204  //============================================================================
205  // Method Description:
215  template<typename dtype, typename dtypeComp>
216  NdArray<dtype> asarray(const std::set<dtype, dtypeComp>& inSet)
217  {
218  return NdArray<dtype>(inSet);
219  }
220 
221  //============================================================================
222  // Method Description:
232  template<typename dtype>
233  NdArray<dtype> asarray(const std::list<dtype>& inList)
234  {
235  return NdArray<dtype>(inList);
236  }
237 
238  //============================================================================
239  // Method Description:
249  template<typename Iterator>
250  auto asarray(Iterator iterBegin, Iterator iterEnd)
251  {
253  }
254 
255  //============================================================================
256  // Method Description:
266  template<typename dtype>
267  NdArray<dtype> asarray(const dtype* iterBegin, const dtype* iterEnd)
268  {
269  return NdArray<dtype>(iterBegin, iterEnd);
270  }
271 
272  //============================================================================
273  // Method Description:
283  template<typename dtype>
284  NdArray<dtype> asarray(const dtype* ptr, uint32 size)
285  {
286  return NdArray<dtype>(ptr, size);
287  }
288 
289  //============================================================================
290  // Method Description:
301  template<typename dtype>
302  NdArray<dtype> asarray(const dtype* ptr, uint32 numRows, uint32 numCols)
303  {
304  return NdArray<dtype>(ptr, numRows, numCols);
305  }
306 
307  //============================================================================
308  // Method Description:
320  template<typename dtype, typename Bool,
321  std::enable_if_t<std::is_same<Bool, bool>::value, int> = 0>
322  NdArray<dtype> asarray(dtype* ptr, uint32 size, Bool takeOwnership) noexcept
323  {
324  return NdArray<dtype>(ptr, size, takeOwnership);
325  }
326 
327  //============================================================================
328  // Method Description:
341  template<typename dtype, typename Bool,
342  std::enable_if_t<std::is_same<Bool, bool>::value, int> = 0>
343  NdArray<dtype> asarray(dtype* ptr, uint32 numRows, uint32 numCols, Bool takeOwnership) noexcept
344  {
345  return NdArray<dtype>(ptr, numRows, numCols, takeOwnership);
346  }
347 } // namespace nc
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
Definition: Coordinate.hpp:45
uint32 size(const NdArray< dtype > &inArray) noexcept
Definition: size.hpp:45
NdArray< dtype > asarray(std::initializer_list< dtype > inList)
Definition: asarray.hpp:58
NdArray< dtype > copy(const NdArray< dtype > &inArray)
Definition: copy.hpp:46
std::uint32_t uint32
Definition: Types.hpp:40