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

add a check for valtypename to comparedims to be used when broadcasting #879

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tiemvanderdeure
Copy link
Contributor

Solves #878

E.g.

using DimensionalData, DimensionalData.Lookups
z = Z(1:2)
z2 = Z([1,2])
zcat = Z(Categorical(1:2))

rand(z) .* rand(z2) # still works
rand(z) .* rand(zcat) # now errors

With the error message ERROR: DimensionMismatch: Lookup types for Z do not match: Sampled and Categorical.

@tiemvanderdeure tiemvanderdeure changed the title add a check for valtypename add a check for valtypename to comparedims to be used when broadcasting Dec 4, 2024
@rafaqz
Copy link
Owner

rafaqz commented Dec 4, 2024

Isn't this too strong? Now Sampled and Projected will also error.

Which may not be what we want?

@tiemvanderdeure
Copy link
Contributor Author

Okay probably not. So maybe we want to check if they have the same abstract type. So if both are AbstractSampled we should allow it. I'm not sure how to implement that robustly, though.

@rafaqz
Copy link
Owner

rafaqz commented Dec 4, 2024

Yeah, this is probably why I didn't do it 😅

Like what does the same abstract type really mean when it's generally accepted that you can add intermediate abstract types without a breaking change.

@@ -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)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could introduce a function for this check and return false as fallback and return true for combinations that assume to be comparable

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a bit complicated to know what the function should do.

We may need to just manually distinguish AbstractSampled from AbstractCategorical, and let promote_dims take care of the rest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this function could return true for identical types, or for combinations where there is some specialized implementation of promote_first (which is I think just for both AbstractSampled or two AbstractCategorical)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason it returns this NoLookup currently is because nothing else is implemented for promote_dims/promote_first (I think?), so it would make sense to kind of mirror that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Its a bit odd to have the same thing in two places... I wonder if we can somehow make it share the same code.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like have this comparison dependent on the results of promote_first

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.

3 participants