2014-05-17 77 views
12

我打算在矢量库和注意到{-# INLINE_FUSED transform #-},我不知道它做什么?我看到它在vector.h中定义,但没有其他地方。INLINE_FUSED编译哈斯克尔

回答

11

的定义是指INLINE_FUSED相同INLINE [1]; INLINE_INNERINLINE [0]相同。 [1][0]是用于排序内联阶段的标准ghc。请参阅标题7.13.5.5下的讨论。相位控制 in http://www.haskell.org/ghc/docs/7.0.4/html/users_guide/pragmas.html

vector需要控制ghc内嵌各种定义的阶段。第一它想要的功能streamunstream暴露所有用途,使得(上述全部)stream.unstream可以通过id在其他情况下取代,并且类似地,根据分布在整个所述(改写)RULE编译指示。

典型向量到向量函数写为unstream . f . stream,其中f是一个流至流函数。 unstreamStream在内存中构建实际向量; 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 

被改写。

+0

谢谢亚瑟,你已经解释清楚了。 – jap