Skip to content

Conversation

gkobeaga
Copy link

@gkobeaga gkobeaga commented Oct 6, 2022

I am trying to maintain the Float type restriction.

If I understand the error correctly, serde tries to guess heuristically the trait bounds but it fails.

We need to write by hand the bounds for deserialize. Using #[serde(bound(deserialize = "D: Deserialize<'de>"))] as follows it compiles:

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(bound(deserialize = "D: Deserialize<'de>"))]
pub struct LogisticRegressionParams<F: Float, D: Dimension>(LogisticRegressionValidParams<F, D>);

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(bound(deserialize = "D: Deserialize<'de>"))]
pub struct LogisticRegressionValidParams<F: Float, D: Dimension> {
    pub(crate) alpha: F,
    pub(crate) fit_intercept: bool,
    pub(crate) max_iterations: u64,
    pub(crate) gradient_tolerance: F,
    pub(crate) initial_params: Option<Array<F, D>>,
}

Note: I am learning Rust and I am not sure about the implications of these bounds, I just know that it compiles XD.

Related:

@levkk
Copy link

levkk commented Oct 6, 2022

If it compiles, it's good enough for me!

@levkk levkk merged commit 9392fe6 into postgresml:master Oct 6, 2022
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.

2 participants