;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; Includes information derived from the GSL (Gnu Scientific Library)
;;;   header files which are copyrighted and distributed under the GPL
;;;   by their respective authors.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(libload "htk/htk-config")



#? *** htk_mem

;; dummy function that adds HTK C header files in C file
(eval `(de dummy_htk_mem () ,htk-cpheader-cmd ()))

#? * (dummy_htk_mem)
#? * (mround <size>)
#? * (initmem)
#? * (createheap <x> <name> <type> <elemsize> <growf> <numelem> <maxelem>)
#? * (resetheap <x>)
#? * (deleteheap <x>)
#? * (newobject <x> <size>)
#? * (disposeobject <x> <p>)
#? * (printheapstats <x>)
#? * (printallheapstats)
#? * (shortvecelemsize <size>)
#? * (intvecelemsize <size>)
#? * (vectorelemsize <size>)
#? * (dvectorelemsize <size>)
#? * (svectorelemsize <size>)
#? * (createshortvec <x> <size>)
#? * (createintvec <x> <size>)
#? * (createvector <x> <size>)
#? * (createdvector <x> <size>)
#? * (createsvector <x> <size>)
#? * (shortvecsize <v>)
#? * (intvecsize <v>)
#? * (vectorsize <v>)
#? * (dvectorsize <v>)
#? * (freeshortvec <x> <v>)
#? * (freeintvec <x> <v>)
#? * (freevector <x> <v>)
#? * (freedvector <x> <v>)
#? * (freesvector <x> <v>)
#? * (matrixelemsize <nrows> <ncols>)
#? * (dmatrixelemsize <nrows> <ncols>)
#? * (smatrixelemsize <nrows> <ncols>)
#? * (trimatelemsize <size>)
#? * (strimatelemsize <size>)
#? * (creatematrix <x> <nrows> <ncols>)
#? * (createdmatrix <x> <nrows> <ncols>)
#? * (createsmatrix <x> <nrows> <ncols>)
#? * (createtrimat <x> <size>)
#? * (createstrimat <x> <size>)
#? * (istrimat <m>)
#? * (numrows <m>)
#? * (numdrows <m>)
#? * (numcols <m>)
#? * (numdcols <m>)
#? * (trimatsize <m>)
#? * (freematrix <x> <m>)
#? * (freedmatrix <x> <m>)
#? * (freesmatrix <x> <m>)
#? * (freetrimat <x> <m>)
#? * (freestrimat <x> <m>)
#? * (setuse <m> <n>)
#? * (incuse <m>)
#? * (decuse <m>)
#? * (getuse <m>)
#? * (isseenv <m>)
#? * (touchv <m>)
#? * (untouchv <m>)
#? * (sethook <m> <p>)
#? * (gethook <m>)
#? * (newstring <x> <size>)
#? * (copystring <x> <s>)

;; ********************************************************


(de MRound (  size )
    ((-int-) size)                          ;; size_t -> int
    (int   #{ MRound(  $size  )  #} )        ;; size_t -> int
)


(de InitMem (  )
    #{ InitMem(  );  #} 
    ()
)


(de CreateHeap (  x  name  type  elemsize  growf  numelem  maxelem )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "char *") name) 
    ((-int-) type)                                   ;; HeapType -> int
    ((-int-) elemsize)                        ;; size_t -> int
    ((-double-) growf)                         ;; float -> double
    ((-int-) numelem)                        ;; size_t -> int
    ((-int-) maxelem)                         ;; size_t -> int
    #{ CreateHeap(  $x   ,$name   ,$type   ,$elemsize   ,$growf   ,$numelem   ,$maxelem  );  #} 
    ()
)


(de ResetHeap (  x )
    ((-gptr- "MemHeap *") x)  
    #{ ResetHeap(  $x  );  #} 
    ()
)


(de DeleteHeap (  x )
    ((-gptr- "MemHeap *") x)  
    #{ DeleteHeap(  $x  );  #} 
    ()
)


(de NewObject (  x  size )
    ((-gptr- "MemHeap *") x) 
    ((-int-) size)                         ;; size_t -> int
    (gptr   #{ New(  $x   ,$size  )  #} )
)


(de DisposeObject (  x  p )
    ((-gptr- "MemHeap *") x) 
    ((-gptr-) p)  
    #{ Dispose(  $x   ,$p  );  #} 
    ()
)


(de PrintHeapStats (  x )
    ((-gptr- "MemHeap *") x)  
    #{ PrintHeapStats(  $x  );  #} 
    ()
)


(de PrintAllHeapStats (  )
    #{ PrintAllHeapStats(  );  #} 
    ()
)


(de ShortVecElemSize (  size )
    ((-int-) size)  
    (int   #{ ShortVecElemSize(  $size  )  #} )           ;; size_t (uint) -> int
)


(de IntVecElemSize (  size )
    ((-int-) size)  
    (int   #{ IntVecElemSize(  $size  )  #} )             ;; size_t (uint) -> int
)


(de VectorElemSize (  size )
    ((-int-) size)  
    (int   #{ VectorElemSize(  $size  )  #} )             ;; size_t (uint) -> int
)




(de DVectorElemSize (  size )
    ((-int-) size)  
    (int   #{ DVectorElemSize(  $size  )  #} )             ;; size_t (uint) -> int
)


(de SVectorElemSize (  size )
    ((-int-) size)  
    (int   #{ SVectorElemSize(  $size  )  #} )             ;; size_t (uint) -> int
)


(de CreateShortVec (  x  size )
    ((-gptr- "MemHeap *") x) 
    ((-int-) size)  
    (gptr   #{ CreateShortVec(  $x   ,$size  )  #} )          ;; ShortVec -> gptr
)


(de CreateIntVec (  x  size )
    ((-gptr- "MemHeap *") x) 
    ((-int-) size)  
    (gptr     #{ CreateIntVec(  $x   ,$size  )  #} )            ;; IntVec -> gptr
)


(de CreateVector (  x  size )
    ((-gptr- "MemHeap *") x) 
    ((-int-) size)  
    (gptr     #{ CreateVector(  $x   ,$size  )  #} )           ;; float * -> gptr
)


(de CreateDVector (  x  size )
    ((-gptr- "MemHeap *") x) 
    ((-int-) size)  
    (gptr    #{ CreateDVector(  $x   ,$size  )  #} )            ;; DVector -> gptr
)


(de CreateSVector (  x  size )
    ((-gptr- "MemHeap *") x) 
    ((-int-) size)  
    (gptr    #{ CreateSVector(  $x   ,$size  )  #} )            ;; SVector -> gptr
)


(de ShortVecSize (  v )
    ((-gptr- "short *") v)  
    (int   #{ ShortVecSize(  $v  )  #} )
)


(de IntVecSize (  v )
    ((-gptr- "int *") v)  
    (int   #{ IntVecSize(  $v  )  #} )
)


(de VectorSize (  v )
    ((-gptr- "float *") v)  
    (int   #{ VectorSize(  $v  )  #} )
)


(de DVectorSize (  v )
    ((-gptr- "double *") v)  
    (int   #{ DVectorSize(  $v  )  #} )
)


(de FreeShortVec (  x  v )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "short *") v)  
    #{ FreeShortVec(  $x   ,$v  );  #} 
    ()
)


(de FreeIntVec (  x  v )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "int *") v)  
    #{ FreeIntVec(  $x   ,$v  );  #} 
    ()
)


(de FreeVector (  x  v )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "float *") v)  
    #{ FreeVector(  $x   ,$v  );  #} 
    ()
)


(de FreeDVector (  x  v )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "double *") v)  
    #{ FreeDVector(  $x   ,$v  );  #} 
    ()
)


(de FreeSVector (  x  v )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "float *") v)  
    #{ FreeSVector(  $x   ,$v  );  #} 
    ()
)


(de MatrixElemSize (  nrows  ncols )
    ((-int-) nrows) 
    ((-int-) ncols)  
    (int   #{ MatrixElemSize(  $nrows   ,$ncols  )  #} )             ;; size_t (uint) -> int
)


(de DMatrixElemSize (  nrows  ncols )
    ((-int-) nrows) 
    ((-int-) ncols)  
    (int   #{ DMatrixElemSize(  $nrows   ,$ncols  )  #} )             ;; size_t (uint) -> int
)


(de SMatrixElemSize (  nrows  ncols )
    ((-int-) nrows) 
    ((-int-) ncols)  
    (int   #{ SMatrixElemSize(  $nrows   ,$ncols  )  #} )             ;; size_t (uint) -> int
)


(de TriMatElemSize (  size )
    ((-int-) size)  
    (int   #{ TriMatElemSize(  $size  )  #} )             ;; size_t (uint) -> int
)


(de STriMatElemSize (  size )
    ((-int-) size)  
    (int   #{ STriMatElemSize(  $size  )  #} )             ;; size_t (uint) -> int
)


(de CreateMatrix (  x  nrows  ncols )
    ((-gptr- "MemHeap *") x) 
    ((-int-) nrows) 
    ((-int-) ncols)  
    (gptr    #{ CreateMatrix(  $x   ,$nrows   ,$ncols  )  #} )         ;; Matrix -> gptr
)


(de CreateDMatrix (  x  nrows  ncols )
    ((-gptr- "MemHeap *") x) 
    ((-int-) nrows) 
    ((-int-) ncols)  
    (gptr   #{ CreateDMatrix(  $x   ,$nrows   ,$ncols  )  #} )          ;; DMatrix -> gptr
)


(de CreateSMatrix (  x  nrows  ncols )
    ((-gptr- "MemHeap *") x) 
    ((-int-) nrows) 
    ((-int-) ncols)  
    (gptr   #{ CreateSMatrix(  $x   ,$nrows   ,$ncols  )  #} )         ;; SMatrix -> gptr
)


(de CreateTriMat (  x  size )
    ((-gptr- "MemHeap *") x) 
    ((-int-) size)  
    (gptr    #{ CreateTriMat(  $x   ,$size  )  #} )                   ;; TriMat -> gptr
)


(de CreateSTriMat (  x  size )
    ((-gptr- "MemHeap *") x) 
    ((-int-) size)  
    (gptr   #{ CreateSTriMat(  $x   ,$size  )  #} )                    ;; STriMat -> gptr
)


(de IsTriMat (  m )
    ((-gptr- "float **") m)  
    (int   #{ IsTriMat(  $m  )  #} )
)


(de NumRows (  m )
    ((-gptr- "float **") m)  
    (int   #{ NumRows(  $m  )  #} )
)


(de NumDRows (  m )
    ((-gptr- "double **") m)  
    (int   #{ NumDRows(  $m  )  #} )
)


(de NumCols (  m )
    ((-gptr- "float **") m)  
    (int   #{ NumCols(  $m  )  #} )
)


(de NumDCols (  m )
    ((-gptr- "double **") m)  
    (int   #{ NumDCols(  $m  )  #} )
)


(de TriMatSize (  m )
    ((-gptr- "float **") m)  
    (int   #{ TriMatSize(  $m  )  #} )
)


(de FreeMatrix (  x  m )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "float **") m)  
    #{ FreeMatrix(  $x   ,$m  );  #} 
    ()
)


(de FreeDMatrix (  x  m )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "double **") m)  
    #{ FreeDMatrix(  $x   ,$m  );  #} 
    ()
)


(de FreeSMatrix (  x  m )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "float **") m)           ;; SMatrix -> float **
    #{ FreeSMatrix(  $x   ,$m  );  #} 
    ()
)


(de FreeTriMat (  x  m )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "float **") m)  
    #{ FreeTriMat(  $x   ,$m  );  #} 
    ()
)


(de FreeSTriMat (  x  m )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "float **") m)  
    #{ FreeSTriMat(  $x   ,$m  );  #} 
    ()
)


(de SetUse (  m  n )
    ((-gptr-) m) 
    ((-int-) n)  
    #{ SetUse(  $m   ,$n  );  #} 
    ()
)


(de IncUse (  m )
    ((-gptr-) m)  
    #{ IncUse(  $m  );  #} 
    ()
)


(de DecUse (  m )
    ((-gptr-) m)  
    #{ DecUse(  $m  );  #} 
    ()
)

(de GetUse (  m )
    ((-gptr-) m)  
    (int    #{ GetUse(  $m  )  #} )
)


(de IsSeenV (  m )
    ((-gptr-) m)  
    (int   #{ IsSeenV(  $m  )  #} )
)


(de TouchV (  m )
    ((-gptr-) m)  
    #{ TouchV(  $m  );  #} 
    ()
)


(de UntouchV (  m )
    ((-gptr-) m)  
    #{ UntouchV(  $m  );  #} 
    ()
)


(de SetHook (  m  p )
    ((-gptr-) m) 
    ((-gptr-) p)  
    #{ SetHook(  $m   ,$p  );  #} 
    ()
)


(de GetHook (  m )
    ((-gptr-) m)  
    (gptr   #{ GetHook(  $m  )  #} )
)


(de NewString (  x  size )
    ((-gptr- "MemHeap *") x) 
    ((-int-) size)  
    (gptr #{ NewString(  $x   ,$size  )  #} )            ;; char *   -> gptr
)


(de CopyString (  x  s )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "char *") s)  
    (gptr #{ CopyString(  $x   ,$s  )  #} )            ;; char *   -> gptr
)

;; ********************************************************

(dhc-make-with-libs () (list htk-libhtk)
  dummy_htk_mem
  mround
  initmem
  createheap
  resetheap
  deleteheap
  newobject
  disposeobject
  printheapstats
  printallheapstats
  shortvecelemsize
  intvecelemsize
  vectorelemsize
  dvectorelemsize
  svectorelemsize
  createshortvec
  createintvec
  createvector
  createdvector
  createsvector
  shortvecsize
  intvecsize
  vectorsize
  dvectorsize
  freeshortvec
  freeintvec
  freevector
  freedvector
  freesvector
  matrixelemsize
  dmatrixelemsize
  smatrixelemsize
  trimatelemsize
  strimatelemsize
  creatematrix
  createdmatrix
  createsmatrix
  createtrimat
  createstrimat
  istrimat
  numrows
  numdrows
  numcols
  numdcols
  trimatsize
  freematrix
  freedmatrix
  freesmatrix
  freetrimat
  freestrimat
  setuse
  incuse
  decuse
  getuse
  isseenv
  touchv
  untouchv
  sethook
  gethook
  newstring
  copystring
)
