Random Number Generation#

MatX provides the capability to generate random numbers on the host and device using the random() operator. random() uses cuRAND on the device to generate random numbers from device code.

Note

randomGenerator_t has been deprecated after release 0.5.0. Please use the random() operator instead

template<typename T, typename ShapeType, typename LowerType = typename inner_op_type_t<T>::type, std::enable_if_t<!std::is_array_v<remove_cvref_t<ShapeType>>, bool> = true>
inline auto matx::random(ShapeType &&s, Distribution_t dist, uint64_t seed = 0, LowerType alpha = 1, LowerType beta = 0)#

Return a random number with a specified shape.

Template Parameters:
  • ShapeType – Shape type

  • T – Type of output

  • LowerType – Either T or the inner type of T if T is complex*

Parameters:
  • s – Shape of operator

  • dist – Distribution (either NORMAL or UNIFORM)

  • seed – Random number seed

  • alpha – Value to multiply by each number

  • beta – Value to add to each number

Returns:

Random number operator

template<typename T, int RANK, typename LowerType = typename inner_op_type_t<T>::type>
inline auto matx::random(const index_t (&s)[RANK], Distribution_t dist, uint64_t seed = 0, LowerType alpha = 1, LowerType beta = 0)#

Return a random number with a specified shape.

Template Parameters:
  • RANK – Rank of operator

  • T – Type of output

  • LowerType – Either T or the inner type of T if T is complex

Parameters:
  • s – Array of dimensions

  • dist – Distribution (either NORMAL or UNIFORM)

  • seed – Random number seed

  • alpha – Value to multiply by each number

  • beta – Value to add to each number

Returns:

Random number operator

Examples#

index_t count = 50;

tensor_t<TestType, 3> t3f({count, count, count});

(t3f = (TestType)-1000000).run(this->exec);
(t3f = random<TestType>({count, count, count}, UNIFORM)).run(this->exec);