Skip to content

Commit 6a5874c

Browse files
Update FixedEffectSolverCPU.jl (#53)
* Update FixedEffectSolverCPU.jl Correct GLFixedEffectModels * Update Project.toml * Update FixedEffectSolverCPU.jl * Update solve.jl * Update FixedEffectSolverGPU.jl * Update Project.toml
1 parent 7b390d5 commit 6a5874c

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

Diff for: Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FixedEffects"
22
uuid = "c8885935-8500-56a7-9867-7708b20db0eb"
3-
version = "2.0.8"
3+
version = "2.1.0"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

Diff for: src/FixedEffectSolvers/FixedEffectSolverCPU.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ end
132132

133133

134134
function scale!(scale::AbstractVector, refs::AbstractVector, interaction::AbstractVector, weights::AbstractVector)
135+
fill!(scale, 0)
135136
@inbounds @simd for i in eachindex(refs)
136137
scale[refs[i]] += abs2(interaction[i]) * weights[i]
137138
end
@@ -153,14 +154,13 @@ function solve_residuals!(r::AbstractVector, feM::FixedEffectSolverCPU{T}; tol::
153154
feM.r .*= sqrt.(feM.weights)
154155
end
155156
copyto!(feM.b, feM.r)
156-
if length(feM.x.x) == 1
157-
mul!(feM.x, feM.m', feM.b, 1, 0)
158-
iter, converged = 1, true
159-
else
160-
mul!(feM.x, feM.m', feM.b, 1, 0)
161-
x, ch = lsmr!(feM.x, feM.m, feM.b, feM.v, feM.h, feM.hbar; atol = tol, btol = tol, maxiter = maxiter)
162-
iter, converged = ch.mvps + 1, ch.isconverged
163-
end
157+
mul!(feM.x, feM.m', feM.b, 1, 0)
158+
if length(feM.x.x) > 1
159+
x, ch = lsmr!(feM.x, feM.m, feM.b, feM.v, feM.h, feM.hbar; atol = tol, btol = tol, maxiter = maxiter)
160+
iter, converged = ch.mvps + 1, ch.isconverged
161+
else
162+
iter, converged = 1, true
163+
end
164164
mul!(feM.r, feM.m, feM.x, -1, 1)
165165
if !(feM.weights isa UnitWeights)
166166
feM.r ./= sqrt.(feM.weights)

Diff for: src/FixedEffectSolvers/FixedEffectSolverGPU.jl

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ end
146146

147147
function scale!(scale::CuVector, refs::CuVector, interaction::CuVector, weights::CuVector, nthreads::Integer)
148148
nblocks = cld(length(refs), nthreads)
149+
fill!(scale, 0)
149150
@cuda threads=nthreads blocks=nblocks scale_kernel!(scale, refs, interaction, weights)
150151
@cuda threads=nthreads blocks=nblocks inv_kernel!(scale)
151152
end

Diff for: test/solve.jl

+12-9
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ r_ols = [-0.2015993617092453, 0.2015993617092464, -0.2015993617092463, 0.2015
2222
(c, iter, conv) = solve_residuals!([x x], fes)
2323

2424

25-
# test update_weights
26-
weights = ones(10)
27-
feM = FixedEffects.AbstractFixedEffectSolver{Float64}(fes, Weights(weights), Val{:cpu})
28-
weights = Weights([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
29-
FixedEffects.update_weights!(feM, weights)
30-
solve_residuals!(deepcopy(x), feM)[1] solve_residuals!(deepcopy(x), fes, weights)[1]
31-
32-
33-
3425
method_s = [:cpu]
3526
if FixedEffects.has_CUDA()
3627
push!(method_s, :gpu)
@@ -45,3 +36,15 @@ end
4536
fe = FixedEffect([1, 2])
4637
@test_throws "FixedEffects must have the same length as y"= solve_residuals!(ones(100), [fe])
4738

39+
40+
# test update_weights
41+
weights = ones(10)
42+
fes = [FixedEffect(p1)]
43+
feM = FixedEffects.AbstractFixedEffectSolver{Float64}(fes, Weights(weights), Val{:cpu})
44+
weights = Weights([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
45+
FixedEffects.update_weights!(feM, weights)
46+
solve_residuals!(deepcopy(x), feM)[1] solve_residuals!(deepcopy(x), fes, weights)[1]
47+
48+
weights = Weights(reverse([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
49+
FixedEffects.update_weights!(feM, weights)
50+
solve_residuals!(deepcopy(x), feM)[1] solve_residuals!(deepcopy(x), fes, weights)[1]

0 commit comments

Comments
 (0)