This section describes the Rand class provided by VSIPL++.
A Rand object provides member functions to generate scalar random numbers and views of random numbers.
template <typename T>
class Rand;Template parameters
The type of the random numbers generated by this class.
Rand objects may not be assigned or copied.
typedef Vector<T> vector_type; typedef Matrix<T> matrix_type; typedef Tensor<T> tensor_type;
Description: These types specify the return values for the non-scalar number generators.
Rand(
index_type seed
index_type numprocs
index_type id,
bool portable = true);Requires: 0 < id <= numprocs <=
231 − 1
Description: See [VSPEC101] section Random number
generation for more information and this quote.
“Constructs a random number generator object using the specified seed
seed . If portable == false, the
random number generator characteristics are implementation defined.
Otherwise, the random number generator object obeys the VSIPL 1.1 API and
guidelines in VSIPL 1.1 API sections “Random Numbers,” “VSIPL Random Number
Generator Functions,” and “Sample Implementation.”” When
portable == false, the
implementation may select an algorithm that yields performance better than
the portable method.
Rand(index_type seed, bool portable = true);
Description: Using this constructor is short-hand for using the previous constructor as follows:
Rand(seed, 1, 1, portable);
T randu()
T randn()Description: Return scalar random numbers.
const_Vector<T, unspecified> randu(length_type len) const_Vector<T, unspecified> randn(length_type len)
Description: Construct and return vectors of random numbers.
const_Matrix<T, unspecified> randu( length_type rows, length_type columns) const_Matrix<T, unspecified> randn( length_type rows, length_type columns)
Description: Construct and return matrices of random numbers.
const_Tensor<T, unspecified> randu( length_type z, length_type y, length_type x) const_Tensor<T, unspecified> randn( length_type z, length_type y, length_type x)
Description: Construct and return tensors of random numbers.
template <typename Predicate, typename Vector1, typename Vector2> index_type first(index_type begin, Predicate p, Vector1 v, Vector2 w);
Returns:
The smallest index k >= j such that
f(v.get(k), w.get(k)). A return value at least
v.size() indicates f(v.get(k), w.get(k))
is false for all k >= j.
This value will equal v.size() if j < v.size().
template <typename VectorT> length_type index_bool(VectorT source, Vector<Index<1> > indices); template <typename MatrixT> length_type index_bool(MatrixT source, Vector<Index<2> > indices); template <typename TensorT> length_type index_bool(TensorT source, Vector<Index<3> > indices);
Description:
Obtain all indices for which source evaluates to
true, in lexicographical order.
Returns: The number of elements returned.
template <typename T, typename B0, typename B1> Vector<T, unspecified > gather(const_Vector<T, B0> source, Vector<Index<1>, B1> indices); template <typename T, typename B0, typename B1> Vector<T, unspecified > gather(const_Matrix<T, B0> source, Vector<Index<2>, B1> indices); template <typename T, typename B0, typename B1> Vector<T, unspecified > gather(const_Tensor<T, B0> source, Vector<Index<3>, B1> indices);
Description:
Returns value from source, at positions given by indices.
template <typename T, typename B0, typename B1, typename B2>
void
scatter(const_Vector<T, B0> source,
Vector<Index<1>, B1> indices,
Vector<T, B1> destination);
template <typename T, typename B0, typename B1, typename B2>
void
scatter(const_Vector<T, B0> source,
Vector<Index<2>, B1> indices,
Matrix<T, B1> destination);
template <typename T, typename B0, typename B1, typename B2>
void
scatter(const_Vector<T, B0> source,
Vector<Index<3>, B1> indices,
Tensor<T, B1> destination);Description: Copies all values from source into
destination, at the index given by indices.