以下是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 程序员通常应该尽可能使用Inner Product以及Outer Product。那是对的吗?
你能举一个例子,当使用内积会导致性能提升?当我使用内部产品(在较低级别)时,究竟会发生什么?下面介绍的第一个解决方案是否很糟糕,仅仅是因为它没有以正确的方式使用 APL 语法,还是实际上性能更差?
我知道有几个问题,但我想问的一般是内部/外部产品是如何工作的,以及 APL 程序员应该在什么时候使用它们。