Created
March 10, 2015 01:22
-
-
Save Elzair/32d59b7c4c93c29f9851 to your computer and use it in GitHub Desktop.
Julia IDX Parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Base.ntoh | |
@vectorize_1arg Number Base.ntoh | |
function readIdx(file_name) | |
fs = open(file_name, "r") | |
magic_number = read(fs, UInt8, 4) | |
if magic_number[3] == 0x08 | |
idx_type = UInt8 | |
elseif magic_number[2] == 0x09 | |
idx_type = Int8 | |
elseif magic_number[2] == 0x0B | |
idx_type = Int16 | |
elseif magic_number[2] == 0x0C | |
idx_type = Int32 | |
elseif magic_number[2] == 0x0D | |
idx_type = Float32 | |
elseif magic_number[2] == 0x0E | |
idx_type = Float64 | |
end | |
dims = Array{Int64}(ntoh(read(fs, Int32, magic_number[4]))) | |
contents = read(fs, idx_type, prod(dims)) | |
if idx_type != UInt8 && idx_type != Int8 | |
contents = ntoh(contents) | |
end | |
out = reshape(contents, tuple(dims...)) | |
return out | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment