Class Shapes


  • public final class Shapes
    extends java.lang.Object
    Contains utility methods to deal with tensor shapes.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Set<java.lang.Class<?>> dimensionalIntersection​(Shape left, Shape right)
      Extracts those dimensions, which are contained in both shapes.
      static Shape dimensionStripped​(Shape shape, java.util.Set<? extends java.lang.Class<?>> dimensionsToStrip)
      Constructs a shape that contains positions, which are derived from the positions of the given shape by stripping (removing) the given dimensions.
      static Shape intersection​(java.lang.Iterable<Shape> shapes)
      Creates a shape, containing the positions which are contained in each of the given shapes.
      static Shape intersection​(Shape left, Shape right)
      Creates a shape, containing all the positions that are contained in both given shapes.
      static Shape outerProduct​(Shape left, Shape right)
      Constructs a shape that contains all positions resulting from the outer product of the positions of the left shape with those of the right shape.
      static java.util.Set<java.lang.Class<?>> parentDimensionalIntersection​(Shape left, Shape right)  
      static Shape union​(java.lang.Iterable<Shape> shapes)
      Creates a shape, containing all the positions that are contained at least in one of the given shapes.
      static Shape union​(Shape left, Shape right)
      Creates a shape, containing all the positions that are either contained in the left or the right shape.This only makes sense, if the dimensions of the two shapes are the same.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • intersection

        public static Shape intersection​(Shape left,
                                         Shape right)
        Creates a shape, containing all the positions that are contained in both given shapes. This only makes sense, if the dimensions of the two shapes are compatible. If they are not, then an IllegalArgumentException is thrown.
        Parameters:
        left - the first shape from which to take positions
        right - the second shape from which to take positions
        Returns:
        a shape containing all positions, which are contained in both given shapes
      • union

        public static Shape union​(Shape left,
                                  Shape right)
        Creates a shape, containing all the positions that are either contained in the left or the right shape.This only makes sense, if the dimensions of the two shapes are the same. If they are not, then an IllegalArgumentException is thrown.
        Parameters:
        left - the first shape from which to take positions
        right - the second shape from which to take positions
        Returns:
        a shape containing all positions, which are contained in at least one of the two shapes
      • union

        public static final Shape union​(java.lang.Iterable<Shape> shapes)
        Creates a shape, containing all the positions that are contained at least in one of the given shapes. This only makes sense, if the dimensions of the shapes are compatible. If they are not, then an IllegalArgumentException is thrown. Further, it is required that at least one element is contained in the iterable.
        Parameters:
        shapes - the shapes for which the union shall be found
        Returns:
        a shape which represents the union of all the shapes
        Throws:
        java.lang.IllegalArgumentException - if the shapes are not of the same dimension
        java.util.NoSuchElementException - in case the iterable is empty
        java.lang.NullPointerException - if the given iterable is null
      • intersection

        public static final Shape intersection​(java.lang.Iterable<Shape> shapes)
        Creates a shape, containing the positions which are contained in each of the given shapes. This only makes sense, if the dimensions of the shapes are the same. If they are not, then an IllegalArgumentException is thrown. Further, it is required that at least one element is contained in the iterable.
        Parameters:
        shapes - the shapes for which the intersection shall be found
        Returns:
        a shape which represents the intersection of all the shapes
        Throws:
        java.lang.IllegalArgumentException - if the shapes are not of the same dimension
        java.util.NoSuchElementException - in case the iterable is empty
        java.lang.NullPointerException - if the given iterable is null
      • dimensionalIntersection

        public static java.util.Set<java.lang.Class<?>> dimensionalIntersection​(Shape left,
                                                                                Shape right)
        Extracts those dimensions, which are contained in both shapes.
        Parameters:
        left - the first shape for which to look at the dimensions
        right - the second shape where to look at the dimensions.
        Returns:
        all the dimensions which are present in both shapes
      • parentDimensionalIntersection

        public static java.util.Set<java.lang.Class<?>> parentDimensionalIntersection​(Shape left,
                                                                                      Shape right)
      • dimensionStripped

        public static Shape dimensionStripped​(Shape shape,
                                              java.util.Set<? extends java.lang.Class<?>> dimensionsToStrip)
        Constructs a shape that contains positions, which are derived from the positions of the given shape by stripping (removing) the given dimensions. The returned shape contains then only unique resulting position-parts and thus might be much smaller than the original shape.
        Parameters:
        shape - the shape from which to extract the stripped positions
        dimensionsToStrip - the dimensions which shall be removed from the positions of the shape
        Returns:
        a shape containing unique positions, resulting from the shapes positions, stripping the given dimensions
        Throws:
        java.lang.NullPointerException - if one of the arguments are null
      • outerProduct

        public static Shape outerProduct​(Shape left,
                                         Shape right)
        Constructs a shape that contains all positions resulting from the outer product of the positions of the left shape with those of the right shape. It is required that the two shapes have no overlap of dimensions (i.e. none of the dimensions in the left shape are available in the right and vice versa).
        Parameters:
        left - the left shape to use for the outer product
        right - the right shape to use for the outer product
        Returns:
        a shape containing positions constructed from all combinations of the left positions with the right positions.
        Throws:
        java.lang.NullPointerException - if one of the arguments is null
        java.lang.IllegalArgumentException - if the two shapes have overlapping dimensions