Skip to content

Commit

Permalink
+ and - for DiagTrav (#142)
Browse files Browse the repository at this point in the history
* + and - for DiagTrav

* overload /, \ and - for DiagTrav
  • Loading branch information
dlfivefifty authored Jan 28, 2025
1 parent f6b5f1c commit 9ed8340
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LazyBandedMatrices"
uuid = "d7e5e226-e90b-4449-9968-0f923699bf6f"
authors = ["Sheehan Olver <[email protected]>"]
version = "0.11.2"
version = "0.11.3"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
13 changes: 13 additions & 0 deletions src/blockkron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,19 @@ end
invdiagtrav(a) = InvDiagTrav(a)
invdiagtrav(a::DiagTrav) = a.array

-(A::DiagTrav) = DiagTrav(-A.array)

for op in (:+, :-)
@eval $op(A::DiagTrav, B::DiagTrav) = DiagTrav($op(A.array, B.array))
end

for op in (:*, :/)
@eval $op(A::DiagTrav, k::Number) = DiagTrav($op(A.array, k))
end

for op in (:*, :\)
@eval $op(k::Number, A::DiagTrav) = DiagTrav($op(k, A.array))
end

"""
KronTrav(A,B,C...)
Expand Down
14 changes: 14 additions & 0 deletions test/test_blockkron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ LinearAlgebra.factorize(A::MyLazyArray) = factorize(A.data)
A = [1 2; 3 4; 5 6]
@test DiagTrav(A) == [1, 3, 2, 5, 4]

@test DiagTrav(A) + DiagTrav(A) isa DiagTrav
@test DiagTrav(A) - DiagTrav(A) isa DiagTrav
@test 2DiagTrav(A) isa DiagTrav
@test 2\DiagTrav(A) isa DiagTrav
@test DiagTrav(A)*2 isa DiagTrav
@test DiagTrav(A)/2 isa DiagTrav
@test -DiagTrav(A) isa DiagTrav


@test DiagTrav(A) + DiagTrav(A) == 2DiagTrav(A) == DiagTrav(A)*2 == 2Vector(DiagTrav(A))
@test DiagTrav(A) - DiagTrav(A) == 0DiagTrav(A) == 0Vector(DiagTrav(A))
@test 2\DiagTrav(A) == DiagTrav(A)/2 == Vector(DiagTrav(A))/2
@test -DiagTrav(A) == -Vector(DiagTrav(A))

@test resize!(DiagTrav(A), Block(2)) == [1, 3,2]

A = DiagTrav(randn(3,3,3))
Expand Down

2 comments on commit 9ed8340

@dlfivefifty
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
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/123874

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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 v0.11.3 -m "<description of version>" 9ed83402d3fae142f268ff3ddcd1fe3bac19f760
git push origin v0.11.3

Please sign in to comment.