Tensor Creation#
Warning
The Gluon API is experimental and may undergo breaking changes in future releases.
APIs on IrisGluon
that create and initialize tensors on the Iris symmetric heap.
- IrisGluon.zeros(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False)[source]#
Create a tensor filled with zeros on the symmetric heap.
- Parameters:
size – Shape of the tensor
dtype – Data type (default: torch.float32)
device – Device (must match Iris device)
layout – Layout (default: torch.strided)
requires_grad – Whether to track gradients
- Returns:
Zero-initialized tensor on the symmetric heap
- Return type:
torch.Tensor
- IrisGluon.zeros_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format)[source]#
Returns a tensor filled with the scalar value 0, with the same size as input, allocated on the Iris symmetric heap.
- Parameters:
input (Tensor) – the size of input will determine size of the output tensor.
- Keyword Arguments:
dtype (torch.dtype, optional) – the desired data type of returned Tensor. Default: if None, defaults to the dtype of input.
layout (torch.layout, optional) – the desired layout of returned tensor. Default: if None, defaults to the layout of input. Note: Iris tensors are always contiguous (strided).
device (torch.device, optional) – the desired device of returned tensor. Default: if None, defaults to the device of input. Must be compatible with this Iris instance.
requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.
memory_format (torch.memory_format, optional) – the desired memory format of returned Tensor. Default: torch.preserve_format.
Example
>>> ctx = iris_gluon.iris(1 << 20) >>> input_tensor = ctx.ones(2, 3) >>> zeros_tensor = ctx.zeros_like(input_tensor) >>> print(zeros_tensor.shape) # torch.Size([2, 3])
- IrisGluon.ones(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False)[source]#
Returns a tensor filled with the scalar value 1, with the shape defined by the variable argument size. The tensor is allocated on the Iris symmetric heap.
- Parameters:
*size (int...) – a sequence of integers defining the shape of the output tensor. Can be a variable number of arguments or a collection like a list or tuple.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see torch.set_default_dtype()).
layout (torch.layout, optional) – the desired layout of returned Tensor. Default: torch.strided. Note: Iris tensors always use torch.strided regardless of this parameter.
device (torch.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type.
requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.
Example
>>> ctx = iris_gluon.iris(1 << 20) >>> tensor = ctx.ones(2, 3) >>> print(tensor.shape) # torch.Size([2, 3]) >>> print(tensor[0]) # tensor([1., 1., 1.], device='cuda:0')
- IrisGluon.full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False)[source]#
Creates a tensor of size size filled with fill_value. The tensor’s dtype is inferred from fill_value. The tensor is allocated on the Iris symmetric heap.
- Parameters:
size (int...) – a list, tuple, or torch.Size of integers defining the shape of the output tensor.
fill_value (Scalar) – the value to fill the output tensor with.
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see torch.set_default_dtype()).
layout (torch.layout, optional) – the desired layout of returned Tensor. Default: torch.strided. Note: Iris tensors always use torch.strided regardless of this parameter.
device (torch.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type.
requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.
Example
>>> ctx = iris_gluon.iris(1 << 20) >>> tensor = ctx.full((2, 3), 3.14) >>> print(tensor.shape) # torch.Size([2, 3]) >>> print(tensor[0]) # tensor([3.1400, 3.1400, 3.1400], device='cuda:0')