Skip to content

WIP: Adds operator Base.:*(::ToeplitzFactorization, ::StridedVector) - #103

Open
adomasbaliuka wants to merge 2 commits into
JuliaLinearAlgebra:masterfrom
adomasbaliuka:feature/threadsafe-multiplication-with-precomputed-factorization
Open

WIP: Adds operator Base.:*(::ToeplitzFactorization, ::StridedVector)#103
adomasbaliuka wants to merge 2 commits into
JuliaLinearAlgebra:masterfrom
adomasbaliuka:feature/threadsafe-multiplication-with-precomputed-factorization

Conversation

@adomasbaliuka

@adomasbaliuka adomasbaliuka commented Jun 9, 2023

Copy link
Copy Markdown

For performing many Toeplitz-vector products using the same matrix, it is efficient to reuse the factorization of the Toeplitz matrix. The README suggests that this is intended, however it's not documented how to do it. I found out (1, 2) that this works:

using ToeplitzMatrices, LinearAlgebra, Test
T = Toeplitz([0.;randn(499)], [0.;randn(999)])
x = randn(1000)
Tfac = factorize(T)
result = zeros(Float64, 500); @test mul!(result, Tfac, x, 1., 0.) == T*x

The method facilitating this is

mul!(y::StridedVector{T} where T, A::ToeplitzMatrices.ToeplitzFactorization, x::StridedVector{T} where T, α::Number, β::Number) @ ToeplitzMatrices ~/.julia/packages/ToeplitzMatrices/5gW1c/src/linearalgebra.jl:42

Besides being undocumented, it modifies the temp buffer inside the factorization A. This doesn't invalidate the factorization object (because the buffer is "temporary", I guess) but the method is not thread-safe. I think the way to make it thread-safe is to make a copy of the tmp buffer and thus not changing it. However, this obviously has an unwanted performance overhead and I don't know if thread-safety of the method (is it internal? is exporting it intented) is desired. I also didn't look at other similar methods.

I suggest possible measures including

  1. Make this mul! method thread safe, perhaps controlled by a parameter making it thread-safe by default but avoiding the copy when the factorization is not being reused
  2. Add an operator Base.:*(::ToeplitzFactorization, ::StridedVector) that is thread-safe.

I implemented a suggestion for measure 2. I added comments indicating how one may approach measure 1. What do you think?

The code is not ready to merge, it has a lot of comments that should be removed and additional unit tests that illustrate my points, rather than properly testing functionality.

Tests contain some superfluous stuff for illustrating what I'm doing! DO not merge this! Should be changed and rebased.
Because Github CI doesn't have multithreading
@codecov

codecov Bot commented Jun 9, 2023

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.90%. Comparing base (49bde1d) to head (e008b1d).
⚠️ Report is 39 commits behind head on master.

Files with missing lines Patch % Lines
src/linearalgebra.jl 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #103      +/-   ##
==========================================
- Coverage   94.98%   94.90%   -0.09%     
==========================================
  Files           7        7              
  Lines         798      844      +46     
==========================================
+ Hits          758      801      +43     
- Misses         40       43       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adomasbaliuka

Copy link
Copy Markdown
Author

I don't know what's wrong with the v1.0.5, I tried starting the package from juliaup's v1.0.5 channel but that errored on instantiate already (ERROR: Unsatisfiable requirements detected for package StatsBase) ...

@putianyi889

Copy link
Copy Markdown
Contributor

hopefully #91 will help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants