UNPKG

@thi.ng/tensors

Version:

0D/1D/2D/3D/4D tensors with extensible polymorphic operations and customizable storage

91 lines 2.58 kB
import type { Fn, Predicate2 } from "@thi.ng/api"; import type { ITensor } from "./api.js"; import type { Tensor1, Tensor2, Tensor3, Tensor4 } from "./tensor.js"; /** * Result type of {@link select}. */ export type SelectResult<T> = { arg: number[]; value: T; }; /** * Same as {@link select} for 1D tensors. * * @param a * @param xform * @param pred * @param initial */ export declare const select1: <A, B>(a: Tensor1<A>, xform: Fn<A, B>, pred: Predicate2<B>, initial: B) => SelectResult<B>; /** * Same as {@link select} for 2D tensors. * * @param a * @param xform * @param pred * @param initial */ export declare const select2: <A, B>(a: Tensor2<A>, xform: Fn<A, B>, pred: Predicate2<B>, initial: B) => SelectResult<B>; /** * Same as {@link select} for 3D tensors. * * @param a * @param xform * @param pred * @param initial */ export declare const select3: <A, B>(a: Tensor3<A>, xform: Fn<A, B>, pred: Predicate2<B>, initial: B) => SelectResult<B>; /** * Same as {@link select} for 4D tensors. * * @param a * @param xform * @param pred * @param initial */ export declare const select4: <A, B>(a: Tensor4<A>, xform: Fn<A, B>, pred: Predicate2<B>, initial: B) => SelectResult<B>; /** * Uses given value transform `xform` and predicate `pred` to select a specific * component value and its position in the tensor. The `initial` value is used * to seed the search. * * @remarks * This function is a generalization of {@link argMin}/{@link argMax}-like * functionality and customizable via arbitrary predicates. * * @example * ```ts * import { select, tensor } from "@thi.ng/tensors"; * * const a = tensor("i8", [2, 2], { data: [1, -2, -3, 4] }); * * // select smallest value * console.log(select(a, (x) => x, (a,b) => a < b, Infinity)); * // { arg: [1, 0], value: -3 } * * // select smallest absolute value * console.log(select(a, Math.abs, (a,b) => a < b, Infinity)); * // { arg: [0, 0], value: 1 } * ``` * * @param a * @param xform * @param pred * @param initial */ export declare const select: <A, B>(a: ITensor<A>, xform: Fn<A, B>, pred: Predicate2<B>, initial: B) => SelectResult<B>; /** * Syntax sugar for {@link select} to find the minimum component value and its * position in a tensor. * * @param a */ export declare const argMin: (a: ITensor) => SelectResult<number>; /** * Syntax sugar for {@link select} to find the maximum component value and its * position in a tensor. * * @param a */ export declare const argMax: (a: ITensor) => SelectResult<number>; //# sourceMappingURL=select.d.ts.map