org.eclipse.january.dataset

## Class BroadcastUtils

- java.lang.Object
- - org.eclipse.january.dataset.BroadcastUtils

-     public final class BroadcastUtils
      extends Object

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BroadcastUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static List<int[]>` | `broadcastShapes(int[]... shapes)` Take in shapes and broadcast them to same rank
    `static List<int[]>` | `broadcastShapesToMax(int[] maxShape, int[]... shapes)` Take in shapes and broadcast them to maximum shape
    `static int[][]` | `calculateBroadcastShapes(int[] oldShape, int size, int... newShape)` Calculate shapes for broadcasting
    `static Dataset[]` | `convertAndBroadcast(Object... objects)` Converts and broadcast all objects as datasets of same shape
    `static int[]` | `createBroadcastStrides(Dataset a, int[] broadcastShape)` Create a stride array from a dataset to a broadcast shape
    `static int[]` | `createBroadcastStrides(int isize, int[] oShape, int[] oStride, int[] broadcastShape)` Create a stride array from a dataset to a broadcast shape
    `static int[]` | `padShape(int[] shape, int padding)` Pad shape by prefixing with ones

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### BroadcastUtils

          public BroadcastUtils()

  - ### Method Detail

    - #### calculateBroadcastShapes

          public static int[][] calculateBroadcastShapes(int[] oldShape,
                                                         int size,
                                                         int... newShape)

      Calculate shapes for broadcasting
      Parameters:
        `oldShape` - old shape
        `size` - dataset size
        `newShape` - new shape
      Returns:
        broadcasted shape and full new shape or null if it cannot be done

    - #### padShape

          public static int[] padShape(int[] shape,
                                       int padding)

      Pad shape by prefixing with ones
      Parameters:
        `shape` - to pad
        `padding` - number of dimensions to add
      Returns:
        new shape or old shape if padding is zero

    - #### broadcastShapes

          public static List<int[]> broadcastShapes(int[]... shapes)

      Take in shapes and broadcast them to same rank
      Parameters:
        `shapes` - null shapes are ignored and passed through
      Returns:
        list of broadcasted shapes plus the first entry is the maximum shape

    - #### broadcastShapesToMax

          public static List<int[]> broadcastShapesToMax(int[] maxShape,
                                                         int[]... shapes)

      Take in shapes and broadcast them to maximum shape
      Parameters:
        `maxShape` - maximum shape
        `shapes` - inputs
      Returns:
        list of broadcasted shapes

    - #### createBroadcastStrides

          public static int[] createBroadcastStrides(Dataset a,
                                                     int[] broadcastShape)

      Create a stride array from a dataset to a broadcast shape
      Parameters:
        `a` - dataset
        `broadcastShape` - shape to broadcast
      Returns:
        stride array

    - #### createBroadcastStrides

          public static int[] createBroadcastStrides(int isize,
                                                     int[] oShape,
                                                     int[] oStride,
                                                     int[] broadcastShape)

      Create a stride array from a dataset to a broadcast shape
      Parameters:
        `isize` - item size
        `oShape` - original shape
        `oStride` - original stride
        `broadcastShape` - shape to broadcast
      Returns:
        stride array

    - #### convertAndBroadcast

          public static Dataset[] convertAndBroadcast(Object... objects)

      Converts and broadcast all objects as datasets of same shape
      Parameters:
        `objects` - to convert and broadcast
      Returns:
        all as broadcasted to same shape

Copyright © 2014–2022 Eclipse Foundation. All rights reserved.