OGeek|极客世界-中国程序员成长平台

标题: ios - NSLog matrix_float4x4 或 simd::float4x4 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:02
标题: ios - NSLog matrix_float4x4 或 simd::float4x4

Apple 没有提供类似于“OpenCV”或“Eigen”的加速矩阵调试工具吗?

Eigen 和 OpenCV 如何打印矩阵的示例代码

Eigen::Matrix4f matrix;
std::cout << matrix << std::endl;

4x4 矩阵的输出

-0.483662   0.86859   0.10781   51.8456
 0.865028  0.455597  0.210137   29.6781
 0.133405  0.194894 -0.971709    192.69
        0         0         0         1

我想要的粗略近似,但还不够笼统。

这是我的快速和肮脏的版本。我最终可能会在处理 C 或 C++ 版本的地方使它更彻底,但我真的希望 Apple 提供它,我只是没有找到文档。

void logSIMD(const simd::float4x4 &matrix) 
{
   std::stringstream output;
   int columnCount = sizeof(matrix.columns) / sizeof(matrix.columns[0]);
   for (int column = 0; column < columnCount; column++) {
      int rowCount = sizeof(matrix.columns[column]) / sizeof(matrix.columns[column][0]);
      for (int row = 0; row < rowCount; row++) {
         output << std::setfill(' ') << std::setw(9) << matrix.columns[column][row];
         output << ' ';
      }
      output << std::endl;
   }
   output << std::endl;
   NSLog(@"%s", output.str().c_str());
}

有没有人为 Accelerate 中各种大小的矩阵和向量的 C/C++ 打印提供通用解决方案,或者 Apple 提供了我还没有找到的功能?



Best Answer-推荐答案


没有提供这样的功能。这有一些很好的理由,最重要的是,人们对于如何格式化向量和矩阵非常固执己见,所以没有提供的格式将是一小部分用户真正想要的,而且它足够直截了当编写您自己的打印例程,完全符合您的要求。一个可以处理任意用户定义格式的完全通用的格式化程序函数会更合理,但与 接口(interface)的其余部分相比,它会非常重,所以它不会看起来也不太合适。

也就是说,如果您认为这些作为 API 有用,并且您可以提出一个令人信服的理由来说明为什么您的首选格式是正确的标准化格式,我鼓励您向 Apple 报告一个错误,请求该功能.

关于ios - NSLog matrix_float4x4 或 simd::float4x4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29533104/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4