热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Haskell数组索引超出范围-HaskellArrayIndexoutofrange

Mycodeispastedhere.Belowismyghcidebugsession.Istilldontunderstandwhyithasarange

My code is pasted here. Below is my ghci debug session. I still don't understand why it has a range of (0, -193459561) when the 'len' binding is 90570.

我的代码粘贴在这里。下面是我的ghci调试会话。当'len'绑定为90570时,我仍然不明白为什么它的范围为(0,-193459561)。

*Main> :break 125
Breakpoint 4 activated at SVMCF.hs:125:13-86
*Main> :trace main
Stopped at SVMCF.hs:125:13-86
_result :: UA.Array Int [User] = _
len :: Int = 90570
rts :: [RTuple] = (1,1,5.0) : (1,2,3.0) : (1,3,4.0) : (1,4,3.0) :
                  (1,5,3.0) : ....
[SVMCF.hs:125:13-86] *Main> :lis
124      points :: A.Array Int [Int]
125      points = assert (len > 0) $ A.listArray (1::Int, len) $ map (\(u,i,r) -> [u,i]) rts
126      values :: UA.UArray Int Double
[SVMCF.hs:125:13-86] *Main> :ste
Stopped at SVMCF.hs:125:13-28
_result :: UA.Array Int [User] -> UA.Array Int [User] = _
len :: Int = 90570
[SVMCF.hs:125:13-28] *Main> :ste
Stopped at SVMCF.hs:125:21-27
_result :: Bool = _
len :: Int = 90570
[SVMCF.hs:125:21-27] *Main> :ste
Stopped at SVMCF.hs:125:32-86
_result :: UA.Array Int [User] = _
len :: Int = 90570
rts :: [RTuple] = (1,1,5.0) : (1,2,3.0) : (1,3,4.0) : (1,4,3.0) :
                  (1,5,3.0) : ....
[SVMCF.hs:125:32-86] *Main> :ste
Stopped at SVMCF.hs:125:32-56
_result :: [[User]] -> UA.Array Int [User] = _
len :: Int = 90570
[SVMCF.hs:125:32-56] *Main> :lis
124      points :: A.Array Int [Int]
125      points = assert (len > 0) $ A.listArray (1::Int, len) $ map (\(u,i,r) -> [u,i]) rts
126      values :: UA.UArray Int Double
[SVMCF.hs:125:32-56] *Main> len
90570
[SVMCF.hs:125:32-56] *Main> :ste
Stopped at SVMCF.hs:125:60-86
_result :: [[User]] = _
rts :: [RTuple] = (1,1,5.0) : (1,2,3.0) : (1,3,4.0) : (1,4,3.0) :
                  (1,5,3.0) : ....
[SVMCF.hs:125:60-86] *Main> :ste
*** Exception: Ix{Int}.index: Index (1) out of range ((1,-193459561))

1 个解决方案

#1


3  

I suspect the index out of range exception is not being caused in the expression that you think it is!

我怀疑索引超出范围异常不会在您认为的表达式中引起!

Data.Array.listArray (1,-10) [2,3,4,5]

Data.Array.listArray(1,-10)[2,3,4,5]

does not throw any exception, it just gives you an empty array. Also note the column numbers in the last debug message:

不抛出任何异常,只是给你一个空数组。另请注意上一个调试消息中的列号:

Stopped at SVMCF.hs:125:60-86

停在SVMCF.hs:125:60-86

60 to 86 is map (\(u,i,r) -> [u,i]) rts which doesn't obviously have any indexing going on in it: There's certainly none in map, nor in its first argument, and rts looks clean too as it comes straight from ua.base via Parsec.

60到86是map(\(你,我,r) - > [u,i])rts,其中显然没有任何索引:地图中没有,也没有第一个参数和rts看起来很干净,因为它直接来自ua.base通过Parsec。

Because Haskell is allowed to be fairly free with its evaluation order, it's possible that the exception is being thrown by a reduction in a completely different expression. Are you sure all the other things you're passing into SVM are set up correctly? In particular, given that you're using Int-indexed arrays, are you sure there's no integer overflow occurring in any array? Are any of your datasets, for example, 4101507735 or 8396475031 records long, because these overflow to -193459561 as Int).

因为Haskell允许其评估顺序相当自由,所以可能通过减少完全不同的表达式来抛出异常。您确定要传递给SVM的所有其他内容是否已正确设置?特别是,鉴于您使用的是Int-indexed数组,您确定在任何数组中都没有发生整数溢出吗?您的任何数据集(例如,4101507735或8396475031)都是长的,因为这些数据集溢出到-193459561作为Int)。

Does the :history command in the GHCi debugger give you any more information?

GHCi调试器中的:history命令是否为您提供了更多信息?


推荐阅读
  • 本文详细介绍了Java中org.neo4j.helpers.collection.Iterators.single()方法的功能、使用场景及代码示例,帮助开发者更好地理解和应用该方法。 ... [详细]
  • 本文介绍如何使用 Python 编写程序,检查给定列表中的元素是否形成交替峰值模式。我们将探讨两种不同的方法来实现这一目标,并提供详细的代码示例。 ... [详细]
  • 本文详细介绍了Java中org.w3c.dom.Text类的splitText()方法,通过多个代码示例展示了其实际应用。该方法用于将文本节点在指定位置拆分为两个节点,并保持在文档树中。 ... [详细]
  • 尽管使用TensorFlow和PyTorch等成熟框架可以显著降低实现递归神经网络(RNN)的门槛,但对于初学者来说,理解其底层原理至关重要。本文将引导您使用NumPy从头构建一个用于自然语言处理(NLP)的RNN模型。 ... [详细]
  • 本文详细介绍了 GWT 中 PopupPanel 类的 onKeyDownPreview 方法,提供了多个代码示例及应用场景,帮助开发者更好地理解和使用该方法。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 导航栏样式练习:项目实例解析
    本文详细介绍了如何创建一个具有动态效果的导航栏,包括HTML、CSS和JavaScript代码的实现,并附有详细的说明和效果图。 ... [详细]
  • 1.如何在运行状态查看源代码?查看函数的源代码,我们通常会使用IDE来完成。比如在PyCharm中,你可以Ctrl+鼠标点击进入函数的源代码。那如果没有IDE呢?当我们想使用一个函 ... [详细]
  • 主要用了2个类来实现的,话不多说,直接看运行结果,然后在奉上源代码1.Index.javaimportjava.awt.Color;im ... [详细]
  • 本文详细介绍了Java中org.eclipse.ui.forms.widgets.ExpandableComposite类的addExpansionListener()方法,并提供了多个实际代码示例,帮助开发者更好地理解和使用该方法。这些示例来源于多个知名开源项目,具有很高的参考价值。 ... [详细]
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • 本文介绍如何使用 NSTimer 实现倒计时功能,详细讲解了初始化方法、参数配置以及具体实现步骤。通过示例代码展示如何创建和管理定时器,确保在指定时间间隔内执行特定任务。 ... [详细]
  • 深入理解Redis的数据结构与对象系统
    本文详细探讨了Redis中的数据结构和对象系统的实现,包括字符串、列表、集合、哈希表和有序集合等五种核心对象类型,以及它们所使用的底层数据结构。通过分析源码和相关文献,帮助读者更好地理解Redis的设计原理。 ... [详细]
  • 本文介绍如何使用 Python 的 xlrd 库读取 Excel 文件,并将其数据处理后存储到数据库中。通过实际案例,详细讲解了文件路径、合并单元格处理等常见问题。 ... [详细]
  • 开发笔记:2020 BJDCTF Re encode
    开发笔记:2020 BJDCTF Re encode ... [详细]
author-avatar
mobiledu2502869467
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有