我需要在3个维度中使用查找表。该表本身具有73x73x73(389017)双值。
module Hammer.Texture.Table3D where
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import Data.Vector.Unboxed (Vector)
table3D :: V.Vector (V.Vector (Vector Double))
table3D = V.fromList [table0, table1, ... table72]
table0 = V.fromList $ map U.fromList [
[1.973921e+01, 0.000000e+00, ... 0.000000e+00],
.....
[1.973921e+01, 0.000000e+00, ... 0.000000e+00]]
.....
table72 = V.fromList $ map U.fromList [
[1.973921e+01, 0.000000e+00, ... 0.000000e+00],
.....
[1.973921e+01, 0.000000e+00, ... 0.000000e+00]]
问题是GHC无法处理Vector Double或[Double]的这个大小,GHC编译需要花费很多时间(约2分钟),最后,内存会爆炸。似乎GHC上存在内存泄漏或某些bug,因为它适用于非常大的String([Char])。
有哪些解决方案可用于使用GHC创建“大型”查找表(双重类型)?
答案 0 :(得分:8)
我可以想到两种可能性:
Data.Map
甚至只是一个简单的函数。如有必要,您可以使用此稀疏数据结构生成向量(再次在运行时)。