Skip to content
Draft
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
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ ndarray = { version = "^0.16", features = ["serde"] }
ndarray-stats = "^0.6"
num-complex = "^0.4" # the same version as used by fftw
num-traits = "^0.2"
ordered-float = { version = "5", features = ["serde", "schemars"] }
# Using git dependency until ordered-float releases schemars 1.x support (see https://github.com/reem/rust-ordered-float/pull/174)
ordered-float = { git = "https://github.com/mdepta42/rust-ordered-float", rev = "3e80f4219129ae98b2d29ec58286f754cd17a254", features = ["serde", "schemars"] }
paste = "1"
schemars = "^0.8"
schemars = "^1"
serde = { version = "1", features = ["derive"] }
thiserror = "2"
thread_local = "1.1"
Expand Down
10 changes: 2 additions & 8 deletions src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ Bulk feature extractor
}

#[doc = DOC!()]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(
into = "FeatureExtractorParameters<F>",
from = "FeatureExtractorParameters<F>",
bound = "T: Float, F: FeatureEvaluator<T>"
)]
#[schemars(with = "FeatureExtractorParameters::<F>", bound = "F: JsonSchema")]
pub struct FeatureExtractor<T, F> {
features: Vec<F>,
info: Box<EvaluatorInfo>,
Expand Down Expand Up @@ -169,13 +170,6 @@ where
}
}

impl<T, F> JsonSchema for FeatureExtractor<T, F>
where
F: JsonSchema,
{
json_schema!(FeatureExtractorParameters<F>, true);
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
10 changes: 2 additions & 8 deletions src/features/beyond_n_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ D’Isanto et al. 2016 [DOI:10.1093/mnras/stw157](https://doi.org/10.1093/mnras/
/// assert!((1.0 - ts.m.get_std()).abs() < 1e-15);
/// assert_eq!(vec![4.0 / 21.0, 2.0 / 21.0], fe.eval(&mut ts).unwrap());
/// ```
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(
from = "BeyondNStdParameters",
into = "BeyondNStdParameters",
bound(deserialize = "T: Float")
)]
#[schemars(with = "BeyondNStdParameters")]
pub struct BeyondNStd<T>
where
T: Float,
Expand Down Expand Up @@ -173,13 +174,6 @@ where
}
}

impl<T> JsonSchema for BeyondNStd<T>
where
T: Float,
{
json_schema!(BeyondNStdParameters, false);
}

#[cfg(test)]
#[allow(clippy::unreadable_literal)]
#[allow(clippy::excessive_precision)]
Expand Down
14 changes: 5 additions & 9 deletions src/features/bins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ considering bin. Bins takes any other feature evaluators to extract features fro
}

#[doc = DOC!()]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(
into = "BinsParameters<T, F>",
from = "BinsParameters<T, F>",
bound(deserialize = "T: Float, F: FeatureEvaluator<T>")
)]
#[schemars(
with = "BinsParameters::<T, F>",
bound = "T: Float, F: FeatureEvaluator<T>"
)]
pub struct Bins<T, F>
where
T: Float,
Expand Down Expand Up @@ -277,14 +281,6 @@ where
}
}

impl<T, F> JsonSchema for Bins<T, F>
where
T: Float,
F: FeatureEvaluator<T>,
{
json_schema!(BinsParameters<T, F>, false);
}

#[cfg(test)]
#[allow(clippy::unreadable_literal)]
#[allow(clippy::excessive_precision)]
Expand Down
7 changes: 2 additions & 5 deletions src/features/inter_percentile_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ inter-percentile range for $p = 0.1$.
}

#[doc = DOC!()]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Hash)]
#[serde(
from = "InterPercentileRangeParameters",
into = "InterPercentileRangeParameters"
)]
#[schemars(with = "InterPercentileRangeParameters")]
pub struct InterPercentileRange {
quantile: NotNan<f32>,
name: String,
Expand Down Expand Up @@ -126,10 +127,6 @@ impl From<InterPercentileRangeParameters> for InterPercentileRange {
}
}

impl JsonSchema for InterPercentileRange {
json_schema!(InterPercentileRangeParameters, false);
}

#[cfg(test)]
#[allow(clippy::unreadable_literal)]
#[allow(clippy::excessive_precision)]
Expand Down
10 changes: 2 additions & 8 deletions src/features/median_buffer_range_percentage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ D’Isanto et al. 2016 [DOI:10.1093/mnras/stw157](https://doi.org/10.1093/mnras/
}

#[doc = DOC!()]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(
into = "MedianBufferRangePercentageParameters",
from = "MedianBufferRangePercentageParameters",
bound(deserialize = "T: Float")
)]
#[schemars(with = "MedianBufferRangePercentageParameters")]
pub struct MedianBufferRangePercentage<T>
where
T: Float,
Expand Down Expand Up @@ -154,13 +155,6 @@ where
}
}

impl<T> JsonSchema for MedianBufferRangePercentage<T>
where
T: Float,
{
json_schema!(MedianBufferRangePercentageParameters, false);
}

#[cfg(test)]
#[allow(clippy::unreadable_literal)]
#[allow(clippy::excessive_precision)]
Expand Down
7 changes: 2 additions & 5 deletions src/features/percent_difference_magnitude_percentile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ D’Isanto et al. 2016 [DOI:10.1093/mnras/stw157](https://doi.org/10.1093/mnras/
}

#[doc = DOC!()]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Hash)]
#[serde(
into = "PercentDifferenceMagnitudePercentileParameters",
from = "PercentDifferenceMagnitudePercentileParameters"
)]
#[schemars(with = "PercentDifferenceMagnitudePercentileParameters")]
pub struct PercentDifferenceMagnitudePercentile {
quantile: NotNan<f32>,
name: String,
Expand Down Expand Up @@ -129,10 +130,6 @@ impl From<PercentDifferenceMagnitudePercentileParameters> for PercentDifferenceM
}
}

impl JsonSchema for PercentDifferenceMagnitudePercentile {
json_schema!(PercentDifferenceMagnitudePercentileParameters, false);
}

#[cfg(test)]
#[allow(clippy::unreadable_literal)]
#[allow(clippy::excessive_precision)]
Expand Down
21 changes: 7 additions & 14 deletions src/features/periodogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ Peak evaluator for [Periodogram]

#[doc(hidden)]
#[doc = PERIODOGRAM_PEAK_DOC!()]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(
from = "PeriodogramPeaksParameters",
into = "PeriodogramPeaksParameters"
)]
#[schemars(with = "PeriodogramPeaksParameters")]
pub struct PeriodogramPeaks {
peaks: usize,
properties: Box<EvaluatorProperties>,
Expand Down Expand Up @@ -156,10 +157,6 @@ impl From<PeriodogramPeaksParameters> for PeriodogramPeaks {
}
}

impl JsonSchema for PeriodogramPeaks {
json_schema!(PeriodogramPeaksParameters, false);
}

macro_const! {
const DOC: &str = r#"
Peaks of Lomb–Scargle periodogram and periodogram as a meta-feature
Expand All @@ -183,12 +180,16 @@ series without observation errors (unity weights are used if required). You can
}

#[doc = DOC!()]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(
bound = "T: Float, F: FeatureEvaluator<T> + From<PeriodogramPeaks> + TryInto<PeriodogramPeaks>, <F as std::convert::TryInto<PeriodogramPeaks>>::Error: Debug,",
from = "PeriodogramParameters<T, F>",
into = "PeriodogramParameters<T, F>"
)]
#[schemars(
with = "PeriodogramParameters::<T, F>",
bound = "T: Float, F: FeatureEvaluator<T>"
)]
pub struct Periodogram<T, F>
where
T: Float,
Expand Down Expand Up @@ -521,14 +522,6 @@ where
}
}

impl<T, F> JsonSchema for Periodogram<T, F>
where
T: Float,
F: FeatureEvaluator<T>,
{
json_schema!(PeriodogramParameters<T, F>, false);
}

#[cfg(test)]
#[allow(clippy::unreadable_literal)]
#[allow(clippy::excessive_precision)]
Expand Down
12 changes: 11 additions & 1 deletion src/features/transformed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ where
F: FeatureEvaluator<T>,
Tr: TransformerTrait<T>,
{
json_schema!(TransformedParameters<F, Tr>, false);
fn inline_schema() -> bool {
true
}

fn schema_name() -> std::borrow::Cow<'static, str> {
<TransformedParameters<F, Tr>>::schema_name()
}

fn json_schema(r#gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
<TransformedParameters<F, Tr>>::json_schema(r#gen)
}
}

#[cfg(test)]
Expand Down
17 changes: 0 additions & 17 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,6 @@ macro_rules! transformer_eval {
};
}

/// Helper implementing JsonSchema crate
macro_rules! json_schema {
($parameters: ty, $is_referenceable: expr) => {
fn is_referenceable() -> bool {
$is_referenceable
}

fn schema_name() -> String {
<$parameters>::schema_name()
}

fn json_schema(r#gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
<$parameters>::json_schema(r#gen)
}
};
}

/// Helper implementing *Fit feature evaluators
/// You must:
/// - implement all traits of [nl_fit::evaluator]
Expand Down
20 changes: 2 additions & 18 deletions src/nl_fit/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,15 @@ pub trait FitDerivalivesTrait<T: Float, const NPARAMS: usize> {
fn derivatives(t: T, param: &[T; NPARAMS], jac: &mut [T; NPARAMS]);
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(
into = "FitArraySerde<T>",
try_from = "FitArraySerde<T>",
bound = "T: Debug + Clone + Serialize + DeserializeOwned + JsonSchema"
)]
#[schemars(with = "FitArraySerde::<T>", bound = "T: JsonSchema")]
pub struct FitArray<T, const NPARAMS: usize>(pub [T; NPARAMS]);

impl<T, const NPARAMS: usize> JsonSchema for FitArray<T, NPARAMS>
where
T: schemars::JsonSchema,
{
fn is_referenceable() -> bool {
false
}

fn schema_name() -> String {
FitArraySerde::<T>::schema_name()
}

fn json_schema(r#gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
FitArraySerde::<T>::json_schema(r#gen)
}
}

impl<T, const NPARAMS: usize> From<[T; NPARAMS]> for FitArray<T, NPARAMS> {
fn from(item: [T; NPARAMS]) -> Self {
Self(item)
Expand Down
17 changes: 2 additions & 15 deletions src/nl_fit/prior/ln_prior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ impl<const NPARAMS: usize> LnPriorTrait<NPARAMS> for NoneLnPrior {
}
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Hash)]
#[serde(
into = "IndComponentsLnPriorSerde",
try_from = "IndComponentsLnPriorSerde"
)]
#[schemars(with = "IndComponentsLnPriorSerde")]
pub struct IndComponentsLnPrior<const NPARAMS: usize> {
pub components: [LnPrior1D; NPARAMS],
}
Expand All @@ -86,20 +87,6 @@ impl<const NPARAMS: usize> LnPriorTrait<NPARAMS> for IndComponentsLnPrior<NPARAM
}
}

impl<const NPARAMS: usize> JsonSchema for IndComponentsLnPrior<NPARAMS> {
fn is_referenceable() -> bool {
false
}

fn schema_name() -> String {
IndComponentsLnPriorSerde::schema_name()
}

fn json_schema(r#gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
IndComponentsLnPriorSerde::json_schema(r#gen)
}
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename = "IndComponentsLnPrior")]
struct IndComponentsLnPriorSerde {
Expand Down
10 changes: 2 additions & 8 deletions src/periodogram/power_fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ use thread_local::ThreadLocal;
/// especially for large grids.
///
/// The implementation is inspired by Numerical Recipes, Press et al., 1997, Section 13.8
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(
into = "PeriodogramPowerFftParameters",
from = "PeriodogramPowerFftParameters",
bound = "T: Float"
)]
#[schemars(with = "PeriodogramPowerFftParameters")]
pub struct PeriodogramPowerFft<T>
where
T: Float,
Expand Down Expand Up @@ -197,13 +198,6 @@ where
}
}

impl<T> JsonSchema for PeriodogramPowerFft<T>
where
T: Float,
{
json_schema!(PeriodogramPowerFftParameters, false);
}

struct PeriodogramArrays<T>
where
T: Float,
Expand Down
Loading
Loading