Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gaussian sampler crashes randomly with ArrayIndexOutOfBoundsException #1315

Open
wasowski opened this issue Jan 13, 2024 · 0 comments
Open

Comments

@wasowski
Copy link

wasowski commented Jan 13, 2024

The following invocation in console, spire 0.18, scala 3.3.1:

val rng = spire.random.rng.SecureJava.apply

spire.random.Gaussian (0.0, 1.0)
  .toLazyList (rng)
  .take(500)
  .toList

Call it a few times, and eventually I am getting:

scala> spire.random.Gaussian(0.0, 1.0).toLazyList(rng).take(500).toList
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 128
  at spire.random.Ziggurat$.loop$1(Ziggurat.scala:83)
  at spire.random.Ziggurat$.nfix(Ziggurat.scala:92)
  at spire.random.Ziggurat$.rnor(Ziggurat.scala:52)
  at spire.random.GaussianInstances.spire$random$GaussianInstances$$anon$2$$_$apply$$anonfun$2(Gaussian.scala:50)
  at spire.random.DistFromGen.apply(Dist.scala:177)
  at spire.random.Dist.toLazyList$$anonfun$1(Dist.scala:127)
  at scala.collection.immutable.LazyList$.$anonfun$continually$1(LazyList.scala:1220)
  at scala.collection.immutable.LazyList.scala$collection$immutable$LazyList$$state$lzycompute(LazyList.scala:259)
  at scala.collection.immutable.LazyList.scala$collection$immutable$LazyList$$state(LazyList.scala:252)
  at scala.collection.immutable.LazyList.isEmpty(LazyList.scala:269)
  at scala.collection.immutable.LazyList.$anonfun$takeImpl$1(LazyList.scala:693)
  at scala.collection.immutable.LazyList.scala$collection$immutable$LazyList$$state$lzycompute(LazyList.scala:259)
  at scala.collection.immutable.LazyList.scala$collection$immutable$LazyList$$state(LazyList.scala:252)
  at scala.collection.immutable.LazyList.isEmpty(LazyList.scala:269)
  at scala.collection.immutable.LazyList$LazyIterator.hasNext(LazyList.scala:1250)
  at scala.collection.immutable.List.prependedAll(List.scala:155)
  at scala.collection.IterableOnceOps.toList(IterableOnce.scala:1288)
  at scala.collection.IterableOnceOps.toList$(IterableOnce.scala:1288)
  at scala.collection.AbstractIterable.toList(Iterable.scala:933)
  ... 42 elided

It seems to happen faster and more often if I increase the number 500.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant