c++ - Indexing into CHOLMOD dense vector array -


i have cholmod_dense data structure:

cholmod_dense* ex = cholmod_l_solve(cholmod_a, l, b, &com);

and want extract values , copy them variable. means need index double array , copy values over.

for (int k=0; k<ncols; k++) t_x[k]=((double*)ex->x)[k];    

which compiler ok segmenation fault. or think should able do:

double* e_x =(double*)ex->x; (int k=0; k<ncols; k++) t_x[k]=*e_x[k]; 

but compiler dislikes this:

error: invalid type argument of unary ‘*’ (have ‘double’) (int k=0; k<ncols; k++) t_x[k]= *e_x[k]; 

according cholmod userguide:

  1. cholmod dense: dense matrix, either real, complex or zomplex, in column-major order. differs row-major convention used in c. dense matrix x contains • x->x, double array of size x->nzmax or twice complex case. • x->z, double array of size x->nzmax if x zomplex.

so should able grab ex->x , index double array, cannot without getting segmentation fault. can me out?

the cholmod library written in c , code linking cholmod library (the code snippet shown above) c++.

ok, looks likes made couple mistakes.

first of all, running segmentation fault because using cholmod_l_zeros(); assumes long integers. instead, should using cholmod_zeros(); since using doubles.

after fixing ran error cholmod error: invalid xtype right after cholmod_solve(cholmod_a, l, b, &com); statement. because cholmod_factor* l defined out of scope. after fixing both of these issues, code copies values cholmod_dense ex->x double array on t_x double vector:

cholmod_dense* ex = cholmod_solve(cholmod_a, l, b, &com); double* e_x = (double*)ex->x; (int k=0; k<ncols; k++) t_x[k] = e_x[k]; 

i unaware [] operator automatically dereferences pointers. know!


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -