Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jul 3, 2024
1 parent 8159b7a commit 25ba823
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/sparse_coeffs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Base.broadcastable(sc::SparseCoefficients) = sc
Base.BroadcastStyle(::Type{<:SparseCoefficients{K}}) where {K} = BroadcastStyle{K}()
# Disallow mixing broadcasts.
function Base.BroadcastStyle(::BroadcastStyle, ::Base.BroadcastStyle)
@show @__LINE__
return throw(
ArgumentError(
"Cannot broadcast `StarAlgebras.SparseCoefficients` with" *
Expand All @@ -68,7 +67,6 @@ end

# Allow broadcasting over scalars.
function Base.BroadcastStyle(style::BroadcastStyle, ::Base.Broadcast.DefaultArrayStyle{0})
@show @__LINE__
return style
end

Expand All @@ -79,8 +77,8 @@ Base.axes(sc::SparseCoefficients) = (sc.basis_elements,)

# `_get_arg` and `getindex` are inspired from `JuMP.Containers.SparseAxisArray`
_getindex(x::SparseCoefficients, index) = getindex(x, index)
_getindex(x::Any, ::Any) = (@show @__LINE__; x)
_getindex(x::Ref, ::Any) = (@show @__LINE__; x[])
_getindex(x::Any, ::Any) = x
_getindex(x::Ref, ::Any) = x[]

function _get_arg(args::Tuple, index)
return (_getindex(first(args), index), _get_arg(Base.tail(args), index)...)
Expand Down
4 changes: 4 additions & 0 deletions test/caching_allocations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,9 @@ end
@test c .* 2 == res
@test c .+ 1 == res
@test 1 .+ c == res
@test MA.Zero() .+ c == c
@test c .+ MA.Zero() == c
err = ArgumentError("Cannot broadcast `StarAlgebras.SparseCoefficients` with another array of different type")
@test_throws err c .+ ones(3)
end
end

0 comments on commit 25ba823

Please sign in to comment.