Vector.randomFilled constructor

Vector.randomFilled(
  1. int length, {
  2. int? seed,
  3. num min = 0,
  4. num max = 1,
  5. DType dtype = DType.float32,
})

Creates a vector of length equal to length, filled with random values within the range min (inclusive) - max (exclusive). If min greater than or equal to max - an argument error will be thrown. The random values are generated by Random class instance, that is created with a seed value equals seed

A usage example:

import 'package:ml_linalg/vector.dart';

final vector = Vector.randomFilled(5, seed: 1, min: -5, max: -1,
  dtype: DType.float64);

print(vector);

the output will be like that:

(-2.6859948542351675, -3.977462789496658, -1.3201339513128914, -1.2556185255852372, -3.254262886438903)

Implementation

factory Vector.randomFilled(
  int length, {
  int? seed,
  num min = 0,
  num max = 1,
  DType dtype = DType.float32,
}) {
  switch (dtype) {
    case DType.float32:
      return Float32x4Vector.randomFilled(
        length,
        seed,
        CacheManagerFactoryImpl().create(vectorCacheKeys),
        const Float32x4Helper(),
        max: max,
        min: min,
      );

    case DType.float64:
      return Float64x2Vector.randomFilled(
        length,
        seed,
        CacheManagerFactoryImpl().create(vectorCacheKeys),
        const Float64x2Helper(),
        max: max,
        min: min,
      );

    default:
      throw UnimplementedError(
          'Vector of $dtype type is not implemented yet');
  }
}