-
Notifications
You must be signed in to change notification settings - Fork 30
Make RArray
a subtype of DenseArray
#1696
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,33 @@ Base.strides(x::TracedRArray) = Base.size_to_strides(1, size(x)...) | |
|
||
Base.IndexStyle(::Type{<:TracedRArray}) = Base.IndexLinear() | ||
|
||
Base.elsize(::Type{TracedRArray{T,N}}) where {T,N} = sizeof(T) | ||
|
||
const ArrayTypesAlias = ( | ||
:(TracedRArray), | ||
:(SubArray{<:TracedRNumber,<:Any,<:TracedRArray}), | ||
:(Base.ReshapedArray{<:TracedRNumber,<:Any,<:TracedRArray}), | ||
:(SubArray{<:TracedRNumber,<:Any,<:Base.ReshapedArray{<:TracedRNumber,<:Any,<:TracedRArray}}), | ||
:(Base.ReshapedArray{<:TracedRNumber,<:Any,<:SubArray{<:TracedRNumber,<:Any,<:TracedRArray}}), | ||
) | ||
for ArrayType1 in ArrayTypesAlias | ||
for ArrayType2 in ArrayTypesAlias | ||
@eval Base.mightalias(::$ArrayType1, ::$ArrayType2) = false | ||
end | ||
end | ||
|
||
# Base.mightalias(::TracedRArray, ::TracedRArray) = false | ||
# Base.mightalias( | ||
# ::SubArray{<:TracedRNumber,<:Any,<:TracedRArray}, | ||
# ::SubArray{<:TracedRNumber,<:Any,<:TracedRArray}, | ||
# ) = false | ||
# Base.mightalias( | ||
# ::SubArray{<:TracedRNumber,<:Any,<:TracedRArray}, ::TracedRArray | ||
# ) = false | ||
# Base.mightalias( | ||
# ::TracedRArray, ::SubArray{<:TracedRNumber,<:Any,<:TracedRArray} | ||
# ) = false | ||
|
||
# This is required otherwise we will copy a tracedrarray each time | ||
# we use it | ||
Base.convert(T::Type{<:TracedRArray}, x::AbstractArray) = Reactant.promote_to(T, x) | ||
|
@@ -265,8 +292,15 @@ function Base.show(io::IOty, X::TracedRArray{T,N}) where {T,N,IOty<:Union{IO,IOC | |
return print(io, "TracedRArray{", T, ",", N, "N}(", X.paths, ", size=", size(X), ")") | ||
end | ||
|
||
function Base.permutedims(A::AnyTracedRArray{T,N}, perm) where {T,N} | ||
return @opcall transpose(materialize_traced_array(A), Int64[perm...]) | ||
for ArrayType in ( | ||
:(AnyTracedRArray{T,N}), | ||
:(TracedRArray{T,N}), | ||
:(SubArray{<:TracedRNumber{T},N,<:TracedRArray}), | ||
:(Base.ReshapedArray{<:TracedRNumber{T},N,<:TracedRArray}) | ||
) | ||
@eval function Base.permutedims(A::$ArrayType, perm) where {T,N} | ||
return @opcall transpose(materialize_traced_array(A), Int64[perm...]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why doesn't anytacedrarray work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently julia> SubArray{<:TracedRNumber,1,<:TracedRArray} <: AnyTracedRArray
false
julia> SubArray{<:TracedRNumber,1,<:TracedRArray} |> supertypes
(SubArray{<:TracedRNumber, 1, <:TracedRArray}, AbstractVector{<:TracedRNumber}, Any) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cc @avik-pal i thought anytracedrarray was just an abstractarray of a traced number? |
||
end | ||
end | ||
|
||
for (jlop, hloop, hlocomp, merge) in | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this definitely seems wrong since if they are equal they certainly may alias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with the internal structure of
TracedRArray
. I could in principle see the implementation for Base arrays if I know where to look inTracedRArray
.