Skip to content

Instantly share code, notes, and snippets.

@gkthiruvathukal
Last active February 24, 2016 05:03
Show Gist options
  • Select an option

  • Save gkthiruvathukal/4bb286f33f3966ecb9e9 to your computer and use it in GitHub Desktop.

Select an option

Save gkthiruvathukal/4bb286f33f3966ecb9e9 to your computer and use it in GitHub Desktop.
Scala multidimensional array (problems)
// This takes forever and seems to use a lot more memory than expected
Array.ofDim[Double](2048, 2048, 2048)
// This seems to work faster and uses less memory.
def get1d(d1 : Int, init : Double) = Stream.continually(init) take d1 toArray
def get2d(d1 : Int, d2 : Int, init : Double) = Stream.continually( get1d(d2, init) ) take d1 toArray
def get3d(d1 : Int, d2 : Int, d3 : Int, init : Double) = Stream.continually( get2d(d2, d3, init) ) take d1 toArray
// More testing is needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment