Ruby 核心 Matrix 与 NArray 的 NMatrix
我发现 Ruby 中似乎有三个矩阵模块
目前看来 NArray
的 NMatrix
比 Matrix< /code>,有一些更有用的方法,但需要更多设置。
有没有对这两种方法都有经验的人可以粗略地概述一下为什么我应该使用其中一种而不是另一种?
There seems to be three matrix modules in Ruby that I've found
- Matrix: Part of core Ruby it seems
- NArray: NMatrix is part of the NArray library (github)
- NMatrix: Part of SciRuby
At the moment it seems NArray
's NMatrix
is faster than Matrix
, has some more helpful methods, but require a bit more setup.
Is there anyone with experience of both who can give a rough overview of why I should use one over the other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在只是偶然发现这个问题......自您提出问题以来已经过去了 7 个月,所以我确信您现在已经找到了答案。
不过,请在此处查找信息。
基本上,核心 Matrix 类的作者没有添加在实例化数组后对数组执行运行时修改的方法。 NArray 类允许这样做。
至于计算时间,我将把它留给其他人,因为我不知道。
Just stumbling on this question now... It's been 7 months since you've asked, so I'm sure you've found your answer by now.
However, please find information here.
Basically, the author of the core Matrix class did not add methods to perform run-time modifications to the array once it is instantiated. The NArray class allows for this.
As far as computation time, I'll leave that to somebody else, for I don't know.
虽然有点晚了,但你见过新的 NMatrix gem 吗?它的灵感来自 NArray。它也是用 C/C++ 编写的,而 Ruby Matrix 仅用 Ruby 编写——所以 NMatrix 肯定更快。
对于仅 C 语言的 NArray 也是如此。
使用 NMatrix 代替
NArray::NMatrix
的优点是您可以在不同的存储类型(稀疏、密集等)之间进行选择。A bit late to the ballgame, but have you seen the new NMatrix gem? It's inspired by NArray. It's also written in C/C++, whereas Ruby Matrix is written only in Ruby --- so NMatrix is definitely faster.
That's also true for NArray, which is C-only.
The advantage to using NMatrix instead of
NArray::NMatrix
is that you can choose between different storage types (sparse, dense, etc.).