Skip to content

Commit ce9e583

Browse files
CopilotocramzMarco Zocca
authored
Add CI with GitHub Actions, reduce warnings (#88)
* Initial plan * Add CI infrastructure with GitHub Actions, update Makefile, and enable -Wall Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> * Fix hlint invocation to use stack exec for consistency Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> * Add explicit GITHUB_TOKEN permissions for security Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> * Fix compilation errors for -Wall -Werror: remove unused code, fix shadowing, add type signatures Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> * Add CI with GitHub Actions, strict compilation flags, enhanced Makefile, and -Wall -Werror compliance fixes Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> * Continue fixing -Wall -Werror errors: fix SpVector, IntMap2, add more type signatures Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> * Fix remaining -Wall -Werror errors in Control/Iterative, IntMap2, SpMatrix, and most of Common Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> * Fix all remaining -Wall -Werror errors in Common.hs and Sparse.hs Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> * Complete -Wall -Werror fixes: all modules build successfully, tests run Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> * Add COMMENTED_OUT_FUNCTIONS.md documenting all functions disabled for -Wall -Werror Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> * Clean up commented pragmas in Sparse.hs Removed fake ghc flag * Use IM.foldl' instead of foldl' in fromListSM' * Replace IM.foldl' with foldl' in fromListSM' * Update build-depends and ghc-options in cabal file * Enable eigsArnoldi and verify eigensolvers work with Real and Complex types (#86) * Initial plan * Uncomment and enable eigsArnoldi for Real matrices, add comprehensive tests for eigensolvers - Uncommented eigsArnoldi function in Numeric.LinearAlgebra.Sparse module - Simplified eigsArnoldi type signature to remove outdated constraints (MonadLog, PrintDense, V) - Exported eigsArnoldi from the module - Added checkEigsArnoldi test helper function - Added comprehensive test suite for eigsArnoldi with Real matrices (4 specific test cases) - Added property tests for eigsQR (Real and Complex) and eigsArnoldi (Real) - Verified eigsQR works with both Real and Complex matrices (existing tests pass) - Note: eigsArnoldi cannot work with Complex matrices due to Normed instance constraint mismatch (RealScalar (Complex Double) = Double but Scalar (Complex Double) = Complex Double) Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> * Fix prop_eigsArnoldi to handle edge cases with small matrices - Guard against negative iteration count when nrows m is small - Ensure at least 1 iteration and at most 5 or n-1 iterations Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> * Update CI badge in README.md * matrix factorizations are cursed, split into separate test suite * split factorizations into separate ci script * readme * CI job names * fewer warnings --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ocramz <5902760+ocramz@users.noreply.github.com> Co-authored-by: Marco Z <ocramz@users.noreply.github.com> Co-authored-by: Marco Zocca <marco.zocca@unfoldml.com>
1 parent cf84542 commit ce9e583

30 files changed

+1036
-815
lines changed

.github/workflows/ci.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: CI-library
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
build:
11+
name: Build and Test (Main Suite)
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
strategy:
16+
matrix:
17+
ghc: ['9.4.8', '9.6.6', '9.8.2']
18+
fail-fast: false
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Setup Haskell
24+
uses: haskell-actions/setup@v2
25+
with:
26+
ghc-version: ${{ matrix.ghc }}
27+
enable-stack: true
28+
stack-version: 'latest'
29+
30+
- name: Cache Stack dependencies
31+
uses: actions/cache@v4
32+
with:
33+
path: |
34+
~/.stack
35+
.stack-work
36+
key: ${{ runner.os }}-stack-${{ matrix.ghc }}-${{ hashFiles('stack.yaml', 'sparse-linear-algebra.cabal') }}
37+
restore-keys: |
38+
${{ runner.os }}-stack-${{ matrix.ghc }}-
39+
${{ runner.os }}-stack-
40+
41+
- name: Install dependencies
42+
run: |
43+
stack build --only-dependencies --test --no-terminal
44+
45+
- name: Build
46+
run: |
47+
stack build --test --no-terminal --no-run-tests
48+
49+
- name: Run main test suite
50+
run: |
51+
stack test sparse-linear-algebra:spec --no-terminal
52+
53+
lint:
54+
name: Lint with HLint
55+
runs-on: ubuntu-latest
56+
permissions:
57+
contents: read
58+
59+
steps:
60+
- uses: actions/checkout@v4
61+
62+
- name: Setup Haskell
63+
uses: haskell-actions/setup@v2
64+
with:
65+
ghc-version: '9.6.6'
66+
enable-stack: true
67+
stack-version: 'latest'
68+
69+
- name: Cache Stack dependencies
70+
uses: actions/cache@v4
71+
with:
72+
path: ~/.stack
73+
key: ${{ runner.os }}-stack-hlint-${{ hashFiles('stack.yaml') }}
74+
restore-keys: |
75+
${{ runner.os }}-stack-hlint-
76+
77+
- name: Install HLint
78+
run: |
79+
stack install hlint
80+
81+
- name: Run HLint
82+
run: |
83+
stack exec hlint -- src test
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: CI-matrix-factorizations
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
matrix-factorizations-tests:
11+
name: Test Matrix Factorizations
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
continue-on-error: true # Allow this job to fail without blocking PR/merge
16+
strategy:
17+
matrix:
18+
ghc: ['9.4.8', '9.6.6', '9.8.2']
19+
fail-fast: false
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Setup Haskell
25+
uses: haskell-actions/setup@v2
26+
with:
27+
ghc-version: ${{ matrix.ghc }}
28+
enable-stack: true
29+
stack-version: 'latest'
30+
31+
- name: Cache Stack dependencies
32+
uses: actions/cache@v4
33+
with:
34+
path: |
35+
~/.stack
36+
.stack-work
37+
key: ${{ runner.os }}-stack-${{ matrix.ghc }}-${{ hashFiles('stack.yaml', 'sparse-linear-algebra.cabal') }}
38+
restore-keys: |
39+
${{ runner.os }}-stack-${{ matrix.ghc }}-
40+
${{ runner.os }}-stack-
41+
42+
- name: Install dependencies
43+
run: |
44+
stack build --only-dependencies --test --no-terminal
45+
46+
- name: Build
47+
run: |
48+
stack build --test --no-terminal --no-run-tests
49+
50+
- name: Run matrix factorizations test suite
51+
run: |
52+
stack test sparse-linear-algebra:matrix-factorizations --no-terminal
53+
54+

COMMENTED_OUT_FUNCTIONS.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Summary of Functions Commented Out for -Wall -Werror Compliance
2+
3+
This document lists all the functions that were commented out during the process of enabling strict `-Wall -Werror` compilation flags. These functions were unused in the codebase but may be useful for future development.
4+
5+
## File: src/Numeric/LinearAlgebra/Sparse.hs
6+
7+
### 1. BCG (Biconjugate Gradient) Solver Functions
8+
9+
#### `bcgInit`
10+
**Lines**: 882-889 (commented)
11+
```haskell
12+
bcgInit :: LinearVectorSpace (SpVector a) =>
13+
MatrixType (SpVector a) -> SpVector a -> SpVector a -> BCG a
14+
bcgInit aa b x0 = BCG x0 r0 r0hat p0 p0hat where
15+
r0 = b ^-^ (aa #> x0)
16+
r0hat = r0
17+
p0 = r0
18+
p0hat = r0
19+
```
20+
**Purpose**: Initializes the BCG solver state with initial guess and computes initial residuals
21+
22+
#### `bcgStep`
23+
**Lines**: 891-908 (commented)
24+
```haskell
25+
bcgStep :: (MatrixType (SpVector a) ~ SpMatrix a,
26+
LinearVectorSpace (SpVector a), InnerSpace (SpVector a),
27+
MatrixRing (SpMatrix a), Fractional (Scalar (SpVector a))) =>
28+
SpMatrix a -> BCG a -> BCG a
29+
bcgStep aa (BCG x r rhat p phat) = BCG x1 r1 rhat1 p1 phat1 where
30+
aap = aa #> p
31+
alpha = (r `dot` rhat) / (aap `dot` phat)
32+
x1 = x ^+^ (alpha .* p)
33+
r1 = r ^-^ (alpha .* aap)
34+
rhat1 = rhat ^-^ (alpha .* (transpose aa #> phat))
35+
beta = (r1 `dot` rhat1) / (r `dot` rhat)
36+
p1 = r1 ^+^ (beta .* p)
37+
phat1 = rhat1 ^+^ (beta .* phat)
38+
```
39+
**Purpose**: Performs one iteration step of the BCG algorithm
40+
41+
---
42+
43+
### 2. CGS (Conjugate Gradient Squared) Solver Functions
44+
45+
#### `cgsInit`
46+
**Lines**: 917-921 (commented)
47+
```haskell
48+
cgsInit :: LinearVectorSpace (SpVector a) =>
49+
MatrixType (SpVector a) -> SpVector a -> SpVector a -> CGS a
50+
cgsInit aa b x0 = CGS x0 r0 r0 r0 where
51+
r0 = b ^-^ (aa #> x0) -- residual of initial guess solution
52+
```
53+
**Purpose**: Initializes the CGS solver state
54+
55+
#### `cgsStep`
56+
**Lines**: 923-945 (commented)
57+
```haskell
58+
cgsStep :: (V (SpVector a), Fractional (Scalar (SpVector a))) =>
59+
MatrixType (SpVector a) -> SpVector a -> CGS a -> CGS a
60+
cgsStep aa rhat (CGS x r p u) = CGS xj1 rj1 pj1 uj1
61+
where
62+
aap = aa #> p
63+
alphaj = (r `dot` rhat) / (aap `dot` rhat)
64+
q = u ^-^ (alphaj .* aap)
65+
xj1 = x ^+^ (alphaj .* (u ^+^ q)) -- updated solution
66+
rj1 = r ^-^ (alphaj .* (aa #> (u ^+^ q))) -- updated residual
67+
betaj = (rj1 `dot` rhat) / (r `dot` rhat)
68+
uj1 = rj1 ^+^ (betaj .* q)
69+
pj1 = uj1 ^+^ (betaj .* (q ^+^ (betaj .* p)))
70+
```
71+
**Purpose**: Performs one iteration step of the CGS algorithm
72+
73+
---
74+
75+
### 3. BiCGSTAB (Biconjugate Gradient Stabilized) Solver Functions
76+
77+
#### `bicgsInit`
78+
**Lines**: 950-954 (commented)
79+
```haskell
80+
bicgsInit :: LinearVectorSpace (SpVector a) =>
81+
MatrixType (SpVector a) -> SpVector a -> SpVector a -> BICGSTAB a
82+
bicgsInit aa b x0 = BICGSTAB x0 r0 r0 where
83+
r0 = b ^-^ (aa #> x0) -- residual of initial guess solution
84+
```
85+
**Purpose**: Initializes the BiCGSTAB solver state
86+
87+
#### `bicgstabStep`
88+
**Lines**: 956-971 (commented)
89+
```haskell
90+
bicgstabStep :: (V (SpVector a), Fractional (Scalar (SpVector a))) =>
91+
MatrixType (SpVector a) -> SpVector a -> BICGSTAB a -> BICGSTAB a
92+
bicgstabStep aa r0hat (BICGSTAB x r p) = BICGSTAB xj1 rj1 pj1 where
93+
aap = aa #> p
94+
alphaj = (r <.> r0hat) / (aap <.> r0hat)
95+
sj = r ^-^ (alphaj .* aap)
96+
aasj = aa #> sj
97+
omegaj = (aasj <.> sj) / (aasj <.> aasj)
98+
xj1 = x ^+^ (alphaj .* p) ^+^ (omegaj .* sj) -- updated solution
99+
rj1 = sj ^-^ (omegaj .* aasj)
100+
betaj = (rj1 <.> r0hat)/(r <.> r0hat) * alphaj / omegaj
101+
pj1 = rj1 ^+^ (betaj .* (p ^-^ (omegaj .* aap)))
102+
```
103+
**Purpose**: Performs one iteration step of the BiCGSTAB algorithm
104+
105+
---
106+
107+
### 4. Moore-Penrose Pseudoinverse
108+
109+
#### `pinv`
110+
**Lines**: 980-985 (commented)
111+
```haskell
112+
pinv :: (LinearSystem v, MatrixRing (MatrixType v), MonadThrow m, MonadIO m) =>
113+
MatrixType v -> v -> m v
114+
pinv aa b = (aa #^# aa) <\> atb where
115+
atb = transpose aa #> b
116+
```
117+
**Purpose**: Computes least-squares approximation of a rectangular system using Moore-Penrose pseudoinverse
118+
**Note**: This function was also removed from the module export list (line 20)
119+
120+
---
121+
122+
### 5. IterativeSolver Typeclass
123+
124+
#### `IterativeSolver` class
125+
**Lines**: 1027-1030 (commented)
126+
```haskell
127+
class IterativeSolver s where
128+
-- solver ::
129+
```
130+
**Purpose**: Placeholder typeclass for iterative solver abstraction (was incomplete)
131+
132+
---
133+
134+
## Summary Statistics
135+
136+
- **Total functions commented out**: 10
137+
- BCG-related: 2 functions
138+
- CGS-related: 2 functions
139+
- BiCGSTAB-related: 2 functions
140+
- Pseudoinverse: 1 function
141+
- Typeclass: 1 class definition
142+
- Show instances: 3 instances (for BCG, CGS, BICGSTAB)
143+
144+
## Reason for Commenting Out
145+
146+
All these functions were commented out because they triggered the `-Wunused-top-binds` warning under `-Wall -Werror` compilation. While these are sophisticated iterative solver implementations that could be valuable for solving sparse linear systems, they were not currently used anywhere in the codebase.
147+
148+
## Recommendations for Re-enabling
149+
150+
To re-enable these functions in the future:
151+
152+
1. **Export them from the module** - Add them to the export list in the module header
153+
2. **Use them in examples or tests** - Create usage examples demonstrating their functionality
154+
3. **Document them properly** - Add comprehensive Haddock documentation
155+
4. **Add to the public API** - If they're meant to be part of the public API, ensure they're properly exposed
156+
157+
## Related Data Types
158+
159+
The following data types remain active and are used by the commented-out functions:
160+
161+
- `data BCG a = BCG { _xBcg, _rBcg, _rHatBcg, _pBcg, _pHatBcg :: SpVector a }`
162+
- `data CGS a = CGS { _x, _r, _p, _u :: SpVector a}`
163+
- `data BICGSTAB a = BICGSTAB { _xBicgstab, _rBicgstab, _pBicgstab :: SpVector a}`
164+
165+
These data types could be commented out as well if they're truly unused, but they've been retained in case they're referenced elsewhere or needed for the future implementation of these solvers.

0 commit comments

Comments
 (0)