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

chore: add has_trivial_array_constructor #443

Merged
merged 8 commits into from
Jun 5, 2024

Conversation

DhairyaLGandhi
Copy link
Contributor

@DhairyaLGandhi DhairyaLGandhi commented Jun 3, 2024

We need to know if we can construct the parent type given some arguments. This adds a check for whether an applicable method exists. It currently doesn't check for unionalls, and I am not sure of how to check for them. In some cases we want to keep the concrete type:

julia> ca = ComponentVector((x = rand(3), y = rand(4),))
ComponentVector{Float64}(x = [0.6549137106381634, 0.37555505280294565, 0.8521039568665254], y = [0.40314196291239024, 0.35484725607638834, 0.6580528978034597, 0.10055508457632167])

julia> convert(typeof(ca), rand(7))
ComponentVector{Float64}(x = [0.2282005678229746, 0.5803510438411744, 0.734611658286954], y = [0.9325262248600694, 0.49927588841708803, 0.01698109918493529, 0.16806075729787862])

I also need to understand what the appropriate tests here would be.

Copy link

codecov bot commented Jun 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.17%. Comparing base (061c0c9) to head (193993c).
Report is 31 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #443      +/-   ##
==========================================
- Coverage   71.22%   70.17%   -1.05%     
==========================================
  Files           9       10       +1     
  Lines         549      560      +11     
==========================================
+ Hits          391      393       +2     
- Misses        158      167       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Tokazama
Copy link
Member

Tokazama commented Jun 3, 2024

I like the direction this is going but I'm not sure how widely applicable this will be given how the appropriate constructor method for may not always be the type itself. For example, if you have a reshaped array you generally use reshape and view if dealing with SubArray.

As far as tests, we just need to demonstrate that it works consistently for appropriate method definitions. In this case I think you'd just want to try the reconstruction in tests.

Should also have docs to make sure we can appropriately maintain and explain what's going on here.

@DhairyaLGandhi
Copy link
Contributor Author

DhairyaLGandhi commented Jun 4, 2024

Agreed, its related to how we want to use this trait within SciMLStructures as well. Maybe a slightly more generalized version of this question could be "can we convert to given type given certain arguments". In which case we can check for

applicable(convert, T, args...)

which is more idiomatic overall as well.

@ChrisRackauckas
Copy link
Member

Doc build failing from this.

@ChrisRackauckas ChrisRackauckas merged commit 93a7908 into JuliaArrays:master Jun 5, 2024
15 of 18 checks passed
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