code stringlengths 17 6.64M |
|---|
class Sequential(ModuleList):
'\n Sequential Module, takes callable of Modules which are then executed in sequence\n '
def __call__(self, inp, *, collected_outputs: Optional[Dict[(str, Tensor)]]=None, **kwargs) -> Tensor:
'\n Forward\n '
for (name, module) in self.items():... |
def sequential(source: Tensor, *modules) -> Tensor:
'\n Wraps ``Sequential(*modules)(source)``\n '
return Sequential(*modules)(source)
|
def _convert_to_module(obj: _ModT) -> rf.Module:
if isinstance(obj, rf.Module):
return obj
elif callable(obj):
return rf.Functional(obj)
else:
raise TypeError(f'Expected rf.Module or callable, did not expect {obj!r} ({type(obj)})')
|
def _is_iterable(obj) -> bool:
try:
iter(obj)
return True
except TypeError:
return False
|
class ParameterList(rf.Module):
'\n Parameter list, getting passed an Iterable of Parameters and creates a list of Parameters in that order\n '
def __init__(self, *parameters: Union[(rf.Parameter, Iterable[rf.Parameter], Dict[(str, rf.Parameter)], ParameterList)]):
super().__init__()
if... |
def _is_int_str(s: str) -> bool:
try:
int(s)
return True
except ValueError:
return False
|
@contextmanager
def control_flow_ctx(ctx: Optional[ControlFlowContext]=None):
'\n Activates the given control flow context.\n '
global _ctx
prev_ctx = _ctx
try:
_ctx = ctx
(yield ctx)
finally:
_ctx = prev_ctx
|
def get_current_control_flow_ctx() -> Optional[ControlFlowContext]:
'\n :return: current control flow context\n '
return _ctx
|
class _ConvOrTransposedConv(rf.Module):
'\n Base class for both convolution and transposed convolution.\n '
nd: Optional[int] = None
_transposed: bool
groups: Optional[int] = None
def __init__(self, in_dim: Dim, out_dim: Dim, filter_size: Union[(Sequence[Union[(int, Dim)]], int, Dim)], *, p... |
class _Conv(_ConvOrTransposedConv):
'\n A generic convolution layer which supports 1D, 2D and 3D convolution.\n Base class for :class:`Conv1d`, :class:`Conv2d`, :class:`Conv3d`.\n '
_transposed = False
def __init__(self, in_dim: Dim, out_dim: Dim, filter_size: Union[(Sequence[Union[(int, Dim)]],... |
def conv(source: Tensor, *, in_dim: Dim, out_dim: Dim, in_spatial_dims: Sequence[Dim], out_spatial_dims: Optional[Sequence[Dim]]=None, filter: Tensor, filter_size: Sequence[Dim], padding: str, strides: Optional[Union[(int, Sequence[int])]]=None, dilation_rate: Optional[Union[(int, Sequence[int])]]=None, groups: Optio... |
class Conv1d(_Conv):
'\n 1D convolution\n '
nd = 1
def __init__(self, in_dim: Dim, out_dim: Dim, filter_size: Union[(int, Dim)], *, padding: str, strides: Optional[int]=None, dilation_rate: Optional[int]=None, groups: Optional[int]=None, with_bias: bool=True):
'\n :param Dim in_dim:\... |
class Conv2d(_Conv):
'\n 2D convolution\n '
nd = 2
|
class Conv3d(_Conv):
'\n 3D convolution\n '
nd = 3
|
class _TransposedConv(_ConvOrTransposedConv):
'\n Transposed convolution, sometimes also called deconvolution.\n See :func:`tf.nn.conv2d_transpose` (currently we support 1D/2D).\n '
nd: Optional[int] = None
_transposed = True
def __init__(self, in_dim: Dim, out_dim: Dim, filter_size: Sequenc... |
def transposed_conv(source: Tensor, *, in_dim: Dim, out_dim: Dim, in_spatial_dims: Sequence[Dim], out_spatial_dims: Optional[Sequence[Dim]]=None, filter: Tensor, filter_size: Sequence[Dim], padding: str, remove_padding: Union[(Sequence[int], int)]=0, output_padding: Optional[Union[(Sequence[Optional[int]], int)]]=Non... |
class TransposedConv1d(_TransposedConv):
'\n 1D transposed convolution\n '
nd = 1
__call__ = _ConvOrTransposedConv._call_nd1
|
class TransposedConv2d(_TransposedConv):
'\n 2D transposed convolution\n '
nd = 2
|
class TransposedConv3d(_TransposedConv):
'\n 3D transposed convolution\n '
nd = 3
|
def pool(source: Tensor, *, mode: str, pool_size: Union[(Sequence[int], int)], padding: str='valid', dilation_rate: Union[(Sequence[int], int)]=1, strides: Optional[Union[(Sequence[int], int)]]=None, in_spatial_dims: Union[(Sequence[Dim], Dim)], out_spatial_dims: Optional[Union[(Sequence[Dim], Dim)]]=None, nd: Option... |
def max_pool(source: Tensor, *, pool_size: Union[(Sequence[int], int)], padding: str='valid', dilation_rate: Union[(Sequence[int], int)]=1, strides: Optional[Union[(Sequence[int], int)]]=None, in_spatial_dims: Union[(Sequence[Dim], Dim)], out_spatial_dims: Optional[Union[(Sequence[Dim], Dim)]]=None) -> Tuple[(Tensor,... |
def max_pool1d(source: Tensor, *, pool_size: int, padding: str='valid', dilation_rate: int=1, strides: Optional[int]=None, in_spatial_dim: Dim, out_spatial_dim: Optional[Dim]=None) -> Tuple[(Tensor, Dim)]:
'max pool'
return pool1d(source=source, mode='max', pool_size=pool_size, padding=padding, dilation_rate=... |
def pool1d(source: Tensor, *, mode: str, pool_size: int, padding: str='valid', dilation_rate: int=1, strides: Optional[int]=None, in_spatial_dim: Dim, out_spatial_dim: Optional[Dim]=None) -> Tuple[(Tensor, Dim)]:
'\n 1D pooling.\n\n :param Tensor source:\n :param str mode: "max" or "avg"\n :param tupl... |
def pool2d(source: Tensor, *, mode: str, pool_size: Union[(Sequence[int], int)], padding: str='valid', dilation_rate: Union[(Sequence[int], int)]=1, strides: Optional[Union[(Sequence[int], int)]]=None, in_spatial_dims: Sequence[Dim], out_spatial_dims: Optional[Sequence[Dim]]=None) -> Tuple[(Tensor, Sequence[Dim])]:
... |
def pool3d(source: Tensor, *, mode: str, pool_size: Union[(Sequence[int], int)], padding: str='valid', dilation_rate: Union[(Sequence[int], int)]=1, strides: Optional[Union[(Sequence[int], int)]]=None, in_spatial_dims: Sequence[Dim], out_spatial_dims: Optional[Sequence[Dim]]=None) -> Tuple[(Tensor, Sequence[Dim])]:
... |
def make_conv_out_spatial_dims(in_spatial_dims: Sequence[Dim], *, filter_size: Union[(Sequence[Union[(int, Dim)]], int, Dim)], padding: str, strides: Union[(Sequence[int], int)]=1, dilation_rate: Union[(Sequence[int], int)]=1, description_prefix: Optional[str]=None) -> Sequence[Dim]:
'create out spatial dims from... |
def _calc_out_dim(in_dim, filter_size, stride, padding, dilation_rate=1):
'\n Copied and adapted from TF ConvLayer.calc_out_dim.\n\n :param T|int|Tensor|torch.Tensor|tensorflow.Tensor|Dim in_dim: dimension in some axis\n :param int filter_size: e.g. 2, for the corresponding axis\n :param int stride: e... |
class TransformerDecoder(rf.Module):
'\n Represents Transformer decoder architecture\n '
def __init__(self, encoder_dim: Dim, vocab_dim: Dim, model_dim: Dim=Dim(512, name='transformer-dec-default-model-dim'), *, num_layers: int, ff_dim: Dim=NotSpecified, ff_activation: Callable[([Tensor], Tensor)]=rf.r... |
class TransformerDecoderLayer(rf.Module):
'\n Represents a conformer block\n '
def __init__(self, encoder_dim: Dim, out_dim: Dim=Dim(512, name='transformer-dec-default-out-dim'), *, ff_dim: Dim=NotSpecified, ff_activation: Callable[([Tensor], Tensor)]=rf.relu, dropout: float=0.1, num_heads: int=8, self... |
class FeedForward(rf.Module):
'\n Conformer position-wise feedforward neural network layer\n FF -> Activation -> Dropout -> FF\n '
def __init__(self, out_dim: Dim, *, ff_dim: Optional[Dim]=NotSpecified, dropout: float, activation: Callable[([Tensor], Tensor)]):
'\n :param out_dim:... |
def copy_to_device(x: Tensor, device: Optional[str]=None) -> Tensor:
'\n Copy tensor to device.\n\n :param x: tensor\n :param device:\n :return: tensor on device\n '
if (not device):
device = get_default_device()
if (not device):
return x
if (x.raw_tensor is None):
... |
def get_default_device() -> Optional[str]:
'\n :return: default device, where to put new tensors (via random number generators, constant, range_over_dim, etc)\n '
return _default_device
|
@contextmanager
def set_default_device_ctx(device: Optional[str]):
'\n :param device: see :func:`get_default_device`\n '
global _default_device
old_device = _default_device
try:
_default_device = device
(yield)
finally:
_default_device = old_device
|
def range_over_dim(dim: Dim, *, dtype: Optional[str]=None, device: Optional[str]=None) -> Tensor[T]:
'\n :param dim:\n :param dtype:\n :param device,\n :return: tensor with shape [dim]\n '
if dim.dyn_size_ext:
backend = get_backend_by_tensor(dim.dyn_size_ext, fallback=global_backend)
... |
def range_over_dim_strided(dim: Dim, *, stride: Union[(int, Tensor)], out_dim: Optional[Dim]=None, dtype: Optional[str]=None, device: Optional[str]=None) -> Tuple[(Tensor[T], Dim)]:
'\n :param dim:\n :param stride:\n :param out_dim:\n :param dtype:\n :param device,\n :return: tensor with shape [... |
def range_over_merged_dims(dims: Sequence[Dim], *, dtype: Optional[str]=None, device: Optional[str]=None) -> Tensor[T]:
'\n This is if you want to index into a merged dim.\n Related: :func:`rf.merge_dims`.\n\n :param dims:\n :param dtype:\n :param device:\n :return: tensor with shape [dim_0, ...... |
def replace_dim(source: Tensor, *, in_dim: Dim, out_dim: Optional[Dim]=None) -> Tuple[(Tensor, Dim)]:
'\n Also see: :func:`rf.merge_dims`, :func:`rf.split_dims`.\n\n :param source:\n :param in_dim:\n :param out_dim:\n :return: source with in_dim replaced by out_dim, and new out_dim.\n this d... |
def dim_match_priority_when_needed(dim: Dim, *other_dims: Dim) -> Dim:
'\n :return: maybe copy of dim with higher match_priority if needed to distinguish from other_dims\n\n Why or when is this needed?\n\n For activation values, this should never be needed,\n and all dims should be unique.\n\n In c... |
def num_elements_of_shape(dims: Sequence[Dim]) -> Union[(int, Tensor)]:
'\n :param dims:\n :return: num elements of a tensor of shape dims, properly considering masking\n '
if all((dim.is_static() for dim in dims)):
n = 1
for dim in dims:
n *= dim.dimension
return ... |
def dropout(source: Tensor, drop_prob: Union[(float, Tensor)], *, axis: Optional[Union[(Dim, Sequence[Dim], bool)]]=None, on_forward: bool=False) -> Tensor:
'\n Applies dropout.\n\n Dropout will only be applied during training (unless you set on_forward=True).\n\n When dropout is applied, the output will... |
def _dropout(x: Tensor, keep_prob: Union[(float, Tensor)], noise_dims: Sequence[Dim], seed=None, apply_correction_factor=True) -> Tensor:
'\n Computes dropout.\n\n Adopted from tf_util.dropout.\n Like :func:`tf.nn.dropout` but avoid :func:`tf.div` if possible.\n\n Note that in tf_util.dropout, we had ... |
def dropout_broadcast_default() -> bool:
'\n Check the global RETURNN config\n whether we should broadcast on non-related dropout dimensions.\n\n Historically in RETURNN, when we did dropout in the feature dimension,\n we broadcasted the dropout mask over the other dimensions (e.g. time and batch).\n\... |
def get_default_float_dtype() -> str:
'\n https://data-apis.org/array-api/latest/API_specification/data_types.html#default-data-types\n\n :return: default dtype for float\n '
return _default_float_dtype
|
def get_default_int_dtype() -> str:
'\n https://data-apis.org/array-api/latest/API_specification/data_types.html#default-data-types\n\n :return: default dtype for int\n '
return _default_int_dtype
|
def get_default_array_index_dtype() -> str:
'\n https://data-apis.org/array-api/latest/API_specification/data_types.html#default-data-types\n\n :return: default dtype for array index - currently just the same as :func:`get_default_int_dtype`\n '
return get_default_int_dtype()
|
def is_float_dtype(dtype: str) -> bool:
'\n :return: whether the dtype is float, e.g. it supports backprop etc\n '
return dtype.startswith('float')
|
class IEncoder(rf.Module, ABC):
'\n Generic encoder interface\n\n The encoder is a function x -> y.\n The input can potentially be sparse or dense.\n The output is dense with feature dim `out_dim`.\n '
out_dim: Dim
def __call__(self, source: Tensor) -> Tensor:
'\n Encode the... |
class ISeqFramewiseEncoder(rf.Module, ABC):
'\n This specializes IEncoder that it operates on a sequence.\n The output sequence length here is the same as the input.\n '
out_dim: Dim
def __call__(self, source: Tensor, *, spatial_dim: Dim) -> Tensor:
raise NotImplementedError
|
class ISeqDownsamplingEncoder(rf.Module, ABC):
'\n This is more specific than IEncoder in that it operates on a sequence.\n The output sequence length here is shorter than the input.\n\n This is a common scenario for speech recognition\n where the input might be on 10ms/frame\n and the output might... |
class ConformerPositionwiseFeedForward(rf.Module):
'\n Conformer position-wise feedforward neural network layer\n FF -> Activation -> Dropout -> FF\n '
def __init__(self, out_dim: Dim, *, ff_dim: Dim, dropout: float, activation: Callable[([Tensor], Tensor)]):
'\n :param out_dim: o... |
class ConformerConvBlock(rf.Module):
'\n Conformer convolution block\n FF -> GLU -> depthwise conv -> BN -> Swish -> FF\n '
def __init__(self, out_dim: Dim, *, kernel_size: int, norm: Union[(rf.BatchNorm, Any)]):
'\n :param out_dim: output feature dimension\n :param kernel_... |
class ConformerConvSubsample(ISeqDownsamplingEncoder):
'\n Conv 2D block with optional max-pooling or striding.\n\n References:\n\n https://github.com/espnet/espnet/blob/4138010fb66ad27a43e8bee48a4932829a0847ae/espnet/nets/pytorch_backend/transformer/subsampling.py#L162\n https://github.com/rwth-i... |
class ConformerEncoderLayer(rf.Module):
'\n Represents a conformer block\n '
def __init__(self, out_dim: Dim=Dim(512, name='conformer-enc-default-out-dim'), *, ff_dim: Dim=NotSpecified, ff_activation: Callable[([Tensor], Tensor)]=rf.swish, dropout: float=0.1, conv_kernel_size: int=32, conv_norm: Union[... |
class ConformerEncoder(ISeqDownsamplingEncoder):
'\n Represents Conformer encoder architecture\n '
def __init__(self, in_dim: Dim, out_dim: Dim=Dim(512, name='conformer-enc-default-out-dim'), *, num_layers: int, input_layer: Union[(ConformerConvSubsample, ISeqDownsamplingEncoder, rf.Module, Any)], inpu... |
def set_requires_gradient(source: Tensor):
'\n :param source:\n :return: nothing, modifies source in-place\n '
return source._raw_backend.set_requires_gradient(source)
|
def gradient(y: Tensor, x: Tensor) -> Tensor:
'\n :param y: some scalar\n :param x: some tensor\n :return: gradient of y w.r.t. x\n '
return y._raw_backend.gradient(y, x)
|
def stop_gradient(source: Tensor) -> Tensor:
'wraps tf.stop_gradient or torch detach'
return source._raw_backend.stop_gradient(source)
|
def scaled_gradient(source: Tensor, scale: Union[(float, Tensor)]) -> Tensor:
'\n :param source:\n :param scale: if constant 0., will use :func:`stop_gradient`.\n Can be used as gradient reversal layer (with negative factor).\n :return: source with scaled gradient\n '
if ((not isinstance(sc... |
def scaled_gradient_ext(source: Tensor, *, scale: Union[(float, Tensor)], shift: Optional[Union[(float, Tensor)]]=None, scale_shift_by_sum_over_axis: Optional[Dim]=None) -> Tensor:
'\n Just `identity` in the forward pass.\n Scales the gradient by some factor in backprop.\n Can be used as gradient reversa... |
def get_tensor_dependencies(x: Tensor) -> Sequence[Tensor]:
'\n :param x: tensor\n :return: list of tensors which are inputs to x\n '
return x._raw_backend.get_tensor_dependencies(x)
|
def get_tensor_consumers(x: Tensor) -> Sequence[Tensor]:
'\n :param x: tensor\n :return: list of tensors which consume x\n '
return x._raw_backend.get_tensor_consumers(x)
|
def walk_tensor_consumers(seed: Union[(Tensor, Sequence[Tensor])], *, filter_outputs: Callable[([Tensor], bool)]=None, ending_condition: Callable[([Tensor], bool)]=None) -> List[Tensor]:
'\n :param seed: tensor\n :param filter_outputs: if given, this function will be called with each tensor,\n and if... |
class ParamInit():
'API for param init'
def __call__(self, dims: Sequence[Dim], dtype: str, *, sparse_dim: Optional[Dim]=None, device: Optional[str]=None, out: Optional[Tensor]=None) -> Union[(Tensor, rf.RawTensorTypes)]:
raise NotImplementedError
|
class Normal(ParamInit):
'\n Initialization by normal distribution (truncated by default),\n independent of the dimensions (fan in/out).\n\n See :class:`VarianceScaling` and derivatives for variants which depend on fan in/out.\n '
def __init__(self, stddev: float, *, truncated: bool=True, dtype: ... |
class VarianceScaling(ParamInit):
'\n Provides a generalized way for initializing weights.\n All the common initialization methods are special cases\n such as Xavier Glorot and Kaiming He.\n\n Code adopted from TensorFlow VarianceScaling.\n '
scale = 1.0
mode = 'fan_in'
distribution = '... |
class Glorot(VarianceScaling):
'\n Xavier Glorot (http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf).\n scale 1, fan_avg, uniform\n '
scale = 1.0
mode = 'fan_avg'
distribution = 'uniform'
|
class He(VarianceScaling):
'\n Kaiming He (https://arxiv.org/pdf/1502.01852.pdf).\n scale 2, fan_in, normal\n '
scale = 2.0
mode = 'fan_in'
distribution = 'normal'
|
class HeUniform(He):
'\n He-init (:class:`He`) but using a uniform distribution.\n scale 2, fan_in, uniform\n '
distribution = 'uniform'
|
def _compute_fans(dims: Sequence[Dim]):
'Computes the number of input and output units for a weight shape.\n\n Args:\n dims: Integer shape tuple or TF tensor shape.\n\n Returns:\n A tuple of integer scalars (fan_in, fan_out).\n '
dims = [dim.dimension for dim in dims]
if (len(dims) < 1)... |
def label_smoothing(prob: Tensor, smoothing: Union[(Tensor, float)], *, axis: Optional[Dim]=None) -> Tensor:
'\n Label smoothing, often used for cross entropy.\n\n In case of sparse data, it will become dense (via :func:`smooth_one_hot`)\n and the target label will get probability (1 - smoothing).\n '... |
def smooth_one_hot(source: Tensor, *, label_prob: Union[(Tensor, float)]) -> Tensor:
'\n Smooth variant of :func:`one_hot`.\n Uses ``label_prob`` for the labels and ``(1 - label_prob) / (dim - 1)`` for the remaining values.\n This is used for label smoothing.\n '
assert source.sparse_dim
if (s... |
def label_smoothed_log_prob_gradient(log_prob: Tensor, smoothing: Union[(Tensor, float)], *, axis: Optional[Dim]=None, exclude_labels: Optional[Sequence[int]]=None) -> Tensor:
'\n :param log_prob: shape [...,D] (not necessarily the same as loss)\n :param smoothing: smoothing factor, for :func:`label_smoothi... |
class Linear(rf.Module):
'\n Linear transformation.\n '
def __init__(self, in_dim: Dim, out_dim: Dim, *, with_bias=True):
super().__init__()
assert (isinstance(in_dim, Dim) and isinstance(out_dim, Dim))
self.in_dim = in_dim
self.out_dim = out_dim
self.weight = rf... |
class Embedding(rf.Module):
'\n Embedding.\n '
def __init__(self, in_dim: Dim, out_dim: Dim):
super().__init__()
assert (isinstance(in_dim, Dim) and isinstance(out_dim, Dim))
self.in_dim = in_dim
self.out_dim = out_dim
self.weight = rf.Parameter((rf.dim_match_pri... |
def while_loop(cond: Callable[([S], Union[(bool, Tensor)])], body: Callable[([S], S)], initial: S) -> S:
'\n It executes::\n\n while cond(loop_vars):\n loop_vars = body(loop_vars)\n\n And then it returns the final loop vars.\n\n If you want to iterate over some axis,\n maybe of an ex... |
def _get_bool_value_eager(v: Union[(Tensor, bool)]) -> bool:
if isinstance(v, Tensor):
assert ((v.dims == ()) and (v.dtype == 'bool'))
assert (v.device in (None, 'cpu')), f'while_loop: cond should be on CPU, got {v} on device {v.device}'
return bool(v.raw_tensor)
elif isinstance(v, boo... |
def scan(*, spatial_dim: Optional[Dim]=None, cond_dims: Optional[Sequence[Dim]]=None, cond_before_body: bool=True, initial: S=None, xs: X=None, ys: Y=None, cond: Optional[Callable[([X, S], Tensor)]]=None, body: Callable[([X, S], Tuple[(Y, S)])], max_seq_len: Optional[Union[(int, Tensor)]]=None, return_tensor_arrays: ... |
def _templates_for_loop_vars(loop_vars: S) -> S:
def _get_template(x):
if isinstance(x, Tensor):
return x.copy_template()
elif isinstance(x, Dim):
return x
elif isinstance(x, TensorArray):
return x
elif (x is None):
return None
... |
def _check_matching_loop_var_templates(loop_var_templates: S, loop_vars: S):
def _check(path, template, x):
if isinstance(template, Tensor):
assert isinstance(x, Tensor), f'loop var {path} is not a Tensor but {type(x)}'
assert (template.batch_ndim == x.batch_ndim), f'loop var {pat... |
class _DimUpdatesEager():
'\n In case dims are updated in the loop body, we need to keep track of this.\n\n This implementation is for eager-based backends.\n\n A graph-based backend would need to distinguish:\n - initial dim\n - dim in loop body (temporarily), input from prev iteration state\n ... |
def cross_entropy(*, estimated: Tensor, target: Tensor, axis: Dim, estimated_type: str) -> Tensor:
'\n ``target`` is supposed to be in probability space (normalized). It can also be sparse, i.e. contain class indices.\n ``estimated`` can be probs, log-probs or logits, specified via ``estimated_type``.\n\n ... |
def ctc_loss(*, logits: Tensor, targets: Tensor, input_spatial_dim: Dim, targets_spatial_dim: Dim, blank_index: int, max_approx: bool=False) -> Tensor:
'\n Calculates the CTC loss.\n\n Internally, this uses :func:`returnn.tf.native_op.ctc_loss`\n which is equivalent to tf.nn.ctc_loss but more efficient.\... |
@typing.overload
def compare(a: Tensor, kind: str, b: Tensor, *, allow_broadcast_all_sources: Optional[bool]=None, dim_order: Optional[Sequence[Dim]]=None) -> Tensor:
'compare with two tensors'
|
def compare_bc(a: Tensor, kind: str, b: Tensor, *, dim_order: Optional[Sequence[Dim]]=None) -> Tensor:
':func:`compare` with allow_broadcast_all_sources=True'
return compare(a, kind, b, allow_broadcast_all_sources=True, dim_order=dim_order)
|
@typing.overload
def combine(a: Tensor, kind: str, b: Tensor, *, allow_broadcast_all_sources: Optional[bool]=None, dim_order: Optional[Sequence[Dim]]=None) -> Tensor:
'combine with two tensors'
|
def combine_bc(a: Tensor, kind: str, b: Tensor, *, dim_order: Optional[Sequence[Dim]]=None) -> Tensor:
':func:`combine` with allow_broadcast_all_sources=True'
return combine(a, kind, b, allow_broadcast_all_sources=True, dim_order=dim_order)
|
def equal(a: Tensor, b: Tensor) -> Tensor:
'equal'
return compare(a, 'equal', b)
|
def less(a: Tensor, b: Tensor) -> Tensor:
'less'
return compare(a, 'less', b)
|
def less_equal(a: Tensor, b: Tensor) -> Tensor:
'less_equal'
return compare(a, 'less_equal', b)
|
def greater(a: Tensor, b: Tensor) -> Tensor:
'greater'
return compare(a, 'greater', b)
|
def greater_equal(a: Tensor, b: Tensor) -> Tensor:
'greater_equal'
return compare(a, 'greater_equal', b)
|
def not_equal(a: Tensor, b: Tensor) -> Tensor:
'not_equal'
return compare(a, 'not_equal', b)
|
def add(a: Tensor, b: Tensor) -> Tensor:
'add'
return combine(a, 'add', b)
|
def sub(a: Tensor, b: Tensor) -> Tensor:
'sub'
return combine(a, 'sub', b)
|
def mul(a: Tensor, b: Tensor) -> Tensor:
'mul'
return combine(a, 'mul', b)
|
def true_divide(a: Tensor, b: Tensor) -> Tensor:
'truediv'
return combine(a, 'truediv', b)
|
def floor_divide(a: Tensor, b: Tensor) -> Tensor:
'floordiv'
return combine(a, 'floordiv', b)
|
def ceil_divide(a: Tensor, b: Tensor) -> Tensor:
'ceildiv'
return (- ((- a) // b))
|
def neg(a: Tensor) -> Tensor:
'neg'
return a._raw_backend.activation(a, 'neg')
|
def reciprocal(a: Tensor) -> Tensor:
'reciprocal / inverse, i.e. 1/a'
return a._raw_backend.activation(a, 'reciprocal')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.