torch.ShapedTensor
export interface ShapedTensor<S extends Shape = DynamicShape> {
readonly shape: S;
readonly dtype: string;
readonly device: string;
readonly requires_grad: boolean;
// Shape-preserving unary operations
neg(): ShapedTensor<S>;
abs(): ShapedTensor<S>;
exp(): ShapedTensor<S>;
log(): ShapedTensor<S>;
sqrt(): ShapedTensor<S>;
relu(): ShapedTensor<S>;
sigmoid(): ShapedTensor<S>;
tanh(): ShapedTensor<S>;
sin(): ShapedTensor<S>;
cos(): ShapedTensor<S>;
square(): ShapedTensor<S>;
clone(): ShapedTensor<S>;
// Scalar operations preserve shape
add(scalar: number): ShapedTensor<S>;
sub(scalar: number): ShapedTensor<S>;
mul(scalar: number): ShapedTensor<S>;
div(scalar: number): ShapedTensor<S>;
pow(scalar: number): ShapedTensor<S>;
// Tensor binary operations with broadcasting
add<O extends Shape>(other: ShapedTensor<O>): ShapedTensor<BroadcastShape<S, O>>;
sub<O extends Shape>(other: ShapedTensor<O>): ShapedTensor<BroadcastShape<S, O>>;
mul<O extends Shape>(other: ShapedTensor<O>): ShapedTensor<BroadcastShape<S, O>>;
div<O extends Shape>(other: ShapedTensor<O>): ShapedTensor<BroadcastShape<S, O>>;
// Matrix operations
matmul<O extends Shape>(other: ShapedTensor<O>): ShapedTensor<MatmulShape<S, O>>;
mm<O extends Shape>(other: ShapedTensor<O>): ShapedTensor<Matmul2DShape<S, O>>;
t(): ShapedTensor<TransposeShape<S>>;
transpose<D0 extends number, D1 extends number>(
dim0: D0,
dim1: D1
): ShapedTensor<TransposeDimsShape<S, D0, D1>>;
permute<P extends readonly number[]>(dims: P): ShapedTensor<PermuteShape<S, P>>;
// Shape operations
reshape<const T extends Shape>(...shape: T): ShapedTensor<T>;
view<const T extends Shape>(...shape: T): ShapedTensor<T>;
squeeze<D extends number>(dim?: D): ShapedTensor<SqueezeShape<S, D>>;
unsqueeze<D extends number>(dim: D): ShapedTensor<UnsqueezeShape<S, D>>;
flatten(): ShapedTensor<FlattenShape<S>>;
// Reductions
sum(): ShapedTensor<readonly []>;
sum<D extends number>(dim: D, keepdim?: false): ShapedTensor<ReduceShape<S, D, false>>;
sum<D extends number>(dim: D, keepdim: true): ShapedTensor<ReduceShape<S, D, true>>;
mean(): ShapedTensor<readonly []>;
mean<D extends number>(dim: D, keepdim?: false): ShapedTensor<ReduceShape<S, D, false>>;
mean<D extends number>(dim: D, keepdim: true): ShapedTensor<ReduceShape<S, D, true>>;
// Comparison (returns same shape with bool dtype)
eq(other: ShapedTensor<S> | number): ShapedTensor<S>;
ne(other: ShapedTensor<S> | number): ShapedTensor<S>;
lt(other: ShapedTensor<S> | number): ShapedTensor<S>;
le(other: ShapedTensor<S> | number): ShapedTensor<S>;
gt(other: ShapedTensor<S> | number): ShapedTensor<S>;
ge(other: ShapedTensor<S> | number): ShapedTensor<S>;
}Sextends Shape- readonly
shape(S) - readonly
dtype(string) - readonly
device(string) - readonly
requires_grad(boolean) neg(() => ShapedTensor<S>)abs(() => ShapedTensor<S>)exp(() => ShapedTensor<S>)log(() => ShapedTensor<S>)sqrt(() => ShapedTensor<S>)relu(() => ShapedTensor<S>)sigmoid(() => ShapedTensor<S>)tanh(() => ShapedTensor<S>)sin(() => ShapedTensor<S>)cos(() => ShapedTensor<S>)square(() => ShapedTensor<S>)clone(() => ShapedTensor<S>)add((scalar: number) => ShapedTensor<S>)sub((scalar: number) => ShapedTensor<S>)mul((scalar: number) => ShapedTensor<S>)div((scalar: number) => ShapedTensor<S>)pow((scalar: number) => ShapedTensor<S>)add((other: ShapedTensor<O>) => ShapedTensor<BroadcastShape<S, O>>)sub((other: ShapedTensor<O>) => ShapedTensor<BroadcastShape<S, O>>)mul((other: ShapedTensor<O>) => ShapedTensor<BroadcastShape<S, O>>)div((other: ShapedTensor<O>) => ShapedTensor<BroadcastShape<S, O>>)matmul((other: ShapedTensor<O>) => ShapedTensor<MatmulShape<S, O>>)mm((other: ShapedTensor<O>) => ShapedTensor<Matmul2DShape<S, O>>)t(() => ShapedTensor<TransposeShape<S>>)transpose((dim0: D0, dim1: D1) => ShapedTensor<TransposeDimsShape<S, D0, D1>>)permute((dims: P) => ShapedTensor<PermuteShape<S, P>>)reshape((...shape: T) => ShapedTensor<T>)view((...shape: T) => ShapedTensor<T>)squeeze((dim?: D) => ShapedTensor<SqueezeShape<S, D>>)unsqueeze((dim: D) => ShapedTensor<UnsqueezeShape<S, D>>)flatten(() => ShapedTensor<FlattenShape<S>>)sum(() => ShapedTensor<readonly []>)sum((dim: D, keepdim?: false) => ShapedTensor<ReduceShape<S, D, false>>)sum((dim: D, keepdim: true) => ShapedTensor<ReduceShape<S, D, true>>)mean(() => ShapedTensor<readonly []>)mean((dim: D, keepdim?: false) => ShapedTensor<ReduceShape<S, D, false>>)mean((dim: D, keepdim: true) => ShapedTensor<ReduceShape<S, D, true>>)eq((other: ShapedTensor<S> | number) => ShapedTensor<S>)ne((other: ShapedTensor<S> | number) => ShapedTensor<S>)lt((other: ShapedTensor<S> | number) => ShapedTensor<S>)le((other: ShapedTensor<S> | number) => ShapedTensor<S>)gt((other: ShapedTensor<S> | number) => ShapedTensor<S>)ge((other: ShapedTensor<S> | number) => ShapedTensor<S>)
A tensor with compile-time shape information.