rstsr-dtype-traits: implement ext_sign for integers, floats and complex - #93
Merged
Conversation
Add ext_sign(self) -> Self to ExtNum following NumPy's np.sign semantics: signed integers map to -1/0/1 (comparison form, no overflow at the type minimum), unsigned to 0/1, floats map NaN to NaN, infinities to +-1 and both signed zeros to +0.0, complex maps z/|z| with zero magnitude to zero; half f16/bf16 follow the float rules. rstsr-core: switch OpSignAPI device impls (DeviceCpuSerial and DeviceRayonAutoImpl) from the ComplexFloat + Div bound to ExtNum, so rt::sign now accepts integer dtypes. The closed ExtNum type set replaces the open ComplexFloat bound as the fallback for sign. This also fixes two NumPy divergences of the previous x/|x| formula: sign(+-inf) returned NaN instead of +-1, and sign(-0.0) kept -0.0 instead of +0.0. Tests: extend core_func math tests to i32/u8 sign and add float special-value coverage (NaN/inf/signed zeros). Most or all contents generated by AI (model glm-5.3). Co-authored-by: Claude Code <noreply@anthropic.com> Co-authored-by: glm-5.3 <service@zhipuai.cn>
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.
Summary
ext_sign(self) -> Selfto theExtNumtrait, following NumPy'snp.signsemantics:-1/0/1(comparison form, no overflow at the type minimum)0/1+0.0z / |z|, zero magnitude → zerof16/bf16follow the float rules (feature-gated)OpSignAPIdevice impls (DeviceCpuSerial,DeviceRayonAutoImpl) from theComplexFloat + Divbound toExtNum, sort::signnow accepts integer dtypes. The closedExtNumtype set replaces the openComplexFloatbound as the fallback for sign (not allComplexFloat-bounded types remain covered).x / |x|formula:sign(±inf)returned NaN instead of ±1, andsign(-0.0)kept-0.0instead of+0.0.core_funcmath sign tests extended toi32/u8tensors plus float special-value coverage (NaN/inf/signed zeros). Local runs green:entry_row_cpu257 passed,rstsr-core --lib94/101 (cpu_serial/rayon), workspace check + clippy clean.Most or all contents generated by AI (model glm-5.3).
🤖 Generated with Claude Code
Co-authored-by: Claude Code noreply@anthropic.com
Co-authored-by: glm-5.3 service@zhipuai.cn