Conversation
Variable now takes the same type parameters as NamedArray, Variable[ShapeType, DType, DimType]. The constructor infers the dtype from duck arrays; the shape type is tuple[int, ...], as it cannot be inferred and Any would make mypy drop all type arguments in overloaded functions. Methods that returned Self although they can change the shape or dtype now return a Variable with the respective types: indexing, transpose, reductions, astype, real/imag, ufuncs and the arithmetic operators, whose generated mixin is now generic too. Comparisons have a boolean dtype, argsort an intp dtype. Binary and unary operators also return a Variable for subclasses, like at runtime; in-place operators keep returning Self. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add overloads to Variable, IndexVariable and NamedArray's from_array for scalars and lists (nested up to three levels) of bool, int, float, complex and str, which numpy converts to arrays of a known dtype. They are tried in order, so that e.g. a list literal of ints is not taken for a list of floats; an empty list becomes float64. Tuples are not included, as they become 0-d object arrays. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AbstractArray.__array__ cannot type the dtype, as AbstractArray is not generic in it. Add typing-only overloads to Variable, so that e.g. np.asarray(variable) keeps the dtype. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
headtr1ck
enabled auto-merge (squash)
October 12, 2026 10:34
Co-authored-by: Claude <noreply@anthropic.com>
6 tasks done
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Follow-up of #11677:
Variableis now generic in its shape and dtype as well, likeNamedArray:Variable[ShapeType, DType, DimType].Variables and Python scalars and lists, e.g.Variable("x", [1, 2])has an integer dtype (also inNamedArray'sfrom_array); other data givesAnynp.asarray(variable)keeps the dtypeVariablewith the respective types instead ofSelf, e.g. comparisons have a boolean dtype; the generated arithmetic mixin is generic tooVariablefor subclasses, as they do at runtime; in-place operators keepSelfChecklist
whats-new.rstAI Disclosure
Tools: Claude Code
[This is Claude Code on behalf of Michael Niklas]
🤖 Generated with Claude Code