torch.ShapeCheckedResult
export type ShapeCheckedResult<ResultShape extends Shape, SuccessType> = ResultShape extends {
__isShapeError: true;
}
? ShapeErrorMessage<ResultShape>
: SuccessType;ResultShapeextends ShapeSuccessTypeWraps a result type to check for shape errors in the result shape. If the result shape is an error, returns the error message as a string literal. Otherwise returns the success type.
Examples
// Valid shape - returns Tensor
type Valid = ShapeCheckedResult<readonly [2, 3], Tensor<readonly [2, 3]>>;
// = Tensor<readonly [2, 3]>
// Error shape - returns error message
type Invalid = ShapeCheckedResult<broadcast_error_incompatible_dimensions<3, 5>, Tensor<...>>;
// = "SHAPE_ERROR: broadcast_error_incompatible_dimensions<3, 5>"