Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/charisee/src/compiler/c-util/nrrd-types.sml
ViewVC logotype

View of /branches/charisee/src/compiler/c-util/nrrd-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2838 - (download) (annotate)
Tue Nov 25 03:40:24 2014 UTC (4 years, 8 months ago) by cchiw
File size: 2525 byte(s)
edit split-ein
(* nrrd-types.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * 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)
                (*Added larger tensors just to test output*)
            | Ty.TensorTy[n, m,_] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat)

            | Ty.SeqTy(Ty.IntTy, _) => (if !N.doublePrecision then nrrdTypeLLong else nrrdTypeInt)
            | Ty.AddrTy(ImageInfo.ImgInfo{...}) => nrrdTypeUnknown
            | Ty.ImageTy(ImageInfo.ImgInfo{...}) => 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.TensorTy[n, m,k] => IntInf.fromInt (n * m*k)
                 | Ty.SeqTy(_, n) => IntInf.fromInt n
                 | Ty.AddrTy(ImageInfo.ImgInfo{...}) => 0
                 | Ty.ImageTy(ImageInfo.ImgInfo{...}) => 0
                 | _ => raise Fail(concat["trNrrdType(", Ty.toString ty, ")"])
               (* end case *))
          in 
            num * (if !N.doublePrecision then 8 else 4)
          end

    end (* local *)
  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0