Skip to content
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
1 change: 1 addition & 0 deletions codegen/src/targets/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fn module_tokens(
#definition

#function_docs
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn #name(#(#inputs: f64),*) -> #return_type {
#(#variables)*
Expand Down
4 changes: 4 additions & 0 deletions targets/ptfkit-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ readme = "README.md"
repository = "https://github.com/AgroDT/ptfkit"
documentation = "https://docs.rs/ptfkit"

[features]
default = ["inline"]
inline = []

[dev-dependencies]
assertables = "10.1.0"
39 changes: 38 additions & 1 deletion targets/ptfkit-rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ their source publications.

```toml
[dependencies]
ptfkit = "0.1"
ptfkit = "0.2"
```

## Usage
Expand All @@ -19,6 +19,43 @@ use ptfkit::jabro1992::calc_ptf_jabro1992;
let k_sat = calc_ptf_jabro1992(20.0, 30.0, 1.3);
```

## Features

The `inline` feature is enabled by default. It marks generated PTF functions
with `#[inline]`, making their bodies available to downstream optimization and
letting the compiler decide whether inlining is beneficial at each call site.
This is useful when an application evaluates several PTFs in a single pass over
a dataset while keeping control of its own data layout and iteration strategy.

For example, two saturated hydraulic conductivity estimates can be collected
in separate arrays during the same pass over the input data:

```rust
use ptfkit::ferrerjulia2004::{
calc_ptf_ferrerjulia2004_campbell_shiozawa,
calc_ptf_ferrerjulia2004_saxton,
};

let sand = [50.0, 42.0, 61.0];
let clay = [25.0, 31.0, 18.0];
let mut campbell_shiozawa = Vec::with_capacity(sand.len());
let mut saxton = Vec::with_capacity(sand.len());

for i in 0..sand.len() {
campbell_shiozawa.push(calc_ptf_ferrerjulia2004_campbell_shiozawa(
sand[i], clay[i],
));
saxton.push(calc_ptf_ferrerjulia2004_saxton(sand[i], clay[i]));
}
```

To disable the inline hint, disable the crate's default features:

```toml
[dependencies]
ptfkit = { version = "0.2", default-features = false }
```

## Documentation

- [Rust API on docs.rs](https://docs.rs/ptfkit/)
Expand Down
1 change: 1 addition & 0 deletions targets/ptfkit-rs/src/ahuja1984.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ for the soil being evaluated.
Callers must supply the exponent. The paper evaluates both n = 4 and n = 5 and does not select
one as a unique transferable value.
total_porosity must be greater than or equal to theta_33."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_ahuja1984(
total_porosity: f64,
Expand Down
1 change: 1 addition & 0 deletions targets/ptfkit-rs/src/aimrun2009.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Applicability: Clayey rice soils with compacted subsoil.
# Warnings

The formula uses natural logarithms of all inputs."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_aimrun2009(clay: f64, bulk_density: f64, organic_matter: f64, gmd: f64) -> f64 {
let ln_k_sat_m_per_day = -2.368f64 + 3.846f64 * bulk_density + 0.091f64 * organic_matter
Expand Down
11 changes: 11 additions & 0 deletions targets/ptfkit-rs/src/beniaich2023.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Source regressions operate in percentage points; outputs are divided by 100 to r

Developed from Moroccan agricultural topsoils and not independently validated outside the source
territory."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_beniaich2023_slr1(clay: f64) -> Beniaich2023PTFResult {
let water_saturation = (46.307f64 + 0.556f64 * clay) / 100.0f64;
Expand Down Expand Up @@ -118,6 +119,7 @@ Source regressions operate in percentage points; outputs are divided by 100 to r

Developed from Moroccan agricultural topsoils and not independently validated outside the source
territory."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_beniaich2023_slr2(silt: f64) -> Beniaich2023PTFResult {
let water_saturation = (59.508f64 + 0.299f64 * silt) / 100.0f64;
Expand Down Expand Up @@ -184,6 +186,7 @@ Source regressions operate in percentage points; outputs are divided by 100 to r

Developed from Moroccan agricultural topsoils and not independently validated outside the source
territory."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_beniaich2023_slr3(sand: f64) -> Beniaich2023PTFResult {
let water_saturation = (81.420f64 - 0.427f64 * sand) / 100.0f64;
Expand Down Expand Up @@ -251,6 +254,7 @@ Source regressions operate in percentage points; outputs are divided by 100 to r

Developed from Moroccan agricultural topsoils and not independently validated outside the source
territory."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_beniaich2023_slr4(clay: f64, silt: f64) -> Beniaich2023PTFResult {
let clay_silt = clay + silt;
Expand Down Expand Up @@ -319,6 +323,7 @@ Source regressions operate in percentage points; outputs are divided by 100 to r

Developed from Moroccan agricultural topsoils and not independently validated outside the source
territory."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_beniaich2023_slr5(clay: f64, silt: f64) -> Beniaich2023PTFResult {
let clay_silt_ratio = clay / silt;
Expand Down Expand Up @@ -386,6 +391,7 @@ Source regressions operate in percentage points; outputs are divided by 100 to r

Developed from Moroccan agricultural topsoils and not independently validated outside the source
territory."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_beniaich2023_slr6(soil_organic_matter: f64) -> Beniaich2023PTFResult {
let water_saturation = (61.163f64 + 2.793f64 * soil_organic_matter) / 100.0f64;
Expand Down Expand Up @@ -454,6 +460,7 @@ Source regressions operate in percentage points; outputs are divided by 100 to r

Developed from Moroccan agricultural topsoils and not independently validated outside the source
territory."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_beniaich2023_mlr1(
silt: f64,
Expand Down Expand Up @@ -528,6 +535,7 @@ Source regressions operate in percentage points; outputs are divided by 100 to r

Developed from Moroccan agricultural topsoils and not independently validated outside the source
territory."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_beniaich2023_mlr2(sand: f64, soil_organic_matter: f64) -> Beniaich2023PTFResult {
let water_saturation =
Expand Down Expand Up @@ -598,6 +606,7 @@ Source regressions operate in percentage points; outputs are divided by 100 to r

Developed from Moroccan agricultural topsoils and not independently validated outside the source
territory."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_beniaich2023_mlr3(silt: f64, soil_organic_matter: f64) -> Beniaich2023PTFResult {
let water_saturation =
Expand Down Expand Up @@ -668,6 +677,7 @@ Source regressions operate in percentage points; outputs are divided by 100 to r

Developed from Moroccan agricultural topsoils and not independently validated outside the source
territory."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_beniaich2023_mlr4(clay: f64, soil_organic_matter: f64) -> Beniaich2023PTFResult {
let water_saturation =
Expand Down Expand Up @@ -739,6 +749,7 @@ Source regressions operate in percentage points; outputs are divided by 100 to r

Developed from Moroccan agricultural topsoils and not independently validated outside the source
territory."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_beniaich2023_mlr5(
clay: f64,
Expand Down
6 changes: 6 additions & 0 deletions targets/ptfkit-rs/src/chakraborty2011.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ respective potentials.
# Warnings

Use outside the source Indian-soil dataset requires independent validation."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_chakraborty2011_eq1(clay: f64, silt: f64) -> Chakraborty2011PTFResult {
let water_content_33 = (0.297f64 * clay + 0.478f64 * silt + 4.600f64) / 100.0f64;
Expand Down Expand Up @@ -133,6 +134,7 @@ respective potentials.
# Warnings

Use outside the source Indian-soil dataset requires independent validation."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_chakraborty2011_eq2(sand: f64, bulk_density: f64) -> Chakraborty2011PTFResult {
let water_content_33 = (-0.377f64 * sand - 0.215f64 * bulk_density + 41.114f64) / 100.0f64;
Expand Down Expand Up @@ -211,6 +213,7 @@ respective potentials.
# Warnings

Use outside the source Indian-soil dataset requires independent validation."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_chakraborty2011_eq3(
clay: f64,
Expand Down Expand Up @@ -297,6 +300,7 @@ respective potentials.
# Warnings

Use outside the source Indian-soil dataset requires independent validation."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_chakraborty2011_eq4(clay: f64, silt: f64, sand: f64) -> Chakraborty2011PTFResult {
let water_content_33 =
Expand Down Expand Up @@ -380,6 +384,7 @@ respective potentials.
# Warnings

Use outside the source Indian-soil dataset requires independent validation."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_chakraborty2011_eq5(
clay: f64,
Expand Down Expand Up @@ -473,6 +478,7 @@ respective potentials.
# Warnings

Use outside the source Indian-soil dataset requires independent validation."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_chakraborty2011_eq6(
clay: f64,
Expand Down
1 change: 1 addition & 0 deletions targets/ptfkit-rs/src/cosby1984.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Public API names are provisional for pilot testing.
# Warnings

Log-transformed output units use the pilot contract `reported log value`."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_cosby1984_univariate(
sand: f64,
Expand Down
5 changes: 5 additions & 0 deletions targets/ptfkit-rs/src/dharumarajan2019.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Reported cross-validation RMSE values are 5.25% for FC and 3.71% for PWP.
The paper does not state whether its water-content percentages are gravimetric or volumetric.
The source gives inconsistent profile counts and district lists for the Northern dataset; see
the scientific notes."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_dharumarajan2019_nkp(
clay: f64,
Expand Down Expand Up @@ -130,6 +131,7 @@ Reported cross-validation RMSE values are 7.05% for FC and 4.74% for PWP.
The paper does not state whether its water-content percentages are gravimetric or volumetric.
The source gives inconsistent profile counts and district lists for the Northern dataset; see
the scientific notes."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_dharumarajan2019_nkp_clay(clay: f64) -> Dharumarajan2019WaterRetentionResult {
let field_capacity = 4.968f64 + 0.586f64 * clay;
Expand Down Expand Up @@ -195,6 +197,7 @@ Reported cross-validation RMSE values are 3.05% for FC and 2.17% for PWP.
# Warnings

The paper does not state whether its water-content percentages are gravimetric or volumetric."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_dharumarajan2019_skp(
clay: f64,
Expand Down Expand Up @@ -264,6 +267,7 @@ Reported cross-validation RMSE values are 5.39% for FC and 3.13% for PWP.
# Warnings

The paper does not state whether its water-content percentages are gravimetric or volumetric."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_dharumarajan2019_skp_clay(clay: f64) -> Dharumarajan2019WaterRetentionResult {
let field_capacity = 3.724f64 + 0.581f64 * clay;
Expand Down Expand Up @@ -328,6 +332,7 @@ The reported model R-squared is 41%, and the reported RMSE is 6.71%.
# Warnings

Predictor calibration ranges are not reported for the 100-observation dataset."]
#[cfg_attr(feature = "inline", inline)]
#[must_use]
pub fn calc_ptf_dharumarajan2019_infiltration(sand: f64, silt: f64, clay: f64) -> f64 {
177.55f64 - 1.47f64 * sand - 1.80f64 * clay - 1.58f64 * silt
Expand Down
Loading