From 09e5a5dbc0579ea96c226ac00076a8d39e58e2c8 Mon Sep 17 00:00:00 2001
From: Justin Carpentier <justin.carpentier@inria.fr>
Date: Fri, 30 Jul 2021 13:54:52 +0200
Subject: [PATCH] types: add fill function

---
 include/eigenpy/register.hpp  |  1 +
 include/eigenpy/user-type.hpp | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/include/eigenpy/register.hpp b/include/eigenpy/register.hpp
index f57d847..c658616 100644
--- a/include/eigenpy/register.hpp
+++ b/include/eigenpy/register.hpp
@@ -86,6 +86,7 @@ namespace eigenpy
                                PyArray_CopySwapFunc * copyswap,
                                PyArray_CopySwapNFunc * copyswapn,
                                PyArray_DotFunc * dotfunc,
+                               PyArray_FillFunc * fill,
                                PyArray_FillWithScalarFunc * fillwithscalar);
     
     static Register & instance();
diff --git a/include/eigenpy/user-type.hpp b/include/eigenpy/user-type.hpp
index 0e7cd93..53d08de 100644
--- a/include/eigenpy/user-type.hpp
+++ b/include/eigenpy/user-type.hpp
@@ -24,6 +24,7 @@ namespace eigenpy
       inline static npy_bool nonzero(void * /*ip*/, void * /*array*/) /*{ return (npy_bool)false; }*/;
       inline static void dotfunc(void * /*ip0_*/, npy_intp /*is0*/, void * /*ip1_*/, npy_intp /*is1*/,
                           void * /*op*/, npy_intp /*n*/, void * /*arr*/);
+      inline static int fill(void* data_, npy_intp length, void* arr);
       inline static int fillwithscalar(void* buffer_, npy_intp length,
                                        void* value, void* arr);
 //      static void cast(void * /*from*/, void * /*to*/, npy_intp /*n*/, void * /*fromarr*/, void * /*toarr*/) {};
@@ -205,6 +206,21 @@ namespace eigenpy
 //      static void cast(void * from, void * to, npy_intp n, void * fromarr, void * toarr)
 //      {
 //      }
+      
+      static int fill(void* data_, npy_intp length, void* /*arr*/)
+      {
+//        std::cout << "fillwithscalar" << std::endl;
+        T* data = static_cast<T*>(data_);
+        const T delta = data[1] - data[0];
+        T r = data[1];
+        npy_intp i;
+        for (i = 2; i < length; i++) {
+          r = r + delta;
+          data[i] = r;
+        }
+        return 0;
+      }
+      
 
     };  //     struct SpecialMethods<T,NPY_USERDEF>
   
@@ -233,6 +249,7 @@ namespace eigenpy
     PyArray_CopySwapFunc * copyswap = &internal::SpecialMethods<Scalar>::copyswap;
     PyArray_CopySwapNFunc * copyswapn = reinterpret_cast<PyArray_CopySwapNFunc*>(&internal::SpecialMethods<Scalar>::copyswapn);
     PyArray_DotFunc * dotfunc = &internal::SpecialMethods<Scalar>::dotfunc;
+    PyArray_FillFunc * fill = &internal::SpecialMethods<Scalar>::fill;
     PyArray_FillWithScalarFunc * fillwithscalar = &internal::SpecialMethods<Scalar>::fillwithscalar;
 //    PyArray_CastFunc * cast = &internal::SpecialMethods<Scalar>::cast;
     
@@ -243,6 +260,7 @@ namespace eigenpy
                                          getitem, setitem, nonzero,
                                          copyswap, copyswapn,
                                          dotfunc,
+                                         fill,
                                          fillwithscalar);
     
     call_PyArray_RegisterCanCast(call_PyArray_DescrFromType(NPY_OBJECT),
-- 
GitLab