Skip to content

fix: align non-float/complex ops, @ matmul, index keys, and TF creation dtypes - #53

Merged
nicola-bastianello merged 6 commits into
team-decent:mainfrom
Lethephyr:main
Nov 20, 2026
Merged

nicola-bastianello merged 6 commits into
team-decent:mainfrom
Lethephyr:main

Conversation

@Lethephyr

Copy link
Copy Markdown
Contributor

Fixes a few cross-backend inconsistencies found while integrating decent-array in team-decent/decent-bench#362:

  • PytorchBackend.mean / TensorflowBackend.mean: promote bool/int inputs to float instead of raising (PyTorch, TF bool) or truncating (TF int)
  • TensorflowBackend.isfinite / isinf / isnan: return constant bools for int/bool inputs and check real/imag parts separately for complex inputs
  • Array.__matmul__ / __rmatmul__: delegate to self._backend.matmul so 1-D operands hit TensorflowBackend.matmul's tf.tensordot fallback
  • TensorflowBackend.empty / eye: default to tf.float32, matching zeros and ones
  • unwrap_key: unwrap Array keys and coerce custom __index__ objects (e.g. W[agent_i, agent_j]) to int in get_item/set_item across backends

Added cross-backend tests in tests/test_array.py and tests/test_iop_functions.py. All pytest and ruff checks pass across NumPy, PyTorch, TensorFlow, and JAX.

Drop branches no caller exercises: complex isfinite/isinf/isnan, TF
bool sum/min/max, PyTorch uint8 any/all cast, and the tf.Tensor key
conversion in TF set_item (numpy already accepts eager tensors).
Simplify unwrap_key, keeping custom __index__ support for
W[agent_i, agent_j] since TF and JAX reject such keys.
fix: align TF/PyTorch non-float ops, 1D matmul, custom index keys, and TF creation dtypes
@nicola-bastianello

Copy link
Copy Markdown
Member

looks good, thank you for catching these inconsistencies!

can you please fix the issue that fails the mypy check?

for your background: we are aligning with https://data-apis.org/array-api/latest/index.html. no change needed, since e.g. isfinite is as it should be

@nicola-bastianello

nicola-bastianello commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

also, since the change in mean fixes the issue in team-decent/decent-bench#362: can you please bump the version to 0.2.8 in this PR? then after I merge I'll make a release and we can update the dependency in decent-bench to use this new version, and fall back to using mean instead of the workaround you now have with sum

@Lethephyr

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the Array API pointer!

Done — fixed the [redundant-cast] mypy error in JaxBackend._next_key and bumped the version to 0.2.8 in pyproject.toml. Once 0.2.8 is out, I'll update decent-bench in team-decent/decent-bench#362 to switch back to iop.mean.

@nicola-bastianello
nicola-bastianello merged commit 99a2a64 into team-decent:main Nov 20, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants