Guest User

Untitled

a guest
Jan 25th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.77 KB | None | 0 0
  1. type 'a cube_type =
  2. | U16 : int16_cube cube_type
  3. | F64 : float64_cube cube_type
  4. (* with sexp *)
  5.  
  6. let cube_type_of_sexp : type a . Sexp.t -> a cube_type = function
  7.   | Sexp.Atom "U16" -> U16
  8.   | Sexp.Atom "F64" -> F64
  9.    
  10. let map_cube ?(mode=`Read) cube_type { frames; rows; cols } path =
  11.   let open Unix in
  12.   let flags, shared =
  13.     match mode with
  14.     | `Read -> [O_RDONLY], false
  15.     | `Write -> [O_RDWR], true
  16.     | `Create -> [O_RDWR;O_CREAT;O_TRUNC], true
  17.   in
  18.   let fd = Unix.openfile path flags 0o644 in
  19.   let get : type a . a cube_type -> a = function
  20.     | U16 -> Array3.map_file fd ~pos:0L int16_unsigned fortran_layout shared cols rows frames
  21.     | F64 -> Array3.map_file fd ~pos:0L float64 fortran_layout shared cols rows frames
  22.   in
  23.   get cube_type
Advertisement
Add Comment
Please, Sign In to add comment