asc-community / GenericTensor

The only library allowing to create Tensors (matrices extension) with custom types
https://angouri.org/#generictensor
MIT License
50 stars 5 forks source link

[WIP] GenericTensor 2.0 API Design #31

Open WhiteBlackGoose opened 2 years ago

WhiteBlackGoose commented 2 years ago

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>;
Happypig375 commented 2 years ago

Consider integration with .NET6/7 numeric interfaces?

WhiteBlackGoose commented 2 years ago

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