org.eclipse.january.dataset

## Class ShapeUtils

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

-     public class ShapeUtils
      extends Object

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `areShapesBroadcastCompatible(int[] ashape, int[] bshape)` Check if shapes are broadcast compatible
    `static boolean` | `areShapesCompatible(int[] ashape, int[] bshape)` Check if shapes are compatible, ignoring extra axes of length 1
    `static boolean` | `areShapesCompatible(int[] ashape, int[] bshape, int axis)` Check if shapes are compatible but skip axis
    `static long` | `calcLongSize(int[] shape)` Calculate total number of items in given shape
    `static int[]` | `calcShapePadding(int[] aShape, int[] bShape)` Calculate the padding difference between two shapes.
    `static int` | `calcSize(int[] shape)` Calculate total number of items in given shape
    `static int[]` | `checkAxes(int rank, int... axes)` Check that all axes are in range [-rank,rank)
    `static int` | `checkAxis(int rank, int axis)` Check that axis is in range [-rank,rank)
    `static void` | `checkCompatibility(ILazyDataset g, ILazyDataset h)` This function takes a dataset and checks its shape against another dataset.
    `static boolean` | `differsByOnes(int[] a, int[] b)`
    `static int` | `getFlat1DIndex(int[] shape, int[] pos)` Get flattened view index of given position
    `static int[]` | `getNDPositionFromShape(int n, int[] shape)` Get n-D position from given index
    `static int[]` | `getReducedShapeKeepRank(int[] shape, int... axes)` Set reduced axes to 1
    `static int[]` | `getRemainingAxes(int rank, int... axes)`
    `static int[]` | `getShapeFromObject(Object obj)` Get shape from object (array or list supported)
    `static int[]` | `reduceShape(int[] shape, int... axes)` Remove axes from shape
    `static int[]` | `squeezeShape(int[] shape, boolean onlyFromEnds)` Remove dimensions of 1 in given shape - from both ends only, if true
    `static int[]` | `squeezeShape(int[] shape, int axis)` Remove dimension of 1 in given shape

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

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

- - ### Method Detail

    - #### calcLongSize

          public static long calcLongSize(int[] shape)

      Calculate total number of items in given shape
      Parameters:
        `shape` - dataset shape
      Returns:
        size

    - #### calcSize

          public static int calcSize(int[] shape)

      Calculate total number of items in given shape
      Parameters:
        `shape` - dataset shape
      Returns:
        size

    - #### areShapesBroadcastCompatible

          public static boolean areShapesBroadcastCompatible(int[] ashape,
                                                             int[] bshape)

      Check if shapes are broadcast compatible
      Parameters:
        `ashape` - first shape
        `bshape` - second shape
      Returns:
        true if they are compatible

    - #### areShapesCompatible

          public static boolean areShapesCompatible(int[] ashape,
                                                    int[] bshape)

      Check if shapes are compatible, ignoring extra axes of length 1
      Parameters:
        `ashape` - first shape
        `bshape` - second shape
      Returns:
        true if they are compatible

    - #### areShapesCompatible

          public static boolean areShapesCompatible(int[] ashape,
                                                    int[] bshape,
                                                    int axis)

      Check if shapes are compatible but skip axis
      Parameters:
        `ashape` - first shape
        `bshape` - second shape
        `axis` - to skip
      Returns:
        true if they are compatible

    - #### squeezeShape

          public static int[] squeezeShape(int[] shape,
                                           boolean onlyFromEnds)

      Remove dimensions of 1 in given shape - from both ends only, if true
      Parameters:
        `shape` - dataset shape
        `onlyFromEnds` - if true, trim ends
      Returns:
        newly squeezed shape (or original if unsqueezed)

    - #### squeezeShape

          public static int[] squeezeShape(int[] shape,
                                           int axis)

      Remove dimension of 1 in given shape
      Parameters:
        `shape` - dataset shape
        `axis` - to remove
      Returns:
        newly squeezed shape

    - #### getShapeFromObject

          public static int[] getShapeFromObject(Object obj)

      Get shape from object (array or list supported)
      Parameters:
        `obj` - object
      Returns:
        shape can be null if obj is null

    - #### getNDPositionFromShape

          public static int[] getNDPositionFromShape(int n,
                                                     int[] shape)

      Get n-D position from given index
      Parameters:
        `n` - absolute index
        `shape` - dataset shape
      Returns:
        n-D position

    - #### getFlat1DIndex

          public static int getFlat1DIndex(int[] shape,
                                           int[] pos)

      Get flattened view index of given position
      Parameters:
        `shape` - dataset shape
        `pos` - the integer array specifying the n-D position
      Returns:
        the index on the flattened dataset

    - #### checkCompatibility

          public static void checkCompatibility(ILazyDataset g,
                                                ILazyDataset h)
                                         throws IllegalArgumentException

      This function takes a dataset and checks its shape against another dataset. If they are both of the same size, then this returns with no error, if there is a problem, then an error is thrown.
      Parameters:
        `g` - The first dataset to be compared
        `h` - The second dataset to be compared
      Throws:
        `IllegalArgumentException` - This will be thrown if there is a problem with the compatibility

    - #### checkAxis

          public static int checkAxis(int rank,
                                      int axis)

      Check that axis is in range [-rank,rank)
      Parameters:
        `rank` - number of dimensions
        `axis` - dimension to check
      Returns:
        sanitized axis in range [0, rank)
      Since:
        2.1

    - #### checkAxes

          public static int[] checkAxes(int rank,
                                        int... axes)

      Check that all axes are in range [-rank,rank)
      Parameters:
        `rank` - number of dimensions
        `axes` - to skip
      Returns:
        sanitized axes in range [0, rank) and sorted in increasing order
      Since:
        2.2

    - #### getRemainingAxes

          public static int[] getRemainingAxes(int rank,
                                               int... axes)

      Parameters:
        `rank` - number of dimensions
        `axes` - to skip
      Returns:
        remaining axes not given by input
      Since:
        2.2

    - #### reduceShape

          public static int[] reduceShape(int[] shape,
                                          int... axes)

      Remove axes from shape
      Parameters:
        `shape` - to use
        `axes` - to remove
      Returns:
        reduced shape
      Since:
        2.2

    - #### getReducedShapeKeepRank

          public static int[] getReducedShapeKeepRank(int[] shape,
                                                      int... axes)

      Set reduced axes to 1
      Parameters:
        `shape` - input
        `axes` - to set to 1
      Returns:
        shape with same rank
      Since:
        2.2

    - #### differsByOnes

          public static boolean differsByOnes(int[] a,
                                              int[] b)

      Parameters:
        `a` - first shape
        `b` - second shape
      Returns:
        true if arrays only differs by unit entries
      Since:
        2.2

    - #### calcShapePadding

          public static int[] calcShapePadding(int[] aShape,
                                               int[] bShape)

      Calculate the padding difference between two shapes. Padding can be positive (negative) for added (removed) dimensions. NB positive or negative padding is given after matched dimensions
      Parameters:
        `aShape` - first shape
        `bShape` - second shape
      Returns:
        padding can be null if shapes are equal
      Throws:
        `IllegalArgumentException` - if one shape is null but not the other, or if shapes do not possess common non-unit lengths
      Since:
        2.2

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