import type { array, matrix } from "../types"; /** * Reshape an array or matrix into a new matrix of given dimensions. * * Rearranges elements of an array or matrix into a new shape while preserving order. * * @param x The array or matrix to reshape. * @param m Number of rows for the new matrix. * @param n Number of columns for the new matrix. * @param flag Flag (0: row-wise, 1: column-wise). Defaults to 0. * @returns The reshaped matrix. * @throws If dimensions are invalid or inconsistent. * * @example Reshape a row vector into a column vector * ```ts * import { assertEquals, assertThrows } from "jsr:@std/assert"; * * assertEquals(reshape([5, 6, 3], 3, 1), [[5], [6], [3]]); * * ``` * * @example Reshape a column vector into a row vector * ```ts * import { assertEquals, assertThrows } from "jsr:@std/assert"; * * assertEquals(reshape([5, 6, 3], 1, 3), [[5, 6, 3]]); * * ``` * * @example Reshape a 2x3 matrix into a 3x2 matrix (row-wise) * ```ts * import { assertEquals, assertThrows } from "jsr:@std/assert"; * * assertEquals(reshape([[-1, 3, -1], [4, 5, 9]], 3, 2), [[-1, 3], [-1, 4], [5, 9]]); * * ``` * * @example Reshape a 2x3 matrix into a 3x2 matrix (column-wise) * ```ts * import { assertEquals, assertThrows } from "jsr:@std/assert"; * * assertEquals(reshape([[-1, 3, -1], [4, 5, 9]], 3, 2, 1), [[-1, 4], [3, 5], [-1, 9]]); * * ``` * * @example Reshape into a single-column matrix * ```ts * import { assertEquals, assertThrows } from "jsr:@std/assert"; * * assertEquals(reshape([[-1, 3, -1], [4, 5, 9]], 6, 1), [[-1], [3], [-1], [4], [5], [9]]); * * ``` * * @example Reshape into a single-column matrix (column-wise) * ```ts * import { assertEquals, assertThrows } from "jsr:@std/assert"; * * assertEquals(reshape([[-1, 3, -1], [4, 5, 9]], 6, 1, 1), [[-1], [4], [3], [5], [-1], [9]]); * * ``` */ export default function reshape(x: array | matrix, m: number, n: number, flag?: 0 | 1): matrix; //# sourceMappingURL=reshape.d.ts.map