def incorrects() -> None:
    # T1 + T2 is incorrectly typed, due to different dimensions in the tensors
    # pyre-fixme[58]: `+` is not supported for operand types `Tensor[int, [int,
    # int]]` and `Tensor[int, [int, int]]`.
    Err1 = T1 + T2  # noqa
    # T1 * T3 is incorrectly typed
    # pyre-fixme[6]: Expected `Tensor[DType, B, C]` for 2nd param but got
    #  `Tensor[int, T, T]`.
    Err2 = mm(T1, T3)  # noqa
    # T1 + T4 is incorrectly type (dtype)
    # pyre-fixme[58]: `+` is not supported for operand types `Tensor[int, [int,
    # int]]` and `Tensor[float, [int, int]]`.
    Err3 = T1 + T3  # noqa
Example #2
0
def incorrects() -> None:
    # T1 + T2 is incorrectly typed
    # pyre-fixme[6]: Expected `Tensor[int, typing_extensions.Literal[42],
    #  typing_extensions.Literal[16]]` for 1st param but got `Tensor[int,
    #  typing_extensions.Literal[16], typing_extensions.Literal[64]]`.
    Err1 = T1 + T2  # noqa
    # T1 * T3 is incorrectly typed
    # pyre-fixme[6]: Expected `Tensor[DType, B, C]` for 2nd param but got
    #  `Tensor[int, T, T]`.
    Err2 = mm(T1, T3)  # noqa
    # T1 + T4 is incorrectly type (dtype)
    # pyre-fixme[6]: Expected `Tensor[int, typing_extensions.Literal[42],
    #  typing_extensions.Literal[16]]` for 1st param but got `Tensor[int, T, T]`.
    Err3 = T1 + T3  # noqa
Example #3
0
def f(x: Tensor[float32, [N, D4]]) -> Tensor[float32, [N, D1]]:
    """Approximated function."""
    return torch.mm(x, W_target) + b_target.item()
Example #4
0
# and a dummy one without a real value (could be an unknown Batch Size)
class T:
    pass


T1: Tensor[int32, [D1, D2]] = Tensor()
T2: Tensor[int32, [D2, D3]] = Tensor()
T3: Tensor[int32, [T, T]] = Tensor()
T4: Tensor[float32, [D1, D2]] = Tensor()

# T1 + T1 is correctly typed
T1p1: Tensor[int32, [D1, D2]] = T1 + T1

# T1 * T2 is correctly typed
T1m2: Tensor[int32, [D1, D3]] = mm(T1, T2)


def incorrects() -> None:
    # T1 + T2 is incorrectly typed
    # pyre-fixme[6]: Expected `Tensor[int, typing_extensions.Literal[42],
    #  typing_extensions.Literal[16]]` for 1st param but got `Tensor[int,
    #  typing_extensions.Literal[16], typing_extensions.Literal[64]]`.
    Err1 = T1 + T2  # noqa
    # T1 * T3 is incorrectly typed
    # pyre-fixme[6]: Expected `Tensor[DType, B, C]` for 2nd param but got
    #  `Tensor[int, T, T]`.
    Err2 = mm(T1, T3)  # noqa
    # T1 + T4 is incorrectly type (dtype)
    # pyre-fixme[6]: Expected `Tensor[int, typing_extensions.Literal[42],
    #  typing_extensions.Literal[16]]` for 1st param but got `Tensor[int, T, T]`.
# and a dummy one without a real value (could be an unknown Batch Size)
class T:
    pass


T1: Tensor[int32, D1, D2] = Tensor()
T2: Tensor[int32, D2, D3] = Tensor()
T3: Tensor[int32, T, T] = Tensor()
T4: Tensor[float32, D1, D2] = Tensor()
T5: Tensor[str, D1, D1] = Tensor()

# T1 + T1 is correctly typed
T1p1: Tensor[int32, D1, D2] = T1 + T1

# T1 * T2 is correctly typed
T1m2: Tensor[int32, D1, D3] = mm(T1, T2)


def incorrects() -> None:
    # T1 + T2 is incorrectly typed
    # pyre-fixme[6]: Expected `Tensor[int, typing_extensions.Literal[42],
    #  typing_extensions.Literal[16]]` for 1st param but got `Tensor[int,
    #  typing_extensions.Literal[16], typing_extensions.Literal[64]]`.
    Err1 = T1 + T2  # noqa
    # T1 * T3 is incorrectly typed
    # pyre-fixme[6]: Expected `Tensor[DType, B, C]` for 2nd param but got
    #  `Tensor[int, T, T]`.
    Err2 = mm(T1, T3)  # noqa
    # T1 + T4 is incorrectly type (dtype)
    # pyre-fixme[6]: Expected `Tensor[int, typing_extensions.Literal[42],
    #  typing_extensions.Literal[16]]` for 1st param but got `Tensor[int, T, T]`.