c++ - 查找 GSL 矩阵中的行数/列数?

标签 c++ matrix linear-algebra gsl

假设我有一些 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/

相关文章:

java - 如何使用 Java 发送 HTTP GET 并使用用 C++ 编写的 CGI 应用程序打印 QUERY_STRING 环境变量?

opengl - 如何从模型 View 矩阵中消除旋转,使对象始终面对相机?

c++ - 在 Linux 上 boost windows_shared_memory

android - 位图矩阵postRotate改变X和Y轴方向

R - 如何将自定义对象存储在矩阵(或类似结构)中?

math - 如何检查单纯形是否包含原点?

c++ - 在 Armadillo 中对立方体切片进行操作

matlab - 简化行阶梯形式 (rref)

c++ - 如何强制编译器发出去虚拟化代码

C++在末尾计算跳跃范围