Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type 'a cube_type =
- | U16 : int16_cube cube_type
- | F64 : float64_cube cube_type
- (* with sexp *)
- let cube_type_of_sexp : type a . Sexp.t -> a cube_type = function
- | Sexp.Atom "U16" -> U16
- | Sexp.Atom "F64" -> F64
- let map_cube ?(mode=`Read) cube_type { frames; rows; cols } path =
- let open Unix in
- let flags, shared =
- match mode with
- | `Read -> [O_RDONLY], false
- | `Write -> [O_RDWR], true
- | `Create -> [O_RDWR;O_CREAT;O_TRUNC], true
- in
- let fd = Unix.openfile path flags 0o644 in
- let get : type a . a cube_type -> a = function
- | U16 -> Array3.map_file fd ~pos:0L int16_unsigned fortran_layout shared cols rows frames
- | F64 -> Array3.map_file fd ~pos:0L float64 fortran_layout shared cols rows frames
- in
- get cube_type
Advertisement
Add Comment
Please, Sign In to add comment