Skip to content

Commit

Permalink
correct implementation of ndim ... (#40)
Browse files Browse the repository at this point in the history
* correct implementation of ndim in order to work in compile mode with tensorflow (see issue tensorflow/tensorflow#48612 and #36)

* correct flake8

* Implement __len__ with shape for tf.function works

* import cast
  • Loading branch information
eserie committed Apr 28, 2021
1 parent 4656839 commit fa9912b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions eagerpy/tensor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __bool__(self: TensorType) -> bool:

@final
def __len__(self: TensorType) -> int:
return len(self.raw)
return cast(int, self.raw.shape[0])

@final
def __abs__(self: TensorType) -> TensorType:
Expand Down Expand Up @@ -112,4 +112,4 @@ def __pow__(self: TensorType, exponent: TensorOrScalar) -> TensorType:
@final
@property
def ndim(self: TensorType) -> int:
return cast(int, self.raw.ndim)
return len(self.raw.shape)

0 comments on commit fa9912b

Please sign in to comment.