-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adcbc2c
commit da3ab61
Showing
5 changed files
with
225 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//! builder utility | ||
|
||
use std::num::NonZeroUsize; | ||
|
||
#[cfg(feature = "serde-serialize")] | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Type of generation | ||
#[non_exhaustive] | ||
#[derive(Debug, PartialEq)] | ||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] | ||
pub enum GenType<'rng, Rng: rand::Rng + ?Sized> { | ||
/// Cold generation all ellements are set to the default | ||
Cold, | ||
/// Random deterministe | ||
#[cfg_attr(feature = "serde-serialize", serde(skip_deserializing))] | ||
HotDeterministe(&'rng mut Rng), | ||
/// Random deterministe but own the RNG (for instance the result of `clone`) | ||
HotDeterministeOwned(Box<Rng>), | ||
/// Random threaded (non deterministe) | ||
HotThreaded(NonZeroUsize), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::borrow::Cow; | ||
use std::fmt::Debug; | ||
use std::num::NonZeroUsize; | ||
|
||
use rand::distributions::Distribution; | ||
use rand_distr::Normal; | ||
#[cfg(feature = "serde-serialize")] | ||
use serde::Serialize; | ||
|
||
use super::EField; | ||
use crate::builder::GenType; | ||
use crate::lattice::LatticeCyclique; | ||
use crate::{CMatrix3, Real}; | ||
|
||
#[derive(Debug, Clone)] | ||
enum DistributionForBuilder<'dis, Dis: Distribution<Real> + ?Sized> { | ||
Default(Normal<Real>), | ||
Given(&'dis Dis), // TODO box dyn | ||
} | ||
|
||
impl<'d, Dis: Distribution<Real> + ?Sized> Default for DistributionForBuilder<'d, Dis> { | ||
fn default() -> Self { | ||
Self::Default(Normal::new(0_f64, 0.5_f64).unwrap()) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct EFieldProceduralBuilder< | ||
'rng, | ||
'lat, | ||
'dis, | ||
Rng: rand::Rng + ?Sized, | ||
Dis: Distribution<Real> + ToOwned + ?Sized, | ||
const D: usize, | ||
> { | ||
gen_type: GenType<'rng, Rng>, | ||
lattice: Cow<'lat, LatticeCyclique<D>>, | ||
distribution: DistributionForBuilder<'dis, Dis>, | ||
} | ||
|
||
/* | ||
impl<'r, 'l, 'd, Rng: rand::Rng + ?Sized, Dis, const D: usize> Debug | ||
for EFieldProceduralBuilder<'r, 'l, 'd, Rng, Dis, D> | ||
where | ||
Dis: Distribution<Real> + ?Sized + ToOwned + Debug, | ||
Rng: Debug, | ||
Dis::Owned: Debug, | ||
{ | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("EFieldProceduralBuilder") | ||
.field("gen_type", &self.gen_type) | ||
.field("lattice", &self.lattice) | ||
.field("distribution", &self.distribution) | ||
.finish() | ||
} | ||
} | ||
*/ | ||
|
||
impl< | ||
'rng, | ||
'lat, | ||
'dis, | ||
Rng: rand::Rng + ?Sized, | ||
Dis: Distribution<Real> + ToOwned + ?Sized, | ||
const D: usize, | ||
> EFieldProceduralBuilder<'rng, 'lat, 'dis, Rng, Dis, D> | ||
{ | ||
pub fn new(lattice: impl Into<Cow<'lat, LatticeCyclique<D>>>) -> Self { | ||
Self { | ||
gen_type: GenType::Cold, | ||
lattice: lattice.into(), | ||
distribution: DistributionForBuilder::default(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters