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

[WIP] read/write of sparse data in Python

This commit is contained in:
q-posev 2021-12-23 18:27:24 +01:00
parent 31ccd27a0a
commit 72897e4b5d
2 changed files with 45 additions and 19 deletions

View File

@ -83,6 +83,17 @@ assert rc==0
rc = trexio_write_safe_basis_nucleus_index(test_file, indices_np) rc = trexio_write_safe_basis_nucleus_index(test_file, indices_np)
assert rc==0 assert rc==0
# test writing of sparse data
rc = trexio_write_mo_num(test_file, 600)
assert rc==0
indices = [i for i in range(400)]
values = [(3.14 + float(i)) for i in range(100)]
rc = trexio_write_mo_2e_int_eri_safe(test_file, 0, 100, indices, values)
assert rc==0
point_group = 'B3U' point_group = 'B3U'
rc = trexio_write_nucleus_point_group(test_file, point_group, 10) rc = trexio_write_nucleus_point_group(test_file, point_group, 10)
@ -172,16 +183,20 @@ print(f'Read point group: {rpoint_group}')
assert rc==0 assert rc==0
assert rpoint_group==point_group assert rpoint_group==point_group
num = 100
ret_tuple = trexio_read_mo_2e_int_eri_safe(test_file2, 0, num)
print(ret_tuple)
assert ret_tuple[0]==0
rc = trexio_close(test_file2) rc = trexio_close(test_file2)
assert rc==0 assert rc==0
try: #try:
if TEST_TREXIO_BACKEND == 0: # if TEST_TREXIO_BACKEND == 0:
os.remove(output_filename) # os.remove(output_filename)
elif TEST_TREXIO_BACKEND == 1: # elif TEST_TREXIO_BACKEND == 1:
shutil.rmtree(output_filename) # shutil.rmtree(output_filename)
except: #except:
print (f'No output file {output_filename} has been produced') # print (f'No output file {output_filename} has been produced')
#==========================================================# #==========================================================#

View File

@ -33,11 +33,17 @@
Useful for TREXIO read_num functions where the Useful for TREXIO read_num functions where the
num variable is modified by address num variable is modified by address
*/ */
/* Return num variables as part of the output tuple */
%apply int *OUTPUT { int32_t* const num}; %apply int *OUTPUT { int32_t* const num};
%apply int *OUTPUT { int64_t* const num}; %apply int *OUTPUT { int64_t* const num};
%apply float *OUTPUT { float* const num}; %apply float *OUTPUT { float* const num};
%apply float *OUTPUT { double* const num}; %apply float *OUTPUT { double* const num};
/* Return TREXIO exit code from trexio_open as part of the output tuple */
%apply int *OUTPUT { trexio_exit_code* const rc_open}; %apply int *OUTPUT { trexio_exit_code* const rc_open};
/* Return number of sparse data points stored in the file as part of the output tuple */
%apply int *OUTPUT { int64_t* const size_max};
/* Return number of sparse data points read from the file as part of the output tuple */
/* %apply int *INOUT { int64_t* const buffer_size_read}; */
/* Does not work for arrays (SIGSEGV) */ /* Does not work for arrays (SIGSEGV) */
@ -81,6 +87,12 @@ import_array();
/* Enable write|read_safe functions to convert numpy arrays from/to int64 arrays */ /* Enable write|read_safe functions to convert numpy arrays from/to int64 arrays */
%apply (int64_t* ARGOUT_ARRAY1, int64_t DIM1) {(int64_t* const dset_out, const int64_t dim_out)}; %apply (int64_t* ARGOUT_ARRAY1, int64_t DIM1) {(int64_t* const dset_out, const int64_t dim_out)};
%apply (int64_t* IN_ARRAY1, int64_t DIM1) {(const int64_t* dset_in, const int64_t dim_in)}; %apply (int64_t* IN_ARRAY1, int64_t DIM1) {(const int64_t* dset_in, const int64_t dim_in)};
/* Enable write|read_safe functions to convert numpy arrays from/to sparse arrays */
%apply (double* IN_ARRAY1, int64_t DIM1) {(const double* value_sparse, const int64_t size_value_write)};
%apply (int32_t* IN_ARRAY1, int64_t DIM1) {(const int32_t* index_sparse, const int64_t size_index_write)};
%apply (int32_t* ARGOUT_ARRAY1, int DIM1) {(int32_t* const index_sparse_read, const int64_t size_index_read)};
%apply (double* ARGOUT_ARRAY1, int DIM1) {(double* const value_sparse_read, const int64_t size_value_read)};
/* This tells SWIG to treat char ** dset_in pattern as a special case /* This tells SWIG to treat char ** dset_in pattern as a special case
Enables access to trexio_[...]_write_dset_str set of functions directly, i.e. Enables access to trexio_[...]_write_dset_str set of functions directly, i.e.
@ -116,4 +128,3 @@ import_array();
/* Parse the header files to generate wrappers */ /* Parse the header files to generate wrappers */
%include "trexio_s.h" %include "trexio_s.h"
%include "trexio.h" %include "trexio.h"