4.6. Selection, generation, and manipulation functions

4.6.1. Generation functions

4.6.1.1. Random Number Generation

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

T

The type of the random numbers generated by this class.

Rand objects may not be assigned or copied.

4.6.1.1.1. Public types
  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.

4.6.1.1.2. Constructors
        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);
4.6.1.1.3. Number Generators
        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.

4.6.1.1.4. Example
// Construct a random number generator for floats.
Rand<float> vgen(0, 0);

// Create a vector of 35 uniform random numbers.
Rand<float>::vector_type v1 = vgen.randu(35);

4.6.1.2. ramp()

    template <typename T>
    const_Vector<T, unspecified >
    ramp(T a, T b, length_type len);
    

Returns:  A Vector of size len. For 0 <= i < len, w.get(i) == a + i * b.

4.6.2. Selection functions

4.6.2.1. first()

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().

4.6.2.2. indexbool()

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.

4.6.2.3. gather()

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.

4.6.2.4. scatter()

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.