diff --git a/packages/dev/core/src/Maths/tensor.ts b/packages/dev/core/src/Maths/tensor.ts index a6ec5c3cc7f..021e4ca0cf6 100644 --- a/packages/dev/core/src/Maths/tensor.ts +++ b/packages/dev/core/src/Maths/tensor.ts @@ -1,4 +1,4 @@ -import type { DeepImmutable, Flatten, FloatArray, Length } from "../types"; +import type { DeepImmutable, Flatten, FloatArray, Length, Tuple } from "../types"; /** * Computes the tensor dimension of a multi-dimensional array */ @@ -14,6 +14,8 @@ export type TensorValue = number[] | TensorValue[]; */ export type ValueOfTensor = T extends Tensor ? V : TensorValue; +type TensorNumberArray = Length> extends 2 ? Tuple : V; + /** * Describes a mathematical tensor. * @see https://wikipedia.org/wiki/Tensor @@ -67,7 +69,7 @@ export interface Tensor { * Copy the current instance to an array * @returns a new array with the instance coordinates. */ - asArray(): Flatten; + asArray(): TensorNumberArray; /** * Sets the current instance coordinates with the given source coordinates @@ -81,13 +83,13 @@ export interface Tensor { * @returns the current updated instance */ - copyFromFloats(...floats: Flatten): this; + copyFromFloats(...floats: TensorNumberArray): this; /** * Sets the instance coordinates with the given floats * @returns the current updated instance */ - set(...values: Flatten): this; + set(...values: TensorNumberArray): this; /** * Sets the instance coordinates to the given value @@ -122,7 +124,7 @@ export interface Tensor { * @param floats the floats to add * @returns the current updated instance */ - addInPlaceFromFloats(...floats: Flatten): this; + addInPlaceFromFloats(...floats: TensorNumberArray): this; /** * Returns a new instance set with the subtracted coordinates of other's coordinates from the current coordinates. @@ -151,7 +153,7 @@ export interface Tensor { * @param floats the coordinates to subtract * @returns the resulting instance */ - subtractFromFloats(...floats: Flatten): this; + subtractFromFloats(...floats: TensorNumberArray): this; /** * Subtracts the given floats from the current instance coordinates and set the given instance "result" with this result @@ -159,7 +161,7 @@ export interface Tensor { * @param args the coordinates to subtract with the last element as the result * @returns the result */ - subtractFromFloatsToRef(...args: [...Flatten, this]): this; + subtractFromFloatsToRef(...args: [...TensorNumberArray, this]): this; /** * Returns a new instance set with the multiplication of the current instance and the given one coordinates @@ -187,7 +189,7 @@ export interface Tensor { * Gets a new instance set with the instance coordinates multiplied by the given floats * @returns a new instance */ - multiplyByFloats(...floats: Flatten): this; + multiplyByFloats(...floats: TensorNumberArray): this; /** * Returns a new instance set with the instance coordinates divided by the given one coordinates @@ -223,7 +225,7 @@ export interface Tensor { * @param floats defines the floats to compare against * @returns this current updated instance */ - minimizeInPlaceFromFloats(...floats: Flatten): this; + minimizeInPlaceFromFloats(...floats: TensorNumberArray): this; /** * Updates the current instance with the maximal coordinate values between its and the given instance ones. @@ -237,7 +239,7 @@ export interface Tensor { * @param floats defines the floats to compare against * @returns this current updated instance */ - maximizeInPlaceFromFloats(...floats: Flatten): this; + maximizeInPlaceFromFloats(...floats: TensorNumberArray): this; /** * Gets a new instance with current instance negated coordinates @@ -308,7 +310,7 @@ export interface Tensor { * @param floats defines the coordinates to compare against * @returns true if both instances are equal */ - equalsToFloats(...floats: Flatten): boolean; + equalsToFloats(...floats: TensorNumberArray): boolean; /** * Gets a new instance from current instance floored values