Skip to content

Commit 20f7259

Browse files
authored
ix keepdims for min, max, argmin, argmax (#707)
1 parent be15d62 commit 20f7259

File tree

6 files changed

+50
-115
lines changed

6 files changed

+50
-115
lines changed

code/numpy/numerical.c

-4
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,6 @@ static mp_obj_t numerical_argmin_argmax_ndarray(ndarray_obj_t *ndarray, mp_obj_t
546546
}
547547

548548
m_del(int32_t, strides, ULAB_MAX_DIMS);
549-
550-
if(results->len == 1) {
551-
return mp_binary_get_val_array(results->dtype, results->array, 0);
552-
}
553549
return ulab_tools_restore_dims(ndarray, results, keepdims, _shape_strides);
554550
}
555551
// we should never get to this point

code/ulab.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "user/user.h"
3434
#include "utils/utils.h"
3535

36-
#define ULAB_VERSION 6.7.2
36+
#define ULAB_VERSION 6.7.3
3737
#define xstr(s) str(s)
3838
#define str(s) #s
3939

docs/manual/source/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
author = 'Zoltán Vörös'
2828

2929
# The full version, including alpha/beta/rc tags
30-
release = '6.7.2'
30+
release = '6.7.3'
3131

3232

3333
# -- General configuration ---------------------------------------------------

docs/ulab-change-log.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Sun, 26 Jan 2025
2+
3+
version 6.7.3
4+
5+
fix keepdims for min, max, argmin, argmax
6+
17
Sun, 19 Jan 2025
28

39
version 6.7.2

docs/ulab-convert.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"author = 'Zoltán Vörös'\n",
6262
"\n",
6363
"# The full version, including alpha/beta/rc tags\n",
64-
"release = '6.7.2'\n",
64+
"release = '6.7.3'\n",
6565
"\n",
6666
"\n",
6767
"# -- General configuration ---------------------------------------------------\n",
@@ -217,7 +217,7 @@
217217
},
218218
{
219219
"cell_type": "code",
220-
"execution_count": 4,
220+
"execution_count": 2,
221221
"metadata": {
222222
"ExecuteTime": {
223223
"end_time": "2022-02-09T06:27:21.647179Z",
@@ -258,7 +258,7 @@
258258
},
259259
{
260260
"cell_type": "code",
261-
"execution_count": 5,
261+
"execution_count": 3,
262262
"metadata": {
263263
"ExecuteTime": {
264264
"end_time": "2022-02-09T06:27:42.024028Z",

docs/ulab-numerical.ipynb

+39-106
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
{
5252
"cell_type": "code",
53-
"execution_count": 5,
53+
"execution_count": 3,
5454
"metadata": {
5555
"ExecuteTime": {
5656
"end_time": "2022-01-07T19:16:37.453883Z",
@@ -245,115 +245,11 @@
245245
"\n",
246246
"**WARNING:** Difference to `numpy`: the `out` keyword argument is not implemented.\n",
247247
"\n",
248-
"These functions follow the same pattern, and work with generic iterables, and `ndarray`s. `min`, and `max` return the minimum or maximum of a sequence. If the input array is two-dimensional, the `axis` keyword argument can be supplied, in which case the minimum/maximum along the given axis will be returned. If `axis=None` (this is also the default value), the minimum/maximum of the flattened array will be determined.\n",
248+
"These functions follow the same pattern, and work with generic iterables, and `ndarray`s. `min`, and `max` return the minimum or maximum of a sequence. If the input array is two-dimensional, the `axis` keyword argument can be supplied, in which case the minimum/maximum along the given axis will be returned. If `axis=None` (this is also the default value), the minimum/maximum of the flattened array will be determined. The functions also accept the `keepdims=True` or `keepdims=False` keyword argument. The latter case is the default, while the former keeps the dimensions (the number of axes) of the supplied array. \n",
249249
"\n",
250250
"`argmin/argmax` return the position (index) of the minimum/maximum in the sequence."
251251
]
252252
},
253-
{
254-
"cell_type": "code",
255-
"execution_count": 8,
256-
"metadata": {
257-
"ExecuteTime": {
258-
"end_time": "2020-10-17T21:26:22.507996Z",
259-
"start_time": "2020-10-17T21:26:22.492543Z"
260-
}
261-
},
262-
"outputs": [
263-
{
264-
"name": "stdout",
265-
"output_type": "stream",
266-
"text": [
267-
"array([1.0, 2.0, 3.0], dtype=float64)\n",
268-
"array([], dtype=float64)\n",
269-
"[] 0\n",
270-
"array([1.0, 2.0, 3.0], dtype=float64)\n",
271-
"array([], dtype=float64)\n",
272-
"\n",
273-
"\n"
274-
]
275-
}
276-
],
277-
"source": [
278-
"%%micropython -unix 1\n",
279-
"\n",
280-
"from ulab import numpy as np\n",
281-
"\n",
282-
"a = np.array([1, 2, 3])\n",
283-
"print(a)\n",
284-
"print(a[-1:-1:-3])\n",
285-
"try:\n",
286-
" sa = list(a[-1:-1:-3])\n",
287-
" la = len(sa)\n",
288-
"except IndexError as e:\n",
289-
" sa = str(e)\n",
290-
" la = -1\n",
291-
" \n",
292-
"print(sa, la)\n",
293-
"\n",
294-
"a[-1:-1:-3] = np.ones(0)\n",
295-
"print(a)\n",
296-
"\n",
297-
"b = np.ones(0) + 1\n",
298-
"print(b)"
299-
]
300-
},
301-
{
302-
"cell_type": "code",
303-
"execution_count": 9,
304-
"metadata": {
305-
"ExecuteTime": {
306-
"end_time": "2020-10-17T21:54:49.123748Z",
307-
"start_time": "2020-10-17T21:54:49.093819Z"
308-
}
309-
},
310-
"outputs": [
311-
{
312-
"name": "stdout",
313-
"output_type": "stream",
314-
"text": [
315-
"array([], dtype=float64)\n",
316-
"\n",
317-
"\n"
318-
]
319-
}
320-
],
321-
"source": [
322-
"%%micropython -unix 1\n",
323-
"\n",
324-
"from ulab import numpy as np\n",
325-
"\n",
326-
"a = np.array([1, 2, 3])\n",
327-
"print(a[0:1:-3])"
328-
]
329-
},
330-
{
331-
"cell_type": "code",
332-
"execution_count": 81,
333-
"metadata": {
334-
"ExecuteTime": {
335-
"end_time": "2020-10-17T20:59:58.285134Z",
336-
"start_time": "2020-10-17T20:59:58.263605Z"
337-
}
338-
},
339-
"outputs": [
340-
{
341-
"data": {
342-
"text/plain": [
343-
"(0,)"
344-
]
345-
},
346-
"execution_count": 81,
347-
"metadata": {},
348-
"output_type": "execute_result"
349-
}
350-
],
351-
"source": [
352-
"a = np.array([1, 2, 3])\n",
353-
"np.ones(0, dtype=uint8) / np.zeros(0, dtype=uint16)\n",
354-
"np.ones(0).shape"
355-
]
356-
},
357253
{
358254
"cell_type": "code",
359255
"execution_count": 10,
@@ -400,6 +296,43 @@
400296
"print('min of b (axis=1):', np.min(b, axis=1))"
401297
]
402298
},
299+
{
300+
"cell_type": "code",
301+
"execution_count": 6,
302+
"metadata": {},
303+
"outputs": [
304+
{
305+
"name": "stdout",
306+
"output_type": "stream",
307+
"text": [
308+
"a: array([[0.0, 1.0, 2.0, 3.0],\n",
309+
" [4.0, 5.0, 6.0, 7.0],\n",
310+
" [8.0, 9.0, 10.0, 11.0]], dtype=float64)\n",
311+
"\n",
312+
"min of a (axis=1):\n",
313+
" array([[0.0],\n",
314+
" [4.0],\n",
315+
" [8.0]], dtype=float64)\n",
316+
"\n",
317+
"min of a (axis=0):\n",
318+
" array([[0.0, 1.0, 2.0, 3.0]], dtype=float64)\n",
319+
"\n",
320+
"\n"
321+
]
322+
}
323+
],
324+
"source": [
325+
"%%micropython -unix 1\n",
326+
"\n",
327+
"from ulab import numpy as np\n",
328+
"\n",
329+
"a = np.array(range(12)).reshape((3, 4))\n",
330+
"\n",
331+
"print('a:', a)\n",
332+
"print('\\nmin of a (axis=1):\\n', np.min(a, axis=1, keepdims=True))\n",
333+
"print('\\nmin of a (axis=0):\\n', np.min(a, axis=0, keepdims=True))"
334+
]
335+
},
403336
{
404337
"cell_type": "markdown",
405338
"metadata": {},

0 commit comments

Comments
 (0)