Skip to content

Conversation

@starovoid
Copy link
Collaborator

@starovoid starovoid commented Feb 7, 2025

Add two required methods for FloatMeasure, BoundedMeasure and UnitMeasure traits:

/// A floating-point measure.
pub trait FloatMeasure: Measure + Copy {
    fn zero() -> Self;
    fn infinite() -> Self;

    // NEW:
    fn from_f32(val: f32) -> Self;
    fn from_f64(val: f64) -> Self;
}

Motivation

This will add flexibility in programming operations with edge weights and make possible the behavior requested in issue #723.


BREAKING CHANGE:

This PR adds new required methods to the public trait

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2025

This PR contains breaking changes to the public Rust API.

cargo-semver-checks summary

--- failure trait_method_added: pub trait method added ---

Description:
A non-sealed public trait added a new method without a default implementation, which breaks downstream implementations of the trait
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/trait_method_added.ron

Failed in:
trait method petgraph::algo::BoundedMeasure::from_f32 in file /home/runner/work/petgraph/petgraph/PR_BRANCH/src/algo/mod.rs:775
trait method petgraph::algo::BoundedMeasure::from_f64 in file /home/runner/work/petgraph/petgraph/PR_BRANCH/src/algo/mod.rs:776
trait method petgraph::algo::FloatMeasure::from_f32 in file /home/runner/work/petgraph/petgraph/PR_BRANCH/src/algo/mod.rs:737
trait method petgraph::algo::FloatMeasure::from_f64 in file /home/runner/work/petgraph/petgraph/PR_BRANCH/src/algo/mod.rs:738
trait method petgraph::algo::UnitMeasure::from_f32 in file /home/runner/work/petgraph/petgraph/PR_BRANCH/src/algo/mod.rs:858
trait method petgraph::algo::UnitMeasure::from_f64 in file /home/runner/work/petgraph/petgraph/PR_BRANCH/src/algo/mod.rs:859

@starovoid starovoid changed the title Add FloatMeasure methods for constructing Self from f32 & f64 !Add FloatMeasure methods for constructing Self from f32 & f64 Feb 7, 2025
@ABorgna ABorgna added the S-breaking-change Status: Need a breaking change release to progress label Feb 7, 2025
@ABorgna ABorgna added this to the 0.8 milestone Feb 7, 2025
@ABorgna ABorgna changed the title !Add FloatMeasure methods for constructing Self from f32 & f64 feat!: Add FloatMeasure methods for constructing Self from f32 & f64 Feb 7, 2025
@starovoid
Copy link
Collaborator Author

I think it would be nice to add the same methods also for UnitMeasure, PositiveMeasure and maybe for BoundedMeasure bedore release 0.8.0. It may also be worth keeping only the from_f64 method, but I still prefer to have two options for better integration with algebra libraries (such as nalgebra) in the future.
The Measure trait looks too general and in my opinion does not have to be a real number semantically, so we should not implement from_f64 and from_f32 for it.

But whatever my reasoning, I would like to see the opinion of colleagues and the maintainers on this matter. Nevertheless, measure types are one of the key abstractions of petgraph.

@starovoid starovoid mentioned this pull request Feb 13, 2025
3 tasks
@starovoid starovoid self-assigned this Mar 21, 2025
@starovoid starovoid changed the title feat!: Add FloatMeasure methods for constructing Self from f32 & f64 feat!: Add Float, Unit, Bounded measure's methods from_f32/f64 Mar 26, 2025
@starovoid starovoid linked an issue Mar 26, 2025 that may be closed by this pull request
3 tasks
@starovoid starovoid changed the title feat!: Add Float, Unit, Bounded measure's methods from_f32/f64 feat!: Add from_f32/64 methods for Float, Unit, and Bounded measures Mar 26, 2025
@starovoid starovoid added this pull request to the merge queue Mar 26, 2025
Merged via the queue into petgraph:master with commit 7b7c67a Mar 26, 2025
16 checks passed
@starovoid starovoid deleted the fm-from branch March 26, 2025 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-breaking-change Status: Need a breaking change release to progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Construct Measures from f32 & f64

2 participants