Skip to contents

Ensures that input is propagated appropriately to a matrix of dimension output_rows x output_cols. Handles the following cases:

  1. input is a scalar: output is simply a (output_rows, output_cols) matrix with input repeated for each element

  2. input is a vector of length output_rows: output is a (output_rows, output_cols) array with input broadcast across each of output_cols columns

  3. input is a vector of length output_cols: output is a (output_rows, output_cols) array with input broadcast across each of output_rows rows

  4. input is a matrix of dimension (output_rows, output_cols): input is passed through as-is All other cases throw an error.

Usage

expand_dims_2d(input, output_rows, output_cols)

Arguments

input

Input to be converted to a matrix (or passed through as-is)

output_rows

Intended number of rows in the output array

output_cols

Intended number of columns in the output array

Value

A matrix of dimension output_rows x output_cols