MCPcopy Create free account
hub / github.com/apple/ml-pointersect / randn_like

Function randn_like

cdslib/core/nn/nn_utils.py:119–129  ·  view source on GitHub ↗

Create a new tensor or nested list of tensors that has the same shape as x. Each of the tensor is filled with iid samples from a standard normal distribution.

(x: T.Union[torch.Tensor, T.Sequence[torch.Tensor]])

Source from the content-addressed store, hash-verified

117
118
119def randn_like(x: T.Union[torch.Tensor, T.Sequence[torch.Tensor]]):
120 """
121 Create a new tensor or nested list of tensors that has the same shape as x.
122 Each of the tensor is filled with iid samples from a standard normal distribution.
123 """
124 if isinstance(x, torch.Tensor):
125 return torch.randn_like(x)
126 elif isinstance(x, T.Sequence):
127 return [randn_like(xi) for xi in x]
128 else:
129 raise NotImplementedError
130
131
132def get_constant_rnn_hidden_states(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected