Skip to content

Commit

Permalink
add a check for valtypename
Browse files Browse the repository at this point in the history
  • Loading branch information
tiemvanderdeure committed Dec 4, 2024
1 parent a5585f5 commit 3d5be5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Dimensions/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,18 @@ _valmsg(a, b) = "Lookup values for $(basetypeof(a)) of $(parent(a)) and $(parent
_dimsizemsg(a, b) = "Found both lengths $(length(a)) and $(length(b)) for $(basetypeof(a))."
_valtypemsg(a, b) = "Lookup for $(basetypeof(a)) of $(lookup(a)) and $(lookup(b)) do not match."
_ordermsg(a, b) = "Lookups do not all have the same order: $(order(a)), $(order(b))."
function _valtypenameaction(a, b)
typenamea = Base.nameof(typeof(parent(a)))
typenameb = Base.nameof(typeof(parent(b)))
return "Lookup types for $(basetypeof(a)) do not match: $typenamea and $typenameb."
end

@noinline _dimsmismatchaction(err, a, b) = _failed_comparedims(err, _dimsmismatchmsg(a, b))
@noinline _valaction(err, a, b) = _failed_comparedims(err, _valmsg(a, b))
@noinline _dimsizeaction(err, a, b) = _failed_comparedims(err, _dimsizemsg(a, b))
@noinline _valtypeaction(err, a, b) = _failed_comparedims(err, _valtypemsg(a, b))
@noinline _orderaction(err, a, b) = _failed_comparedims(err, _ordermsg(a, b))
@noinline _valtypenameaction(err, a, b) = _failed_comparedims(err, _valtypenameaction(a, b))

_failed_comparedims(w::Warn, msg_intro) = @warn string(msg_intro, msg(w))
_failed_comparedims(t::Throw, msg_intro) = throw(DimensionMismatch(string(msg_intro, msg(t))))
Expand Down Expand Up @@ -602,7 +608,7 @@ end
@inline _comparedims2(a::Dimension, b::AnonDim; kw...) = true
@inline _comparedims2(a::AnonDim, b::Dimension; kw...) = true
@inline function _comparedims2(a::Dimension, b::Dimension;
type=true, valtype=false, val=false, length=true, order=false,
type=true, valtypename = false, valtype=false, val=false, length=true, order=false,
ignore_length_one=false, msg
)
if type && basetypeof(a) != basetypeof(b)
Expand All @@ -616,6 +622,10 @@ end
isnothing(msg) || _orderaction(msg, a, b)
return false
end
if valtypename && Base.typename(typeof(parent(a))) != Base.typename(typeof(parent(b)))
isnothing(msg) || _valtypenameaction(msg, a, b)
return false
end
if valtype && typeof(parent(a)) != typeof(parent(b))
isnothing(msg) || _valtypeaction(msg, a, b)
return false
Expand Down
2 changes: 1 addition & 1 deletion src/array/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ broadcast_options(A::BroadcastOptionsDimArray) = A.options
@inline function _comparedims_broadcast(A, dims...)
isstrict = _is_strict(A)
comparedims(dims...;
ignore_length_one=isstrict, order=isstrict, val=isstrict, length=false
ignore_length_one=isstrict, order=isstrict, val=isstrict, valtypename=isstrict, length=false
)
end

Expand Down

0 comments on commit 3d5be5a

Please sign in to comment.