public final class Shape
extends java.lang.Object
implements java.io.Serializable
This class is immutable
Modifier and Type | Class and Description |
---|---|
static class |
Shape.Builder
The builder for a tensor shape.
|
Modifier and Type | Method and Description |
---|---|
static Shape.Builder |
builder()
Creates a new builder for a shape.
|
static Shape.Builder |
builder(java.util.Set<? extends java.lang.Class<?>> dimensions)
Creates a new builder for a shape with predefined dimensions.
|
boolean |
contains(java.lang.Object... coordinates)
Convenience method for
contains(Position) , with the position constructed from the given coordinates. |
boolean |
contains(Position position)
Returns
true if the shape contains the given position, false otherwise. |
<T> java.util.Set<T> |
coordinatesOfType(java.lang.Class<T> ofClass)
Extracts the provided class of the coordinate from the provided shape.
|
boolean |
covers(Shape other)
returns
true if this shape contains at least all the positions of the the other. |
int |
dimensionality()
Returns the number of dimensions of a tensor of this shape.
|
java.util.Set<java.lang.Class<?>> |
dimensionSet()
Retrieves all the dimensions of this shape.
|
static Shape |
empty()
Returns an empty shape with no dimensions and no positions.
|
boolean |
equals(java.lang.Object obj) |
int |
hashCode() |
boolean |
hasSameDimensionsAs(Shape other)
returns
true if this shape has the same dimensions as the other shape. |
static Shape |
of(java.lang.Iterable<Position> positions)
Deprecated.
Using this method to construct a shape guesses the dimensionality from the passed positions.
|
static Shape |
of(Position... positions)
Deprecated.
Using this method to construct a shape guesses the dimensionality from the passed positions.
|
static Shape |
of(java.util.Set<java.lang.Class<?>> dimensions,
java.lang.Iterable<Position> positions)
Creates a shape from the given set of positions and dimensions (types of coordinates).
|
static Shape |
of(java.util.Set<java.lang.Class<?>> dimensions,
Position... positions)
This is a convenience method to be used instead of
of(Set,Iterable) . |
java.util.Set<Position> |
positionSet()
Retrieves all the positions which are available in a tensor for this shape.
|
int |
size()
Returns the number of entries of a tensor of this shape.
|
java.lang.String |
toString() |
static Shape |
viewOf(java.util.Set<? extends java.lang.Class<?>> dimensions,
java.util.Set<Position> positions)
Directly creates a shape using the given dimensions and positions.
|
static Shape |
zeroDimensional()
Returns a shape corresponding to a zero-dimensional tensor with one entry (an empty position).
|
public java.util.Set<Position> positionSet()
public java.util.Set<java.lang.Class<?>> dimensionSet()
public int dimensionality()
dimensionSet()
;public int size()
positionSet()
;public boolean covers(Shape other)
true
if this shape contains at least all the positions of the the other.other
- the set which to compare to.true
if the other shape is covered, false
otherwise.public boolean contains(Position position)
true
if the shape contains the given position, false
otherwise.position
- the position to be checkedtrue
if the position is contained in the shape, false
otherwise.public boolean contains(java.lang.Object... coordinates)
contains(Position)
, with the position constructed from the given coordinates.coordinates
- the coordinates which represent the position to be checkedtrue
if the position represented by the given coordinates is contained in the shape,
false
otherwise.public boolean hasSameDimensionsAs(Shape other)
true
if this shape has the same dimensions as the other shape.other
- the other shape with which to compare this shapetrue
if the dimensions are the same, false
otherwisepublic static Shape.Builder builder()
public static Shape.Builder builder(java.util.Set<? extends java.lang.Class<?>> dimensions)
dimensions
- the dimensions for the new shapepublic static Shape viewOf(java.util.Set<? extends java.lang.Class<?>> dimensions, java.util.Set<Position> positions)
dimensions
- the dimensions for the shapepositions
- the positions of the shape@Deprecated public static Shape of(java.lang.Iterable<Position> positions)
IllegalArgumentException
will be thrown.positions
- the positions which shall be used for the new shapejava.lang.IllegalArgumentException
- if the dimensions of the individual positions are not consistent.@SafeVarargs @Deprecated public static Shape of(Position... positions)
of(Iterable)
.positions
- the positions for the new shapejava.lang.IllegalArgumentException
- if the dimensions of the positions are inconsistentof(Iterable)
public static Shape of(java.util.Set<java.lang.Class<?>> dimensions, java.lang.Iterable<Position> positions)
IllegalArgumentException
will be thrown.dimensions
- the dimensions for the new shapepositions
- the positions which shall be used for the new shapejava.lang.IllegalArgumentException
- if the dimensions of the individual positions are not consistent.@SafeVarargs public static Shape of(java.util.Set<java.lang.Class<?>> dimensions, Position... positions)
of(Set,Iterable)
.dimensions
- the dimensions for the new shapepositions
- the positions for the new shapejava.lang.IllegalArgumentException
- if the dimensions of the positions are inconsistentof(Iterable)
public static Shape empty()
of()
(with no arguments). However, using this
method is preferred, since no unnecessary instances are created this way.public static Shape zeroDimensional()
Position.empty()
)public <T> java.util.Set<T> coordinatesOfType(java.lang.Class<T> ofClass)
ofClass
- a class of the coordinate to be extractedpublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object