Skip to content

Type class for operations #68

@benikm91

Description

@benikm91

This is low priority.

Currently, we implement most TensorOps operations in the operator extension statements, for example:

extension [T <: Tuple: Labels, V](t: Tensor[T, V])
  def <(other: Tensor[T, V]): Tensor[T, Boolean] = Tensor(Jax.jnp.less(t.jaxValue, other.jaxValue))

As far as I understand a cleaner pattern is to have operator operations just as facade calling a type class implementation behind the scene:

extension [T <: Tuple: Labels, V](t: Tensor[T, V])(using c: TensorComparision)
  def <(other: Tensor[T, V]): Tensor[T, Boolean] = c.smallerThan(t, other)

This would fix

  • Code clean up. The TensorOps could be split into multiple files, one per type class.
  • Clearer abstraction of Tensor operations, helping to find missing operations.
  • Ambiguous overload, when wanting to provide the same operations in FloatTensorTree (which is why we currently have ** operations). This fixes it as the Type class can be provided by FloatTensorTree (leading to same operator implementation) instead of having a second overload of the operator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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