Repository navigation
DArray: Add diag - #766
Merged
Merged
DArray: Add diag#766
diag#766Conversation
`diag(::DMatrix)` and `tr(::DMatrix)` threw
ArgumentError: Cannot convert StepRangeLen{CartesianIndex{2}, ...} to UnitRange
`Base`'s fallback indexes with `diagind`, a stepped range of
`CartesianIndex`, and `getindex(::DArray, ...)` can only split unit
ranges across partitions.
Copy each partition's stretch of the diagonal into a `DVector` instead.
Only the partitions that the diagonal crosses are read, and for the main
diagonal of square blocks each one fills exactly one partition of the
result. `tr` and `Diagonal` work through `Base` once `diag` does.
`k` may be any `Integer`, and a `k` outside of the matrix gives an
empty diagonal, as it does for a `Matrix`.
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #765.
diag(::DMatrix)fell back toBase, which indexes with a stepped range ofCartesianIndexthatgetindex(::DArray, ...)cannot split across partitions.trandDiagonalfailed the same way.This adds
LinearAlgebra.diag(A::DMatrix, k::Integer=0). It allocates aDVectorand copies each partition's stretch of the diagonal into it underspawn_datadeps. Only the partitions that the diagonal crosses are read. The result usesBlocks(min(mb, nb)), so for the main diagonal of square blocks each partition fills exactly one partition of the result.kcan be anyInteger, and akoutside of the matrix gives an empty diagonal, as it does for aMatrix.trandDiagonalneed no method of their own oncediagworks.Tests cover every
kfrom-m-2ton+2for square, single partition, ragged, wide and tall layouts inFloat64andComplexF64,kgiven asUInt,Int8,BigIntandBool, andtr.array/linalg/corepasses on Julia 1.10, 1.11 and 1.12 (853 tests, 3 workers).I also ran it on a
DArrayofCuArrays (Quadro RTX 8000, CUDA.jl 6.4.2): everykmatches the CPU result and the partitions of the result areCuArrays.trdoes not work there yet, becausesumof a GPU backedDArrayfails on master for an unrelated reason. I will report that separately.