Promote mixed-type list literals like NumPy (#539) - #543
Merged
Conversation
…ead of collapsing to the first element's type
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.
What
Fixes #539.
pecos.array([0, 1.5, True])produced aboolarray, silently destroying the1.5. Root cause: the generic inference path had a correct promotion lattice for int -> float -> complex, but bool was wired backwards --promote_type_to_boolDEMOTED accumulated integers and floats into!= 0bools whenever a Python bool appeared. In NumPy's lattice, bool is the bottom: it never drags a numeric type down.The fix inverts the flow and deletes the demoter:
[True, False]is stillbool); otherwise it is absorbed into the already-promoted type as 0/1.promote_bools_to_i64/promote_bools_to_f64; the complex direction already existed and was correct).TypeError(previously an internal shape error).The #540 homogeneous fast paths are untouched -- they bail to this generic path on any mixed list, which is exactly where the defect lived.
Verification
[True, 2**63]-> uint64, complex both directions, and nested[[1, True], [2.5, False]]; plus the Pauli-mixing TypeError.cargo clippy -p pecos-rslib --all-targets -- -D warnings,cargo fmt --check, unshieldedpre-commit run --all-files: clean.