Skip to content

feat: f32 support via FloatElem trait, both dtypes accept - #2

Merged
asjad2401 merged 1 commit into
masterfrom
feature/f32-support
May 11, 2026
Merged

feat: f32 support via FloatElem trait, both dtypes accept#2
asjad2401 merged 1 commit into
masterfrom
feature/f32-support

Conversation

@asjad2401

Copy link
Copy Markdown
Owner

What this does

Adds float32 support to all three functions. Public API is unchanged — pass either dtype and the output matches the input automatically.

Changes

  • Introduced FloatElem trait implemented by both f32 and f64
  • All implementations (relu, sigmoid, softmax) are now generic over F: FloatElem
  • Python-facing functions dispatch via dtype-aware downcast at runtime
  • #![allow(deprecated)] suppresses PyO3 0.28 deprecation warning pending upstream fix
    (see PyO3/rust-numpy#)

Benchmark results (1000×1000, 200 runs, AMD x86-64)

Function dtype NumPy rustnum Speedup
sigmoid f64 16.02ms 6.45ms 2.5×
sigmoid f32 3.73ms 3.41ms 1.1×
softmax f64 15.94ms 3.63ms 4.4×
softmax f32 4.05ms 1.77ms 2.3×

Correctness

16/16 checks pass — 1D, 2D, 3D, both dtypes, multiple axes, error handling.

@asjad2401
asjad2401 merged commit cd11a8c into master May 11, 2026
17 checks passed
@asjad2401
asjad2401 deleted the feature/f32-support branch May 11, 2026 20:10
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