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

Use newer action for toolchain management #2

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 6 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rustfmt
- name: Cache
uses: actions/cache@v4.0.2
with:
Expand All @@ -22,13 +27,7 @@ jobs:
~/.cargo/git
~/.rustup
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Setup toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt, clippy
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{steps.toolchain.outputs.name}}
- name: Formatting
run: cargo fmt --check
- name: Build
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
colorous = "1.0.14"
fftw = { path = "/Users/russell/projects/rust/fftw3-rs/fftw", features = ["system"] }
fftw = { git = "https://github.com/SallySoul/fftw3-rs.git", tag = "fftw3-v0.8.1" }

image = "0.25.2"
num = "0.4.3"
Expand Down
4 changes: 0 additions & 4 deletions examples/heat_2d_p_fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ fn main() {
fft_backwards_buffer[i] = fft_ic_output_buffer[i];
}

for i in 0..width * height {
fft_ic_input_buffer[i] = 0.0;
}

backward_plan
.c2r(&mut fft_backwards_buffer, &mut fft_ic_input_buffer)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pub mod basic_domain;
pub mod domain;
pub mod linear_stencil;
pub mod naive_solver;
pub mod squaring;
pub mod stencil;
55 changes: 55 additions & 0 deletions src/squaring.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
pub fn log2ceil(i: usize) -> usize {
(usize::BITS - i.leading_zeros()) as usize
}

pub fn repeated_square(exp0: usize, i: usize) -> usize {
let mut exp = exp0;
let mut squares = i;
let mut result = 1;
let n = log2ceil(exp0);
println!(
"repeated, n: {}, exp: {}, result: {}, squares: {}",
n, exp, result, squares
);
for _ in 0..n {
if exp % 2 == 1 {
result *= squares;
exp -= 1;
println!(
" - odd exp, result: {}, squares: {}, exp: {}",
result, squares, exp
);
}
exp /= 2;
squares *= squares;
println!(" * exp: {}, result: {}, squares: {}", exp, result, squares);
}

result
}

#[cfg(test)]
mod unit_tests {
use super::*;

#[test]
fn log2ceil_test() {
assert_eq!(log2ceil(1), 1);
assert_eq!(log2ceil(2), 2);
assert_eq!(log2ceil(3), 2);
assert_eq!(log2ceil(4), 3);
assert_eq!(log2ceil(5), 3);
assert_eq!(log2ceil(6), 3);
assert_eq!(log2ceil(7), 3);
assert_eq!(log2ceil(8), 4);
}

#[test]
fn repeated_square_test() {
assert_eq!(repeated_square(2, 2), 4);
assert_eq!(repeated_square(3, 2), 8);
assert_eq!(repeated_square(4, 2), 16);
assert_eq!(repeated_square(5, 2), 32);
assert_eq!(repeated_square(9, 3), 19683);
}
}