Skip to content

Commit f874ff7

Browse files
committed
Changed: Improves linting and validation workflows
Adds markdown linting with configuration and JSON validation to the linting process. Also refactors linting targets in the justfile to incorporate the new linting and validation steps. Updates cspell configuration to include markdownlint. Improves matrix tests. Updates WARP.md file.
1 parent 7486dfd commit f874ff7

File tree

6 files changed

+82
-11
lines changed

6 files changed

+82
-11
lines changed

.markdownlint.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"MD013": {"line_length": 160},
3+
"MD018": false,
4+
"MD024": false,
5+
"MD029": false,
6+
"MD033": false,
7+
"MD038": false,
8+
"MD041": false,
9+
"MD060": false,
10+
"_comment": "MD029 disabled - we prefer manual numbering over lazy numbering (1. 1. 1.) for better readability; MD060 disabled to avoid auto-reformatting tables"
11+
}

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[![Docs.rs](https://docs.rs/la-stack/badge.svg)](https://docs.rs/la-stack)
77
[![CI](https://github.com/acgetchell/la-stack/actions/workflows/ci.yml/badge.svg)](https://github.com/acgetchell/la-stack/actions/workflows/ci.yml)
88
[![rust-clippy analyze](https://github.com/acgetchell/la-stack/actions/workflows/rust-clippy.yml/badge.svg)](https://github.com/acgetchell/la-stack/actions/workflows/rust-clippy.yml)
9+
[![codecov](https://codecov.io/gh/acgetchell/la-stack/graph/badge.svg?token=4eKXa5QjuZ)](https://codecov.io/gh/acgetchell/la-stack)
910
[![Audit dependencies](https://github.com/acgetchell/la-stack/actions/workflows/audit.yml/badge.svg)](https://github.com/acgetchell/la-stack/actions/workflows/audit.yml)
1011

1112
Fast, stack-allocated linear algebra for fixed dimensions in Rust.
@@ -31,7 +32,9 @@ This crate exists primarily to support the [`delaunay`](https://crates.io/crates
3132

3233
## 🔢 Scalar types
3334

34-
Today, the core types are implemented for `f64`. The intent is to support `f32` and `f64` (and `f128` if/when Rust gains a stable primitive for it). Longer term, we may add optional arbitrary-precision support (e.g. via `rug`) depending on performance.
35+
Today, the core types are implemented for `f64`. The intent is to support `f32` and `f64`
36+
(and `f128` if/when Rust gains a stable primitive for it). Longer term, we may add optional
37+
arbitrary-precision support (e.g. via `rug`) depending on performance.
3538

3639
## 🚀 Quickstart
3740

WARP.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
This file provides guidance to WARP (warp.dev) when working with code in this repository.
44

5+
## Priorities
6+
7+
When making changes in this repo, prioritize (in order):
8+
9+
- Correctness
10+
- Speed
11+
- Coverage (but keep the code idiomatic Rust)
12+
513
## Common commands
614

715
- Build (debug): `cargo build` (or `just build`)
@@ -31,4 +39,4 @@ This file provides guidance to WARP (warp.dev) when working with code in this re
3139

3240
## Publishing note
3341

34-
- If you publish this crate to crates.io, prefer updating documentation *before* publishing a new version (doc-only changes still require a version bump on crates.io).
42+
- If you publish this crate to crates.io, prefer updating documentation *before* publishing a new version (doc-only changes still require a version bump on crates.io).

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"Justfile",
1616
"justfile",
1717
"lu",
18+
"markdownlint",
1819
"MSRV",
1920
"msvc",
2021
"mult",

justfile

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,22 @@ lint: lint-code lint-docs lint-config
115115

116116
lint-code: fmt-check clippy doc-check
117117

118-
lint-config: action-lint
118+
lint-config: validate-json action-lint
119119

120-
lint-docs: spell-check
120+
lint-docs: markdown-lint spell-check
121+
122+
markdown-lint:
123+
#!/usr/bin/env bash
124+
set -euo pipefail
125+
files=()
126+
while IFS= read -r -d '' file; do
127+
files+=("$file")
128+
done < <(git ls-files -z '*.md')
129+
if [ "${#files[@]}" -gt 0 ]; then
130+
printf '%s\0' "${files[@]}" | xargs -0 -n100 npx markdownlint --config .markdownlint.json --fix
131+
else
132+
echo "No markdown files found to lint."
133+
fi
121134

122135
# Spell check (cspell)
123136
#
@@ -151,3 +164,17 @@ test-all: test test-integration
151164

152165
test-integration:
153166
cargo test --tests --verbose
167+
168+
# File validation
169+
validate-json:
170+
#!/usr/bin/env bash
171+
set -euo pipefail
172+
files=()
173+
while IFS= read -r -d '' file; do
174+
files+=("$file")
175+
done < <(git ls-files -z '*.json')
176+
if [ "${#files[@]}" -gt 0 ]; then
177+
printf '%s\0' "${files[@]}" | xargs -0 -n1 jq empty
178+
else
179+
echo "No JSON files found to validate."
180+
fi

src/matrix.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ impl<const D: usize> Matrix<D> {
5858
#[inline]
5959
pub fn identity() -> Self {
6060
let mut m = Self::zero();
61-
for i in 0..D {
61+
62+
let mut i = 0;
63+
while i < D {
6264
m.rows[i][i] = 1.0;
65+
i += 1;
6366
}
67+
6468
m
6569
}
6670

@@ -122,16 +126,15 @@ impl<const D: usize> Matrix<D> {
122126
#[inline]
123127
#[must_use]
124128
pub fn inf_norm(&self) -> f64 {
125-
let mut max_row_sum = 0.0;
126-
for r in 0..D {
127-
let mut row_sum = 0.0;
128-
for c in 0..D {
129-
row_sum += self.rows[r][c].abs();
130-
}
129+
let mut max_row_sum: f64 = 0.0;
130+
131+
for row in &self.rows {
132+
let row_sum: f64 = row.iter().map(|&x| x.abs()).sum();
131133
if row_sum > max_row_sum {
132134
max_row_sum = row_sum;
133135
}
134136
}
137+
135138
max_row_sum
136139
}
137140

@@ -222,4 +225,22 @@ mod tests {
222225
let det = Matrix::<3>::identity().det(DEFAULT_PIVOT_TOL).unwrap();
223226
assert_approx(det, 1.0, 1e-12);
224227
}
228+
229+
#[test]
230+
fn identity_has_ones_on_diag_and_zeros_off_diag() {
231+
let m = Matrix::<3>::identity();
232+
233+
for r in 0..3 {
234+
for c in 0..3 {
235+
let expected = if r == c { 1.0 } else { 0.0 };
236+
assert_approx(m.get(r, c).unwrap(), expected, 0.0);
237+
}
238+
}
239+
}
240+
241+
#[test]
242+
fn default_is_zero() {
243+
let m = Matrix::<3>::default();
244+
assert_approx(m.inf_norm(), 0.0, 0.0);
245+
}
225246
}

0 commit comments

Comments
 (0)