Skip to content

Commit

Permalink
Merge pull request #153 from Chris00/master
Browse files Browse the repository at this point in the history
Initial work on a `Vector` trait
  • Loading branch information
GuillaumeGomez authored Jan 18, 2025
2 parents 9e148b5 + 0f02667 commit 2d9e2b1
Show file tree
Hide file tree
Showing 51 changed files with 4,020 additions and 2,633 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ name: CI
jobs:
build-linux:
runs-on: ubuntu-latest
container:
image: ubuntu:23.10
strategy:
matrix:
rust:
- stable
- nightly
steps:
- run: apt-get update -y
- run: apt-get install -y libgsl0-dev curl build-essential python3
- run: sudo apt-get update -y
- run: sudo apt-get install -y libgsl0-dev curl build-essential python3
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
Expand All @@ -36,10 +34,8 @@ jobs:
- name: run tests
run: cargo test --features v2_7
- name: check examples
working-directory: examples
run: cargo check --features GSL/v2_7
run: cargo check --features v2_7
- name: run examples
working-directory: examples
run: python3 run-examples.py

build-osx:
Expand Down Expand Up @@ -67,7 +63,7 @@ jobs:
- run: cargo check --features v2_7
- name: check examples
working-directory: examples
run: cargo check --features GSL/v2_7
run: cargo check --features v2_7

fmt:
name: rust fmt
Expand Down
37 changes: 37 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ edition = "2021"
[dependencies]
sys = { path = "gsl-sys", package = "GSL-sys", version = "3.0.0" }
paste = "1.0"
num-complex = { version = "0.4.6", optional = true }

[features]
default = ["complex"]
v2_1 = ["sys/v2_1"]
v2_2 = ["sys/v2_2", "v2_1"]
v2_3 = ["sys/v2_3", "v2_2"]
Expand All @@ -23,6 +25,8 @@ v2_5 = ["sys/v2_5", "v2_4"]
v2_6 = ["sys/v2_6", "v2_5"]
v2_7 = ["sys/v2_7", "v2_6"]
dox = ["v2_7", "sys/dox"]
# Enable complex number functions:
complex = ["dep:num-complex"]

[package.metadata.docs.rs]
features = ["dox"]
Expand All @@ -31,3 +35,36 @@ rustdoc-args = ["--generate-link-to-definition"]
[lib]
name = "rgsl"
crate-type = ["dylib", "rlib"]

# Examples with special requirements
[[example]]
name = "filt_edge"
required-features = ["v2_5"]

[[example]]
name = "fitreg"
required-features = ["v2_5"]

[[example]]
name = "fitreg2"
required-features = ["v2_5"]

[[example]]
name = "fitting"
required-features = ["v2_5"]

[[example]]
name = "gaussfilt"
required-features = ["v2_5"]

[[example]]
name = "gaussfilt2"
required-features = ["v2_5"]

[[example]]
name = "impulse"
required-features = ["v2_5"]

[[example]]
name = "largefit"
required-features = ["v2_2"]
126 changes: 0 additions & 126 deletions examples/Cargo.toml

This file was deleted.

4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This folder contains the `rgsl` examples. To run one, just use `cargo`:

```bash
$ cargo run --bin intro
$ cargo run --example intro
```

And that's it!
Expand All @@ -12,7 +12,7 @@ Some examples might require a higher GSL version. `rgsl` supports versions throu
So for example:

```bash
$ cargo run --bin largefit --features GSL/v2_2
$ cargo run --example largefit --features v2_2
```

# Original examples
Expand Down
7 changes: 1 addition & 6 deletions examples/bspline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ fn main() {
let chisq = mw.wlinear(&mat_x, &w, &y, &mut c, &mut cov).unwrap();

let dof = N - NCOEFFS;
let tss = stats::wtss(
w.as_slice().expect("as_slice failed"),
1,
y.as_slice().expect("as_slice failed"),
1,
);
let tss = stats::wtss(&w, &y);
let rsq = 1. - chisq / tss;

eprintln!("chisq/dof = {}, rsq = {}", chisq / dof as f64, rsq);
Expand Down
4 changes: 2 additions & 2 deletions examples/eigen_nonsymm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ fn main() {
for i in 0..4 {
let eval_i = eval.get(i);
evec.column(i, |evec_i| {
println!("eigenvalue = {} + {}", eval_i.real(), eval_i.imaginary());
println!("eigenvalue = {eval_i}");
evec_i.expect("Failed to get get column").vector(|v| {
let v = v.expect("Failed to get vector from column");
println!("eigenvector = ");
for j in 0..4 {
let z = v.get(j);
println!("{} + {}", z.real(), z.imaginary());
println!("{z}");
}
});
});
Expand Down
33 changes: 8 additions & 25 deletions examples/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,30 @@
// A rust binding for the GSL library by Guillaume Gomez ([email protected])
//

extern crate rgsl;

use num_complex::c64;
use rgsl::fft;

macro_rules! real {
($z:ident, $i:expr) => {
$z[2 * ($i)]
};
}
macro_rules! imag {
($z:ident, $i:expr) => {
$z[2 * ($i) + 1]
};
}

const N: usize = 128;

fn main() {
let data = &mut [0.; 2 * N];
let data = &mut [c64(0., 0.); N];

real!(data, 0) = 1.;
data[0].re = 1.;

for i in 1..=10 {
real!(data, i) = 1.;
real!(data, N - i) = 1.;
data[i].re = 1.;
data[N - i].re = 1.;
}

for i in 0..N {
println!("{} {} {}", i, real!(data, i), imag!(data, i));
println!("{} {}", i, data[i]);
}
println!();
println!();

fft::radix2::forward(data, 1, N).unwrap();
fft::radix2::forward(data).unwrap();

for i in 0..N {
println!(
"{} {} {}",
i,
real!(data, i) / 128f64.sqrt(),
imag!(data, i) / 128f64.sqrt()
);
println!("{} {}", i, data[i] / 128f64.sqrt());
}
}
28 changes: 9 additions & 19 deletions examples/fftmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,35 @@

extern crate rgsl;

use num_complex::c64;
use rgsl::{FftComplexF64WaveTable, FftComplexF64Workspace};

macro_rules! real {
($z:ident, $i:expr) => {
$z[2 * ($i)]
};
}
macro_rules! imag {
($z:ident, $i:expr) => {
$z[2 * ($i) + 1]
};
}

const N: usize = 630;
const N: usize = 128;

fn main() {
let data = &mut [0.; 2 * N];
let data = &mut [c64(0., 0.); N];
let wavetable = FftComplexF64WaveTable::new(N).expect("FftComplexF64WaveTable::new failed");
let mut workspace = FftComplexF64Workspace::new(N).expect("FftComplexF64Workspace::new failed");

data[0] = 1.;
data[0].re = 1.;

for i in 1..=10 {
real!(data, i) = 1.;
real!(data, N - i) = 1.;
data[i].re = 1.;
data[N - i].re = 1.;
}

for i in 0..N {
println!("{}: {} {}", i, real!(data, i), imag!(data, i));
println!("{}: {}", i, data[i]);
}
println!();

for i in 0..wavetable.nf() {
println!("# factor {}: {}", i, wavetable.factor()[i]);
}

workspace.forward(data, 1, N, &wavetable).unwrap();
workspace.forward(data, &wavetable).unwrap();

for i in 0..N {
println!("{}: {} {}", i, real!(data, i), imag!(data, i));
println!("{}: {}", i, data[i]);
}
}
Loading

0 comments on commit 2d9e2b1

Please sign in to comment.