NumCpp  2.8.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
asarray.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <array>
31 #include <deque>
32 #include <forward_list>
33 #include <initializer_list>
34 #include <iterator>
35 #include <list>
36 #include <set>
37 #include <vector>
38 
40 #include "NumCpp/NdArray.hpp"
41 
42 namespace nc
43 {
44  //============================================================================
45  // Method Description:
54  template<typename dtype, std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
55  NdArray<dtype> asarray(std::initializer_list<dtype> inList)
56  {
57  return NdArray<dtype>(inList);
58  }
59 
60  //============================================================================
61  // Method Description:
70  template<typename dtype>
71  NdArray<dtype> asarray(std::initializer_list<std::initializer_list<dtype>> inList)
72  {
73  return NdArray<dtype>(inList);
74  }
75 
76  //============================================================================
77  // Method Description:
87  template<typename dtype, size_t ArraySize, std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
88  NdArray<dtype> asarray(std::array<dtype, ArraySize>& inArray, bool copy = true)
89  {
90  return NdArray<dtype>(inArray, copy);
91  }
92 
93  //============================================================================
94  // Method Description:
104  template<typename dtype, size_t Dim0Size, size_t Dim1Size>
105  NdArray<dtype> asarray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& inArray, bool copy = true)
106  {
107  return NdArray<dtype>(inArray, copy);
108  }
109 
110  //============================================================================
111  // Method Description:
121  template<typename dtype, std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
122  NdArray<dtype> asarray(std::vector<dtype>& inVector, bool copy = true)
123  {
124  return NdArray<dtype>(inVector, copy);
125  }
126 
127  //============================================================================
128  // Method Description:
136  template<typename dtype>
137  NdArray<dtype> asarray(const std::vector<std::vector<dtype>>& inVector)
138  {
139  return NdArray<dtype>(inVector);
140  }
141 
142  //============================================================================
143  // Method Description:
153  template<typename dtype, size_t Dim1Size>
154  NdArray<dtype> asarray(std::vector<std::array<dtype, Dim1Size>>& inVector, bool copy = true)
155  {
156  return NdArray<dtype>(inVector, copy);
157  }
158 
159  //============================================================================
160  // Method Description:
168  template<typename dtype, std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
169  NdArray<dtype> asarray(const std::deque<dtype>& inDeque)
170  {
171  return NdArray<dtype>(inDeque);
172  }
173 
174  //============================================================================
175  // Method Description:
183  template<typename dtype>
184  NdArray<dtype> asarray(const std::deque<std::deque<dtype>>& inDeque)
185  {
186  return NdArray<dtype>(inDeque);
187  }
188 
189  //============================================================================
190  // Method Description:
198  template<typename dtype, typename dtypeComp>
199  NdArray<dtype> asarray(const std::set<dtype, dtypeComp>& inSet)
200  {
201  return NdArray<dtype>(inSet);
202  }
203 
204  //============================================================================
205  // Method Description:
213  template<typename dtype>
214  NdArray<dtype> asarray(const std::list<dtype>& inList)
215  {
216  return NdArray<dtype>(inList);
217  }
218 
219  //============================================================================
220  // Method Description:
229  template<typename Iterator>
230  auto asarray(Iterator iterBegin, Iterator iterEnd)
231  {
233  }
234 
235  //============================================================================
236  // Method Description:
245  template<typename dtype>
246  NdArray<dtype> asarray(const dtype* iterBegin, const dtype* iterEnd)
247  {
248  return NdArray<dtype>(iterBegin, iterEnd);
249  }
250 
251  //============================================================================
252  // Method Description:
261  template<typename dtype>
262  NdArray<dtype> asarray(const dtype* ptr, uint32 size)
263  {
264  return NdArray<dtype>(ptr, size);
265  }
266 
267  //============================================================================
268  // Method Description:
278  template<typename dtype>
279  NdArray<dtype> asarray(const dtype* ptr, uint32 numRows, uint32 numCols)
280  {
281  return NdArray<dtype>(ptr, numRows, numCols);
282  }
283 
284  //============================================================================
285  // Method Description:
296  template<typename dtype, typename BoolType, std::enable_if_t<std::is_same<BoolType, bool>::value, int> = 0>
297  NdArray<dtype> asarray(dtype* ptr, uint32 size, BoolType takeOwnership) noexcept
298  {
299  return NdArray<dtype>(ptr, size, takeOwnership);
300  }
301 
302  //============================================================================
303  // Method Description:
315  template<typename dtype, typename BoolType, std::enable_if_t<std::is_same<BoolType, bool>::value, int> = 0>
316  NdArray<dtype> asarray(dtype* ptr, uint32 numRows, uint32 numCols, BoolType takeOwnership) noexcept
317  {
318  return NdArray<dtype>(ptr, numRows, numCols, takeOwnership);
319  }
320 } // 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:43
NdArray< dtype > asarray(std::initializer_list< dtype > inList)
Definition: asarray.hpp:55
NdArray< dtype > copy(const NdArray< dtype > &inArray)
Definition: copy.hpp:44
std::uint32_t uint32
Definition: Types.hpp:40