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

How to use gin-config with data types and namedtuples? #103

Open
RylanSchaeffer opened this issue Dec 22, 2020 · 2 comments
Open

How to use gin-config with data types and namedtuples? #103

RylanSchaeffer opened this issue Dec 22, 2020 · 2 comments

Comments

@RylanSchaeffer
Copy link

RylanSchaeffer commented Dec 22, 2020

I'm using a codebase that uses gin-config and one function argument I want to modify is a list consisting of tuples (str array name, array shape, array data type). How does one specify a data type using gin-config?

@RylanSchaeffer RylanSchaeffer changed the title How to specify a data type? How to use gin-config with data types and namedtuples? Dec 22, 2020
@RylanSchaeffer
Copy link
Author

RylanSchaeffer commented Dec 22, 2020

Ok this just became a little more complicated. The function doesn't accept a list of tuples - it requires a list of named tuples. How can I specify these with gin-config?

@sguada
Copy link
Collaborator

sguada commented May 10, 2021

You can define a NamedTuple and register with gin and then use it configure other functions.

import typing
from typing import List
import gin

@gin.register
MyTuple(typing.NamedTuple):
  arg1: int
  arg2: str

@gin.register
def function(configs: List[MyTuple])
   ...

And the configure MyTuple

# Gin file

A/MyTuple.arg1 = 23
A/MyType.arg2 = 'A'

B/MyTuple.arg1 = 12
B/MyType.arg2 = 'B'


function.configs = [@A/MyTuple() @B/MyTuple()]

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

No branches or pull requests

2 participants