2

I have been working in a project that has been using lists to calculate artificial neural network operations. Now, I would like to transform that to Data.Vector to improve its efficiency. However, I have been having a trouble at the moment to implement Foreign.Storable for a definition that is essential.

Ok, so first, I have used Data.Array.Repa for the calculations, with a type synonym like the following (CAMTypes.hs):

type NTTVU = Array U VShape NTT

Then later I wanted to use Data.Vector as follows:

import qualified Data.Vector.Storable as VS
-- ...
trs = createThreshold 3 0 [9,8,7] :: NTTVU

However, I get the following error:

$> VS.singleton trs
*** Exception: Prelude.undefined
CallStack (from HasCallStack):
  error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err
  undefined, called at ./Data/Vector/Storable/Mutable.hs:131:22 in vector-0.12.0.1-JlawpRjIcMJIYPJVsWriIA:Data.Vector.Storable.Mutable
CallStack (from -prof):
  Data.Vector.Storable.Mutable.basicUnsafeNew.size (Data/Vector/Storable/Mutable.hs:131:7-36)
  Data.Vector.Storable.Mutable.basicUnsafeNew (Data/Vector/Storable/Mutable.hs:(124,3)-(132,38))
  Data.Vector.Storable.Mutable.CAF:lvl12_r7YZK (<no location info>)

I have already done the implementation for instance Storable NTTVU where, but still complains; I enabled profiling, but does not tell me more about it; tried debugging by steps but no success as well. Hopefully someone knows a lot about it and how to solve it.

For more context, the whole project, and the related files:

HTNW
  • 27,182
  • 1
  • 32
  • 60
Invoke
  • 215
  • 1
  • 10

1 Answers1

1

I found the problem: sizeOf.

As I was implement it, it relied on vec to exist and have defined values, however, that's not the case. The memory size should be known to the Vector storable implementation before hand, which is why it was creating the error.

So, for now I have fixed the size to "4", but do not use that if what you want is to have a runtime allocation.

Here is the commit for that solution:

Invoke
  • 215
  • 1
  • 10