Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/MatrixFields/band_matrix_row.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,11 @@ inv(::BandMatrixRow{ld, bw}) where {ld, bw} = error(
"The inverse of a matrix with $bw diagonals is generally a dense matrix, \
so it cannot be represented using BandMatrixRows",
)

@generated function (row::BandMatrixRow{ld, bw, T})(args::Vararg{Any, N}) where {ld, bw, T, N}
N == bw || error(
"BandMatrixRow with bandwidth $bw expected $bw arguments, but got $N"
)
terms = [:(row.entries[$i] * args[$i]) for i in 1:bw]
return Expr(:call, :+, terms...)
end
7 changes: 7 additions & 0 deletions test/MatrixFields/band_matrix_row.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@ include("matrix_field_test_utils.jl")
@test zero(typeof(DiagonalMatrixRow(1))) == DiagonalMatrixRow(0)
@test eltype(typeof(DiagonalMatrixRow(1))) == Int
@test inv(DiagonalMatrixRow(1)) == DiagonalMatrixRow(float(1))

# Test callable behaviour
@test DiagonalMatrixRow(2.0)(10.0) == 20.0
@test BidiagonalMatrixRow(1.0, 2.0)(10.0, 5.0) == 20.0
@test TridiagonalMatrixRow(-1.0, 2.0, -1.0)(10.0, 25.0, 12.0) == 28.0
@test_throws ErrorException TridiagonalMatrixRow(1, 2, 3)(10.0, 5.0)
@test_throws ErrorException TridiagonalMatrixRow(1, 2, 3)(10.0, 5.0, 1.0, 2.0)
end