MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / random_hadamard_matrix

Function random_hadamard_matrix

fastdeploy/model_executor/layers/utils.py:379–393  ·  view source on GitHub ↗

Generate a random Hadamard matrix. Args: block_size (int): The size of the block, i.e., the number of rows and columns of the matrix. dtype (str): The data type, for example 'float32'. Returns: paddle.Tensor: The generated random Hadamard matrix.

(block_size: int, dtype: Union[paddle.dtype, str])

Source from the content-addressed store, hash-verified

377
378
379def random_hadamard_matrix(block_size: int, dtype: Union[paddle.dtype, str]) -> paddle.Tensor:
380 """
381 Generate a random Hadamard matrix.
382
383 Args:
384 block_size (int): The size of the block, i.e., the number of rows and columns of the matrix.
385 dtype (str): The data type, for example 'float32'.
386
387 Returns:
388 paddle.Tensor: The generated random Hadamard matrix.
389
390 """
391 Q = paddle.diag(paddle.ones((block_size), dtype=dtype))
392 block = matmul_hadU(Q)
393 return block
394
395
396def create_hadamard_matrix(hidden_size: int) -> paddle.Tensor:

Callers 1

create_hadamard_matrixFunction · 0.85

Calls 1

matmul_hadUFunction · 0.85

Tested by

no test coverage detected