Skip to content

Commit 2c7923b

Browse files
committed
Run JuliaFormatter
1 parent 4f75adc commit 2c7923b

File tree

12 files changed

+811
-720
lines changed

12 files changed

+811
-720
lines changed

docs/make.jl

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
using Distributions, Documenter, GLM, StatsBase
22

3-
makedocs(
4-
format = Documenter.HTML(),
5-
sitename = "GLM",
6-
modules = [GLM],
7-
pages = [
8-
"Home" => "index.md",
9-
"examples.md",
10-
"api.md",
11-
],
12-
debug = false,
13-
doctest = true,
14-
warnonly = [:missing_docs]
15-
)
3+
makedocs(; format=Documenter.HTML(),
4+
sitename="GLM",
5+
modules=[GLM],
6+
pages=["Home" => "index.md",
7+
"examples.md",
8+
"api.md"],
9+
debug=false,
10+
doctest=true,
11+
warnonly=[:missing_docs])
1612

17-
deploydocs(
18-
repo = "github.com/JuliaStats/GLM.jl.git",
19-
push_preview = true
20-
)
13+
deploydocs(; repo="github.com/JuliaStats/GLM.jl.git",
14+
push_preview=true)

ext/GLMSparseArraysExt.jl

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,33 @@ mutable struct SparsePredQR{T,M<:SparseMatrixCSC,F} <: GLM.LinPred
1111
qr::F
1212
scratch::M
1313
end
14-
function SparsePredQR(X::SparseMatrixCSC{T}) where T
14+
function SparsePredQR(X::SparseMatrixCSC{T}) where {T}
1515
# The one(float(T))* part is because of a promotion issue in SPQR.jl on Julia 1.9
1616
fqr = qr(sparse(one(float(T))*I, size(X)...))
17-
return SparsePredQR{eltype(X),typeof(X),typeof(fqr)}(
18-
X,
19-
zeros(T, size(X, 2)),
20-
zeros(T, size(X, 2)),
21-
zeros(T, size(X, 2)),
22-
fqr,
23-
similar(X)
24-
)
17+
return SparsePredQR{eltype(X),typeof(X),typeof(fqr)}(X,
18+
zeros(T, size(X, 2)),
19+
zeros(T, size(X, 2)),
20+
zeros(T, size(X, 2)),
21+
fqr,
22+
similar(X))
2523
end
2624

2725
GLM.qrpred(X::SparseMatrixCSC, pivot::Bool) = SparsePredQR(X)
2826

29-
function GLM.delbeta!(p::SparsePredQR{T}, r::Vector{T}, wt::Vector{T}) where T
27+
function GLM.delbeta!(p::SparsePredQR{T}, r::Vector{T}, wt::Vector{T}) where {T}
3028
wtsqrt = sqrt.(wt)
3129
Wsqrt = Diagonal(wtsqrt)
3230
scr = mul!(p.scratch, Wsqrt, p.X)
3331
p.qr = qr(scr)
34-
p.delbeta = p.qr \ (Wsqrt*r)
32+
return p.delbeta = p.qr \ (Wsqrt*r)
3533
end
3634

37-
function GLM.delbeta!(p::SparsePredQR{T}, r::Vector{T}) where T
35+
function GLM.delbeta!(p::SparsePredQR{T}, r::Vector{T}) where {T}
3836
p.qr = qr(p.X)
39-
p.delbeta = p.qr \ r
37+
return p.delbeta = p.qr \ r
4038
end
4139

42-
function GLM.inverse(x::SparsePredQR{T}) where T
40+
function GLM.inverse(x::SparsePredQR{T}) where {T}
4341
Rinv = UpperTriangular(x.qr.R) \ Diagonal(ones(T, size(x.qr.R, 2)))
4442
pinv = invperm(x.qr.pcol)
4543
RinvRinvt = Rinv*Rinv'
@@ -56,38 +54,41 @@ mutable struct SparsePredChol{T,M<:SparseMatrixCSC,C} <: GLM.LinPred
5654
chol::C
5755
scratch::M
5856
end
59-
function SparsePredChol(X::SparseMatrixCSC{T}) where T
60-
chol = cholesky(sparse(I, size(X, 2), size(X,2)))
57+
function SparsePredChol(X::SparseMatrixCSC{T}) where {T}
58+
chol = cholesky(sparse(I, size(X, 2), size(X, 2)))
6159
return SparsePredChol{eltype(X),typeof(X),typeof(chol)}(X,
62-
X',
63-
zeros(T, size(X, 2)),
64-
zeros(T, size(X, 2)),
65-
zeros(T, size(X, 2)),
66-
chol,
67-
similar(X))
60+
X',
61+
zeros(T, size(X, 2)),
62+
zeros(T, size(X, 2)),
63+
zeros(T, size(X, 2)),
64+
chol,
65+
similar(X))
6866
end
6967

7068
GLM.cholpred(X::SparseMatrixCSC, pivot::Bool=false) = SparsePredChol(X)
7169

72-
function GLM.delbeta!(p::SparsePredChol{T}, r::Vector{T}, wt::Vector{T}) where T
70+
function GLM.delbeta!(p::SparsePredChol{T}, r::Vector{T}, wt::Vector{T}) where {T}
7371
scr = mul!(p.scratch, Diagonal(wt), p.X)
7472
XtWX = p.Xt*scr
7573
c = p.chol = cholesky(Symmetric{eltype(XtWX),typeof(XtWX)}(XtWX, 'L'))
76-
p.delbeta = c \ mul!(p.delbeta, adjoint(scr), r)
74+
return p.delbeta = c \ mul!(p.delbeta, adjoint(scr), r)
7775
end
7876

79-
function GLM.delbeta!(p::SparsePredChol{T}, r::Vector{T}) where T
77+
function GLM.delbeta!(p::SparsePredChol{T}, r::Vector{T}) where {T}
8078
scr = p.scratch = p.X
8179
XtWX = p.Xt*scr
8280
c = p.chol = cholesky(Symmetric{eltype(XtWX),typeof(XtWX)}(XtWX, 'L'))
83-
p.delbeta = c \ mul!(p.delbeta, adjoint(scr), r)
81+
return p.delbeta = c \ mul!(p.delbeta, adjoint(scr), r)
8482
end
8583

8684
LinearAlgebra.cholesky(p::SparsePredChol{T}) where {T} = copy(p.chol)
8785
LinearAlgebra.cholesky!(p::SparsePredChol{T}) where {T} = p.chol
8886

89-
GLM.invchol(x::SparsePredChol) = cholesky!(x) \ Matrix{Float64}(I, size(x.X, 2), size(x.X, 2))
87+
function GLM.invchol(x::SparsePredChol)
88+
return cholesky!(x) \
89+
Matrix{Float64}(I, size(x.X, 2), size(x.X, 2))
90+
end
9091

9192
GLM.inverse(x::SparsePredChol) = GLM.invchol(x)
9293

93-
end
94+
end

perf/glm.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
using GLM, Random, StatsModels
2-
# create a column table with dummy response
2+
# create a column table with dummy response
33
n = 2_500_000
44
rng = MersenneTwister(1234321)
5-
tbl = (
6-
x1 = randn(rng, n),
7-
x2 = Random.randexp(rng, n),
8-
ss = rand(rng, string.(50:99), n),
9-
y = zeros(n),
10-
)
11-
# apply a formula to create a model matrix
5+
tbl = (x1=randn(rng, n),
6+
x2=Random.randexp(rng, n),
7+
ss=rand(rng, string.(50:99), n),
8+
y=zeros(n))
9+
# apply a formula to create a model matrix
1210
f = @formula(y ~ 1 + x1 + x2 + ss)
1311
f = apply_schema(f, schema(f, tbl))
1412
resp, pred = modelcols(f, tbl)
15-
# simulate β and the response
13+
# simulate β and the response
1614
β = randn(rng, size(pred, 2))
1715
β[1] = 0.5 # to avoid edge cases
1816
logistic(x::Real) = inv(1 + exp(-x))
1917
resp .= rand(rng, n) .< logistic.(pred * β)
20-
# fit a subset of the data
18+
# fit a subset of the data
2119
gm6 = glm(pred[1:1000, :], resp[1:1000], Bernoulli())
22-
# time the fit on the whole data set
20+
# time the fit on the whole data set
2321
@time glm(pred, resp, Bernoulli());

0 commit comments

Comments
 (0)