Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Return a BandedMatrix from a view of a BandedBlockBandedMatrix#223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dlfivefifty wants to merge3 commits intomaster
base:master
Choose a base branch
Loading
fromviewblock_is_banded

Conversation

@dlfivefifty
Copy link
Member

@MikaelSlevinsky This gets rid of the allocations (for lazy axes at least).

Still need to figure out why it's slow.

julia>for nin20:20:200                  ax= BlockArrays.BlockedOneTo(ArrayLayouts.RangeCumsum(Base.OneTo(n)))                  D=BandedBlockBandedMatrix{Float64}(I, (ax,ax), (0,0), (0,0))                  x=BlockVector(randn(sum(1:n)), (ax,))                  y=zero(x)@timemy_special_mul_through_data!(y, D, x);@timemul!(y, D, x);end0.000002 seconds0.000066 seconds (1 allocation:32 bytes)0.000004 seconds0.000035 seconds (1 allocation:32 bytes)0.000007 seconds0.000045 seconds (1 allocation:32 bytes)0.000011 seconds0.000056 seconds (1 allocation:32 bytes)0.000016 seconds0.000140 seconds (1 allocation:32 bytes)0.000023 seconds0.000172 seconds (1 allocation:32 bytes)0.000057 seconds0.000179 seconds (1 allocation:32 bytes)0.000041 seconds0.000316 seconds (1 allocation:32 bytes)0.000067 seconds0.000180 seconds (1 allocation:32 bytes)0.000062 seconds0.000212 seconds (1 allocation:32 bytes)

@codecov
Copy link

codecovbot commentedMar 26, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.06%. Comparing base(629276d) to head(159d05f).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@##           master     #223      +/-   ##==========================================- Coverage   88.16%   86.06%   -2.10%==========================================  Files          11       11                Lines        1115     1134      +19     ==========================================- Hits          983      976       -7- Misses        132      158      +26

☔ View full report in Codecov by Sentry.
📢 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.

@dlfivefifty
Copy link
MemberAuthor

@MikaelSlevinsky With this (and the just tagged BlockArrays v1.6.2) we have the following:

julia>using AppleAccelerate# needed so banded matrices aren't insanely slowjulia>for nin20:20:200                  ax= BlockArrays.BlockedOneTo(ArrayLayouts.RangeCumsum(Base.OneTo(n)))                  D=BandedBlockBandedMatrix{Float64}(I, (ax,ax), (0,0), (0,0))                  x=BlockVector(randn(sum(1:n)), (ax,))                  y=zero(x)@timemy_special_mul_through_data!(y, D, x);@timemy_special_mul!(y, D, x);@timemy_special_mul_with_a_view!(y, D, x);@timemul!(y, D, x);end0.000003 seconds0.000011 seconds (80 allocations:5.938 KiB)0.000003 seconds0.000012 seconds (2 allocations:64 bytes)0.000002 seconds0.000008 seconds (160 allocations:18.219 KiB)0.000002 seconds0.000026 seconds (2 allocations:64 bytes)0.000002 seconds0.000012 seconds (240 allocations:37.188 KiB)0.000003 seconds0.000007 seconds (2 allocations:64 bytes)0.000003 seconds0.000017 seconds (320 allocations:62.438 KiB)0.000006 seconds0.000011 seconds (2 allocations:64 bytes)0.000004 seconds0.000029 seconds (400 allocations:94.500 KiB)0.000009 seconds0.000011 seconds (2 allocations:64 bytes)0.000005 seconds0.000034 seconds (480 allocations:133.469 KiB)0.000013 seconds0.000015 seconds (2 allocations:64 bytes)0.000007 seconds0.000039 seconds (560 allocations:178.156 KiB)0.000013 seconds0.000020 seconds (2 allocations:64 bytes)0.000009 seconds0.000049 seconds (640 allocations:229.531 KiB)0.000022 seconds0.000027 seconds (2 allocations:64 bytes)0.000012 seconds0.000052 seconds (720 allocations:287.469 KiB)0.000059 seconds0.000034 seconds (2 allocations:64 bytes)0.000017 seconds0.000072 seconds (800 allocations:351.938 KiB)0.000029 seconds0.000045 seconds (2 allocations:64 bytes)

So we have got rid of almost all allocations. The remaining speed difference is due togbmv! being too slow for diagonal matrices:

julia> n=10_000; D=BandedMatrix(0=>1:n); x=randn(n);@time D*x;0.000042 seconds (3 allocations:78.188 KiB)julia> D=Diagonal(1:n); x=randn(n);@time D*x;0.000010 seconds (3 allocations:78.188 KiB)

We could special case diagonal blocks not to call BLAS... actually I suspect the fastest would be to get rid of all calls to banded BLAS and just do naive for loops....

@MikaelSlevinsky
Copy link
Member

Awesome, thanks!

@dlfivefifty
Copy link
MemberAuthor

The reason ApproxFun is broken is that

https://github.com/JuliaApproximation/ApproxFunBase.jl/blob/569ff3c493c3f288214dfc874a1e32be7a9ce566/src/PDE/KroneckerOperator.jl#L321

is assuming thatview returns aSubArray that can be reindexed. This is arguably a bad design.

@jishnub thoughts?

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@dlfivefifty@MikaelSlevinsky

[8]ページ先頭

©2009-2025 Movatter.jp