-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
'int' object has no attribute 'item' on conv shapes calculation (issu…
…e 96) (#101) * make sure shape is indexed correctly * Improved and tested convolution shape inference * Added torch support for _index_tuple * Updated ruff syntax --------- Co-authored-by: Jens E. Pedersen <[email protected]>
- Loading branch information
1 parent
2c87511
commit cea08f3
Showing
5 changed files
with
58 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from nir.ir.utils import _index_tuple | ||
|
||
import importlib | ||
|
||
_TORCH_SPEC = importlib.util.find_spec("torch") is not None | ||
|
||
|
||
def test_index_tuple(): | ||
assert _index_tuple(1, 0) == 1 | ||
assert _index_tuple([1, 2], 0) == 1 | ||
assert _index_tuple(np.array([1, 2]), 0) == 1 | ||
assert np.all( | ||
np.equal(_index_tuple(np.array([[1, 2], [3, 4]]), 1), np.array([3, 4])) | ||
) | ||
|
||
|
||
@pytest.mark.skipif(_TORCH_SPEC is not None, reason="requires torch") | ||
def test_index_tuple_torch(): | ||
torch = _TORCH_SPEC.loader.load_module() | ||
assert _index_tuple(torch.tensor([1, 2]), 0) == 1 | ||
assert _index_tuple(torch.tensor([[1, 2], [3, 4]]), 1).equal(torch.tensor([3, 4])) |