以下是Mastering Dyalog APL一书的摘录,摘自内部产品章节:
HMS is a variable which contains duration in Hours, Minutes, and Seconds: HMS ← 3 44 29 Chapter J – Operators 397
We would like to convert it into seconds. We shall see 3 methods just now, and a 4th
method
will be given in another chapter.
A horrible solution (3600×HMS[1]) + (60×HMS[2]) + HMS[3]
A good APL solution +/ 3600 60 1 × HMS
An excellent solution with Inner Product 3600 60 1 +.× HMS
然后它说第二个和第三个解决方案在输入的字符数和性能方面是等效的。
据我了解,APL 程序员通常应该尽可能使用内积以及外积。这是正确的吗?
您能否举一个使用内积会带来性能提升的例子?当我使用内积(在较低级别)时到底会发生什么?下面介绍的第一个解决方案是否可怕只是因为它没有以正确的方式使用 APL 语法,还是实际上性能更差?
我知道有几个问题,但我想问的一般是内部/外部产品如何工作以及 APL 程序员何时应该使用它们。
最佳答案
我们已经完成了 +/和 +.× 的优化工作。
MBaas 是正确的,因为在这种情况下 +/恰好比 +.× 稍好一些
我们的一般建议是:使用最适合工作的语言结构,最终实现会 catch 。
“可怕”的解决方案被认为是糟糕的,因为它没有使用数组思维。
问候,
Vince,Dyalog 支持
关于matrix - 了解 APL 的内积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24141989/