size_t aa_io_getvector( FILE *fin, struct aa_mem_region *reg, size_t n, double *X, size_t incx ) { if ( NULL == reg ) reg = aa_mem_region_local_get(); char *line = aa_io_getline( fin, reg ); size_t i = 0; if(line) { i = aa_io_parsevector( line, n, X, incx, NULL ); aa_mem_region_pop( reg, line ); } return i; }
size_t aa_io_fread_matrix_fix( FILE *fin, size_t m, size_t n, double *A, size_t lda ) { struct aa_mem_region *reg = aa_mem_region_local_get(); void *ptr = aa_mem_region_tmpalloc(reg,1); size_t cnt = 0; for( size_t i = 0; i < m; i ++ ) { cnt += aa_io_getvector( fin, reg, n, &AA_MATREF(A, lda, i, 0), lda ); } aa_mem_region_pop( reg, ptr ); return cnt; }
AA_API int aa_rx_wf_obj_push_mtl( struct aa_rx_wf_obj *obj, const char *mtl_file ) { svec_type_push_dup(&obj->mtl_files, mtl_file ); aa_mem_region_t *reg = aa_mem_region_local_get(); char *buf = aa_mem_region_printf(reg, "%s/%s", obj->dirname, mtl_file); struct aa_rx_wf_mtl *mtl = aa_rx_wf_mtl_parse(buf); aa_mem_region_pop(reg, buf); if( mtl ) { mtlvec_type_push( &obj->mtl, mtl ); return 0; } else { return -1; } }
ssize_t aa_io_fread_matrix_heap( FILE *fin, size_t n, double **A, size_t *_elts ) { size_t tmp_elts = 0; size_t *elts = _elts ? _elts : &tmp_elts; struct aa_mem_region *reg = aa_mem_region_local_get(); if( NULL == *A || 0 == *elts ) { *elts = n; *A = (double*) malloc( *elts * sizeof(double) ); } size_t lineno = 0; size_t read_elts = 0; while( !feof(fin) ) { lineno++; char *line = aa_io_getline(fin, reg); if( NULL == line ) continue; char *line2 = aa_io_skipblank(line); if('\0' == *line2 || AA_IO_ISCOMMENT(*line2)) continue; // maybe realloc if( *elts < read_elts + n ) { *elts *= 2; *A = (double*) realloc(*A, *elts * sizeof(double) ); } // parse size_t i = aa_io_parsevector( line2, n, (*A)+read_elts, 1, NULL ); if( i != n ) return -(ssize_t)lineno; read_elts += i; aa_mem_region_pop(reg, line); } return (ssize_t)(read_elts / n); }
void aa_mem_region_local_release( void ) { aa_mem_region_release( aa_mem_region_local_get() ); }
void aa_mem_region_local_pop(void *ptr) { aa_mem_region_pop( aa_mem_region_local_get(), ptr ); }
void *aa_mem_region_local_tmpalloc(size_t size) { return aa_mem_region_tmpalloc( aa_mem_region_local_get(), size ); }