mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-11-03 20:54:07 +01:00
add SWIG typemaps for safe API calls in single and double precision
This commit is contained in:
parent
ed7e3902e2
commit
1dcd32ef7d
@ -73,13 +73,21 @@ import_array();
|
||||
|
||||
/* Typemaps below change the type of numpy array dimensions from int to int64_t */
|
||||
%numpy_typemaps(double, NPY_DOUBLE, int64_t)
|
||||
%numpy_typemaps(int32_t, NPY_INT, int64_t)
|
||||
%numpy_typemaps(float, NPY_FLOAT, int64_t)
|
||||
%numpy_typemaps(int32_t, NPY_INT32, int64_t)
|
||||
%numpy_typemaps(int64_t, NPY_INT64, int64_t)
|
||||
/* Enable write|read_safe functions to convert numpy arrays from/to double arrays */
|
||||
%apply (double* ARGOUT_ARRAY1, int64_t DIM1) {(double * const dset_out, const int64_t dim_out)};
|
||||
%apply (double* IN_ARRAY1, int64_t DIM1) {(const double * dset_in, const int64_t dim_in)};
|
||||
/* Enable write|read_safe functions to convert numpy arrays from/to float arrays */
|
||||
%apply (float* ARGOUT_ARRAY1, int64_t DIM1) {(float * const dset_out, const int64_t dim_out)};
|
||||
%apply (float* IN_ARRAY1, int64_t DIM1) {(const float * dset_in, const int64_t dim_in)};
|
||||
/* Enable write|read_safe functions to convert numpy arrays from/to int32 arrays */
|
||||
%apply (int32_t* ARGOUT_ARRAY1, int64_t DIM1) {(int32_t * const dset_out, const int64_t dim_out)};
|
||||
%apply (int32_t* IN_ARRAY1, int64_t DIM1) {(const int32_t * dset_in, const int64_t dim_in)};
|
||||
/* 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* IN_ARRAY1, int64_t DIM1) {(const int64_t * dset_in, const int64_t dim_in)};
|
||||
|
||||
/* 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.
|
||||
|
@ -787,14 +787,15 @@ def open(file_name: str, mode: str, back_end: int):
|
||||
|
||||
Examples:
|
||||
>>> from trexio import open as tr_open
|
||||
>>> trex_file = tr_open("example.h5", "w", TREXIO_HDF5)
|
||||
>>> trex_file = tr_open("example.h5", "w", TREXIO_HDF5)
|
||||
"""
|
||||
|
||||
|
||||
try:
|
||||
trexio_file = trexio_open(file_name, mode, back_end)
|
||||
except:
|
||||
raise
|
||||
assert trexio_file is not None
|
||||
except AssertionError:
|
||||
raise Exception(f"Could not open TREXIO file {file_name} using trexio_open function. Please make sure that there are no typos in the file name.")
|
||||
|
||||
return trexio_file
|
||||
#+end_src
|
||||
@ -1375,6 +1376,10 @@ trexio_exit_code trexio_read_$group_dset$_64(trexio_t* const file, $group_dset_d
|
||||
trexio_exit_code trexio_write_$group_dset$_64(trexio_t* const file, const $group_dset_dtype_double$* $group_dset$);
|
||||
trexio_exit_code trexio_read_safe_$group_dset$(trexio_t* const file, $group_dset_dtype_default$* const dset_out, const int64_t dim_out);
|
||||
trexio_exit_code trexio_write_safe_$group_dset$(trexio_t* const file, const $group_dset_dtype_default$* dset_in, const int64_t dim_in);
|
||||
trexio_exit_code trexio_read_safe_$group_dset$_32(trexio_t* const file, $group_dset_dtype_single$* const dset_out, const int64_t dim_out);
|
||||
trexio_exit_code trexio_write_safe_$group_dset$_32(trexio_t* const file, const $group_dset_dtype_single$* dset_in, const int64_t dim_in);
|
||||
trexio_exit_code trexio_read_safe_$group_dset$_64(trexio_t* const file, $group_dset_dtype_double$* const dset_out, const int64_t dim_out);
|
||||
trexio_exit_code trexio_write_safe_$group_dset$_64(trexio_t* const file, const $group_dset_dtype_double$* dset_in, const int64_t dim_in);
|
||||
#+end_src
|
||||
|
||||
**** Source code for double precision functions
|
||||
|
Loading…
Reference in New Issue
Block a user