Skip to content

Commit 7b61f73

Browse files
authored
Format with Runic (#220)
* Add Runic workflow and badge * Run Runic * Adjust allocation tests on Mac
1 parent dbeb7c7 commit 7b61f73

22 files changed

+287
-268
lines changed

.github/workflows/Format.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Check formatting
2+
on:
3+
push:
4+
branches:
5+
- 'master'
6+
- 'release-'
7+
tags:
8+
- '*'
9+
pull_request:
10+
jobs:
11+
runic:
12+
name: Runic
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: julia-actions/setup-julia@v2
17+
with:
18+
version: '1'
19+
- uses: julia-actions/cache@v2
20+
- uses: fredrikekre/runic-action@v1
21+
with:
22+
version: '1'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Uniform interface for positive definite matrices of various structures.
44

55
[![CI](https://github.com/JuliaStats/PDMats.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/JuliaStats/PDMats.jl/actions/workflows/ci.yml)
66
[![Coverage Status](https://img.shields.io/coveralls/JuliaStats/PDMats.jl.svg)](https://coveralls.io/r/JuliaStats/PDMats.jl?branch=master)
7+
[![code style: runic](https://img.shields.io/badge/code_style-%E1%9A%B1%E1%9A%A2%E1%9A%BE%E1%9B%81%E1%9A%B2-black)](https://github.com/fredrikekre/Runic.jl)
78

89
--------------
910

src/PDMats.jl

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
module PDMats
22

3-
using LinearAlgebra, SparseArrays, SuiteSparse
3+
using LinearAlgebra, SparseArrays, SuiteSparse
44

5-
import Base: +, *, \, /, ==, convert, inv, Matrix, kron
5+
import Base: +, *, \, /, ==, convert, inv, Matrix, kron
66

7-
export
8-
# Types
9-
AbstractPDMat,
10-
PDMat,
11-
PDSparseMat,
12-
PDiagMat,
13-
ScalMat,
7+
export
8+
# Types
9+
AbstractPDMat,
10+
PDMat,
11+
PDSparseMat,
12+
PDiagMat,
13+
ScalMat,
1414

15-
# Functions
16-
dim,
17-
whiten,
18-
whiten!,
19-
unwhiten,
20-
unwhiten!,
21-
pdadd,
22-
pdadd!,
23-
quad,
24-
quad!,
25-
invquad,
26-
invquad!,
27-
X_A_Xt,
28-
Xt_A_X,
29-
X_invA_Xt,
30-
Xt_invA_X
15+
# Functions
16+
dim,
17+
whiten,
18+
whiten!,
19+
unwhiten,
20+
unwhiten!,
21+
pdadd,
22+
pdadd!,
23+
quad,
24+
quad!,
25+
invquad,
26+
invquad!,
27+
X_A_Xt,
28+
Xt_A_X,
29+
X_invA_Xt,
30+
Xt_invA_X
3131

3232

33-
"""
34-
The base type for positive definite matrices.
35-
"""
36-
abstract type AbstractPDMat{T<:Real} <: AbstractMatrix{T} end
33+
"""
34+
The base type for positive definite matrices.
35+
"""
36+
abstract type AbstractPDMat{T <: Real} <: AbstractMatrix{T} end
3737

38-
const HAVE_CHOLMOD = isdefined(SuiteSparse, :CHOLMOD)
38+
const HAVE_CHOLMOD = isdefined(SuiteSparse, :CHOLMOD)
3939

40-
# source files
40+
# source files
4141

42-
include("utils.jl")
43-
include("chol.jl")
42+
include("utils.jl")
43+
include("chol.jl")
4444

45-
include("pdmat.jl")
45+
include("pdmat.jl")
4646

47-
if HAVE_CHOLMOD
48-
include("pdsparsemat.jl")
49-
end
47+
if HAVE_CHOLMOD
48+
include("pdsparsemat.jl")
49+
end
5050

51-
include("pdiagmat.jl")
52-
include("scalmat.jl")
51+
include("pdiagmat.jl")
52+
include("scalmat.jl")
5353

54-
include("generics.jl")
55-
include("addition.jl")
54+
include("generics.jl")
55+
include("addition.jl")
5656

57-
include("deprecates.jl")
57+
include("deprecates.jl")
5858

5959
end # module

src/addition.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# between pdmat and pdmat
32

43
+(a::PDMat, b::AbstractPDMat) = PDMat(a.mat + Matrix(b))

src/chol.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ end
5353
function quad(A::Cholesky, X::AbstractMatrix)
5454
@check_argdims size(A, 1) == size(X, 1)
5555
Z = chol_upper(A) * X
56-
return vec(sum(abs2, Z; dims=1))
56+
return vec(sum(abs2, Z; dims = 1))
5757
end
5858
function quad!(r::AbstractArray, A::Cholesky, X::AbstractMatrix)
5959
@check_argdims eachindex(r) == axes(X, 2)
@@ -75,7 +75,7 @@ end
7575
function invquad(A::Cholesky, X::AbstractMatrix)
7676
@check_argdims size(A, 1) == size(X, 1)
7777
Z = chol_lower(A) \ X
78-
return vec(sum(abs2, Z; dims=1))
78+
return vec(sum(abs2, Z; dims = 1))
7979
end
8080
function invquad!(r::AbstractArray, A::Cholesky, X::AbstractMatrix)
8181
@check_argdims eachindex(r) == axes(X, 2)

src/deprecates.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ using Base: @deprecate
1717

1818
@deprecate dim(a::AbstractMatrix) LinearAlgebra.checksquare(a)
1919

20-
@deprecate PDMat{T,S}(d::Int, m::AbstractMatrix{T}, c::Cholesky{T,S}) where {T,S} PDMat{T,S}(m, c)
20+
@deprecate PDMat{T, S}(d::Int, m::AbstractMatrix{T}, c::Cholesky{T, S}) where {T, S} PDMat{T, S}(m, c)
2121

2222
@deprecate PDiagMat(dim::Int, diag::AbstractVector{<:Real}) PDiagMat(diag)
23-
@deprecate PDiagMat{T,V}(dim, diag) where {T<:Real, V<:AbstractVector{T}} PDiagMat{T,V}(diag)
24-
23+
@deprecate PDiagMat{T, V}(dim, diag) where {T <: Real, V <: AbstractVector{T}} PDiagMat{T, V}(diag)

src/generics.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ AbstractPDMat(A::AbstractPDMat) = A
55
AbstractPDMat(A::AbstractMatrix) = PDMat(A)
66

77
## convert
8-
Base.convert(::Type{AbstractMatrix{T}}, a::AbstractPDMat) where {T<:Real} = convert(AbstractPDMat{T}, a)
9-
Base.convert(::Type{AbstractArray{T}}, a::AbstractPDMat) where {T<:Real} = convert(AbstractMatrix{T}, a)
8+
Base.convert(::Type{AbstractMatrix{T}}, a::AbstractPDMat) where {T <: Real} = convert(AbstractPDMat{T}, a)
9+
Base.convert(::Type{AbstractArray{T}}, a::AbstractPDMat) where {T <: Real} = convert(AbstractMatrix{T}, a)
1010

1111
## arithmetics
1212

13-
pdadd!(r::Matrix, a::Matrix, b::AbstractPDMat{T}) where {T<:Real} = pdadd!(r, a, b, one(T))
13+
pdadd!(r::Matrix, a::Matrix, b::AbstractPDMat{T}) where {T <: Real} = pdadd!(r, a, b, one(T))
1414

1515
pdadd!(a::Matrix, b::AbstractPDMat, c) = pdadd!(a, a, b, c)
16-
pdadd!(a::Matrix, b::AbstractPDMat{T}) where {T<:Real} = pdadd!(a, a, b, one(T))
16+
pdadd!(a::Matrix, b::AbstractPDMat{T}) where {T <: Real} = pdadd!(a, a, b, one(T))
1717

18-
pdadd(a::Matrix{T}, b::AbstractPDMat{S}, c::R) where {T<:Real, S<:Real, R<:Real} = pdadd!(similar(a, promote_type(T, S, R)), a, b, c)
19-
pdadd(a::Matrix{T}, b::AbstractPDMat{S}) where {T<:Real, S<:Real} = pdadd!(similar(a, promote_type(T, S)), a, b, one(T))
18+
pdadd(a::Matrix{T}, b::AbstractPDMat{S}, c::R) where {T <: Real, S <: Real, R <: Real} = pdadd!(similar(a, promote_type(T, S, R)), a, b, c)
19+
pdadd(a::Matrix{T}, b::AbstractPDMat{S}) where {T <: Real, S <: Real} = pdadd!(similar(a, promote_type(T, S)), a, b, one(T))
2020

2121
+(a::Matrix, b::AbstractPDMat) = pdadd(a, b)
2222
+(a::AbstractPDMat, b::Matrix) = pdadd(b, a)
2323

24-
*(a::AbstractPDMat, c::T) where {T<:Real} = a * c
25-
*(c::T, a::AbstractPDMat) where {T<:Real} = a * c
26-
/(a::AbstractPDMat, c::T) where {T<:Real} = a * inv(c)
24+
*(a::AbstractPDMat, c::T) where {T <: Real} = a * c
25+
*(c::T, a::AbstractPDMat) where {T <: Real} = a * c
26+
/(a::AbstractPDMat, c::T) where {T <: Real} = a * inv(c)
2727
Base.kron(A::AbstractPDMat, B::AbstractPDMat) = PDMat(kron(Matrix(A), Matrix(B)))
2828

2929
# LinearAlgebra
@@ -140,4 +140,3 @@ Overwrite `r` with the value of the quadratic form defined by `inv(a)` applied c
140140
function invquad!(r::AbstractArray, a::AbstractMatrix{<:Real}, x::AbstractMatrix)
141141
return invquad!(r, AbstractPDMat(a), x)
142142
end
143-

src/pdiagmat.jl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Positive definite diagonal matrix.
33
"""
4-
struct PDiagMat{T<:Real,V<:AbstractVector{T}} <: AbstractPDMat{T}
4+
struct PDiagMat{T <: Real, V <: AbstractVector{T}} <: AbstractPDMat{T}
55
diag::V
66
end
77

@@ -14,16 +14,16 @@ end
1414
Base.propertynames(::PDiagMat) = (:diag, :dim)
1515

1616
AbstractPDMat(A::Diagonal{<:Real}) = PDiagMat(A.diag)
17-
AbstractPDMat(A::Symmetric{<:Real,<:Diagonal{<:Real}}) = PDiagMat(A.data.diag)
18-
AbstractPDMat(A::Hermitian{<:Real,<:Diagonal{<:Real}}) = PDiagMat(A.data.diag)
17+
AbstractPDMat(A::Symmetric{<:Real, <:Diagonal{<:Real}}) = PDiagMat(A.data.diag)
18+
AbstractPDMat(A::Hermitian{<:Real, <:Diagonal{<:Real}}) = PDiagMat(A.data.diag)
1919

2020
### Conversion
21-
Base.convert(::Type{PDiagMat{T}}, a::PDiagMat{T}) where {T<:Real} = a
22-
function Base.convert(::Type{PDiagMat{T}}, a::PDiagMat) where {T<:Real}
21+
Base.convert(::Type{PDiagMat{T}}, a::PDiagMat{T}) where {T <: Real} = a
22+
function Base.convert(::Type{PDiagMat{T}}, a::PDiagMat) where {T <: Real}
2323
diag = convert(AbstractVector{T}, a.diag)
24-
return PDiagMat{T,typeof(diag)}(diag)
24+
return PDiagMat{T, typeof(diag)}(diag)
2525
end
26-
Base.convert(::Type{AbstractPDMat{T}}, a::PDiagMat) where {T<:Real} = convert(PDiagMat{T}, a)
26+
Base.convert(::Type{AbstractPDMat{T}}, a::PDiagMat) where {T <: Real} = convert(PDiagMat{T}, a)
2727

2828
### Basics
2929

@@ -125,11 +125,11 @@ function quad!(r::AbstractArray, a::PDiagMat, x::AbstractMatrix)
125125
@inbounds for j in axes(x, 2)
126126
s = zero(promote_type(eltype(ad), eltype(x)))
127127
for i in axes(x, 1)
128-
s += ad[i] * abs2(x[i,j])
128+
s += ad[i] * abs2(x[i, j])
129129
end
130130
r[j] = s
131131
end
132-
r
132+
return r
133133
end
134134

135135
function invquad(a::PDiagMat, x::AbstractVecOrMat)
@@ -150,11 +150,11 @@ function invquad!(r::AbstractArray, a::PDiagMat, x::AbstractMatrix)
150150
@inbounds for j in axes(x, 2)
151151
s = zero(zero(eltype(x)) / zero(eltype(ad)))
152152
for i in axes(x, 1)
153-
s += abs2(x[i,j]) / ad[i]
153+
s += abs2(x[i, j]) / ad[i]
154154
end
155155
r[j] = s
156156
end
157-
r
157+
return r
158158
end
159159

160160

@@ -186,15 +186,14 @@ end
186186

187187
### Specializations for `Array` arguments with reduced allocations
188188

189-
function quad(a::PDiagMat{<:Real,<:Vector}, x::Matrix)
189+
function quad(a::PDiagMat{<:Real, <:Vector}, x::Matrix)
190190
@check_argdims a.dim == size(x, 1)
191191
T = typeof(zero(eltype(a)) * abs2(zero(eltype(x))))
192192
return quad!(Vector{T}(undef, size(x, 2)), a, x)
193193
end
194194

195-
function invquad(a::PDiagMat{<:Real,<:Vector}, x::Matrix)
195+
function invquad(a::PDiagMat{<:Real, <:Vector}, x::Matrix)
196196
@check_argdims a.dim == size(x, 1)
197197
T = typeof(abs2(zero(eltype(x))) / zero(eltype(a)))
198198
return invquad!(Vector{T}(undef, size(x, 2)), a, x)
199199
end
200-

0 commit comments

Comments
 (0)