GenericTensor icon indicating copy to clipboard operation
GenericTensor copied to clipboard

[WIP] GenericTensor 2.0 API Design

Open WhiteBlackGoose opened this issue 3 years ago • 2 comments

Name of the type

For now we will assume it's Tensor. However it's opionated, because it might be useful to avoid calling it the same name as other libs.

Operations

Namespace: GenericTensor.Core.

Interfaces with method Invoke: () -> A

IAdditiveIdentity<A>
IMultiplicativeIdentity<A>

Interfaces with method Invoke: A -> B

INegate<A, B>

Interfaces with method Invoke: A x B -> C

IAdd<A, B, C>
ISubtract<A, B, C>
IMultiply<A, B, C>
IDivide<A, B, C>

Interfaces with method Invoke: A -> bool

IEqualsAdditiveIdentity<A>

Interfaces with method Invoke: A x B -> bool

IAreEqual<A, B>

Interfaces with method Invoke: A -> string

IToString<A>

Interfaces with method Invoke: A -> byte[]

ISerialize<A>

Interfaces with method Invoke: byte[] -> A

IDeserialize<A>

Tensor

The main type where all these methods will be is Tensor (but not Tensor<T>!).

Composition

static Tensor<T> Concat<T>(params Tensor<T>[] ts, int axis = -1);
byte[] Serialize<T, TSerializer>() where TSerializer : ISerialize<T>;
Tensor<T> Slice<T>(params Either<int, Index, Range>[] dims);
static Tensor<T> Stack<T>(params Tensor<T>[] ts);
Tensor<T> Transpose<T>(Tensor<T> a);
Tensor<T> Transpose<T>(Tensor<T> a, int axis1, int axis2);
void TransposeInplace(Tensor<T> a);
void TransposeInplace(Tensor<T> a, int axis1, int axis2);

Math operations

...

Elementwise:

void AddPointwise<A, B, C, TAdder>(Tensor<A> a, Tensor<B> b, Tensor<C> destination) where TAdder : struct, IAdder<A, B, C>;
Tensor<C> AddPointwise<A, B, C, TAdder>(Tensor<A> a, Tensor<B> b) where TAdder : struct, IAdder<A, B, C>;

WhiteBlackGoose avatar May 30 '22 16:05 WhiteBlackGoose

Consider integration with .NET6/7 numeric interfaces?

Happypig375 avatar Jun 03 '22 08:06 Happypig375

I think we can do it for multitarget. So if the target is .NET 7+, then we also offer a wrapper which would provide default operations implementing their numeric interfaces

WhiteBlackGoose avatar Jun 03 '22 09:06 WhiteBlackGoose