pub fn random_sym_array<T>(
n: usize,
density: f64,
format: &str,
) -> SparseResult<Box<dyn SymSparseArray<T>>>
Expand description
Create a random symmetric sparse matrix with given density
§Arguments
n
- Size of the matrix (n x n)density
- Density of non-zero elements (0.0 to 1.0)format
- Format of the output matrix (“csr” or “coo”)
§Returns
A random symmetric sparse matrix
§Examples
use scirs2_sparse::construct_sym::random_sym_array;
// Create a 10x10 symmetric random matrix with 20% density
let random = random_sym_array::<f64>(10, 0.2, "csr").unwrap();
assert_eq!(random.shape(), (10, 10));
// Check that it's symmetric
assert!(random.is_symmetric());
// The actual density may vary slightly due to randomness