NumCpp  1.0
A C++ implementation of the Python Numpy library
asarray.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
33 
34 #include <array>
35 #include <deque>
36 #include <forward_list>
37 #include <initializer_list>
38 #include <iterator>
39 #include <list>
40 #include <set>
41 #include <vector>
42 
43 namespace nc
44 {
45  //============================================================================
46  // Method Description:
57  template<typename dtype,
58  std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
59  NdArray<dtype> asarray(std::initializer_list<dtype> inList)
60  {
61  return NdArray<dtype>(inList);
62  }
63 
64  //============================================================================
65  // Method Description:
76  template<typename dtype>
77  NdArray<dtype> asarray(std::initializer_list<std::initializer_list<dtype> > inList)
78  {
79  return NdArray<dtype>(inList);
80  }
81 
82  //============================================================================
83  // Method Description:
94  template<typename dtype, size_t ArraySize,
95  std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
96  NdArray<dtype> asarray(std::array<dtype, ArraySize>& inArray, bool copy = true)
97  {
98  return NdArray<dtype>(inArray, copy);
99  }
100 
101  //============================================================================
102  // Method Description:
113  template<typename dtype, size_t Dim0Size, size_t Dim1Size>
114  NdArray<dtype> asarray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& inArray, bool copy = true)
115  {
116  return NdArray<dtype>(inArray, copy);
117  }
118 
119  //============================================================================
120  // Method Description:
131  template<typename dtype,
132  std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
133  NdArray<dtype> asarray(std::vector<dtype>& inVector, bool copy = true)
134  {
135  return NdArray<dtype>(inVector, copy);
136  }
137 
138  //============================================================================
139  // Method Description:
148  template<typename dtype>
149  NdArray<dtype> asarray(const std::vector<std::vector<dtype>>& inVector)
150  {
151  return NdArray<dtype>(inVector);
152  }
153 
154  //============================================================================
155  // Method Description:
166  template<typename dtype, size_t Dim1Size>
167  NdArray<dtype> asarray(std::vector<std::array<dtype, Dim1Size>>& inVector, bool copy = true)
168  {
169  return NdArray<dtype>(inVector, copy);
170  }
171 
172  //============================================================================
173  // Method Description:
182  template<typename dtype,
183  std::enable_if_t<is_valid_dtype_v<dtype>, int> = 0>
184  NdArray<dtype> asarray(const std::deque<dtype>& inDeque)
185  {
186  return NdArray<dtype>(inDeque);
187  }
188 
189  //============================================================================
190  // Method Description:
199  template<typename dtype>
200  NdArray<dtype> asarray(const std::deque<std::deque<dtype>>& inDeque)
201  {
202  return NdArray<dtype>(inDeque);
203  }
204 
205  //============================================================================
206  // Method Description:
216  template<typename dtype, typename dtypeComp>
217  NdArray<dtype> asarray(const std::set<dtype, dtypeComp>& inSet)
218  {
219  return NdArray<dtype>(inSet);
220  }
221 
222  //============================================================================
223  // Method Description:
233  template<typename dtype>
234  NdArray<dtype> asarray(const std::list<dtype>& inList)
235  {
236  return NdArray<dtype>(inList);
237  }
238 
239  //============================================================================
240  // Method Description:
250  template<typename Iterator>
251  auto asarray(Iterator iterBegin, Iterator iterEnd)
252  {
254  }
255 
256  //============================================================================
257  // Method Description:
267  template<typename dtype>
268  NdArray<dtype> asarray(const dtype* iterBegin, const dtype* iterEnd)
269  {
270  return NdArray<dtype>(iterBegin, iterEnd);
271  }
272 
273  //============================================================================
274  // Method Description:
284  template<typename dtype>
285  NdArray<dtype> asarray(const dtype* ptr, uint32 size)
286  {
287  return NdArray<dtype>(ptr, size);
288  }
289 
290  //============================================================================
291  // Method Description:
302  template<typename dtype>
303  NdArray<dtype> asarray(const dtype* ptr, uint32 numRows, uint32 numCols)
304  {
305  return NdArray<dtype>(ptr, numRows, numCols);
306  }
307 
308  //============================================================================
309  // Method Description:
321  template<typename dtype, typename Bool,
322  std::enable_if_t<std::is_same<Bool, bool>::value, int> = 0>
323  NdArray<dtype> asarray(dtype* ptr, uint32 size, Bool takeOwnership) noexcept
324  {
325  return NdArray<dtype>(ptr, size, takeOwnership);
326  }
327 
328  //============================================================================
329  // Method Description:
342  template<typename dtype, typename Bool,
343  std::enable_if_t<std::is_same<Bool, bool>::value, int> = 0>
344  NdArray<dtype> asarray(dtype* ptr, uint32 numRows, uint32 numCols, Bool takeOwnership) noexcept
345  {
346  return NdArray<dtype>(ptr, numRows, numCols, takeOwnership);
347  }
348 }
nc::size
uint32 size(const NdArray< dtype > &inArray) noexcept
Definition: size.hpp:46
nc::asarray
NdArray< dtype > asarray(std::initializer_list< dtype > inList)
Definition: asarray.hpp:59
nc::NdArray< dtype >
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
NdArray.hpp
nc
Definition: Coordinate.hpp:45
TypeTraits.hpp
nc::copy
NdArray< dtype > copy(const NdArray< dtype > &inArray)
Definition: copy.hpp:47