Function random_array

Source
pub fn random_array<T>(
    shape: (usize, usize),
    density: f64,
    seed: Option<u64>,
    format: &str,
) -> SparseResult<Box<dyn SparseArray<T>>>
where T: Float + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Debug + Copy + 'static,
Expand description

Creates a random sparse array with specified density

§Arguments

  • shape - Shape of the output array (m, n)
  • density - Density of non-zero elements (between 0.0 and 1.0)
  • seed - Optional seed for the random number generator
  • format - Format of the output array (“csr” or “coo”)

§Returns

A sparse array with random non-zero elements

§Examples

use scirs2_sparse::construct::random_array;

// Create a 10x10 array with 30% non-zero elements
let random = random_array::<f64>((10, 10), 0.3, None, "csr").unwrap();
assert_eq!(random.shape(), (10, 10));

// Create a random array with a specific seed
let seeded = random_array::<f64>((5, 5), 0.5, Some(42), "coo").unwrap();
assert_eq!(seeded.shape(), (5, 5));