假设我有一些 gsl_matrix * A
。我想编写一个函数来检索例如该矩阵中的行数,除了对象 A 本身之外无法访问其他任何内容。
示例:
int num_rows(gsl_matrix * A){
//some operation(s) on A that find the number of rows in the matrix
//store that number in an int r
return r;
}
我可以写什么来为我做到这一点?
最佳答案
来自https://www.gnu.org/software/gsl/manual/html_node/Matrices.html
gsl_matrix
定义为:
typedef struct
{
size_t size1;
size_t size2;
size_t tda;
double * data;
gsl_block * block;
int owner;
} gsl_matrix;
还有
The number of rows is size1. The range of valid row indices runs from 0 to size1-1. Similarly size2 is the number of columns. The range of valid column indices runs from 0 to size2-1. The physical row dimension tda, or trailing dimension, specifies the size of a row of the matrix as laid out in memory.
因此,如果您想要 A
中的行数,那么您可以使用:
int num_rows(gsl_matrix * A){
int r = A->size1;
return r;
}
关于c++ - 查找 GSL 矩阵中的行数/列数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30601889/