TensorShape

public struct TensorShape: Equatable, Comparable

The tensor shape description. Specify the shape and data type of a Tensor data object.

## dataType Indicate the initial set data type.

## shapeArray The shape attrribute defines the dimension of a Tensor object. In serrano, we follow row-marjor order to store and access elements in a Tensor object and each row is represented as an array. For a given shape array with n indices [i_0, i_1, ..., i_(n-1)], each index from i_0 to i_(n-2) defines the number of rows in its previous dimension. The last index define the number of elements in its previous dimention. For example, a TensorShape object with shpae as [2, 1, 3]. It’s 1st dimension has 2 rows in which each row has 1 row with 3 elements.

User should be clear and unserstanding what a Tensor object looks like when they passing in a TensorShape argument. For example, a Tensor object with shape [2, 3], it can be visulized as a nested array like below:

     // shape [2, 3]
     [
        [1.0, 0.5, 1.3],
        [2.0, 4.2, 6.7],
     ]

And a typical real-world example, a 3-channel RGB image data could be represented with shape [3, image_hight, image_width]:

     [
        // R channel frame
        [
            [232, ..., 123], // (# of Int elements) = image_width
            .
            .
            .
            [113, ..., 225]
        ], // (# of Array elements) = image_hight

        // G channel frame
        [
            [232, ..., 123],
            .
            .
            .
            [113, ..., 225]
        ],

        // B channel frame
        [
            [232, ..., 123],
            .
            .
            .
            [113, ..., 225]
        ]
    ]

Equatable

Two TensorShape objects are equal (==)if they have the same shape.

Two TensorShape objects are dot equal (.==) if they have the same shape and same dataType.

Rank is 0

If a Tensor object’s shapeArray has 0 rank, it indicates that it just contains a scalar value.

  • Check if shape array is valid

    Declaration

    Swift

    public func shapeVerify() -> Bool
  • Get shape array in reversed

    Declaration

    Swift

    public func reversedShapArray() -> [Int]
  • Get transposed shape of current shape.

    Note

    only works for shapes with rank values as 2. Otherwise, fatalError will be throws.

    Declaration

    Swift

    public func transposed() -> TensorShape
  • Tow shapes dot equals when have same dataType and ==.

    Declaration

    Swift

    public static func .==(shapeA: TensorShape, shapeB: TensorShape) -> Bool

    Parameters

    shapeA

    shape A

    shapeB

    shape B

  • Two shap equals when has same rank and same dimensions.

    Declaration

    Swift

    public static func ==(shapeA: TensorShape, shapeB: TensorShape) -> Bool

    Parameters

    shapeA

    shapeA description

    shapeB

    shapeB description

    Return Value

    return value description

  • shapeA larger than shapeB if:

    • shapeA has a larger rank or
    • shapeA and shapeB has same rank while shapeA has a larger element count

      • shapeA: shapeA description
      • shapeB: shapeB description

    Declaration

    Swift

    public static func >(shapeA: TensorShape, shapeB: TensorShape) -> Bool

    Parameters

    shapeA

    shapeA description

    shapeB

    shapeB description

    Return Value

    return value description

  • shapeA larger than or equal to shapeB if: - shapeA has larger rank or - shapeA and shapeB has same rank while shapeA has a larger or samecount

    Declaration

    Swift

    public static func >=(shapeA: TensorShape, shapeB: TensorShape) -> Bool

    Parameters

    shapeA

    shapeA description

    shapeB

    shapeB description

    Return Value

    return value description

  • shapeA less than shapeB if: - shapeA has smaller rank or - shapeA and shapeB has same rank while shapeA has a smaller count

    Declaration

    Swift

    public static func <(shapeA: TensorShape, shapeB: TensorShape) -> Bool

    Parameters

    shapeA

    shapeA description

    shapeB

    shapeB description

    Return Value

    return value description

  • shapeA less than or equal to shapeB if: - shapeA has smaller rank or - shapeA and shapeB has same rank while shapeA has a smaller or same count

    Declaration

    Swift

    public static func <=(shapeA: TensorShape, shapeB: TensorShape) -> Bool

    Parameters

    shapeA

    shapeA description

    shapeB

    shapeB description

    Return Value

    return value description