import type { array, matrix } from "../types"; /** * Flatten a matrix into an array. * * Flattens a matrix into a 1D array. The default concatenation is row-wise (dim = 0). If `dim = 1`, the concatenation is column-wise. * * @param x The matrix to flatten. * @param dimParam The dimension to flatten by. 0 = row-wise, 1 = column-wise. Defaults to 0. * @returns The flattened 1D array. * @throws If no input is provided or if the input is not a matrix. * * @example Flatten a 2x2 matrix (row-wise by default) * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(flatten([[5, 6], [7, 8]]), [5, 6, 7, 8]); * * ``` * * @example Flatten a 3x3 matrix by rows * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(flatten([[1, 1, -1], [1, -2, 3], [2, 3, 1]]), [1, 1, -1, 1, -2, 3, 2, 3, 1]); * * ``` * * @example Flatten a 3x3 matrix by columns (dim = 1) * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(flatten([[1, 1, -1], [1, -2, 3], [2, 3, 1]], 1), [1, 1, 2, 1, -2, 3, -1, 3, 1]); * * ``` */ export default function flatten(x: number): number; /** * Flatten a matrix into an array. * * Flattens a matrix into a 1D array. The default concatenation is row-wise (dim = 0). If `dim = 1`, the concatenation is column-wise. * * @param x The matrix to flatten. * @param dimParam The dimension to flatten by. 0 = row-wise, 1 = column-wise. Defaults to 0. * @returns The flattened 1D array. * @throws If no input is provided or if the input is not a matrix. * * @example Flatten a 2x2 matrix (row-wise by default) * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(flatten([[5, 6], [7, 8]]), [5, 6, 7, 8]); * * ``` * * @example Flatten a 3x3 matrix by rows * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(flatten([[1, 1, -1], [1, -2, 3], [2, 3, 1]]), [1, 1, -1, 1, -2, 3, 2, 3, 1]); * * ``` * * @example Flatten a 3x3 matrix by columns (dim = 1) * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(flatten([[1, 1, -1], [1, -2, 3], [2, 3, 1]], 1), [1, 1, 2, 1, -2, 3, -1, 3, 1]); * * ``` */ export default function flatten(x: array): array; /** * Flatten a matrix into an array. * * Flattens a matrix into a 1D array. The default concatenation is row-wise (dim = 0). If `dim = 1`, the concatenation is column-wise. * * @param x The matrix to flatten. * @param dimParam The dimension to flatten by. 0 = row-wise, 1 = column-wise. Defaults to 0. * @returns The flattened 1D array. * @throws If no input is provided or if the input is not a matrix. * * @example Flatten a 2x2 matrix (row-wise by default) * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(flatten([[5, 6], [7, 8]]), [5, 6, 7, 8]); * * ``` * * @example Flatten a 3x3 matrix by rows * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(flatten([[1, 1, -1], [1, -2, 3], [2, 3, 1]]), [1, 1, -1, 1, -2, 3, 2, 3, 1]); * * ``` * * @example Flatten a 3x3 matrix by columns (dim = 1) * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(flatten([[1, 1, -1], [1, -2, 3], [2, 3, 1]], 1), [1, 1, 2, 1, -2, 3, -1, 3, 1]); * * ``` */ export default function flatten(x: matrix, dim: 0 | 1): array; /** * Flatten a matrix into an array. * * Flattens a matrix into a 1D array. The default concatenation is row-wise (dim = 0). If `dim = 1`, the concatenation is column-wise. * * @param x The matrix to flatten. * @param dimParam The dimension to flatten by. 0 = row-wise, 1 = column-wise. Defaults to 0. * @returns The flattened 1D array. * @throws If no input is provided or if the input is not a matrix. * * @example Flatten a 2x2 matrix (row-wise by default) * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(flatten([[5, 6], [7, 8]]), [5, 6, 7, 8]); * * ``` * * @example Flatten a 3x3 matrix by rows * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(flatten([[1, 1, -1], [1, -2, 3], [2, 3, 1]]), [1, 1, -1, 1, -2, 3, 2, 3, 1]); * * ``` * * @example Flatten a 3x3 matrix by columns (dim = 1) * ```ts * import { assertEquals } from "jsr:@std/assert"; * * assertEquals(flatten([[1, 1, -1], [1, -2, 3], [2, 3, 1]], 1), [1, 1, 2, 1, -2, 3, -1, 3, 1]); * * ``` */ export default function flatten(x: array | matrix, dim?: 0 | 1): array; //# sourceMappingURL=flatten.d.ts.map