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

Arraylike: AbstractArrays without an eltype #32940

Closed
bramtayl opened this issue Aug 17, 2019 · 11 comments
Closed

Arraylike: AbstractArrays without an eltype #32940

bramtayl opened this issue Aug 17, 2019 · 11 comments

Comments

@bramtayl
Copy link
Contributor

Would be useful for many packages, JuliennedArrays, LightQuery, SplitApplyCombine, MappedArrays, Query, etc. Base already has an AbstractEltypelessArray: the lazy broadcast machinery, it would just be a matter of formalizing the interface. Given that traits aren't coming any time soon, it couldn't be <: AbstractArray, so we would have to duplicate all of the machinery for AbstactArrays. I could try to build a prototype if people are interested?

@JeffBezanson
Copy link
Member

I think it would be more realistic to use eltype Any, and try to get things working as well as possible with such arrays.

@bramtayl
Copy link
Contributor Author

Oh, ok, if that would be easier.

@bramtayl
Copy link
Contributor Author

Ok, while I'm at it, it would be nice to have abstractarray machinery for all sorts of things, zips of arrays, generators of arrays

@bramtayl
Copy link
Contributor Author

Actually, we could just change most AbstractArray functions to be Union{AbstractArray, AbstractEltypelessArray} and nip the problem in the bud, I think.

@bramtayl
Copy link
Contributor Author

bramtayl commented Aug 17, 2019

Took a shower, came back, and realized that because this is a meaningful subtype relationship, we don't need traits or Unions. PR coming.

@bramtayl
Copy link
Contributor Author

bramtayl commented Aug 17, 2019

"""
    abstract type Arraylike{Dimensions} end

Things that have a shape, but not a compile-time [`eltype`](@ref). Use
[`AbstractArray`] if you know the eltype at compile-time.
"""
abstract type Arraylike{Dimensions} end

abstract type AbstractArray{Item, Dimensions} <: Arraylike{Dimensions} end

TADA problem solved

@bramtayl bramtayl changed the title AbstractEltypelessArray Arraylike: AbstractArrays without an eltype Aug 17, 2019
@bramtayl
Copy link
Contributor Author

Welp, its not that easy because AbstractArray is implemented in C according to boot.jl. I'll punt on making a PR.

@JeffBezanson
Copy link
Member

The type is not compile time.

@tkf
Copy link
Member

tkf commented Aug 18, 2019

👍 for this direction. I needed to emulate Arraylike using Union when implementing mapreduce for Broadcasted #31020. There was a small discussion in #31020 (comment)

@bramtayl
Copy link
Contributor Author

@JeffBezanson this is the stickingpoint for adding JuliennedArrays functionality to base. I was looking through src to see how hard it would be to add Arraylike to base. I see that Signed is added in base/boot.jl, and Int64 is added in src/builtins.c, but where is the code that says Int64 <: Signed?

@bramtayl
Copy link
Contributor Author

See discussion in #34196

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 a pull request may close this issue.

3 participants