Dear Chapel devs and users,
I already fixed the reverse reading problem. It is only the config of the
channel reader. Instead of using kind=ionative, I changed kind=iobig :
module Main{
proc main(){
var f = open("train-images.idx3-ubyte", iomode.r);
var r = f.reader(kind=iobig); // <-- I changed here.
var magic:uint(32);
r.read(magic);
writef("magic = %xu\n",magic);
var num_images:uint(32);
r.read(num_images);
writef("Image Numbers = %xu\n",num_images);
var rows:uint(32);
r.read(rows);
writef("rows = %xu\n",rows);
r.close();
f.close();
}
}
Excuse-me, because I asked silly question.
Thank you!
Att.
Marcos Cleison.
2017-05-22 19:25 GMT-03:00 Marcos Cleison Silva Santana <
[email protected]>:
> Hi dear Chapel devs and users,
>
> I have a newbie question about reading a binary file in Chapel.
> I downloaded the MNIST dataset with idx3 file format.
>
> http://yann.lecun.com/exdb/mnist/
>
> This file is composed of the structure like that:
>
> [offset] [type] [value] [description]
> 0000 32 bit integer 0x00000803(2051) magic number
> 0004 32 bit integer 60000 number of images
> 0008 32 bit integer 28 number of rows
> 0012 32 bit integer 28 number of columns
> 0016 unsigned byte ?? pixel
> 0017 unsigned byte ?? pixel
>
>
> I tried to read the beginner three integers (the magic number, the numbers
> of images and the number of rows). The code used is:
>
> module Main{
>
> proc main(){
>
> var f = open("train-images.idx3-ubyte", iomode.r);
> var r = f.reader(kind=ionative);
>
> var magic:uint(32);
> r.read(magic);
> writef("magic = %xu\n",magic);
>
> var num_images:uint(32);
> r.read(num_images);
> writef("Image Number = %xu\n",num_images);
>
> var rows:uint(32);
> r.read(rows);
> writef("rows = %xu\n",rows);
>
> r.close();
> f.close();
>
> }
> }
>
> Instead of outputting:
>
> magic = 0000803
> Image Numbers = 0000ea60
> rows = 0000001c
>
> The program is outputting:
> magic = 3080000
> Image Numbers = 60ea0000
> rows = 1c000000
>
> The value is stored in reverse order.
>
> Is this problem related with big-little endian?
>
> My computer is x86_64, Intel Core I7, Ubuntu 17, Chapel 1.15.
>
> Could you give me some advice?
>
> Thank you very much.
>
> Att.
> Marcos Cleison
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users