matlab中的快速异或数组
有没有比这更胖的方法来对矩阵的每一列进行异或?
mod(sum(matrix),2)
它从逻辑转换为双精度,并使用昂贵的模数。
更新:
根据 此来源,对 uint 求和比对 double 求和慢,因为它涉及最大剪裁和其他原因。 另请注意,逻辑求和(使用 'native'
)在 1 处停止。
Is there a fatser way to xor every column of a matrix than this?
mod(sum(matrix),2)
It converts from logical to double and uses the expensive modulo.
Update:
According to this source, summing uint's is slower than summing doubles because it involves max clipping and other reasons.
Also, note that summing logicals (with 'native'
) stops at 1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我试图避免转换为 double ,但它并没有更好(通常更糟)。
sum 的
native
选项允许您在结果中保留参数的类型。I tried to avoid the cast to
double
but it's not better (often worse).The
native
option of sum allow you to keep the type of the argument in the result.除了 @ClementJ 所说的之外,我还尝试
希望加速器能有所帮助,但它并没有(太多),而且
实际上不起作用,因为 XOR 只允许 2 个输入。
MATLAB 的双精度向量算术几乎是最快的,因此您可能无法做得更好。如果这确实能提高您的性能,那么我建议编写一个 C-MEX 函数:应该很容易。
In addition to what @ClementJ says, I tried
hoping the accelerator would help, but it doesn't (much), and
which doesn't actually work because XOR only allows 2 inputs.
MATLAB's double precision vector arithmetic is about as fast as it gets, so you probably can't do better. If this is really driving your performance, then I suggest writing a C-MEX function: should be easy.