From 3a4726cd783f9f5cc0a6853dfd9c4b190ddadb2b Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 17 Oct 2023 18:56:36 +0200 Subject: [PATCH] Introducing read test --- rust/trexio/build.py | 10 +++++++--- rust/trexio/tests/read_write.rs | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/rust/trexio/build.py b/rust/trexio/build.py index 74fb55d..ecd83f5 100755 --- a/rust/trexio/build.py +++ b/rust/trexio/build.py @@ -324,14 +324,18 @@ pub fn write_{group_l}_{element_l}(&self, data: &[&str]) -> Result<(), ExitCode> typ = "(" + ",".join( [ "usize" for _ in range(size) ]) + ", f64)" r += [ (""" pub fn read_{group_l}_{element_l}(&self, offset: usize, buffer_size:usize) -> Result, ExitCode> { - let idx = Vec::::with_capacity({size}*buffer_size); - let val = Vec::::with_capacity(buffer_size); + let mut idx = Vec::::with_capacity({size}*buffer_size); + let mut val = Vec::::with_capacity(buffer_size); let idx_ptr = idx.as_ptr() as *mut i32; let val_ptr = val.as_ptr() as *mut f64; let offset: i64 = offset.try_into().expect("try_into failed in read_{group}_{element} (offset)"); let mut buffer_size_read: i64 = buffer_size.try_into().expect("try_into failed in read_{group}_{element} (buffer_size)"); let rc = unsafe { c::trexio_read_safe_{group}_{element}(self.ptr, - offset, &mut buffer_size_read, idx_ptr, buffer_size_read, val_ptr, buffer_size_read) }; + offset, &mut buffer_size_read, idx_ptr, buffer_size_read, val_ptr, buffer_size_read) + }; + let buffer_size_read: usize = buffer_size_read.try_into().expect("try_into failed in read_{group}_{element} (buffer_size)"); + unsafe { idx.set_len({size}*buffer_size_read) }; + unsafe { val.set_len(buffer_size_read) }; let idx: Vec::<&[i32]> = idx.chunks({size}).collect(); let mut result = Vec::<{typ}>::with_capacity(buffer_size); diff --git a/rust/trexio/tests/read_write.rs b/rust/trexio/tests/read_write.rs index 6e4c35a..eb72361 100644 --- a/rust/trexio/tests/read_write.rs +++ b/rust/trexio/tests/read_write.rs @@ -191,12 +191,11 @@ fn read(file_name: &str, back_end: BackEnd) -> Result<(), trexio::ExitCode> { let spin = trex_file.read_mo_spin()?; assert_eq!(spin, spin_ref); -/* // Integrals let nmax = 100; let mut ao_2e_int_eri_ref = Vec::<(usize,usize,usize,usize,f64)>::with_capacity(nmax); - let n_buffers = 5; + let n_buffers = 4; let bufsize = nmax/n_buffers; for i in 0..100 { @@ -206,12 +205,16 @@ fn read(file_name: &str, back_end: BackEnd) -> Result<(), trexio::ExitCode> { } let mut offset = 0; - for i in 0..n_buffers { - trex_file.read_ao_2e_int_eri(offset, &ao_2e_int_eri[offset..offset+bufsize])?; + let mut ao_2e_int_eri = Vec::<(usize,usize,usize,usize,f64)>::with_capacity(nmax); + for _ in 0..n_buffers { + let buffer = trex_file.read_ao_2e_int_eri(offset, bufsize)?; offset += bufsize; + ao_2e_int_eri.extend(buffer); } + assert_eq!(ao_2e_int_eri_ref, ao_2e_int_eri); +/* // Determinants let det_num = 50; let mut det_list = Vec::with_capacity(det_num);