Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parametrize vector in BlockDiagonal #38

Closed
wants to merge 2 commits into from

Conversation

theogf
Copy link
Contributor

@theogf theogf commented Sep 15, 2020

Right now the block matrices are hard-coded into a Vector, this makes it too restrictive for some actions like passing a BlockDiagonal to the GPU.
Parametrizing it as

struct BlockDiagonal{T, V<:AbstractMatrix{T}, AV<:AbstractVector{V}} <: AbstractMatrix{T}
    blocks::AV

    function BlockDiagonal{T, V, AV}(blocks::AV) where {T, V<:AbstractMatrix{T}, AV<:AbstractVector{V}}
        return new{T, V, AV}(blocks)
    end
end

solve this issue.

@codecov
Copy link

codecov bot commented Sep 15, 2020

Codecov Report

Merging #38 into master will decrease coverage by 0.20%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #38      +/-   ##
==========================================
- Coverage   95.58%   95.37%   -0.21%     
==========================================
  Files           4        4              
  Lines         181      173       -8     
==========================================
- Hits          173      165       -8     
  Misses          8        8              
Impacted Files Coverage Δ
src/blockdiagonal.jl 82.92% <100.00%> (-0.80%) ⬇️
src/base_maths.jl 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9fdcb28...b7da683. Read the comment docs.

@dkarrasch
Copy link
Contributor

Another option is #33. Would that also solve your issue with the GPU?

@theogf
Copy link
Contributor Author

theogf commented Sep 16, 2020

Aren't Tuple very inefficient for a large number of elements?

@dkarrasch
Copy link
Contributor

Aren't Tuple very inefficient for a large number of elements?

Could be. I simply don't know how that balances with possibly having an abstract eltype for the AbstractVector. Could be that the multiplication cost dominates anyway.

@theogf
Copy link
Contributor Author

theogf commented Sep 16, 2020

So the best approach would be to get a Vector of matrices. Check if the matrices are homogeneous, if yes use a vector, if not use a Tuple. I need to check if it would also work when passing it to the GPU (but I think yes)

@dkarrasch
Copy link
Contributor

In fact, this would be relevant over in LinearMaps.jl as well, see JuliaLinearAlgebra/LinearMaps.jl#84 (comment). One could leave it to the user:

struct BlockDiagonal{T, V} <: AbstractMatrix{T}
     blocks::V
end

and then restrict V via available constructors?

@theogf
Copy link
Contributor Author

theogf commented Mar 28, 2023

Closing this one for a new one using @dkarrasch's comment

@theogf theogf closed this Mar 28, 2023
@theogf theogf deleted the param_abstractvector branch March 28, 2023 15:00
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