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

Add crate that enables the full float APIs in #[no_std] #4002

Closed
wants to merge 13 commits into from
Closed
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
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ members = [

# Utils
"utils/calendrical_calculations",
"utils/core_math",
"utils/crlify",
"utils/databake",
"utils/databake/derive",
Expand Down Expand Up @@ -199,6 +200,7 @@ icu_provider_macros = { version = "~1.2.0", path = "provider/macros", default-fe

# Utils
calendrical_calculations = { version = "0.1.0", path = "utils/calendrical_calculations", default-features = false }
core_math = { version = "0.0.0", path = "utils/core_math", default-features = false }
crlify = { version = "1.0.1", path = "utils/crlify", default-features = false }
databake = { version = "0.1.3", path = "utils/databake", default-features = false }
databake-derive = { version = "0.1.3", path = "utils/databake/derive", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions components/segmenter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ zerovec = { workspace = true, features = ["yoke"] }
databake = { workspace = true, optional = true, features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }

libm = { version = "0.2", default-features = false, optional = true }
core_math = { workspace = true, optional = true }

icu_segmenter_data = { workspace = true, optional = true }
icu_locid_transform = { workspace = true, optional = true, features = ["compiled_data"] }
Expand All @@ -49,7 +49,7 @@ default = ["compiled_data", "auto"]
std = ["icu_collections/std", "icu_locid/std", "icu_provider/std"]
serde = ["dep:serde", "zerovec/serde", "icu_collections/serde", "icu_provider/serde"]
datagen = ["serde", "dep:databake", "zerovec/databake", "icu_collections/databake"]
lstm = ["dep:libm"]
lstm = ["dep:core_math"]
auto = ["lstm"] # Enabled try_new_auto_unstable constructors
compiled_data = ["dep:icu_segmenter_data"]
bench = []
Expand Down
22 changes: 2 additions & 20 deletions components/segmenter/src/complex/lstm/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,11 @@
use alloc::vec;
use alloc::vec::Vec;
use core::ops::Range;
#[allow(unused_imports)]
use core_math::*;
use zerovec::ule::AsULE;
use zerovec::ZeroSlice;

// This will be used in #[no_std] as f32::exp/f32::tanh are not in core.
trait CoreFloat {
fn exp(self) -> Self;
fn tanh(self) -> Self;
}

// TODO: Find a way to do this without libm. There's an intrinsic
// that produces `llvm.exp.f32`, but that's not exposed through
// f32. Another option would be to declare `extern "Rust"` and
// let clients provide these functions.
impl CoreFloat for f32 {
fn exp(self) -> Self {
libm::expf(self)
}

fn tanh(self) -> Self {
libm::tanhf(self)
}
}

/// A `D`-dimensional, heap-allocated matrix.
///
/// This matrix implementation supports slicing matrices into tightly-packed
Expand Down
1 change: 1 addition & 0 deletions docs/tutorials/testing/patch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ databake-derive = { path = "../../utils/databake/derive" }
deduplicating_array = { path = "../../utils/deduplicating_array" }
fixed_decimal = { path = "../../utils/fixed_decimal" }
litemap = { path = "../../utils/litemap" }
core_math = { path = "../../utils/core_math" }
icu_pattern = { path = "../../utils/pattern" }
tinystr = { path = "../../utils/tinystr" }
tzif = { path = "../../utils/tzif" }
Expand Down
9 changes: 8 additions & 1 deletion ffi/gn/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion ffi/gn/icu4x/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ rust_library("calendrical_calculations-v0_1_0") {
visibility = [ ":*" ]
}

rust_library("core_math-v0_0_0") {
crate_name = "core_math"
crate_root = "//utils/core_math/src/lib.rs"
output_name = "core_math-73cb7218c03e07b7"

deps = []
if (false) {
deps += [ ":libm-v0_2_6" ]
}

rustenv = []

rustflags = [
"--cap-lints=allow",
"--edition=2021",
"-Cmetadata=73cb7218c03e07b7",
"-Cextra-filename=-73cb7218c03e07b7",
]

visibility = [ ":*" ]
}

rust_proc_macro("diplomat-v0_5_2") {
crate_name = "diplomat"
crate_root = "//ffi/gn/vendor/diplomat/src/lib.rs"
Expand Down Expand Up @@ -652,11 +674,11 @@ rust_library("icu_segmenter-v1_2_1") {
output_name = "icu_segmenter-9c67817750522b21"

deps = []
deps += [ ":core_math-v0_0_0" ]
deps += [ ":displaydoc-v0_2_4($host_toolchain)" ]
deps += [ ":icu_collections-v1_2_0" ]
deps += [ ":icu_locid-v1_2_0" ]
deps += [ ":icu_provider-v1_2_0" ]
deps += [ ":libm-v0_2_6" ]
deps += [ ":utf8_iter-v1_0_3" ]
deps += [ ":zerovec-v0_9_4" ]

Expand Down Expand Up @@ -732,6 +754,7 @@ rust_library("libm-v0_2_6") {
"--edition=2018",
"-Cmetadata=6b5214f2031c6f9e",
"-Cextra-filename=-6b5214f2031c6f9e",
"--cfg=feature=\"default\"",
]

visibility = [ ":*" ]
Expand Down
3 changes: 2 additions & 1 deletion tools/depcheck/src/allowlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub const BASIC_RUNTIME_DEPS: &[&str] = &[
// ICU4X utils
"calendrical_calculations",
"fixed_decimal",
"core_math",
"icu_provider_adapters", // not included in icu, but needed generally
"icu_provider",
"litemap",
Expand Down Expand Up @@ -102,7 +103,7 @@ pub const EXTRA_EXPERIMENTAL_DATA_DEPS: &[&str] = &[
];

/// Dependencies allowed when opting in to LSTM segmenter
pub const EXTRA_LSTM_DEPS: &[&str] = &["libm"];
pub const EXTRA_LSTM_DEPS: &[&str] = &[];

/// Dependencies allowed when opting in to fixed_decimal's `ryu` backend
/// This should never change
Expand Down
23 changes: 23 additions & 0 deletions utils/core_math/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file is part of ICU4X. For terms of use, please see the file
# called LICENSE at the top level of the ICU4X source tree
# (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

[package]
name = "core_math"
version = "0.0.0"
description = "Extension trait for full float functionality in `#[no_std]` backed by `libm`."

rust-version.workspace = true
authors.workspace = true
edition.workspace = true
repository.workspace = true
homepage.workspace = true
license-file.workspace = true
categories.workspace = true
include.workspace = true

[lib]
name = "core_math"

[dependencies]
libm = "0.2"
44 changes: 44 additions & 0 deletions utils/core_math/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
UNICODE LICENSE V3

COPYRIGHT AND PERMISSION NOTICE

Copyright © 2020-2023 Unicode, Inc.

NOTICE TO USER: Carefully read the following legal agreement. BY
DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.

Permission is hereby granted, free of charge, to any person obtaining a
copy of data files and any associated documentation (the "Data Files") or
software and any associated documentation (the "Software") to deal in the
Data Files or Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, and/or sell
copies of the Data Files or Software, and to permit persons to whom the
Data Files or Software are furnished to do so, provided that either (a)
this copyright and permission notice appear with all copies of the Data
Files or Software, or (b) this copyright and permission notice appear in
associated Documentation.

THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
THIRD PARTY RIGHTS.

IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
FILES OR SOFTWARE.

Except as contained in this notice, the name of a copyright holder shall
not be used in advertising or otherwise to promote the sale, use or other
dealings in these Data Files or Software without prior written
authorization of the copyright holder.


Portions of ICU4X may have been adapted from ICU4C and/or ICU4J.
ICU 1.8.1 to ICU 57.1 © 1995-2016 International Business Machines Corporation and others.
21 changes: 21 additions & 0 deletions utils/core_math/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading