Skip to content

Commit

Permalink
fix: is_tensor now accepts numpy scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
ariG23498 committed Jul 10, 2023
1 parent 6c8293b commit f007fe0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion keras_core/backend/numpy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 1 addition & 6 deletions keras_core/backend/numpy/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.<DTYPE>`. 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"):
Expand Down

0 comments on commit f007fe0

Please sign in to comment.