- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下代码意外地(至少对我而言)产生了一个中间向量:
import qualified Data.Vector as Vector
main :: IO ()
main =
print (test n)
n :: Int
n = 1000000
test :: Int -> Int
test n = Vector.length (Vector.replicate n (0 :: Int))
newArray# 1000000
调用):
Main.main4
:: forall s_a38t.
GHC.Prim.State# s_a38t
-> (# GHC.Prim.State# s_a38t, Vector.Vector Int #)
[GblId,
Arity=1,
Str=DmdType,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [0] 399 30}]
Main.main4 =
\ (@ s_a38t) (s1_a38u [OS=OneShot] :: GHC.Prim.State# s_a38t) ->
case GHC.Prim.newArray#
@ Int
@ (Control.Monad.Primitive.PrimState (GHC.ST.ST s_a38t))
1000000
(Data.Vector.Mutable.uninitialised @ Int)
(s1_a38u
`cast` ((GHC.Prim.State#
(Sym (Control.Monad.Primitive.TFCo:R:PrimStateST[0] <s_a38t>_N)))_R
:: GHC.Prim.State# s_a38t
~R# GHC.Prim.State#
(Control.Monad.Primitive.PrimState (GHC.ST.ST s_a38t))))
of _ [Occ=Dead] { (# ipv_a5RG, ipv1_a5RH #) ->
letrec {
$wa_s609 [InlPrag=[0], Occ=LoopBreaker]
:: GHC.Types.SPEC
-> GHC.Prim.Int#
-> Bool
-> GHC.Prim.State# s_a38t
-> (# GHC.Prim.State# s_a38t, Int #)
[LclId, Arity=4, Str=DmdType <S,1*U><L,U><S,1*U><L,U>]
$wa_s609 =
...
length
与
sum
, 融合正确发生:
test n = Vector.sum (Vector.replicate n (0 :: Int))
Rec {
Main.main_$s$wfoldlM'_loop [Occ=LoopBreaker]
:: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int#
[GblId, Arity=2, Caf=NoCafRefs, Str=DmdType <L,U><L,U>]
Main.main_$s$wfoldlM'_loop =
\ (sc_s6bx :: GHC.Prim.Int#) (sc1_s6by :: GHC.Prim.Int#) ->
case GHC.Prim.tagToEnum# @ Bool (GHC.Prim.<=# sc1_s6by 0)
of _ [Occ=Dead] {
False ->
Main.main_$s$wfoldlM'_loop sc_s6bx (GHC.Prim.-# sc1_s6by 1);
True -> sc_s6bx
}
end Rec }
Main.main2 :: String
[GblId,
Str=DmdType,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=False, ConLike=False,
WorkFree=False, Expandable=False, Guidance=IF_ARGS [] 100 30}]
Main.main2 =
case Main.main_$s$wfoldlM'_loop 0 1000000 of ww_s67W { __DEFAULT ->
case GHC.Show.$wshowSignedInt 0 ww_s67W (GHC.Types.[] @ Char)
of _ [Occ=Dead] { (# ww5_a5Vq, ww6_a5Vr #) ->
GHC.Types.: @ Char ww5_a5Vq ww6_a5Vr
}
}
import qualified Data.Vector.Fusion.Stream.Monadic as Stream
import Data.Functor.Identity
test n = runIdentity $ Stream.length (Stream.replicate n (0 :: Int))
Rec {
Main.main_$s$wfoldlM'_loop [Occ=LoopBreaker]
:: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int#
[GblId, Arity=2, Caf=NoCafRefs, Str=DmdType <L,U><L,U>]
Main.main_$s$wfoldlM'_loop =
\ (sc_s5lE :: GHC.Prim.Int#) (sc1_s5lF :: GHC.Prim.Int#) ->
case GHC.Prim.tagToEnum# @ Bool (GHC.Prim.<=# sc1_s5lF 0)
of _ [Occ=Dead] {
False ->
Main.main_$s$wfoldlM'_loop
(GHC.Prim.+# sc_s5lE 1) (GHC.Prim.-# sc1_s5lF 1);
True -> sc_s5lE
}
end Rec }
Main.main2 :: String
[GblId,
Str=DmdType,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=False, ConLike=False,
WorkFree=False, Expandable=False, Guidance=IF_ARGS [] 100 30}]
Main.main2 =
case Main.main_$s$wfoldlM'_loop 0 1000000 of ww_s5ke { __DEFAULT ->
case GHC.Show.$wshowSignedInt 0 ww_s5ke (GHC.Types.[] @ Char)
of _ [Occ=Dead] { (# ww5_a5gi, ww6_a5gj #) ->
GHC.Types.: @ Char ww5_a5gi ww6_a5gj
}
}
Vector.length
打破融合?
ghc-7.10.3
和
vector-0.11.0.0
.
最佳答案
我用了sum
和 length
来自 Data.Vector.Generic
而不是 Data.Vector
因为后者只是定义为前者。
这是长度的代码(来自 Data.Vector.Generic
)...
-- | /O(1)/ Yield the length of the vector.
length :: Vector v a => v a -> Int
{-# INLINE length #-}
length = Bundle.length . stream
-- | /O(n)/ Compute the sum of the elements
sum :: (Vector v a, Num a) => v a -> a
{-# INLINE sum #-}
sum = Bundle.foldl' (+) 0 . stream
ghc -ddump-inlinings -ddump-rule-firings -O2
总和我看到
Rule fired: SPEC Data.Vector.$fVectorVectora [GHC.Types.Int]
Inlining done: System.IO.print
Inlining done: System.IO.print1
Inlining done: Data.Vector.Generic.sum
Rule fired: Class op +
Rule fired: Class op fromInteger
Inlining done: GHC.Num.$fNumInt_$cfromInteger
Rule fired: integerToInt
Inlining done: Data.Vector.Fusion.Util.unId
Inlining done: Data.Vector.Fusion.Util.unId1
Inlining done: Data.Vector.replicate
Inlining done: Data.Vector.Generic.replicate
length
运行它我懂了:
Rule fired: SPEC Data.Vector.$fVectorVectora [GHC.Types.Int]
Inlining done: System.IO.print
Inlining done: System.IO.print1
Inlining done: Data.Vector.replicate
Inlining done: Data.Vector.Generic.replicate
Rule fired: SPEC Data.Vector.$fVectorVectora [GHC.Types.Int]
sum
被内联和
length
没有,我不明白为什么。甚至将展开的阈值提高到 absurd 的数量也不会改变这一点。
Vector.length
与
Bundle.length . Vector.stream
,
stream/unstream
规则会触发,如
sum
在这种情况下,生成了一个非常整洁的核心,没有分配数组。
关于haskell - 为什么 `Vector.length (Vector.replicate n 0)"没有融合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36095925/
LMAX Disruptor 通常使用以下方法实现: 如本例所示,Replicator 负责将输入事件\命令复制到从节点。跨一组节点进行复制需要我们应用共识算法,以防我们希望系统在出现网络故障、主故障
我对这两个概念感到困惑:In-graph replication和 Between-graph replication阅读 Replicated training 时在 tensorflow 的官方
我对这两个概念感到困惑:In-graph replication和 Between-graph replication阅读 Replicated training 时在 tensorflow 的官方
我在事件监视器中收到以下错误, The row was not found at the Subscriber when applying the replicated command. (Sourc
我正在尝试设置 mysql 复制。我看到了在不同地方使用的两个提到的选项。我觉得replicate-rewrite-db是在master和slave中的数据库名称不同的情况下使用的。这是这两个选项之间
我正在关注 Realm Postgres Connector 引用,用于将我们的 Realm 数据库与我们的 Heroku PostgreSQL 数据库同步:https://docs.realm.io
我很难找到数据同步和复制之间的差异。 据我所知,复制使 2 个数据库之间的所有数据都相同。同步不一定使两个数据库之间的所有数据都相同。复制是一次传输,同步可以是小更新以保持数据一致吗?我不太确定,请在
我们刚刚成功地将一个主服务器备份到了一个热备服务器上。但是,当我们尝试查询热备时,会出现以下错误: ERROR: cannot assign TransactionIds during recover
有两个进程访问共享变量x,y和z。每个进程访问用于保存这些变量的存储的不同副本。 x,y和z的初始值是0。 流程1: x = 1; if (y == 0) z++; 和过程2: y = 1; if
我需要一个图形数据库,该数据库需要备份并可能在较低的抽象级别上访问。为了负载平衡,它也必须分布,(单主复制就可以了)。 我知道可以使用自引用键值存储来实现图形数据库。 Git 对象数据库就是这种模式的
我正在构建一个解决方案,该解决方案将部署在全局多个地区的多个数据中心,每个数据中心都有一个在每个地区主动更新的数据副本。我将在每个数据中心有多个数据库和文件系统的组合,它们的状态必须保持一致(在一个数
我有 2 个数据库 X“生产”和 Y“测试” 数据库 X 的结构应与 Y 相同。但是,他们并不是因为我的疯狂而对制作进行了很多改动。现在,我需要以某种方式导出 X 并将其导入 Y 而不会破坏任何复制。
使用REPLICATE(以指定的次数重复字符表达式)函数 REPLICATE函数用于以指定的次数重复字符表达式。 语法: REPLICATE (character_expression,int
我的理解在这里可能有误。据我了解,Couchbase 使用智能客户端来自动选择要在集群中写入或读取的节点。我不明白的是,当这些数据被写入/读取时,它是否也立即写入所有其他节点?如果是这样,在节点发生故
我目前正在处理 Crystal Reports 中的一个项目,该项目拒绝使用 Oracle 10g 中允许的未记录函数 WM_CONCAT。 这是WM_CONCAT头信息 WM_CONCAT(p1 I
我有一个在防火墙后面运行的 SOLR 实例。我即将建立另一个不会被防火墙保护的实例。但是,SOLR 似乎只支持拉复制而不支持推送复制。 为了保持相同的安全级别,我有哪些选择?我宁愿不要在防火墙中打开太
有人可以解释为 RavenDB 设置复制的基本步骤吗?我正在使用 build 888。根据我在网上找到的内容,我可以猜测可能需要做什么,但我宁愿确定。 我相信这是复制的官方文档: http://rav
我想在SQL Server和MySQL之间设置复制,其中SQL Server是主数据库服务器,而MySQL是从属服务器(在Linux上)。 有没有办法设置这种情况?帮我 。 最佳答案 我的答案可能来不
我想了解以下 Lotus-Domino 服务器到服务器复制场景中会发生什么: 服务器 A 有 A 数据库的副本。 服务器 B 具有相同数据库的副本。 两台服务器都对数据库具有管理员访问权限,包括删除文
我有一个 2 节点的 cassandra 集群,复制因子为 2,AutoBootStrap=true。启动期间一切正常,两个节点都能看到对方。让我们称这些节点为 A 和 B。 通过节点 A 向 cas
我是一名优秀的程序员,十分优秀!