summaryrefslogtreecommitdiffstats
path: root/contrib/python/pythran/pythran/pythonic/numpy/append.hpp
diff options
context:
space:
mode:
authormaxim-yurchuk <[email protected]>2024-10-09 12:29:46 +0300
committermaxim-yurchuk <[email protected]>2024-10-09 13:14:22 +0300
commit9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80 (patch)
treea8fb3181d5947c0d78cf402aa56e686130179049 /contrib/python/pythran/pythran/pythonic/numpy/append.hpp
parenta44b779cd359f06c3ebbef4ec98c6b38609d9d85 (diff)
publishFullContrib: true for ydb
<HIDDEN_URL> commit_hash:c82a80ac4594723cebf2c7387dec9c60217f603e
Diffstat (limited to 'contrib/python/pythran/pythran/pythonic/numpy/append.hpp')
-rw-r--r--contrib/python/pythran/pythran/pythonic/numpy/append.hpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/contrib/python/pythran/pythran/pythonic/numpy/append.hpp b/contrib/python/pythran/pythran/pythonic/numpy/append.hpp
new file mode 100644
index 00000000000..c2d4590a72d
--- /dev/null
+++ b/contrib/python/pythran/pythran/pythonic/numpy/append.hpp
@@ -0,0 +1,61 @@
+#ifndef PYTHONIC_NUMPY_APPEND_HPP
+#define PYTHONIC_NUMPY_APPEND_HPP
+
+#include "pythonic/include/numpy/append.hpp"
+
+#include "pythonic/utils/functor.hpp"
+#include "pythonic/types/ndarray.hpp"
+#include "pythonic/numpy/asarray.hpp"
+
+PYTHONIC_NS_BEGIN
+
+namespace numpy
+{
+ template <class T, class pS, class F>
+ typename std::enable_if<
+ !types::is_dtype<F>::value,
+ types::ndarray<
+ typename __combined<T, typename types::dtype_of<F>::type>::type,
+ types::pshape<long>>>::type
+ append(types::ndarray<T, pS> const &nto, F const &data)
+ {
+ auto ndata = numpy::functor::asarray{}(data);
+ long nsize = nto.flat_size() + ndata.flat_size();
+ types::ndarray<
+ typename __combined<T, typename types::dtype_of<F>::type>::type,
+ types::pshape<long>>
+ out(types::pshape<long>(nsize), builtins::None);
+ auto out_back = std::copy(nto.fbegin(), nto.fend(), out.fbegin());
+ std::copy(ndata.fbegin(), ndata.fend(), out_back);
+ return out;
+ }
+ template <class T, class pS, class F>
+ typename std::enable_if<
+ types::is_dtype<F>::value,
+ types::ndarray<
+ typename __combined<T, typename types::dtype_of<F>::type>::type,
+ types::pshape<long>>>::type
+ append(types::ndarray<T, pS> const &nto, F const &data)
+ {
+ long nsize = nto.flat_size() + 1;
+ types::ndarray<
+ typename __combined<T, typename types::dtype_of<F>::type>::type,
+ types::pshape<long>>
+ out(types::pshape<long>(nsize), builtins::None);
+ auto out_back = std::copy(nto.fbegin(), nto.fend(), out.fbegin());
+ *out_back = data;
+ return out;
+ }
+
+ template <class T, class F>
+ types::ndarray<typename __combined<typename types::dtype_of<T>::type,
+ typename types::dtype_of<F>::type>::type,
+ types::pshape<long>>
+ append(T const &to, F const &data)
+ {
+ return append(numpy::functor::asarray{}(to), data);
+ }
+}
+PYTHONIC_NS_END
+
+#endif