@@ -515,10 +515,9 @@ static mp_obj_t numerical_argmin_argmax_ndarray(ndarray_obj_t *ndarray, mp_obj_t
515515        int8_t  ax  =  tools_get_axis (axis , ndarray -> ndim );
516516
517517        uint8_t  * array  =  (uint8_t  * )ndarray -> array ;
518-         size_t  * shape  =  m_new (size_t , ULAB_MAX_DIMS );
519-         memset (shape , 0 , sizeof (size_t )* ULAB_MAX_DIMS );
520-         int32_t  * strides  =  m_new (int32_t , ULAB_MAX_DIMS );
521-         memset (strides , 0 , sizeof (uint32_t )* ULAB_MAX_DIMS );
518+         size_t  * shape  =  m_new0 (size_t , ULAB_MAX_DIMS );
519+         int32_t  * strides  =  m_new0 (int32_t , ULAB_MAX_DIMS );
520+ 
522521        numerical_reduce_axes (ndarray , ax , shape , strides );
523522        uint8_t  index  =  ULAB_MAX_DIMS  -  ndarray -> ndim  +  ax ;
524523
@@ -543,6 +542,9 @@ static mp_obj_t numerical_argmin_argmax_ndarray(ndarray_obj_t *ndarray, mp_obj_t
543542        } else  {
544543            RUN_ARGMIN (ndarray , mp_float_t , array , results , rarray , shape , strides , index , optype );
545544        }
545+ 
546+         m_del (int32_t , strides , ULAB_MAX_DIMS );
547+ 
546548        if (results -> len  ==  1 ) {
547549            return  mp_binary_get_val_array (results -> dtype , results -> array , 0 );
548550        }
@@ -636,10 +638,9 @@ static mp_obj_t numerical_sort_helper(mp_obj_t oin, mp_obj_t axis, uint8_t inpla
636638        ax  =  tools_get_axis (axis , ndarray -> ndim );
637639    }
638640
639-     size_t  * shape  =  m_new (size_t , ULAB_MAX_DIMS );
640-     memset (shape , 0 , sizeof (size_t )* ULAB_MAX_DIMS );
641-     int32_t  * strides  =  m_new (int32_t , ULAB_MAX_DIMS );
642-     memset (strides , 0 , sizeof (uint32_t )* ULAB_MAX_DIMS );
641+     size_t  * shape  =  m_new0 (size_t , ULAB_MAX_DIMS );
642+     int32_t  * strides  =  m_new0 (int32_t , ULAB_MAX_DIMS );
643+ 
643644    numerical_reduce_axes (ndarray , ax , shape , strides );
644645    ax  =  ULAB_MAX_DIMS  -  ndarray -> ndim  +  ax ;
645646    // we work with the typed array, so re-scale the stride 
@@ -655,6 +656,9 @@ static mp_obj_t numerical_sort_helper(mp_obj_t oin, mp_obj_t axis, uint8_t inpla
655656            HEAPSORT (ndarray , mp_float_t , array , shape , strides , ax , increment , ndarray -> shape [ax ]);
656657        }
657658    }
659+ 
660+     m_del (int32_t , strides , ULAB_MAX_DIMS );
661+ 
658662    if (inplace  ==  1 ) {
659663        return  mp_const_none ;
660664    } else  {
@@ -733,17 +737,15 @@ mp_obj_t numerical_argsort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
733737    }
734738    int8_t  ax  =  tools_get_axis (args [1 ].u_obj , ndarray -> ndim );
735739
736-     size_t  * shape  =  m_new (size_t , ULAB_MAX_DIMS );
737-     memset (shape , 0 , sizeof (size_t )* ULAB_MAX_DIMS );
738-     int32_t  * strides  =  m_new (int32_t , ULAB_MAX_DIMS );
739-     memset (strides , 0 , sizeof (uint32_t )* ULAB_MAX_DIMS );
740+     size_t  * shape  =  m_new0 (size_t , ULAB_MAX_DIMS );
741+     int32_t  * strides  =  m_new0 (int32_t , ULAB_MAX_DIMS );
740742    numerical_reduce_axes (ndarray , ax , shape , strides );
741743
742744    // We could return an NDARRAY_UINT8 array, if all lengths are shorter than 256 
743745    ndarray_obj_t  * indices  =  ndarray_new_ndarray (ndarray -> ndim , ndarray -> shape , NULL , NDARRAY_UINT16 );
744-     int32_t  * istrides  =  m_new (int32_t , ULAB_MAX_DIMS );
745-     memset (istrides , 0 , sizeof (uint32_t )* ULAB_MAX_DIMS );
746+     int32_t  * istrides  =  m_new0 (int32_t , ULAB_MAX_DIMS );
746747    numerical_reduce_axes (indices , ax , shape , istrides );
748+ 
747749    for (uint8_t  i = 0 ; i  <  ULAB_MAX_DIMS ; i ++ ) {
748750        istrides [i ] /= sizeof (uint16_t );
749751    }
@@ -804,6 +806,11 @@ mp_obj_t numerical_argsort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
804806            HEAP_ARGSORT (ndarray , mp_float_t , array , shape , strides , ax , increment , ndarray -> shape [ax ], iarray , istrides , iincrement );
805807        }
806808    }
809+ 
810+     m_del (size_t , shape , ULAB_MAX_DIMS );
811+     m_del (int32_t , strides , ULAB_MAX_DIMS );
812+     m_del (int32_t , istrides , ULAB_MAX_DIMS );
813+ 
807814    return  MP_OBJ_FROM_PTR (indices );
808815}
809816
@@ -931,13 +938,12 @@ mp_obj_t numerical_diff(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
931938
932939    int8_t  * stencil  =  m_new (int8_t , N + 1 );
933940    stencil [0 ] =  1 ;
934-     for (uint8_t  i = 1 ; i  <  N + 1 ; i ++ ) {
941+     for (uint8_t  i   =   1 ; i  <  N + 1 ; i ++ ) {
935942        stencil [i ] =  - stencil [i - 1 ]* (N - i + 1 )/i ;
936943    }
937944
938-     size_t  * shape  =  m_new (size_t , ULAB_MAX_DIMS );
939-     memset (shape , 0 , sizeof (size_t )* ULAB_MAX_DIMS );
940-     for (uint8_t  i = 0 ; i  <  ULAB_MAX_DIMS ; i ++ ) {
945+     size_t  * shape  =  m_new0 (size_t , ULAB_MAX_DIMS );
946+     for (uint8_t  i  =  0 ; i  <  ULAB_MAX_DIMS ; i ++ ) {
941947        shape [i ] =  ndarray -> shape [i ];
942948        if (i  ==  index ) {
943949            shape [i ] -=  N ;
@@ -948,8 +954,7 @@ mp_obj_t numerical_diff(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
948954    uint8_t  * rarray  =  (uint8_t  * )results -> array ;
949955
950956    memset (shape , 0 , sizeof (size_t )* ULAB_MAX_DIMS );
951-     int32_t  * strides  =  m_new (int32_t , ULAB_MAX_DIMS );
952-     memset (strides , 0 , sizeof (int32_t )* ULAB_MAX_DIMS );
957+     int32_t  * strides  =  m_new0 (int32_t , ULAB_MAX_DIMS );
953958    numerical_reduce_axes (ndarray , ax , shape , strides );
954959
955960    if (ndarray -> dtype  ==  NDARRAY_UINT8 ) {
@@ -1083,13 +1088,14 @@ mp_obj_t numerical_median(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_
10831088    } else  {
10841089        int8_t  ax  =  tools_get_axis (args [1 ].u_obj , ndarray -> ndim );
10851090
1086-         size_t  * shape  =  m_new (size_t , ULAB_MAX_DIMS );
1087-         memset (shape , 0 , sizeof (size_t )* ULAB_MAX_DIMS );
1088-         int32_t  * strides  =  m_new (int32_t , ULAB_MAX_DIMS );
1089-         memset (strides , 0 , sizeof (uint32_t )* ULAB_MAX_DIMS );
1091+         size_t  * shape  =  m_new0 (size_t , ULAB_MAX_DIMS );
1092+         int32_t  * strides  =  m_new0 (int32_t , ULAB_MAX_DIMS );
10901093        numerical_reduce_axes (ndarray , ax , shape , strides );
1094+ 
10911095        ax  =  ULAB_MAX_DIMS  -  ndarray -> ndim  +  ax ;
10921096        ndarray_obj_t  * results  =  ndarray_new_dense_ndarray (ndarray -> ndim - 1 , shape , NDARRAY_FLOAT );
1097+         m_del (size_t , shape , ULAB_MAX_DIMS );
1098+ 
10931099        mp_float_t  * rarray  =  (mp_float_t  * )results -> array ;
10941100
10951101        uint8_t  * array  =  (uint8_t  * )ndarray -> array ;
@@ -1237,16 +1243,12 @@ mp_obj_t numerical_roll(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
12371243    } else  if (mp_obj_is_int (args [2 ].u_obj )){
12381244        int8_t  ax  =  tools_get_axis (args [2 ].u_obj , ndarray -> ndim );
12391245
1240-         size_t  * shape  =  m_new (size_t , ULAB_MAX_DIMS );
1241-         memset (shape , 0 , sizeof (size_t )* ULAB_MAX_DIMS );
1242-         int32_t  * strides  =  m_new (int32_t , ULAB_MAX_DIMS );
1243-         memset (strides , 0 , sizeof (int32_t )* ULAB_MAX_DIMS );
1246+         size_t  * shape  =  m_new0 (size_t , ULAB_MAX_DIMS );
1247+         int32_t  * strides  =  m_new0 (int32_t , ULAB_MAX_DIMS );
12441248        numerical_reduce_axes (ndarray , ax , shape , strides );
12451249
1246-         size_t  * rshape  =  m_new (size_t , ULAB_MAX_DIMS );
1247-         memset (rshape , 0 , sizeof (size_t )* ULAB_MAX_DIMS );
1248-         int32_t  * rstrides  =  m_new (int32_t , ULAB_MAX_DIMS );
1249-         memset (rstrides , 0 , sizeof (int32_t )* ULAB_MAX_DIMS );
1250+         size_t  * rshape  =  m_new0 (size_t , ULAB_MAX_DIMS );
1251+         int32_t  * rstrides  =  m_new0 (int32_t , ULAB_MAX_DIMS );
12501252        numerical_reduce_axes (results , ax , rshape , rstrides );
12511253
12521254        ax  =  ULAB_MAX_DIMS  -  ndarray -> ndim  +  ax ;
@@ -1307,9 +1309,16 @@ mp_obj_t numerical_roll(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
13071309            i ++ ;
13081310        } while (i  <  shape [ULAB_MAX_DIMS  -  3 ]);
13091311        #endif 
1312+ 
1313+         m_del (size_t , shape , ULAB_MAX_DIMS );
1314+         m_del (int32_t , strides , ULAB_MAX_DIMS );
1315+         m_del (size_t , rshape , ULAB_MAX_DIMS );
1316+         m_del (int32_t , rstrides , ULAB_MAX_DIMS );
1317+ 
13101318    } else  {
13111319        mp_raise_TypeError (translate ("wrong  axis  index "));
13121320    }
1321+ 
13131322    return  results ;
13141323}
13151324
0 commit comments