[REQ] Allow overriding __init__
of struct.dataclass
#1299
Replies: 5 comments 3 replies
-
To give a more concrete example, we have a series of LinearOperator-like objects called From an high level API they all take as input a model, the training data and the parameters, to be constructed. Ideally we'd do this in the
|
Beta Was this translation helpful? Give feedback.
-
This question pops up quite often but there is a major issue. A smart So in practice: |
Beta Was this translation helpful? Give feedback.
-
Ah, makes sense. Though it remains annoying. I guess you need to flatten/unflatten the data class, right? |
Beta Was this translation helpful? Give feedback.
-
cc @femtobit @attila-i-szabo with whom we were discussing this |
Beta Was this translation helpful? Give feedback.
-
You can always define a vanilla dataclass with a custom flatten/unflatten. But in this case it's your own responsibility to reconstruct without a trivial Disclaimer I'm a big Rust fanboy: The one exception to this could be simple type transformations that operate like a fixpoint. So for example transforming int -> (int,) such that when I pass in the (int,) again it stays (int,). |
Beta Was this translation helpful? Give feedback.
-
Python data classes allow the ovverriding of frozen data classes
__init__
methods, that essentially just set all the relevant fields correctly.I would like to ask that you expose that kwargument in your data class wrapper.
This is useful if a frozen data class is usually constructed starting from object_A but does not store object_A itself, but rather something computed starting from it.
We can get around this by using a constructor method, but for a series of reasons the easiest things for us to do in NetKet would be to just override the
__init__
.I don't see reasons not to allow this, as it is allowed by the standard dataclass specification.
Beta Was this translation helpful? Give feedback.
All reactions