(* nrrd-types.sml * * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu) * * COPYRIGHT (c) 2015 The University of Chicago * All rights reserved. * * NOTE: we may want to generate this file at configure time so that we don't * have to track the nrrd type codes by hand *) structure NrrdTypes = struct local structure N = CNames structure Ty = TreeIL.Ty in (* integer codes for nrrd types (must track nrrdEnums.h) *) val nrrdTypeUnknown : IntInf.int = 0 val nrrdTypeInt : IntInf.int = 5 val nrrdTypeLLong : IntInf.int = 7 val nrrdTypeFloat : IntInf.int = 9 val nrrdTypeDouble : IntInf.int = 10 (* translate a TreeIL type to its nrrd type code *) fun toNrrdType ty = (case ty of Ty.BoolTy => nrrdTypeUnknown | Ty.StringTy => nrrdTypeUnknown | Ty.IntTy => (if !N.doublePrecision then nrrdTypeLLong else nrrdTypeInt) | Ty.TensorTy[] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat) | Ty.TensorTy[n] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat) | Ty.TensorTy[n, m] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat) | Ty.SeqTy(Ty.IntTy, _) => (if !N.doublePrecision then nrrdTypeLLong else nrrdTypeInt) | Ty.AddrTy _ => nrrdTypeUnknown | Ty.ImageTy _ => nrrdTypeUnknown | _ => raise Fail(concat["trNrrdType(", Ty.toString ty, ")"]) (* end case *)) (* translate a TreeIL type and shape to the correct memory size in bytes *) fun toNrrdSize ty = let val num = (case ty of Ty.BoolTy => 0 | Ty.StringTy => 0 | Ty.IntTy => 1 | Ty.TensorTy[] => 1 | Ty.TensorTy[n] => IntInf.fromInt n | Ty.TensorTy[n, m] => IntInf.fromInt (n * m) | Ty.SeqTy(_, n) => IntInf.fromInt n | Ty.AddrTy _ => 0 | Ty.ImageTy _ => 0 | _ => raise Fail(concat["trNrrdType(", Ty.toString ty, ")"]) (* end case *)) in num * (if !N.doublePrecision then 8 else 4) end end (* local *) end
Click to toggle
does not end with </html> tag
does not end with </body> tag
The output has ended thus: in num * (if !N.doublePrecision then 8 else 4) end end (* local *) end