function tomat
tomat(x:
number
| boolean
| array
| matrix
): matrix<number | boolean> | matrix

Converts a number, boolean, or array into a matrix.

If input is a number or boolean, it is converted into a 1x1 matrix. If input is a vector, it is converted into a single-row matrix. If input is already a matrix, it remains unchanged.

Examples

Convert a number to a matrix

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertEquals(tomat(5), [[5]]);

Convert a boolean to a matrix

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertEquals(tomat(true), [[true]]);

Convert a row vector to a matrix

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertEquals(tomat([5, 6, 3]), [[5, 6, 3]]);

Convert an already formatted matrix

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertEquals(tomat([[1, 2], [3, 4]]), [[1, 2], [3, 4]]);

Parameters

x:
number
| boolean
| array
| matrix

The input value.

Return Type

matrix<number | boolean> | matrix

A matrix representation of the input.

Throws

If the input is invalid.