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

Support struct types in create_result #6

Merged
merged 16 commits into from
May 28, 2024
Merged

Support struct types in create_result #6

merged 16 commits into from
May 28, 2024

Conversation

mofeing
Copy link
Collaborator

@mofeing mofeing commented May 25, 2024

This PR adds a case for create_result to be able to process custom struct types.

It also adds support for Symbol and Array.

Copy link
Member

@wsmoses wsmoses left a comment

Choose a reason for hiding this comment

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

Add a test?

src/Reactant.jl Show resolved Hide resolved
create_result(getfield(tocopy, i), sym, (path..., i))
push!(elems, sym)
end
push!(concrete_result_maker, quote
Copy link
Member

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).

Copy link
Collaborator Author

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?

@wsmoses
Copy link
Member

wsmoses commented May 25, 2024 via email

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)))
Copy link
Member

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

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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
Copy link
Collaborator Author

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.

@mofeing
Copy link
Collaborator Author

mofeing commented May 26, 2024

So something which definitely fail right now is a recursive struct of sorts, like a linked list.

I've added a test for this kind of structure, although it fails in create_result due to a problem with results_store.

@mofeing mofeing merged commit 1d5ab77 into EnzymeAD:main May 28, 2024
18 of 19 checks passed
@mofeing mofeing deleted the create_result-struct branch May 28, 2024 17:40
@wsmoses wsmoses mentioned this pull request Oct 1, 2024
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.

2 participants