Skip to content

Commit

Permalink
Update lsmr.jl (#47)
Browse files Browse the repository at this point in the history
* Update lsmr.jl

* Update lsmr.jl

* Update lsmr.jl

* Update Project.toml

* Update FixedEffectSolverCPU.jl

* Create ci.yml

* update
  • Loading branch information
matthieugomez authored Apr 14, 2021
1 parent 841d274 commit fb8d79c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 11 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI
on:
pull_request:
branches:
- master
push:
branches:
- master
tags: '*'
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.3' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'.
- '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia.
os:
- ubuntu-latest
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info

2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FixedEffects"
uuid = "c8885935-8500-56a7-9867-7708b20db0eb"
version = "2.0.3"
version = "2.0.4"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[![Build Status](https://travis-ci.com/FixedEffects/FixedEffects.jl.svg?branch=master)](https://travis-ci.com/FixedEffects/FixedEffects.jl)
[![pipeline status](https://gitlab.com/JuliaGPU/FixedEffects-jl/badges/master/pipeline.svg)](https://gitlab.com/JuliaGPU/FixedEffects-jl/commits/master)
[![Coverage Status](https://coveralls.io/repos/FixedEffects/FixedEffects.jl/badge.svg?branch=master)](https://coveralls.io/r/FixedEffects/FixedEffects.jl?branch=master)
[![Build status](https://github.com/FixedEffects/FixedEffects.jl/workflows/CI/badge.svg)](https://github.com/FixedEffects/FixedEffects.jl/actions)


This package solves least squares problem with high dimensional fixed effects. For a matrix `D` of high dimensional fixed effects, it finds `b` and `ϵ` such that `y = D'b + ϵ` with `E[Dϵ] = 0`.

Expand Down
14 changes: 10 additions & 4 deletions src/FixedEffectSolvers/FixedEffectSolverCPU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,20 @@ function solve_residuals!(r::AbstractVector, feM::FixedEffectSolverCPU{T}; tol::
feM.r .*= sqrt.(feM.weights)
end
copyto!(feM.b, feM.r)
fill!(feM.x, 0)
x, ch = lsmr!(feM.x, feM.m, feM.b, feM.v, feM.h, feM.hbar; atol = tol, btol = tol, maxiter = maxiter)
if length(feM.x.x) == 1
mul!(feM.x, feM.m', feM.b, 1.0, 0.0)
iter, converged = 1, true
else
mul!(feM.x, feM.m', feM.b, 1.0, 0.0)
x, ch = lsmr!(feM.x, feM.m, feM.b, feM.v, feM.h, feM.hbar; atol = tol, btol = tol, maxiter = maxiter)
iter, converged = ch.mvps + 1, ch.isconverged
end
mul!(feM.r, feM.m, feM.x, -1.0, 1.0)
if !(feM.weights isa UnitWeights)
feM.r ./= sqrt.(feM.weights)
end
copyto!(r, feM.r)
return r, div(ch.mvps, 2), ch.isconverged
return r, iter, converged
end

function solve_residuals!(X::AbstractMatrix, feM::FixedEffects.FixedEffectSolverCPU; progress_bar = true, kwargs...)
Expand Down Expand Up @@ -200,4 +206,4 @@ function solve_coefficients!(r::AbstractVector, feM::FixedEffectSolverCPU{T}; to
end
x = Vector{eltype(r)}[x for x in feM.x.x]
full(normalize!(x, feM.m.fes; tol = tol, maxiter = maxiter), feM.m.fes), div(ch.mvps, 2), ch.isconverged
end
end
4 changes: 2 additions & 2 deletions src/FixedEffectSolvers/FixedEffectSolverGPU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ function solve_residuals!(r::AbstractVector, feM::FixedEffectSolverGPU{T}; tol::
feM.r .*= sqrt.(feM.weights)
end
copyto!(feM.b, feM.r)
fill!(feM.x, 0.0)
mul!(feM.x, feM.m', feM.b, 1.0, 0.0)
x, ch = lsmr!(feM.x, feM.m, feM.b, feM.v, feM.h, feM.hbar; atol = tol, btol = tol, maxiter = maxiter)
mul!(feM.r, feM.m, feM.x, -1.0, 1.0)
if !(feM.weights isa UnitWeights)
feM.r ./= sqrt.(feM.weights)
end
copyto!(feM.tmp, feM.r)
copyto!(r, feM.tmp)
return r, div(ch.mvps, 2), ch.isconverged
return r, ch.mvps + 1, ch.isconverged
end

function FixedEffects.solve_residuals!(X::AbstractMatrix, feM::FixedEffects.FixedEffectSolverGPU; progress_bar = true, kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/lsmr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function lsmr!(x, A, b, v, h, hbar;
end
converged = istop (3, 6, 7)
tol = (atol, btol, ctol)
ch = ConvergenceHistory(converged, tol, 2 * iter, tests)
ch = ConvergenceHistory(converged, tol, iter, tests)
return x, ch
end

Expand Down

2 comments on commit fb8d79c

@matthieugomez
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/34300

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.0.4 -m "<description of version>" fb8d79cf5954e5ab9589f2ab58fb7e760aa87d80
git push origin v2.0.4

Please sign in to comment.