pub fn random_array<T>(
shape: (usize, usize),
density: f64,
seed: Option<u64>,
format: &str,
) -> SparseResult<Box<dyn SparseArray<T>>>
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 generatorformat
- 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));