marcoheisig / numpy-file-format

Read and write Numpy .npy and .npz files.
MIT License
16 stars 4 forks source link

Arrays with element-type (signed-byte 8) are not of type (array (signed-byte *)) #5

Closed digikar99 closed 3 years ago

digikar99 commented 3 years ago

I just noted the following on CCL and SBCL:

CL-USER> (typep (make-array 4 :element-type '(signed-byte 8) 
                              :initial-contents '(-2 -1 0 1))
                '(array (signed-byte *)))
NIL

Due to this,

CL-USER> (numpy-file-format:store-array 
          (make-array 4 :element-type '(signed-byte 8) 
                        :initial-contents '(-2 -1 0 1))
          "/tmp/nff.npy")

causes the following error:

The value
  -2
is not of type
  (UNSIGNED-BYTE 8)
   [Condition of type TYPE-ERROR]

Restarts:
 0: [RETRY] Retry SLIME REPL evaluation request.
 1: [*ABORT] Return to SLIME's top level.
 2: [ABORT] abort thread (#<THREAD "repl-thread" RUNNING {10018A0173}>)

Backtrace:
  0: (SB-IMPL::OUTPUT-UNSIGNED-BYTE-FULL-BUFFERED #<SB-SYS:FD-STREAM for "file /tmp/nff.npy" {1008E21FB3}> -2)
  1: (WRITE-BYTE -2 #<SB-SYS:FD-STREAM for "file /tmp/nff.npy" {1008E21FB3}>)
  2: (NUMPY-FILE-FORMAT:STORE-ARRAY #(-2 -1 0 1) "/tmp/nff.npy")

Also,

CL-USER> (subtypep '(signed-byte 8)
                   '(signed-byte *))
T
T
CL-USER> (subtypep '(array (signed-byte 8))
                   '(array (signed-byte *)))
NIL
T

[Update] One fix is to use the following:

CL-USER> (subtypep (array-element-type array)
                   '(signed-byte *))
T
T

Is there a better fix - or regression tests to check if something breaks?