Skip to content

Commit 93130b4

Browse files
committed
chore: merge main
2 parents ae92cab + 5b36c87 commit 93130b4

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
use ndarray::Array1;
2-
use prettytable::{format, row, Table};
2+
use prettytable::{format, row, Cell, Row, Table};
33
use stochastic_rs::plot_1d;
44
use stochastic_rs::stochastic::noise::fgn::FGN;
55
use stochastic_rs::stochastic::Sampling;
66
use std::error::Error;
77
use std::fs::File;
88
use std::io::{BufRead, BufReader};
9+
use std::time::Instant;
10+
use stochastic_rs::stochastic::noise::fgn::FGN;
11+
use stochastic_rs::stochastic::Sampling;
912

1013
use stochastic_rs::stats::fd::FractalDim;
1114
use stochastic_rs::stats::fou_estimator::{
@@ -14,7 +17,7 @@ use stochastic_rs::stats::fou_estimator::{
1417

1518
// Import your estimator modules and types here
1619
// use your_crate::{FOUParameterEstimationV1, FOUParameterEstimationV2, FilterType};
17-
20+
const N: usize = 10000;
1821
fn main() -> Result<(), Box<dyn Error>> {
1922
let fbm = FGN::new(0.7, 10_000, Some(1.0), Some(10000));
2023
let fgn = fbm.sample_cuda().unwrap();

src/stochastic/noise/fgn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::error::Error;
2-
use std::sync::{Arc, Mutex};
2+
use std::sync::{Arc, RwLock};
33

44
use ndarray::parallel::prelude::*;
55
use ndarray::{concatenate, prelude::*};
@@ -70,21 +70,21 @@ impl Sampling<f64> for FGN {
7070
// );
7171
let num_threads = rayon::current_num_threads();
7272
let chunk_size = (2 * self.n) / num_threads;
73-
let rnd = Arc::new(Mutex::new(Array1::<Complex<f64>>::zeros(2 * self.n)));
73+
let rnd = Arc::new(RwLock::new(Array1::<Complex<f64>>::zeros(2 * self.n)));
7474

7575
(0..num_threads).into_par_iter().for_each(|i| {
7676
let chunk = Array1::<Complex<f64>>::random(
7777
chunk_size,
7878
ComplexDistribution::new(StandardNormal, StandardNormal),
7979
);
8080

81-
let mut result_lock = rnd.lock().unwrap();
81+
let mut result_lock = rnd.write().unwrap();
8282
result_lock
8383
.slice_mut(s![i * chunk_size..(i + 1) * chunk_size])
8484
.assign(&chunk);
8585
});
8686

87-
let fgn = &*self.sqrt_eigenvalues * &*rnd.lock().unwrap();
87+
let fgn = &*self.sqrt_eigenvalues * &rnd;
8888
let mut fgn_fft = Array1::<Complex<f64>>::zeros(2 * self.n);
8989
ndfft(&fgn, &mut fgn_fft, &*self.fft_handler, 0);
9090
let scale = (self.n as f64).powf(-self.hurst) * self.t.unwrap_or(1.0).powf(self.hurst);

0 commit comments

Comments
 (0)