From 3d5be5a757bf85e448d687fb3d5b96007c98a3b0 Mon Sep 17 00:00:00 2001 From: tiemvanderdeure Date: Wed, 4 Dec 2024 10:54:00 +0100 Subject: [PATCH] add a check for valtypename --- src/Dimensions/primitives.jl | 12 +++++++++++- src/array/broadcast.jl | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Dimensions/primitives.jl b/src/Dimensions/primitives.jl index 32159ecdf..3f50658e4 100644 --- a/src/Dimensions/primitives.jl +++ b/src/Dimensions/primitives.jl @@ -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)))) @@ -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) @@ -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 diff --git a/src/array/broadcast.jl b/src/array/broadcast.jl index 57f4966d0..d8db348c9 100644 --- a/src/array/broadcast.jl +++ b/src/array/broadcast.jl @@ -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