在 GSL 矩阵中查找 rows/columns 的数量?

Find number of rows/columns in a GSL matrix?

说我有一些 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;
}