From f007fe09086d95b9c96293170a3a8d7016dd2be4 Mon Sep 17 00:00:00 2001 From: ariG23498 Date: Mon, 10 Jul 2023 16:58:05 +0000 Subject: [PATCH] fix: is_tensor now accepts numpy scalars --- keras_core/backend/numpy/core.py | 2 +- keras_core/backend/numpy/numpy.py | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/keras_core/backend/numpy/core.py b/keras_core/backend/numpy/core.py index 8028d0e44..b52155005 100644 --- a/keras_core/backend/numpy/core.py +++ b/keras_core/backend/numpy/core.py @@ -41,7 +41,7 @@ def convert_to_numpy(x): def is_tensor(x): - if isinstance(x, np.ndarray): + if isinstance(x, (np.generic, np.ndarray)): return True return False diff --git a/keras_core/backend/numpy/numpy.py b/keras_core/backend/numpy/numpy.py index b97cf57cd..13dca5517 100644 --- a/keras_core/backend/numpy/numpy.py +++ b/keras_core/backend/numpy/numpy.py @@ -560,12 +560,7 @@ def var(x, axis=None, keepdims=False): def sum(x, axis=None, keepdims=False): axis = tuple(axis) if isinstance(axis, list) else axis - # `np.sum()` function, when applied to an array, returns a scalar - # value that represents the sum of all the elements in the array. - # This operation reduces the dimensionality of the input and hence - # return objects of type `np.`. To fix this behaviour, we - # wrap the result in a list and explicitly reutrns an `np.ndarray`. - return np.array([np.sum(x, axis=axis, keepdims=keepdims)]) + return np.sum(x, axis=axis, keepdims=keepdims) def eye(N, M=None, k=0, dtype="float32"):