Skip to content

Add getindex for ConduitNode#14

Open
benegee wants to merge 1 commit intomainfrom
bg/add-getters
Open

Add getindex for ConduitNode#14
benegee wants to merge 1 commit intomainfrom
bg/add-getters

Conversation

@benegee
Copy link
Collaborator

@benegee benegee commented Dec 4, 2024

This adds getindex for ConduitNode.
Although not required for using the interface it makes testing easier.

@benegee benegee changed the title add getindex for ConduitNode dd getindex for ConduitNode Dec 4, 2024
@benegee benegee changed the title dd getindex for ConduitNode Add getindex for ConduitNode Dec 4, 2024
@benegee
Copy link
Collaborator Author

benegee commented Dec 6, 2024

Implementing this was not straightforward as you have to use the method for the correct data type, which you first have to look up. I now create a symbol from the name of the C datatype and pass this to an internal method as another argument to be able to dispatch on it.
It works but I am a bit unsure about this approach.
@sloede @s6nistam

@sloede
Copy link
Member

sloede commented Dec 6, 2024

It works but I am a bit unsure about this approach.

Me too. Maybe you can ping Valentin and ask him if he knows of a better approach for what you are trying to achieve? Adding some context would be helpful as well.

@charleskawczynski
Copy link
Collaborator

I think we may have something similar in ClimaCore (the DataLayouts module)

return new(nptr)
end

function ConduitNode(ptr::Ptr{API.conduit_node})
Copy link
Member

Choose a reason for hiding this comment

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

What is the ownership model between Julia objects and the pointed to C-object? When is memory going to be released?

node_at_path = API.conduit_node_fetch(node, path)
dtype = API.conduit_node_dtype(node_at_path)
dtypename = Symbol(unsafe_string(API.conduit_datatype_name(dtype)))
return node_get(node_at_path, Val(dtypename))
Copy link
Member

Choose a reason for hiding this comment

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

This Val here seems unnecessarily clever, and guarantees a dynamic dispatch.

return node
end

function node_get(nodeptr::Ptr{API.conduit_node}, ::Val{:object})
Copy link
Member

Choose a reason for hiding this comment

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

It's likely better to have a function that uses if else to select between symbols, rather than using Val

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.

4 participants