def _select_meta(pred: TensorLikeType, a: TensorLikeType, b: TensorLikeType) -> TensorLikeType: utils.check_same_device(pred, a, b, allow_scalars=True) utils.check_same_shape(pred, a, b) assert pred.dtype is torch.bool return _elementwise_meta(a, b)
def _select_meta(pred: TensorLikeType, a: TensorLikeType, b: TensorLikeType) -> TensorLikeType: utils.check_same_device(pred, a, b, allow_cpu_scalar_tensors=True) utils.check_same_shape(pred, a, b, allow_cpu_scalar_tensors=True) assert pred.dtype is torch.bool return _elementwise_meta( a, b, type_promotion=ELEMENTWISE_PRIM_TYPE_PROMOTION_KIND.DEFAULT)
def _elementwise_meta(*args, type_promotion): """ Meta function for elementwise operations that produce outputs in the same dtype as their inputs. Stride logic is currently incorrect. """ assert len(args) > 0 utils.check_same_device(*args, allow_cpu_scalar_tensors=True) utils.check_same_shape(*args, allow_cpu_scalar_tensors=True) utils.check_same_dtype(*args) strides = None tensor = None number = None for arg in args: if isinstance(arg, TensorLike): if strides is None: strides = arg.stride() if tensor is None: tensor = arg if arg.stride() != strides: return TensorMeta(arg, strides=utils.make_contiguous_strides_for( arg.shape)) elif isinstance(arg, Number): if number is None: number = arg # TODO: fix strides if tensor is not None: if 0 in tensor.stride() and tensor.numel() > 0: return TensorMeta(tensor, strides=utils.make_contiguous_strides_for( tensor.shape)) else: return TensorMeta(tensor) return TensorMeta(number)