-
Notifications
You must be signed in to change notification settings - Fork 9
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
Support struct
types in create_result
#6
Conversation
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.
Add a test?
create_result(getfield(tocopy, i), sym, (path..., i)) | ||
push!(elems, sym) | ||
end | ||
push!(concrete_result_maker, quote |
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 think this depends on whether the structure is mutable (Enzyme.make_zero should have some relevant code to look at).
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.
Added a test on a mutable struct
type and seems to work... although it might be too naive?
So something which definitely fail right now is a recursive struct of
sorts, like a linked list.
…On Sat, May 25, 2024 at 7:06 PM Sergio Sánchez Ramírez < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/Reactant.jl
<#6 (comment)>:
> push!(concrete_result_maker, :($resname = $tocopy))
return
end
+ if isstructtype(T)
+ elems = Symbol[]
+ nf = fieldcount(T)
+ for i in 1:nf
+ sym = Symbol(resname, :_, i)
+ create_result(getfield(tocopy, i), sym, (path..., i))
+ push!(elems, sym)
+ end
+ push!(concrete_result_maker, quote
Added a test on a mutable struct type and seems to work... although it
might be too naive?
—
Reply to this email directly, view it on GitHub
<#6 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJTUXGFA7DK3UAVK7W3BE3ZEEKOJAVCNFSM6AAAAABIJGLAJCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDANZZGIYDQOJUHE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
test/struct.jl
Outdated
y = f(x2) | ||
|
||
@test y isa MutableMockTensor{Float64,2,Reactant.ConcreteRArray{Float64,(4, 4),2}} | ||
@test isapprox(parent(y), cos.(parent(x))) |
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.
Can these test against non array values just in case
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.
mmm I don't follow. do you mean to add a test against non-array fields?
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've added a test against the inds
field, which is an Array
but not a RArray
. Is this enough?
@@ -342,7 +342,7 @@ using Enzyme | |||
end | |||
|
|||
if Val(T) ∈ seen | |||
return seen[T] | |||
return T |
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 was crashing. I believe this is a bug because seen
is not a Dict
here, but a vector of types.
I've added a test for this kind of structure, although it fails in |
This PR adds a case for
create_result
to be able to process customstruct
types.It also adds support for
Symbol
andArray
.