Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly check for nested tuple in map_func_over_tuple_of_tuples #500

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scico/numpy/_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import jax.numpy as jnp

import scico.numpy as snp

from ._blockarray import BlockArray


Expand Down Expand Up @@ -83,9 +85,7 @@ def mapped(*args, **kwargs):

map_arg_val = bound_args.arguments.pop(map_arg_name)

if not isinstance(map_arg_val, tuple) or not all(
isinstance(x, tuple) for x in map_arg_val
): # not nested tuple
if not snp.util.is_nested(map_arg_val): # not nested tuple
return func(*args, **kwargs) # no mapping

# map
Expand Down
10 changes: 9 additions & 1 deletion scico/test/numpy/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,17 @@ def test_ufunc_conj():
def test_create_zeros():
A = snp.zeros(2)
assert np.all(A == 0)
assert isinstance(A, jax.Array)

A = snp.zeros((2,))
assert isinstance(A, jax.Array)

A = snp.zeros(((2,), (2,)))
assert all(snp.all(A == 0))
assert isinstance(A, snp.BlockArray)

A = snp.zeros(())
assert isinstance(A, jax.Array) # from issue 499


def test_create_ones():
Expand All @@ -261,7 +269,7 @@ def test_create_ones():
assert all(snp.all(A == 1))


def test_create_zeros():
def test_create_empty():
A = snp.empty(2)
assert np.all(A == 0)

Expand Down
Loading