Skip to content

Improve coercion dunders #9

Description

@nicola-bastianello

as part of #7 I added the coercion dunders __bool__, __int__, __complex__, __index__ alongside __float__ that was already available.

these methods currently do e.g. float(self._backend.squeeze(self).value), but not all frameworks neatly support all coercions (e.g. bool for tf, TypeError: Using a tf.Tensor as a Python bool is not allowed.). this means that we have a dishomogeneous behavior across frameworks

I see two options: 1) we add non-abstract backend methods, like to_float; if a backend does not implement them, we raise a TypeError. 2) we support this in all frameworks (to_float is abstract), and come up with a workaround for frameworks that don't directly allow coercion to scalar

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions