@@ -248,6 +248,105 @@ mp_obj_t ndarray_binary_add(ndarray_obj_t *lhs, ndarray_obj_t *rhs,
248248}
249249#endif /* NDARRAY_HAS_BINARY_OP_ADD */
250250
251+ #if NDARRAY_HAS_BINARY_OP_MODULO
252+ mp_obj_t ndarray_binary_modulo (ndarray_obj_t * lhs , ndarray_obj_t * rhs ,
253+ uint8_t ndim , size_t * shape , int32_t * lstrides , int32_t * rstrides ) {
254+
255+ ndarray_obj_t * results = NULL ;
256+ uint8_t * larray = (uint8_t * )lhs -> array ;
257+ uint8_t * rarray = (uint8_t * )rhs -> array ;
258+
259+ if (lhs -> dtype == NDARRAY_UINT8 ) {
260+ if (rhs -> dtype == NDARRAY_UINT8 ) {
261+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_UINT8 );
262+ BINARY_LOOP (results , uint8_t , uint8_t , uint8_t , larray , lstrides , rarray , rstrides , %);
263+ } else if (rhs -> dtype == NDARRAY_INT8 ) {
264+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_INT16 );
265+ BINARY_LOOP (results , int16_t , uint8_t , int8_t , larray , lstrides , rarray , rstrides , %);
266+ } else if (rhs -> dtype == NDARRAY_UINT16 ) {
267+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_UINT16 );
268+ BINARY_LOOP (results , uint16_t , uint8_t , uint16_t , larray , lstrides , rarray , rstrides , %);
269+ } else if (rhs -> dtype == NDARRAY_INT16 ) {
270+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_INT16 );
271+ BINARY_LOOP (results , int16_t , uint8_t , int16_t , larray , lstrides , rarray , rstrides , %);
272+ } else if (rhs -> dtype == NDARRAY_FLOAT ) {
273+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
274+ MODULO_FLOAT_LOOP (results , mp_float_t , uint8_t , mp_float_t , larray , lstrides , rarray , rstrides );
275+ }
276+ } else if (lhs -> dtype == NDARRAY_INT8 ) {
277+ if (rhs -> dtype == NDARRAY_UINT8 ) {
278+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_INT16 );
279+ BINARY_LOOP (results , int16_t , int8_t , uint8_t , larray , lstrides , rarray , rstrides , %);
280+ } else if (rhs -> dtype == NDARRAY_INT8 ) {
281+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_INT8 );
282+ BINARY_LOOP (results , int8_t , int8_t , int8_t , larray , lstrides , rarray , rstrides , %);
283+ } else if (rhs -> dtype == NDARRAY_UINT16 ) {
284+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_INT16 );
285+ BINARY_LOOP (results , int16_t , int8_t , int16_t , larray , lstrides , rarray , rstrides , %);
286+ } else if (rhs -> dtype == NDARRAY_INT16 ) {
287+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_INT16 );
288+ BINARY_LOOP (results , int16_t , int8_t , int16_t , larray , lstrides , rarray , rstrides , %);
289+ } else if (rhs -> dtype == NDARRAY_FLOAT ) {
290+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
291+ MODULO_FLOAT_LOOP (results , mp_float_t , int8_t , mp_float_t , larray , lstrides , rarray , rstrides );
292+ }
293+ } else if (lhs -> dtype == NDARRAY_UINT16 ) {
294+ if (rhs -> dtype == NDARRAY_UINT8 ) {
295+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_UINT8 );
296+ BINARY_LOOP (results , uint16_t , uint16_t , uint8_t , larray , lstrides , rarray , rstrides , %);
297+ } else if (rhs -> dtype == NDARRAY_INT8 ) {
298+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
299+ BINARY_LOOP (results , mp_float_t , uint16_t , int8_t , larray , lstrides , rarray , rstrides , %);
300+ } else if (rhs -> dtype == NDARRAY_UINT16 ) {
301+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_UINT16 );
302+ BINARY_LOOP (results , uint16_t , uint16_t , uint16_t , larray , lstrides , rarray , rstrides , %);
303+ } else if (rhs -> dtype == NDARRAY_INT16 ) {
304+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
305+ BINARY_LOOP (results , mp_float_t , uint16_t , int16_t , larray , lstrides , rarray , rstrides , %);
306+ } else if (rhs -> dtype == NDARRAY_FLOAT ) {
307+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
308+ MODULO_FLOAT_LOOP (results , mp_float_t , uint16_t , mp_float_t , larray , lstrides , rarray , rstrides );
309+ }
310+ } else if (lhs -> dtype == NDARRAY_INT16 ) {
311+ if (rhs -> dtype == NDARRAY_UINT8 ) {
312+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_INT16 );
313+ BINARY_LOOP (results , int16_t , int16_t , uint8_t , larray , lstrides , rarray , rstrides , %);
314+ } else if (rhs -> dtype == NDARRAY_INT8 ) {
315+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_INT16 );
316+ BINARY_LOOP (results , int16_t , int16_t , int8_t , larray , lstrides , rarray , rstrides , %);
317+ } else if (rhs -> dtype == NDARRAY_UINT16 ) {
318+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
319+ BINARY_LOOP (results , mp_float_t , int16_t , uint16_t , larray , lstrides , rarray , rstrides , %);
320+ } else if (rhs -> dtype == NDARRAY_INT16 ) {
321+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_INT16 );
322+ BINARY_LOOP (results , int16_t , int16_t , int16_t , larray , lstrides , rarray , rstrides , %);
323+ } else if (rhs -> dtype == NDARRAY_FLOAT ) {
324+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
325+ MODULO_FLOAT_LOOP (results , mp_float_t , int16_t , mp_float_t , larray , lstrides , rarray , rstrides );
326+ }
327+ } else if (lhs -> dtype == NDARRAY_FLOAT ) {
328+ if (rhs -> dtype == NDARRAY_UINT8 ) {
329+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
330+ MODULO_FLOAT_LOOP (results , mp_float_t , mp_float_t , uint8_t , larray , lstrides , rarray , rstrides );
331+ } else if (rhs -> dtype == NDARRAY_INT8 ) {
332+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
333+ MODULO_FLOAT_LOOP (results , mp_float_t , mp_float_t , int8_t , larray , lstrides , rarray , rstrides );
334+ } else if (rhs -> dtype == NDARRAY_UINT16 ) {
335+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
336+ MODULO_FLOAT_LOOP (results , mp_float_t , mp_float_t , uint16_t , larray , lstrides , rarray , rstrides );
337+ } else if (rhs -> dtype == NDARRAY_INT16 ) {
338+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
339+ MODULO_FLOAT_LOOP (results , mp_float_t , mp_float_t , int16_t , larray , lstrides , rarray , rstrides );
340+ } else if (rhs -> dtype == NDARRAY_FLOAT ) {
341+ results = ndarray_new_dense_ndarray (ndim , shape , NDARRAY_FLOAT );
342+ MODULO_FLOAT_LOOP (results , mp_float_t , mp_float_t , mp_float_t , larray , lstrides , rarray , rstrides );
343+ }
344+ }
345+
346+ return MP_OBJ_FROM_PTR (results );
347+ }
348+ #endif /* NDARRAY_HAS_BINARY_OP_MODULO */
349+
251350#if NDARRAY_HAS_BINARY_OP_MULTIPLY
252351mp_obj_t ndarray_binary_multiply (ndarray_obj_t * lhs , ndarray_obj_t * rhs ,
253352 uint8_t ndim , size_t * shape , int32_t * lstrides , int32_t * rstrides ) {
@@ -1074,6 +1173,29 @@ mp_obj_t ndarray_inplace_ams(ndarray_obj_t *lhs, ndarray_obj_t *rhs, int32_t *rs
10741173}
10751174#endif /* NDARRAY_HAS_INPLACE_ADD || NDARRAY_HAS_INPLACE_MULTIPLY || NDARRAY_HAS_INPLACE_SUBTRACT */
10761175
1176+
1177+ #if NDARRAY_HAS_INPLACE_MODULO
1178+ mp_obj_t ndarray_inplace_modulo (ndarray_obj_t * lhs , ndarray_obj_t * rhs , int32_t * rstrides ) {
1179+ if ((lhs -> dtype != NDARRAY_FLOAT ) && (rhs -> dtype == NDARRAY_FLOAT )) {
1180+ mp_raise_TypeError (MP_ERROR_TEXT ("results cannot be cast to specified type" ));
1181+ }
1182+ if (lhs -> dtype == NDARRAY_FLOAT ) {
1183+ if (rhs -> dtype == NDARRAY_UINT8 ) {
1184+ INLINE_MODULO_FLOAT_LOOP (lhs , uint8_t , larray , rarray , rstrides );
1185+ } else if (rhs -> dtype == NDARRAY_UINT8 ) {
1186+ INLINE_MODULO_FLOAT_LOOP (lhs , int8_t , larray , rarray , rstrides );
1187+ } else if (rhs -> dtype == NDARRAY_UINT16 ) {
1188+ INLINE_MODULO_FLOAT_LOOP (lhs , uint16_t , larray , rarray , rstrides );
1189+ } else if (rhs -> dtype == NDARRAY_INT16 ) {
1190+ INLINE_MODULO_FLOAT_LOOP (lhs , int16_t , larray , rarray , rstrides );
1191+ } else {
1192+ INLINE_MODULO_FLOAT_LOOP (lhs , mp_float_t , larray , rarray , rstrides );
1193+ }
1194+ }
1195+ return MP_OBJ_FROM_PTR (lhs );
1196+ }
1197+ #endif /* NDARRAY_HAS_INPLACE_MODULO */
1198+
10771199#if NDARRAY_HAS_INPLACE_TRUE_DIVIDE
10781200mp_obj_t ndarray_inplace_divide (ndarray_obj_t * lhs , ndarray_obj_t * rhs , int32_t * rstrides ) {
10791201
0 commit comments