NumCpp  2.7.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 
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:
54  template<typename dtype,
55  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,
89  std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
90  NdArray<dtype> asarray(std::array<dtype, ArraySize>& inArray, bool copy = true)
91  {
92  return NdArray<dtype>(inArray, copy);
93  }
94 
95  //============================================================================
96  // Method Description:
106  template<typename dtype, size_t Dim0Size, size_t Dim1Size>
107  NdArray<dtype> asarray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& inArray, bool copy = true)
108  {
109  return NdArray<dtype>(inArray, copy);
110  }
111 
112  //============================================================================
113  // Method Description:
123  template<typename dtype,
124  std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
125  NdArray<dtype> asarray(std::vector<dtype>& inVector, bool copy = true)
126  {
127  return NdArray<dtype>(inVector, copy);
128  }
129 
130  //============================================================================
131  // Method Description:
139  template<typename dtype>
140  NdArray<dtype> asarray(const std::vector<std::vector<dtype>>& inVector)
141  {
142  return NdArray<dtype>(inVector);
143  }
144 
145  //============================================================================
146  // Method Description:
156  template<typename dtype, size_t Dim1Size>
157  NdArray<dtype> asarray(std::vector<std::array<dtype, Dim1Size>>& inVector, bool copy = true)
158  {
159  return NdArray<dtype>(inVector, copy);
160  }
161 
162  //============================================================================
163  // Method Description:
171  template<typename dtype,
172  std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
173  NdArray<dtype> asarray(const std::deque<dtype>& inDeque)
174  {
175  return NdArray<dtype>(inDeque);
176  }
177 
178  //============================================================================
179  // Method Description:
187  template<typename dtype>
188  NdArray<dtype> asarray(const std::deque<std::deque<dtype>>& inDeque)
189  {
190  return NdArray<dtype>(inDeque);
191  }
192 
193  //============================================================================
194  // Method Description:
202  template<typename dtype, typename dtypeComp>
203  NdArray<dtype> asarray(const std::set<dtype, dtypeComp>& inSet)
204  {
205  return NdArray<dtype>(inSet);
206  }
207 
208  //============================================================================
209  // Method Description:
217  template<typename dtype>
218  NdArray<dtype> asarray(const std::list<dtype>& inList)
219  {
220  return NdArray<dtype>(inList);
221  }
222 
223  //============================================================================
224  // Method Description:
233  template<typename Iterator>
234  auto asarray(Iterator iterBegin, Iterator iterEnd)
235  {
237  }
238 
239  //============================================================================
240  // Method Description:
249  template<typename dtype>
250  NdArray<dtype> asarray(const dtype* iterBegin, const dtype* iterEnd)
251  {
252  return NdArray<dtype>(iterBegin, iterEnd);
253  }
254 
255  //============================================================================
256  // Method Description:
265  template<typename dtype>
266  NdArray<dtype> asarray(const dtype* ptr, uint32 size)
267  {
268  return NdArray<dtype>(ptr, size);
269  }
270 
271  //============================================================================
272  // Method Description:
282  template<typename dtype>
283  NdArray<dtype> asarray(const dtype* ptr, uint32 numRows, uint32 numCols)
284  {
285  return NdArray<dtype>(ptr, numRows, numCols);
286  }
287 
288  //============================================================================
289  // Method Description:
300  template<typename dtype, typename Bool,
301  std::enable_if_t<std::is_same<Bool, bool>::value, int> = 0>
302  NdArray<dtype> asarray(dtype* ptr, uint32 size, Bool takeOwnership) noexcept
303  {
304  return NdArray<dtype>(ptr, size, takeOwnership);
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 numRows, uint32 numCols, Bool takeOwnership) noexcept
323  {
324  return NdArray<dtype>(ptr, numRows, numCols, takeOwnership);
325  }
326 } // 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:56
NdArray< dtype > copy(const NdArray< dtype > &inArray)
Definition: copy.hpp:44
std::uint32_t uint32
Definition: Types.hpp:40