Here is (I think) a translation of that dyalog apl 'read' function into J:
read=:3 :0
r=. ,(8#2)#:a.i.fread y
NB. ??? or instead of a. use A=: a.{~#.|."1#:i.#a.
'magic count rows count'=. #.4 32$r
if. 2051=magic do.
#.0|:(count,rows,cols,8)$128|.r
elseif. 2049=magic do.
#.0|:(count,8)$64}.r
elseif. do. *'fail' end.
)
That said, note that I was not able to find documentation on the bit
order for Dyalog's NREAD (with 11 for the type argument). If I guessed
wrong (you'll get the error from *'fail'), try the suggestion in the
??? comment. (But I may have made other mistakes - without a test
file, and knowing what kind of result it should get, I don't really
know.)
That said, this routine does not look like it's relevant to the .npz
save file format, so it must be for some other save file format.
Thanks,
--
Raul
On Tue, Dec 4, 2018 at 6:21 PM Mike Powell <[email protected]> wrote:
>
> Devon,
>
> If it’s just MNIST data you need, I was able to reformat files from
> http://yann.lecun.com/exdb/mnist/ <http://yann.lecun.com/exdb/mnist/> quite
> satisfactorily.
>
> I used Dyalog APL and did actually write up the format as a pdf file. The
> function I used went like this:
>
> r←read file;⎕IO;tn;d;magic;count;rows;cols
>
> ⍝ Retrieves file contents.
>
> tn←⍬ ⋄ ⎕IO←0 ⋄ r←⍬
> :Trap 0⍴0
> ⍝ Read the file's contents as bits
> tn←file ⎕NTIE 0
> r←⎕NREAD tn,11,2↑⎕NSIZE tn
> ⎕NUNTIE tn
> magic←2⊥32⍴r
> count←2⊥32⍴32↓r
> :If magic=2051
> rows←2⊥32⍴64↓r
> cols←2⊥32⍴96↓r
> r←2⊥1 2 3 0⍉(count,rows,cols,8)⍴128↓r
> :ElseIf magic=2049
> r←2⊥1 0⍉(count,8)⍴64↓r
> :EndIf
> :Else
> ⎕NUNTIE tn
> :EndTrap
>
> If you’d like the PDF, let me know.
>
> Mike
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm