Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use f32::round_ties_even instead of libm::rintf #373

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ include = ["/src", "/CHANGELOG.md", "/README.md"]

[dependencies]
flatbuffers = "24.3.25"
libm = "0.2.6"
rayon = "1.7.0"
smallvec = { version = "1.10.0", features = ["union", "const_generics", "const_new"] }
rten-tensor = { path = "./rten-tensor", version = "0.13.1" }
Expand All @@ -55,6 +54,7 @@ memmap2 = { version = "0.9.4", optional = true }
num_cpus = "1.16.0"

[dev-dependencies]
libm = "0.2.6"
rten = { path = ".", features = ["mmap", "random"] }
rten-bench = { path = "./rten-bench" }
serde_json = { workspace = true }
Expand Down
5 changes: 2 additions & 3 deletions src/ops/unary_elementwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ unary_float_op!(Relu, relu, relu_in_place, |val: f32| val.max(0.));

/// Round float values to the nearest integer. Values with a fractional part
/// of 0.5 are rounded to the nearest even number, like `round` in Python and
/// unlike `f32::round` in Rust.
/// unlike [`f32::round`] in Rust.
#[derive(Debug)]
pub struct Round {}
impl UnaryFloatOp for Round {
Expand All @@ -585,8 +585,7 @@ impl UnaryFloatOp for Round {
}

fn map_element(&self, val: f32) -> f32 {
// Replace this with `f32::round_ties_even` when that is stabilized.
libm::rintf(val)
val.round_ties_even()
}
}

Expand Down
Loading