-
Notifications
You must be signed in to change notification settings - Fork 718
Description
Feature description
Somehow Relax the constraints for the Element trait to make it possible to define elements outside of burn-tensor
Feature motivation
This came up primarily in #3608 in the process of trying to move complex element definitions to the crate burn-complex
. The current major blocker is ElementConversion
, which has explicit function calls per primitive type which relys on ToElement
which has explict calls per type. This made it impossible to define an Element outside of burn-tensor
. ElementComparison
I believe depends on ElementConversion
.
This currently blocks implementing basicOps
(and thus quite a few other traits) on anything outside of burn tensor if the underlying dtype is not one of the already defined and supported primitives.
(Optional) Suggest a Solution
completely spitballing:
- remove the ElementConversion, ElementComparision constraint from element. Make the basic ops that require members of a new trait (maybe
InteropOps
? lol). Really just shuffles the problem around though. - find a way to rework the functions in element conversion to more like the signature of mem::transmute (i.e.
convert<E1,E2>(E1)-> E2
where both are Elements, but elements are not required to cover every implementor. The core primitives will cover all the other primitives in burn-tensor. You can have 2 variants, convert which is fast but unsafe in that it will panic if the required conversion method doesn't exists, and thentry_convert<E1,E2>(E1)-> Result<E2>
that will throw an error. This might be tricky converting external elements from burn-tensor elements since that would probably violate the orphan rule - get rid of ElementConvert, and make the ops that currently require it require a From, Into specific to the 2 elements in question (the current element and product element).
I'm open to other possibilities, and if there are downsides or tradeoffs to the above approaches I'm not seeing, please let me know.