samba.random#

Random#

normal(*args, name: str = '', named_dims: Iterable[str | None] | None = None, region_name: str | None = None, **kwargs) SambaTensor#

Returns a SambaTensor of random numbers that are drawn from separate normal distributions whose mean and standard deviation are given.

Parameters:
  • args – positional args that are passed to torch.normal

  • name – the name of the SambaTensor

  • named_dims – names for each dimension

  • region_name – a name for the memory region that the SambaTensor is assigned to. If two SambaTensors have the same region_name, the two SambaTensors share the same location in memory.

  • kwargs – keyword arguments that are passed to torch.normal

Example:

>>> samba.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1)).data
tensor([2.2767, 2.8268, 2.9410, 3.6725, 5.2463, 6.0850, 7.5083, 7.2790, 9.0880,
        9.9657])

>>> samba.normal(mean=0.5, std=torch.arange(1., 6.)).data
tensor([ 0.3286,  3.0739, -3.2288, -4.4992,  5.2323])

>>> samba.normal(mean=torch.arange(1., 6.)).data
tensor([2.0087, 2.5200, 1.9975, 4.1197, 5.0543])

>>> samba.normal(2, 3, size=(1, 4)).data
tensor([[ 0.1695,  6.4747,  4.6618, -3.1114]])

See also

For details see torch.normal().

rand(*args, name: str = '', named_dims: Iterable[str | None] | None = None, region_name: str | None = None, **kwargs) SambaTensor#

Returns a tensor filled with random numbers from a uniform distribution on the interval [0,1).

Parameters:
  • args – positional args that are passed to torch.normal

  • name – the name of the SambaTensor

  • batch_dim – the batch dimension

  • named_dims – names for each dimension

  • region_name – a name for the memory region that the SambaTensor is assigned to. If two SambaTensors have the same region_name, then the two SambaTensors share the same location in memory.

  • kwargs – keyword arguments that are passed to torch.normal

Example:

>>> samba.rand(4).data
tensor([0.9383, 0.4034, 0.8161, 0.5808])

>>> samba.rand(2, 3).data
tensor([[0.6896, 0.9761, 0.1149],
        [0.1225, 0.8296, 0.7747]])

See also

For details see torch.rand().

rand_like(*args, name: str = '', named_dims: Iterable[str | None] | None = None, region_name: str | None = None, **kwargs) SambaTensor#
Returns a tensor with the same size as input that is filled with random numbers from

a uniform distribution on the interval \([0, 1)\).

Parameters:
  • args – positional args that are passed to torch.rand_like

  • name – the name of the SambaTensor

  • batch_dim – the batch dimension

  • named_dims – names for each dimension

  • region_name – a name for the memory region that the SambaTensor are assigned to. If two SambaTensors have the same region_name, then the two SambaTensors share the same location in memory.

  • kwargs – keyword arguments that are passed to torch.rand_like

See also

For details see torch.rand_like().

randint(*args, name: str = '', named_dims: Iterable[str | None] | None = None, region_name: str | None = None, **kwargs) SambaTensor#

Returns a tensor filled with random integers generated uniformly between low (inclusive) and high (exclusive).

Parameters:
  • args – positional args that are passed to torch.randint

  • name – the name of the SambaTensor

  • batch_dim – the batch dimension

  • named_dims – names for each dimension

  • region_name – a name for the memory region that the SambaTensor are assigned to. If two SambaTensors have the same region_name, then the two SambaTensors share the same location in memory.

  • kwargs – keyword arguments that are passed to torch.randint

Example:

>>> samba.randint(3, 5, (3,)).data
tensor([3, 4, 4])

>>> samba.randint(10, (2, 2)).data
tensor([[8, 5],
        [2, 8]])

>>> samba.randint(3, 10, (2, 2)).data
tensor([[5, 8],
        [3, 5]])

See also

For details see torch.randint().

randint_like(*args, name: str = '', named_dims: Iterable[str | None] | None = None, region_name: str | None = None, **kwargs) SambaTensor#

Returns a tensor with the same shape as Tensor input filled with random integers generated uniformly between low (inclusive) and high (exclusive).

Parameters:
  • args – positional args that are passed to torch.randint_like

  • name – the name of the SambaTensor

  • batch_dim – the batch dimension

  • named_dims – names for each dimension

  • region_name – a name for the memory region that the SambaTensor are assigned to. If two SambaTensors have the same region_name, then the two SambaTensors share the same location in memory.

  • kwargs – keyword arguments that are passed to torch.randint_like

See also

For details see torch.randint_like().

randn(*args, name: str = '', named_dims: Iterable[str | None] | None = None, region_name: str | None = None, **kwargs) SambaTensor#

Returns a tensor filled with random numbers from a normal distribution with mean 0 and variance 1 (also called the standard normal distribution).

\[\text{out}_{i} \sim \mathcal{N}(0, 1)\]
Parameters:
  • args – positional args that are passed to torch.randn

  • name – the name of the SambaTensor

  • batch_dim – the batch dimension

  • named_dims – names for each dimension

  • region_name – a name for the memory region that the SambaTensor are assigned to. If two SambaTensors have the same region_name, then the two SambaTensors share the same location in memory.

  • kwargs – keyword arguments that are passed to torch.randn

Example:

>>> samba.randn(4).data
tensor([ 2.3328, -1.4842,  0.5812, -0.4112])

>>> samba.randn(2, 3).data
tensor([[-1.4422,  0.9957, -1.4014],
        [-1.0818, -0.9322,  2.3616]])

See also

For more details see torch.randn().

randn_like(*args, name: str = '', named_dims: Iterable[str | None] | None = None, region_name: str | None = None, **kwargs) SambaTensor#

Returns a tensor with the same size as input that is filled with random numbers from a normal distribution with mean 0 and variance 1.

Parameters:
  • args – positional args that are passed to torch.randn_like

  • name – the name of the SambaTensor

  • batch_dim – the batch dimension

  • named_dims – names for each dimension

  • region_name – a name for the memory region that the SambaTensor are assigned to. If two SambaTensors have the same region_name, then the two SambaTensors share the same location in memory.

  • kwargs – keyword arguments that are passed to torch.randn_like

See also

For details see torch.randn_like().

set_seed(seed: int = 0) None#

Sets the random seed for PyTorch, TensorFlow, Numpy, and Python random libraries. Can be set by the SAMBA_SEED environment variable when running an app.

Parameters:

seed – the random seed