From 376affa920b1f6dad079908f4ab749d7218b38c8 Mon Sep 17 00:00:00 2001 From: maurapintor Date: Mon, 11 Nov 2024 18:50:33 +0200 Subject: [PATCH] fix cdense min dimensions --- src/secml/array/c_dense.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/secml/array/c_dense.py b/src/secml/array/c_dense.py index 1071ef41..4aff7004 100644 --- a/src/secml/array/c_dense.py +++ b/src/secml/array/c_dense.py @@ -46,6 +46,8 @@ def __init__(self, data=None, dtype=None, copy=False, shape=None): else: # Other inputs... just need to initialize the input shape self._input_shape = None obj = np.asarray(data, dtype=dtype) + if obj.ndim < 1: + obj = obj.reshape(1, *obj.shape) # numpy created an object array, maybe input is malformed?! if obj.dtype.char == "O": raise TypeError("Array is malformed, check input data.") @@ -480,9 +482,8 @@ def _check_index_bool(self, idx): and elem.size != self.shape[elem_idx] ): raise IndexError( - "boolean index array for axis {:} must have " "size {:}.".format( - elem_idx, self.shape[elem_idx] - ) + "boolean index array for axis {:} must have " + "size {:}.".format(elem_idx, self.shape[elem_idx]) ) def _check_index_slice(self, elem_idx, elem): @@ -1506,9 +1507,11 @@ def norm(self, order=None, axis=None, keepdims=False): return self.__class__([0.0]) out = np.linalg.norm( - self.atleast_2d().tondarray().astype(float) - if axis is not None - else self.tondarray().astype(float), + ( + self.atleast_2d().tondarray().astype(float) + if axis is not None + else self.tondarray().astype(float) + ), order, axis, )