#[cfg(feature = "ffi")]
mod ffi;
use opendp_derive::bootstrap;
use crate::core::{MetricSpace, Transformation};
use crate::domains::{AtomDomain, OptionDomain, VectorDomain};
use crate::error::Fallible;
use crate::metrics::EventLevelMetric;
use crate::traits::{CheckAtom, HasNull, RoundCast};
use crate::transformations::make_row_by_row;
#[bootstrap(features("contrib"), generics(M(suppress), TIA(suppress)))]
pub fn make_cast<M, TIA, TOA>(
input_domain: VectorDomain<AtomDomain<TIA>>,
input_metric: M,
) -> Fallible<
Transformation<
VectorDomain<AtomDomain<TIA>>,
M,
VectorDomain<OptionDomain<AtomDomain<TOA>>>,
M,
>,
>
where
M: EventLevelMetric,
TIA: 'static + Clone + CheckAtom,
TOA: 'static + RoundCast<TIA> + CheckAtom,
(VectorDomain<AtomDomain<TIA>>, M): MetricSpace,
(VectorDomain<OptionDomain<AtomDomain<TOA>>>, M): MetricSpace,
{
make_row_by_row(
input_domain,
input_metric,
OptionDomain::new(AtomDomain::default()),
|v| {
TOA::round_cast(v.clone())
.ok()
.and_then(|v| if v.is_null() { None } else { Some(v) })
},
)
}
#[bootstrap(
features("contrib"),
arguments(
input_domain(c_type = "AnyDomain *"),
input_metric(c_type = "AnyMetric *")
),
generics(TIA(suppress), M(suppress)),
derived_types(
TIA = "$get_atom(get_type(input_domain))",
M = "$get_type(input_metric)"
)
)]
pub fn make_cast_default<M, TIA, TOA>(
input_domain: VectorDomain<AtomDomain<TIA>>,
input_metric: M,
) -> Fallible<Transformation<VectorDomain<AtomDomain<TIA>>, M, VectorDomain<AtomDomain<TOA>>, M>>
where
M: EventLevelMetric,
TIA: 'static + Clone + CheckAtom,
TOA: 'static + RoundCast<TIA> + Default + CheckAtom,
(VectorDomain<AtomDomain<TIA>>, M): MetricSpace,
(VectorDomain<AtomDomain<TOA>>, M): MetricSpace,
{
make_row_by_row(input_domain, input_metric, AtomDomain::default(), |v| {
TOA::round_cast(v.clone()).unwrap_or_default()
})
}
#[bootstrap(features("contrib"), generics(M(suppress), TIA(suppress)))]
pub fn make_cast_inherent<M, TIA, TOA>(
input_domain: VectorDomain<AtomDomain<TIA>>,
input_metric: M,
) -> Fallible<Transformation<VectorDomain<AtomDomain<TIA>>, M, VectorDomain<AtomDomain<TOA>>, M>>
where
M: EventLevelMetric,
TIA: 'static + Clone + CheckAtom,
TOA: 'static + RoundCast<TIA> + HasNull + CheckAtom,
(VectorDomain<AtomDomain<TIA>>, M): MetricSpace,
(VectorDomain<AtomDomain<TOA>>, M): MetricSpace,
{
make_row_by_row(input_domain, input_metric, AtomDomain::default(), |v| {
TOA::round_cast(v.clone()).unwrap_or(TOA::NULL)
})
}
#[cfg(test)]
mod test;