Skip to content

Commit e6b759f

Browse files
authored
Merge pull request #221 from mulimoen/documentation
Minor documentation and CI changes
2 parents 43e5504 + f0542a9 commit e6b759f

File tree

11 files changed

+107
-76
lines changed

11 files changed

+107
-76
lines changed

.github/workflows/ci.yml

+56-25
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,59 @@ on:
77
- master
88
schedule:
99
- cron: '0 0 15 * *'
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
RUSTFLAGS: -D warnings
14+
1015
jobs:
16+
rustfmt:
17+
name: rustfmt
18+
runs-on: ubuntu-18.04
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v2
22+
- name: Install rust
23+
uses: actions-rs/toolchain@v1
24+
with:
25+
toolchain: stable
26+
override: true
27+
profile: minimal
28+
components: rustfmt
29+
- name: Check formatting
30+
run: cargo fmt -- --check
31+
32+
documentation:
33+
name: documentation
34+
runs-on: ubuntu-18.04
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v2
38+
- name: Install rust
39+
uses: actions-rs/toolchain@v1
40+
with:
41+
toolchain: stable
42+
override: true
43+
profile: minimal
44+
- name: Documentation
45+
run: cargo doc --all-features --workspace
46+
47+
clippy:
48+
name: clippy
49+
runs-on: ubuntu-18.04
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v2
53+
- name: Install rust
54+
uses: actions-rs/toolchain@v1
55+
with:
56+
toolchain: stable
57+
override: true
58+
profile: minimal
59+
components: clippy
60+
- name: Run Clippy
61+
run: cargo clippy --workspace --all-features
62+
1163
test:
1264
name: test
1365
runs-on: ${{ matrix.os }}
@@ -57,10 +109,8 @@ jobs:
57109
if: matrix.os != 'ubuntu-18.04'
58110

59111
- name: Build (all)
60-
run: env && cargo build --verbose --workspace
112+
run: cargo build --verbose --workspace
61113
if: matrix.os == 'ubuntu-18.04'
62-
env:
63-
RUSTFLAGS: -D warnings
64114

65115
- name: Test (exclude suitesparse)
66116
run: cargo test --verbose --workspace --exclude suitesparse_ldl_sys --exclude sprs_suitesparse_ldl
@@ -74,25 +124,6 @@ jobs:
74124
run: cargo test -p sprs-ldl --features sprs_suitesparse_ldl -Zpackage-features
75125
if: matrix.os == 'ubuntu-18.04' && matrix.build == 'nightly'
76126

77-
rustfmt:
78-
name: rustfmt
79-
runs-on: ubuntu-18.04
80-
steps:
81-
- name: Checkout repository
82-
uses: actions/checkout@v2
83-
- name: Install rust
84-
uses: actions-rs/toolchain@v1
85-
with:
86-
toolchain: stable
87-
override: true
88-
profile: minimal
89-
components: rustfmt
90-
- name: Check formatting
91-
run: |
92-
cargo fmt -- --check
93-
- name: Documentation
94-
run: cargo doc
95-
96127
benches:
97128
name: benchmarks
98129
runs-on: ubuntu-18.04
@@ -112,8 +143,8 @@ jobs:
112143
run: |
113144
cargo bench --workspace
114145
115-
optional_features:
116-
name: Optional features
146+
optional_none:
147+
name: Optional features (none selected)
117148
runs-on: ubuntu-18.04
118149
steps:
119150
- name: Checkout repository
@@ -129,7 +160,7 @@ jobs:
129160
cargo test --no-default-features
130161
131162
optional_approx:
132-
name: Optional features
163+
name: Optional features (approx selected)
133164
runs-on: ubuntu-18.04
134165
steps:
135166
- name: Checkout repository

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ members = [
5454
"sprs-rand",
5555
"sprs-benches",
5656
]
57+
58+
[package.metadata.docs.rs]
59+
all-features = true

sprs-benches/Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ version = "0.1.0"
44
authors = ["Vincent Barrielle <[email protected]>"]
55
edition = "2018"
66

7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8-
97
[dependencies.sprs]
108
version = "0.8.0"
119
path = ".."
@@ -18,7 +16,7 @@ path = "../sprs-rand"
1816
version = "0.2.12"
1917

2018
[dependencies]
21-
pyo3 = { version="0.9.2", optional=true }
19+
pyo3 = { version="0.11.1" }
2220

2321
[build-dependencies]
2422
cc = "1.0.52"
@@ -29,6 +27,5 @@ libflate = {version="1.0.0", optional=true }
2927
[features]
3028

3129
default = []
32-
nightly = ["pyo3"]
3330
dl_eigen = ["reqwest", "tar", "libflate"]
3431
eigen = []

sprs-benches/src/main.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
#[cfg(feature = "nightly")]
21
use pyo3::{
32
prelude::*,
43
types::{IntoPyDict, PyModule},
54
};
65
use sprs::smmp;
76
use sprs_rand::rand_csr_std;
87

9-
#[cfg(feature = "nightly")]
108
fn scipy_mat<'a>(
119
scipy_sparse: &'a PyModule,
1210
py: &Python,
@@ -155,11 +153,8 @@ fn bench_densities() -> Result<(), Box<dyn std::error::Error>> {
155153
},
156154
];
157155

158-
#[cfg(feature = "nightly")]
159156
let gil = Python::acquire_gil();
160-
#[cfg(feature = "nightly")]
161157
let py = gil.python();
162-
#[cfg(feature = "nightly")]
163158
let scipy_sparse = PyModule::import(py, "scipy.sparse").map_err(|e| {
164159
let res = format!("Python error: {:?}", e);
165160
e.print_and_set_sys_last_vars(py);
@@ -169,7 +164,7 @@ fn bench_densities() -> Result<(), Box<dyn std::error::Error>> {
169164
for spec in &bench_specs {
170165
let shape = spec.shape;
171166

172-
let is_shape_bench = spec.shapes.len() != 0;
167+
let is_shape_bench = !spec.shapes.is_empty();
173168
let densities = if is_shape_bench {
174169
spec.shapes
175170
.iter()
@@ -190,7 +185,6 @@ fn bench_densities() -> Result<(), Box<dyn std::error::Error>> {
190185
let mut times_autothread = Vec::with_capacity(densities.len());
191186
let mut times_2threads = Vec::with_capacity(densities.len());
192187
let mut times_4threads = Vec::with_capacity(densities.len());
193-
#[cfg(feature = "nightly")]
194188
let mut times_py = Vec::with_capacity(densities.len());
195189
#[cfg(feature = "eigen")]
196190
let mut times_eigen = Vec::with_capacity(densities.len());
@@ -261,7 +255,6 @@ fn bench_densities() -> Result<(), Box<dyn std::error::Error>> {
261255
res_densities.push(prod.density());
262256

263257
// bench scipy as well
264-
#[cfg(feature = "nightly")]
265258
{
266259
let m1_py = scipy_mat(scipy_sparse, &py, &m1)?;
267260
let m2_py = scipy_mat(scipy_sparse, &py, &m2)?;
@@ -307,7 +300,6 @@ fn bench_densities() -> Result<(), Box<dyn std::error::Error>> {
307300
println!("Product times (sprs, 2 threads): {:?}", times_2threads);
308301
println!("Product times (sprs, 4 threads): {:?}", times_4threads);
309302
println!("Product times (sprs, auto threads): {:?}", times_autothread);
310-
#[cfg(feature = "nightly")]
311303
println!("Product times (scipy): {:?}", times_py);
312304
#[cfg(feature = "eigen")]
313305
println!("Product times (eigen): {:?}", times_eigen);
@@ -352,7 +344,6 @@ fn bench_densities() -> Result<(), Box<dyn std::error::Error>> {
352344
max_time,
353345
*times_eigen.iter().max().unwrap_or(&1),
354346
);
355-
#[cfg(feature = "nightly")]
356347
let max_time =
357348
std::cmp::max(max_time, *times_py.iter().max().unwrap_or(&1));
358349
let max_time = max_time as f32;
@@ -423,7 +414,6 @@ fn bench_densities() -> Result<(), Box<dyn std::error::Error>> {
423414
PathElement::new(vec![(x, y), (x + 20, y)], &BLUE)
424415
});
425416

426-
#[cfg(feature = "nightly")]
427417
chart
428418
.draw_series(LineSeries::new(
429419
abscisses

sprs-ldl/src/lib.rs

+20-13
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ pub struct Ldl {
7878
fill_red_method: FillInReduction,
7979
}
8080

81+
impl Default for Ldl {
82+
fn default() -> Self {
83+
Self {
84+
check_symmetry: SymmetryCheck::CheckSymmetry,
85+
fill_red_method: FillInReduction::ReverseCuthillMcKee,
86+
check_perm: PermutationCheck::CheckPerm,
87+
}
88+
}
89+
}
90+
8191
/// Structure to compute and hold a symbolic LDLT decomposition
8292
#[derive(Debug, Clone)]
8393
pub struct LdlSymbolic<I> {
@@ -101,11 +111,7 @@ pub struct LdlNumeric<N, I> {
101111

102112
impl Ldl {
103113
pub fn new() -> Self {
104-
Self {
105-
check_symmetry: SymmetryCheck::CheckSymmetry,
106-
fill_red_method: FillInReduction::ReverseCuthillMcKee,
107-
check_perm: PermutationCheck::CheckPerm,
108-
}
114+
Self::default()
109115
}
110116

111117
pub fn check_symmetry(self, check: SymmetryCheck) -> Self {
@@ -257,10 +263,10 @@ impl<I: SpIndex> LdlSymbolic<I> {
257263

258264
LdlSymbolic {
259265
colptr: l_colptr,
260-
parents: parents,
266+
parents,
261267
nz: l_nz,
262-
flag_workspace: flag_workspace,
263-
perm: perm,
268+
flag_workspace,
269+
perm,
264270
}
265271
}
266272

@@ -294,11 +300,11 @@ impl<I: SpIndex> LdlSymbolic<I> {
294300
let pattern_workspace = DStack::with_capacity(n);
295301
let mut ldl_numeric = LdlNumeric {
296302
symbolic: self,
297-
l_indices: l_indices,
298-
l_data: l_data,
299-
diag: diag,
300-
y_workspace: y_workspace,
301-
pattern_workspace: pattern_workspace,
303+
l_indices,
304+
l_data,
305+
diag,
306+
y_workspace,
307+
pattern_workspace,
302308
};
303309
ldl_numeric.update(mat).map(|_| ldl_numeric)
304310
}
@@ -466,6 +472,7 @@ pub fn ldl_symbolic<N, I, PStorage>(
466472
/// Perform numeric LDLT decomposition
467473
///
468474
/// pattern_workspace is a DStack of capacity n
475+
#[allow(clippy::too_many_arguments)]
469476
pub fn ldl_numeric<N, I, PStorage>(
470477
mat: CsMatViewI<N, I>,
471478
l_colptr: &[I],

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ pub enum FillInReduction {
162162
///
163163
/// Comparisons of sparse matrices with different storages might be slow.
164164
/// It is advised to compare using the same storage order for efficiency
165+
///
166+
/// These traits requires the `approx` feature to be activated
165167
pub mod approx {
166168
pub use approx::{AbsDiffEq, RelativeEq, UlpsEq};
167169
}

src/sparse/binop.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn csmat_binop<N, I, Iptr, F>(
8787
binop: F,
8888
) -> CsMatI<N, I, Iptr>
8989
where
90-
N: Num,
90+
N: Num + Clone,
9191
I: SpIndex,
9292
Iptr: SpIndex,
9393
F: Fn(&N, &N) -> N,
@@ -109,10 +109,7 @@ where
109109
// Sadly the vec! macro requires Clone, but we don't want to force
110110
// Clone on our consumers, so we have to use this workaround.
111111
// This should compile to decent code however.
112-
let mut out_data = Vec::with_capacity(max_nnz);
113-
for _ in 0..max_nnz {
114-
out_data.push(N::zero());
115-
}
112+
let mut out_data = vec![N::zero(); max_nnz];
116113

117114
let nnz = csmat_binop_same_storage_raw(
118115
lhs,

src/sparse/csmat.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,7 @@ impl<N, I: SpIndex, Iptr: SpIndex>
702702
if outer_ind >= outer_dims {
703703
// we need to add a new outer dimension
704704
let last_nnz = *self.indptr.last().unwrap(); // indptr never empty
705-
self.indptr.reserve(1 + outer_ind - outer_dims);
706-
for _ in outer_dims..outer_ind {
707-
self.indptr.push(last_nnz);
708-
}
705+
self.indptr.resize(outer_ind + 1, last_nnz);
709706
self.set_outer_dims(outer_ind + 1);
710707
self.indptr.push(last_nnz + Iptr::one());
711708
self.indices.push(inner_ind_idx);
@@ -2996,14 +2993,15 @@ mod approx_impls {
29962993
} else {
29972994
// Checks if all elements in self has a matching element
29982995
// in other
2999-
if !self.iter().all(|(n, (i, j))| {
2996+
let all_matching = self.iter().all(|(n, (i, j))| {
30002997
n.abs_diff_eq(
30012998
other
30022999
.get(i.to_usize().unwrap(), j.to_usize().unwrap())
30033000
.unwrap_or(&N::zero()),
30043001
epsilon.clone(),
30053002
)
3006-
}) {
3003+
});
3004+
if !all_matching {
30073005
return false;
30083006
}
30093007

@@ -3055,15 +3053,16 @@ mod approx_impls {
30553053
} else {
30563054
// Checks if all elements in self has a matching element
30573055
// in other
3058-
if !self.iter().all(|(n, (i, j))| {
3056+
let all_matches = self.iter().all(|(n, (i, j))| {
30593057
n.ulps_eq(
30603058
other
30613059
.get(i.to_usize().unwrap(), j.to_usize().unwrap())
30623060
.unwrap_or(&N::zero()),
30633061
epsilon.clone(),
30643062
max_ulps,
30653063
)
3066-
}) {
3064+
});
3065+
if !all_matches {
30673066
return false;
30683067
}
30693068

@@ -3122,15 +3121,16 @@ mod approx_impls {
31223121
} else {
31233122
// Checks if all elements in self has a matching element
31243123
// in other
3125-
if !self.iter().all(|(n, (i, j))| {
3124+
let all_matches = self.iter().all(|(n, (i, j))| {
31263125
n.relative_eq(
31273126
other
31283127
.get(i.to_usize().unwrap(), j.to_usize().unwrap())
31293128
.unwrap_or(&N::zero()),
31303129
epsilon.clone(),
31313130
max_relative.clone(),
31323131
)
3133-
}) {
3132+
});
3133+
if !all_matches {
31343134
return false;
31353135
}
31363136

0 commit comments

Comments
 (0)