我正在浏览矢量库并注意到{-# INLINE_FUSED transform #-}
,我想知道它的作用是什么?我看到它在vector.h
中定义,但在其他任何地方都没有。
答案 0 :(得分:12)
定义表示INLINE_FUSED
与INLINE [1]
相同; INLINE_INNER
与INLINE [0]
相同。 [1]
和[0]
是用于排序内联阶段的标准ghc。请参阅标题 7.13.5.5下的讨论。 http://www.haskell.org/ghc/docs/7.0.4/html/users_guide/pragmas.html
vector
需要控制ghc
内联各种定义的阶段。首先,它希望公开函数stream
和unstream
的所有用法,以便(最重要的)stream.unstream
可以被id
替换,并且在其他情况下也是如此,根据(重写)RULE pragma分布在整个。
向量函数的典型向量写为unstream . f . stream
,其中f是Stream to Stream函数。 unstream
从Stream
在内存中构建实际向量; stream
将实数向量读入Stream
。游戏的目的是减少构建的实际向量的数量。所以三个向量到向量函数的组成
f_vector . g_vector . h_vector
真的是
unstream . f_stream . stream . unstream . g_stream . stream . unstream . h_stream . stream
他改写为
unstream . f_stream . g_stream . h_stream . stream
等等。所以我们写了一个新的向量而不是三个。
transform
的规则比这更有趣,但属于同一个微妙的排序系统:
transform f g (unstream s) = unstream (Bundle.inplace f g s)
transform f1 g1 (transform f2 g2 p) = transform (f1 . f2) (g1 . g2) p
https://github.com/haskell/vector/blob/master/Data/Vector/Generic/New.hs#L76 中的
所以你可以看到表格内联的内容:
unstream . h_stream . stream . transform f1 g1 . transform f2 g2
. unstream . j_stream . stream $ input_vector
将被重写。