Skip to content

feat: add conditional return types for axis-dependent reduction methods - #22

Merged
CodeWithKyrian merged 1 commit into
mainfrom
feat/conditional-return-types-for-axis
May 30, 2026
Merged

CodeWithKyrian merged 1 commit into
mainfrom
feat/conditional-return-types-for-axis

Conversation

@CodeWithKyrian

Copy link
Copy Markdown
Contributor

This PR adds PHPStan conditional return type annotations to reduction and norm methods whose return type depends on whether $axis is null.

Motivation and Context

When calling methods like $arr->sum() with $axis = null, the return is always a scalar (Complex|float|int), but the union return type Complex|float|int|NDArray forces static analysis tools like PHPStan to require type narrowing before using the result. Conditional return types allow tools to infer the correct type based on the $axis argument value, eliminating unnecessary boilerplate assertions.

What's Changed

  • Added @return ($axis is null ? <scalar> : NDArray) PHPDoc annotations to sum, mean, min, max, argmin, argmax, product, var, std in HasReductions trait
  • Added @return ($axis is null ? float : NDArray) PHPDoc annotation to norm in HasLinearAlgebra trait

Breaking Changes

None.

@CodeWithKyrian
CodeWithKyrian merged commit 54f42aa into main May 30, 2026
14 checks passed
@CodeWithKyrian
CodeWithKyrian deleted the feat/conditional-return-types-for-axis branch May 30, 2026 20:45
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.

1 participant