broadcastArguments function

List<List<double>> broadcastArguments(
  1. List<List<double>> arguments,
  2. MaterialBuiltin builtin
)

Spreads a one-component argument across the widest one, for the builtins that take a float beside a vector.

Shared by the folder and the software backend, for the reason applyBinary is.

Implementation

List<List<double>> broadcastArguments(
  List<List<double>> arguments,
  MaterialBuiltin builtin,
) {
  if (!builtin.componentWise) return arguments;
  var width = 1;
  for (final argument in arguments) {
    if (argument.length > width) width = argument.length;
  }
  return <List<double>>[
    for (final argument in arguments)
      argument.length == width
          ? argument
          : List<double>.filled(width, argument.single),
  ];
}