use ulib::{ UVec, Device }; #[cfg(feature = "cuda")] use ulib::{ AsCUDASlice, AsCUDASliceMut }; #[test] fn test_simple_cpu() { let mut uvt: UVec = UVec::new_zeroed(100, Device::CPU); uvt.as_mut()[0] = 10; assert_eq!(uvt.as_mut()[2], 0); assert_eq!(uvt.as_mut()[0], 10); assert_eq!(uvt.clone().as_mut()[0], 10); } #[test] fn test_realloc_cpu() { let mut uvt: UVec = UVec::new_zeroed(2, Device::CPU); uvt.as_mut()[0] = 10; unsafe { uvt.resize_uninit_preserve(3, Device::CPU); } assert!(uvt.len() == 3); assert!(uvt.capacity() >= 3); assert_eq!(uvt.as_ref()[0], 10); assert_eq!(uvt.as_ref()[1], 0); assert_eq!(uvt.clone().as_ref()[1], 0); } #[cfg(feature = "cuda")] #[test] fn test_simple_cuda() { let mut cuvt: UVec = UVec::new_zeroed(100, Device::CUDA(0)); cuvt.as_mut(); for i in 0..*ulib::NUM_CUDA_DEVICES { cuvt.as_cuda_slice(Device::CUDA(i as u8)); } for i in 0..*ulib::NUM_CUDA_DEVICES { cuvt.as_cuda_slice_mut(Device::CUDA(i as u8)); } for i in 0..*ulib::NUM_CUDA_DEVICES { cuvt.as_cuda_slice(Device::CUDA(i as u8)); } } #[cfg(feature = "cuda")] #[test] fn test_realloc_cuda() { let mut uvt: UVec = UVec::new_zeroed(2, Device::CPU); uvt.as_mut()[0] = 10; unsafe { uvt.resize_uninit_preserve(3, Device::CUDA(0)); } assert!(uvt.len() == 3); assert!(uvt.capacity() >= 3); assert_eq!(uvt.as_ref()[0], 10); // back to cpu. assert_eq!(uvt.as_ref()[1], 0); unsafe { uvt.resize_uninit_nopreserve(100, Device::CUDA(0)); } assert!(uvt.len() == 100); assert!(uvt.capacity() >= 100); } #[test] fn test_vec_into() { let uvt = vec![7, 8, 9, 10]; let uvt: UVec = uvt.into(); assert_eq!(uvt.len(), 4); assert_eq!(uvt.capacity(), 4); assert_eq!(uvt.as_ref()[3], 10); assert_eq!(uvt.as_ref()[0], 7); }