mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-08-24 22:21:43 +02:00
write_determinant_list
This commit is contained in:
parent
601dfbba89
commit
3cf8a8c431
@ -35,6 +35,10 @@ impl Bitfield {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_vec(v: &[i64]) -> Bitfield {
|
||||
Bitfield { data: v.to_vec() }
|
||||
}
|
||||
|
||||
pub fn from_alpha_beta(alpha: &Bitfield, beta: &Bitfield) -> Bitfield {
|
||||
if alpha.data.len() != beta.data.len() {
|
||||
panic!("alpha and beta parts have different lengths");
|
||||
@ -98,6 +102,11 @@ impl Bitfield {
|
||||
result
|
||||
}
|
||||
|
||||
/// Converts the bitfield into a vector
|
||||
pub fn as_vec(&self) -> &[i64] {
|
||||
&self.data
|
||||
}
|
||||
|
||||
/// Converts the determinant into a list of orbital indices (0-based)
|
||||
pub fn to_orbital_list_up_dn(&self) -> (Vec<usize>, Vec<usize>) {
|
||||
|
||||
|
@ -98,18 +98,31 @@ impl File {
|
||||
rc_return(num, rc)
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn read_determinant_list(&self, offset_file: usize, dset: Vec<Bitfield>) -> Result<usize, ExitCode> {
|
||||
pub fn write_determinant_list(&self, offset_file: usize, determinants: &[Bitfield]) -> Result<(), ExitCode> {
|
||||
let n_int = self.get_int64_num()?;
|
||||
match determinants.len() {
|
||||
0 => return Ok(()),
|
||||
_ => if determinants[0].as_vec().len() != 2*n_int {
|
||||
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 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() {
|
||||
one_d_array.push(i.clone());
|
||||
}
|
||||
}
|
||||
let dset: *const i64 = one_d_array.as_ptr() as *const i64;
|
||||
let rc = unsafe {
|
||||
let offset_file: i64 = offset_file;
|
||||
let buffer_size: *mut i64 = dset.len().try_into().expect("try_into failed in read_determinant_list");
|
||||
let dset: *mut i64 = dset.to_c().as_mut_ptr();
|
||||
c::trexio_read_determinant_list(self.ptr, offset_file, buffer_size, dset)
|
||||
c::trexio_write_determinant_list(self.ptr, offset_file, buffer_size, dset)
|
||||
};
|
||||
rc_return((), rc)
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
include!("generated.rs");
|
||||
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
use trexio::back_end::BackEnd;
|
||||
use trexio::bitfield::Bitfield;
|
||||
|
||||
pub fn test_write(file_name: &str, back_end: BackEnd) -> Result<(), trexio::ExitCode> {
|
||||
|
||||
let () = trexio::info()?;
|
||||
|
||||
// Prepare data to be written
|
||||
|
||||
let n_buffers = 5;
|
||||
let buf_size_sparse = 100/n_buffers;
|
||||
let buf_size_det = 50/n_buffers;
|
||||
let mut value_sparse_ao_2e_int_eri = vec![0.0f64 ; 100];
|
||||
let mut index_sparse_ao_2e_int_eri = vec![0i32 ; 400];
|
||||
for i in 0..100 {
|
||||
@ -98,6 +99,26 @@ pub fn test_write(file_name: &str, back_end: BackEnd) -> Result<(), trexio::Exit
|
||||
}
|
||||
trex_file.write_mo_spin(spin)?;
|
||||
|
||||
// Determinants
|
||||
//
|
||||
let det_num = 50;
|
||||
let mut det_list = 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) );
|
||||
}
|
||||
|
||||
let n_buffers = 5;
|
||||
let buf_size_det = 50/n_buffers;
|
||||
let mut offset = 0;
|
||||
for i in 0..n_buffers {
|
||||
trex_file.write_determinant_list(offset, &det_list[offset..offset+buf_size_det])?;
|
||||
offset += buf_size_det;
|
||||
}
|
||||
|
||||
|
||||
trex_file.close()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user