[go: up one dir, main page]

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

KernelDictTemplate: Flatten automatically nested dicts #459

Merged
merged 1 commit into from
Oct 30, 2024
Merged

Conversation

leroyvn
Copy link
Member
@leroyvn leroyvn commented Oct 30, 2024

Description

This PR updates the KernelDictTemplate to automatically flatten nested dictionaries used for initialization or assignment.

Example:

Prior to this update, the following:

d = KernelDictTemplate(
    {
        "type": "diffuse", 
        "reflectance": {
            "type": "uniform", 
            "value": InitParameter(lambda ctx: 1 if ctx.si.w == 550 else 0)
        }
    }
)
d.render(ctx)  # assuming ctx initialized somewhere else

would result in the rendered dictionary still containing unrendered parameters, e.g

{
    "type": "diffuse", 
    "reflectance": {
        "type": "uniform", 
        "value": InitParameter(lambda ctx: 1 if ctx.si.w == 550 else 0)
    }
}

While this is expected behaviour, it also means that nested dictionaries must be manually flattened by the user. This is unintuitive.

After this update, nested dicts used for initialization or assignments are flattened automatically, meaning that in the example above, the dictionary is converted to

{
    "type": "diffuse",
    "reflectance.type": "uniform",
    "reflectance.value": InitParameter(lambda ctx: 1 if ctx.si.w == 550 else 0)
}

and renders as

{
    "type": "diffuse", 
    "reflectance": {
        "type": "uniform", 
        "value": 1.0
    }
}

Checklist

  • The code follows the relevant coding guidelines
  • The code generates no new warnings
  • The code is appropriately documented
  • The code is tested to prove its function
  • The feature branch is rebased on the current state of the main branch
  • I updated the change log if relevant
  • I give permission that the Eradiate project may redistribute my contributions under the terms of its license

@leroyvn leroyvn marked this pull request as ready for review October 30, 2024 13:20
@leroyvn leroyvn merged commit f29ecf4 into main Oct 30, 2024
1 of 2 checks passed
@leroyvn leroyvn deleted the kdict_nested branch October 30, 2024 13:21
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.

1 participant