1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-23 04:43:57 +01:00

Need to check sparse read

This commit is contained in:
Anthony Scemama 2023-10-17 19:32:59 +02:00
parent 3a4726cd78
commit 9d2866c84b
2 changed files with 38 additions and 14 deletions

View File

@ -106,8 +106,8 @@ impl File {
panic!("Inconsistent values of n_int")
}
};
let offset_file: i64 = offset_file.try_into().expect("try_into failed in read_determinant_list");
let buffer_size: i64 = determinants.len().try_into().expect("try_into failed in read_determinant_list");
let offset_file: i64 = offset_file.try_into().expect("try_into failed in write_determinant_list");
let buffer_size: i64 = determinants.len().try_into().expect("try_into failed in write_determinant_list");
let mut one_d_array: Vec<i64> = Vec::with_capacity(determinants.len() * n_int);
for det in determinants.iter() {
for i in det.as_vec().iter() {
@ -121,6 +121,26 @@ impl File {
rc_return((), rc)
}
pub fn read_determinant_list(&self, offset_file: usize, buffer_size: usize) -> Result<Vec<Bitfield>, ExitCode> {
let n_int = self.get_int64_num()?;
let mut one_d_array: Vec<i64> = Vec::with_capacity(buffer_size * n_int);
let one_d_array_ptr = one_d_array.as_ptr() as *mut i64;
let rc = unsafe {
let offset_file: i64 = offset_file.try_into().expect("try_into failed in read_determinant_list (offset_file)");
let mut buffer_size_read: i64 = buffer_size.try_into().expect("try_into failed in read_determinant_list (buffer_size)");
let rc = c::trexio_read_determinant_list(self.ptr, offset_file, &mut buffer_size_read, one_d_array_ptr);
one_d_array.set_len(buffer_size_read.try_into()
.expect("try_into failed in read_determinant_list (buffer_size_read)"));
rc
};
let result: Vec::<Bitfield> = one_d_array.chunks(n_int)
.collect::<Vec<_>>()
.iter()
.map(|x| (Bitfield::from_vec(&x)))
.collect::<Vec<_>>();
rc_return(result, rc)
}
}
include!("generated.rs");

View File

@ -195,12 +195,13 @@ fn read(file_name: &str, back_end: BackEnd) -> Result<(), trexio::ExitCode> {
let nmax = 100;
let mut ao_2e_int_eri_ref = Vec::<(usize,usize,usize,usize,f64)>::with_capacity(nmax);
let n_buffers = 4;
let bufsize = nmax/n_buffers;
let n_buffers = 8;
let bufsize = nmax/n_buffers+10;
/* TODO: check from here */
for i in 0..100 {
// Quadruplet of indices + value
let data = (4*i, 4*i+1, 4*i+2, 4*i+3, 3.14 + (i as f64));
let data = (4*i, 4*i+1, 4*i+2, 4*i+3, 3.13 + (i as f64));
ao_2e_int_eri_ref.push(data);
}
@ -214,26 +215,29 @@ fn read(file_name: &str, back_end: BackEnd) -> Result<(), trexio::ExitCode> {
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);
let det_num = trex_file.read_determinant_num()?;
assert_eq!(det_num, 50);
let mut det_list_ref = Vec::with_capacity(det_num);
for i in 0..det_num {
let mut d = [0i64 ; 6 ];
for j in 0..6 {
d[j] = 6*(i as i64)+(j as i64);
}
det_list.push( Bitfield::from_vec(&d) );
det_list_ref.push( Bitfield::from_vec(&d) );
}
let n_buffers = 5;
let bufsize = 50/n_buffers;
let n_buffers = 8;
let bufsize = det_num/n_buffers + 10;
let mut offset = 0;
for i in 0..n_buffers {
trex_file.write_determinant_list(offset, &det_list[offset..offset+bufsize])?;
let mut det_list: Vec<Bitfield> = Vec::with_capacity(det_num);
for _ in 0..n_buffers {
let buffer = trex_file.read_determinant_list(offset, bufsize)?;
det_list.extend(buffer);
offset += bufsize;
}
*/
assert_eq!(det_list_ref, det_list);
trex_file.close()