Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial work on a Vector trait #153

Merged
merged 28 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
733192b
Define a Vector trait and use it in `fit` and `cblas::level1`
Chris00 Mar 24, 2024
3f7f4d5
Minor reformatting
Chris00 Mar 24, 2024
619fb48
Appease clippy
Chris00 Mar 24, 2024
0f27fe4
Don't require Vector types to be sized (e.g. accept slices)
Chris00 Mar 25, 2024
cf90e1a
vector::Vector: use associated functions to avoid conflicts
Chris00 Apr 14, 2024
222c28c
Distinguish mutable and immutable vector traits (for slices)
Chris00 Apr 15, 2024
73b43a9
Let the `sort` module use the vector trait (and be safe)
Chris00 Apr 15, 2024
a1364af
Use the Vector trait in stats (and add documentation & functions)
Chris00 Apr 15, 2024
e3bcd9e
Make clippy happy
Chris00 Apr 15, 2024
631b465
Run cargo fmt
Chris00 Apr 15, 2024
c49db2c
Fix some example using gls::stats
Chris00 Apr 15, 2024
2270077
Fix documentation warnings
Chris00 Dec 23, 2024
09b2689
CI: do not require a specific version of Ubuntu & use "sudo"
Chris00 Dec 23, 2024
e017f9c
Make the traits Vector and VectorMut unsafe
Chris00 Dec 25, 2024
8875632
Use `Vector` for fast Fourier transform algorithms
Chris00 Dec 25, 2024
718b1d2
Fix warnings for doc generation
Chris00 Dec 25, 2024
ba37b0d
Use the standard Complex<T> type
Chris00 Dec 25, 2024
b90f63e
Make the "fft" module use the Vector trait
Chris00 Dec 25, 2024
dc8938e
Act on Clippy warnings
Chris00 Dec 25, 2024
07a88c3
Allow to keep the error handler in a global static var (no warnings)
Chris00 Dec 25, 2024
5735991
Run cargo fmt
Chris00 Dec 25, 2024
45b8a33
Fix errors reported by the custom checker
Chris00 Dec 25, 2024
9c35928
Slightly relax a test on "drotg"
Chris00 Dec 25, 2024
eb99f93
Fix running examples
Chris00 Dec 26, 2024
506d95a
fast_fourier_transforms: use complex types
Chris00 Dec 26, 2024
67a208d
fft: Use complex types
Chris00 Dec 26, 2024
0d11f49
Do not consider examples as a separate crate
Chris00 Dec 26, 2024
0f02667
Use the Vector trait for statistics, permutations, and wavelets
Chris00 Dec 26, 2024
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
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"]
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved

[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
Loading