1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#![feature(const_generics, const_evaluatable_checked)] #![feature(array_methods)] #![feature(array_map)] #![cfg_attr(not(feature = "std"), no_std)] #![allow(dead_code)] mod dimutils; pub mod broadcast; #[cfg(test)] mod tests { use crate::dimutils::*; use crate::broadcast::*; fn linear_iter_test<const N : usize>(size:[usize;N]) { let index_coeffs = linearization_coeffs(size); let indices = ndim_iterator(size); for (i,index) in indices.enumerate() { let lin_index = linearize_index(index,index_coeffs); assert_eq!(i,lin_index); assert_eq!(delinearize_index(lin_index,size),index); } } #[test] fn linearization() { linear_iter_test([3,3]); linear_iter_test([3,4]); linear_iter_test([3,2,4,2]); assert_eq!(linearization_coeffs([4]), [1]); assert_eq!(linearization_coeffs([4,3]), [1,4]); } #[test] fn it_works() { let v = vec![1,2,3]; let bv = (v).lazy_updim([3,4]).into_iter().collect::<Vec<i64>>(); println!("Common size of v, bv is {:?}",commondims(v.size(),bv.size()) ); println!("The elems of bv are {:?}",bv); for x in &bv { println!("{}",x); } assert_eq!(2 + 2, 4); } }