;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; 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 "torch/torch-config")



#? *** matrix

;; dummy function that adds torch header files in C file
(eval `(de dummy_matrix () ,torch-cpheader-cmd ()))

#? * (dummy_matrix)
#? * (torch_mxmataddmat <mat1> <mat2> <out>)
#? * (torch_mxmatsubmat <mat1> <mat2> <out>)
#? * (torch_mxmatmulmat <mat1> <mat2> <out>)
#? * (torch_mxmatmultrmat <mat1> <mat2> <out>)
#? * (torch_mxtrmatmulmat <mat1> <mat2> <out>)
#? * (torch_mxmatmulvec <mat> <b> <out>)
#? * (torch_mxrealmulmat <scalar> <matrix> <out>)
#? * (torch_mxvecmulmat <b> <mat> <out>)
#? * (torch_mxtrmat <in> <out>)
#? * (torch_mxswaprowsmat <mat> <i> <j> <lo> <hi>)
#? * (torch_mxswapcolsmat <mat> <i> <j> <lo> <hi>)
#? * (torch_mxmataddrealmulmat <mat1> <mat2> <s> <out>)
#? * (torch_mxvecaddrealmulmatmulvec <v1> <alpha> <mat> <v2> <out>)
#? * (torch_mxvecaddrealmulvecmulmat <v1> <alpha> <v2> <mat> <out>)
#? * (torch_mx_givens <x> <y> <c> <s>)
#? * (torch_mx_rot_vec <x> <i> <k> <c> <s> <out>)
#? * (torch_mx_rot_rows <mat> <i> <k> <c> <s> <out>)
#? * (torch_mx_rot_cols <mat> <i> <k> <c> <s> <out>)
#? * (torch_mxhfactor <mat> <diag> <beta>)
#? * (torch_mxmakehq <h_mat> <diag> <beta> <q_out>)
#? * (torch_mxmakeh <h_mat> <h_out>)
#? * (torch_mxhhvec <vec> <i0> <beta> <out> <newval>)
#? * (torch_mxhhtrvec <hh> <beta> <i0> <in> <out>)
#? * (torch_mxhhtrrows <mat> <i0> <j0> <hh> <beta>)
#? * (torch_mxhhtrcols <mat> <i0> <j0> <hh> <beta>)
#? * (torch_mxip__ <dp1> <dp2> <len>)
#? * (torch_mxrealmuladd__ <dp1> <dp2> <s> <len>)
#? * (torch_mxrealmul__ <dp> <s> <out> <len>)
#? * (torch_mxadd__ <dp1> <dp2> <out> <len>)
#? * (torch_mxsub__ <dp1> <dp2> <out> <len>)
#? * (torch_mxzero__ <dp> <len>)
#? * (torch_mxlufactor <mat> <pivot>)
#? * (torch_mxlusolve <mat> <pivot> <b> <x>)
#? * (torch_mxlutsolve <mat> <pivot> <b> <x>)
#? * (torch_mxinverse <mat> <out>)
#? * (torch_mxsolve <matrix> <b> <x>)
#? * (torch_mxusolve <matrix> <b> <out> <diag>)
#? * (torch_mxlsolve <matrix> <b> <out> <diag>)
#? * (torch_mxutsolve <mat> <b> <out> <diag>)
#? * (torch_mxdsolve <mat> <b> <x>)
#? * (torch_mxltsolve <mat> <b> <out> <diag>)
#? * (torch_mxtrieig <a> <b> <mat_q>)
#? * (torch_mxsymeig <mat_a> <mat_q> <out>)
#? * (torch_mxperminv <px> <out>)
#? * (torch_mxpermmulperm <px1> <px2> <out>)
#? * (torch_mxpermvec <px> <vec> <out>)
#? * (torch_mxperminvvec <px> <x> <out>)
#? * (torch_mxtrperm <px> <i1> <i2>)
#? * (torch_mxpermcolsmat <px> <mat> <out>)
#? * (torch_mxpermrowsmat <px> <mat> <out>)

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


(de torch_mxMatAddMat  (  mat1 mat2 out )
    ((-gptr- "Torch::Mat *") mat1)
    ((-gptr- "Torch::Mat *") mat2)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mxMatAddMat(  $mat1  ,$mat2  ,$out);  #} 
    ())


(de torch_mxMatSubMat  (  mat1 mat2 out )
    
    ((-gptr- "Torch::Mat *") mat1)
    ((-gptr- "Torch::Mat *") mat2)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mxMatSubMat(  $mat1  ,$mat2  ,$out);  #} 
    ())


(de torch_mxMatMulMat  (  mat1 mat2 out )
    
    ((-gptr- "Torch::Mat *") mat1)
    ((-gptr- "Torch::Mat *") mat2)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mxMatMulMat(  $mat1  ,$mat2  ,$out);  #} 
    ())


(de torch_mxMatMulTrMat  (  mat1 mat2 out )
    
    ((-gptr- "Torch::Mat *") mat1)
    ((-gptr- "Torch::Mat *") mat2)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mxMatMulTrMat(  $mat1  ,$mat2  ,$out);  #} 
    ())


(de torch_mxTrMatMulMat  (  mat1 mat2 out )
    
    ((-gptr- "Torch::Mat *") mat1)
    ((-gptr- "Torch::Mat *") mat2)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mxTrMatMulMat(  $mat1  ,$mat2  ,$out);  #} 
    ())


(de torch_mxMatMulVec  (  mat b out )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Vec *") b)
    ((-gptr- "Torch::Vec *") out)
    #{  Torch::mxMatMulVec(  $mat  ,$b  ,$out);  #} 
    ())


(de torch_mxRealMulMat  (  scalar matrix out )
    
    ((-double-) scalar)
    ((-gptr- "Torch::Mat *") matrix)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mxRealMulMat(  $scalar  ,$matrix  ,$out);  #} 
    ())


(de torch_mxVecMulMat  (  b mat out )
    
    ((-gptr- "Torch::Vec *") b)
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Vec *") out)
    #{  Torch::mxVecMulMat(  $b  ,$mat  ,$out);  #} 
    ())


(de torch_mxTrMat  (  in out )
    
    ((-gptr- "Torch::Mat *") in)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mxTrMat(  $in  ,$out);  #} 
    ())


(de torch_mxSwapRowsMat  (  mat i j lo hi )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-int-) i)
    ((-int-) j)
    ((-int-) lo)
    ((-int-) hi)
    #{  Torch::mxSwapRowsMat(  $mat  ,$i  ,$j  ,$lo  ,$hi);  #} 
    ())


(de torch_mxSwapColsMat  (  mat i j lo hi )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-int-) i)
    ((-int-) j)
    ((-int-) lo)
    ((-int-) hi)
    #{  Torch::mxSwapColsMat(  $mat  ,$i  ,$j  ,$lo  ,$hi);  #} 
    ())


(de torch_mxMatAddRealMulMat  (  mat1 mat2 s out )
    
    ((-gptr- "Torch::Mat *") mat1)
    ((-gptr- "Torch::Mat *") mat2)
    ((-double-) s)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mxMatAddRealMulMat(  $mat1  ,$mat2  ,$s  ,$out);  #} 
    ())


(de torch_mxVecAddRealMulMatMulVec  (  v1 alpha mat v2 out )
    
    ((-gptr- "Torch::Vec *") v1)
    ((-double-) alpha)
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Vec *") v2)
    ((-gptr- "Torch::Vec *") out)
    #{  Torch::mxVecAddRealMulMatMulVec(  $v1  ,$alpha  ,$mat  ,$v2  ,$out);  #} 
    ())


(de torch_mxVecAddRealMulVecMulMat  (  v1 alpha v2 mat out )
    
    ((-gptr- "Torch::Vec *") v1)
    ((-double-) alpha)
    ((-gptr- "Torch::Vec *") v2)
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Vec *") out)
    #{  Torch::mxVecAddRealMulVecMulMat(  $v1  ,$alpha  ,$v2  ,$mat  ,$out);  #} 
    ())


(de torch_mx_givens  (  x y c s )
    
    ((-double-) x)
    ((-double-) y)
    ((-gptr- "double *") c)
    ((-gptr- "double *") s)
    #{  Torch::mx_givens(  $x  ,$y  ,$c  ,$s);  #} 
    ())


(de torch_mx_rot_vec  (  x i k c s out )
    
    ((-gptr- "Torch::Vec *") x)
    ((-int-) i)
    ((-int-) k)
    ((-double-) c)
    ((-double-) s)
    ((-gptr- "Torch::Vec *") out)
    #{  Torch::mx_rot_vec(  $x  ,$i  ,$k  ,$c  ,$s  ,$out);  #} 
    ())


(de torch_mx_rot_rows  (  mat i k c s out )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-int-) i)
    ((-int-) k)
    ((-double-) c)
    ((-double-) s)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mx_rot_rows(  $mat  ,$i  ,$k  ,$c  ,$s  ,$out);  #} 
    ())


(de torch_mx_rot_cols  (  mat i k c s out )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-int-) i)
    ((-int-) k)
    ((-double-) c)
    ((-double-) s)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mx_rot_cols(  $mat  ,$i  ,$k  ,$c  ,$s  ,$out);  #} 
    ())


(de torch_mxHFactor  (  mat diag beta )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Vec *") diag)
    ((-gptr- "Torch::Vec *") beta)
    #{  Torch::mxHFactor(  $mat  ,$diag  ,$beta);  #} 
    ())


(de torch_mxMakeHQ  (  h_mat diag beta q_out )
    
    ((-gptr- "Torch::Mat *") h_mat)
    ((-gptr- "Torch::Vec *") diag)
    ((-gptr- "Torch::Vec *") beta)
    ((-gptr- "Torch::Mat *") q_out)
    #{  Torch::mxMakeHQ(  $h_mat  ,$diag  ,$beta  ,$q_out);  #} 
    ())


(de torch_mxMakeH  (  h_mat h_out )
    
    ((-gptr- "Torch::Mat *") h_mat)
    ((-gptr- "Torch::Mat *") h_out)
    #{  Torch::mxMakeH(  $h_mat  ,$h_out);  #} 
    ())


(de torch_mxHhVec  (  vec i0 beta out newval )
    
    ((-gptr- "Torch::Vec *") vec)
    ((-int-) i0)
    ((-gptr- "double *") beta)
    ((-gptr- "Torch::Vec *") out)
    ((-gptr- "double *") newval)
    #{  Torch::mxHhVec(  $vec  ,$i0  ,$beta  ,$out  ,$newval);  #} 
    ())


(de torch_mxHhTrVec  (  hh beta i0 in out )
    
    ((-gptr- "Torch::Vec *") hh)
    ((-double-) beta)
    ((-int-) i0)
    ((-gptr- "Torch::Vec *") in)
    ((-gptr- "Torch::Vec *") out)
    #{  Torch::mxHhTrVec(  $hh  ,$beta  ,$i0  ,$in  ,$out);  #} 
    ())


(de torch_mxHhTrRows  (  mat i0 j0 hh beta )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-int-) i0)
    ((-int-) j0)
    ((-gptr- "Torch::Vec *") hh)
    ((-double-) beta)
    #{  Torch::mxHhTrRows(  $mat  ,$i0  ,$j0  ,$hh  ,$beta);  #} 
    ())


(de torch_mxHhTrCols  (  mat i0 j0 hh beta )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-int-) i0)
    ((-int-) j0)
    ((-gptr- "Torch::Vec *") hh)
    ((-double-) beta)
    #{  Torch::mxHhTrCols(  $mat  ,$i0  ,$j0  ,$hh  ,$beta);  #} 
    ())


(de torch_mxIp__  (  dp1 dp2 len )
    
    ((-gptr- "double *") dp1)
    ((-gptr- "double *") dp2)
    ((-int-) len)
    (double #{  Torch::mxIp__(  $dp1  ,$dp2  ,$len)  #} ))


(de torch_mxRealMulAdd__  (  dp1 dp2 s len )
    
    ((-gptr- "double *") dp1)
    ((-gptr- "double *") dp2)
    ((-double-) s)
    ((-int-) len)
    #{  Torch::mxRealMulAdd__(  $dp1  ,$dp2  ,$s  ,$len);  #} 
    ())


(de torch_mxRealMul__  (  dp s out len )
    
    ((-gptr- "double *") dp)
    ((-double-) s)
    ((-gptr- "double *") out)
    ((-int-) len)
    #{  Torch::mxRealMul__(  $dp  ,$s  ,$out  ,$len);  #} 
    ())


(de torch_mxAdd__  (  dp1 dp2 out len )
    
    ((-gptr- "double *") dp1)
    ((-gptr- "double *") dp2)
    ((-gptr- "double *") out)
    ((-int-) len)
    #{  Torch::mxAdd__(  $dp1  ,$dp2  ,$out  ,$len);  #} 
    ())


(de torch_mxSub__  (  dp1 dp2 out len )
    
    ((-gptr- "double *") dp1)
    ((-gptr- "double *") dp2)
    ((-gptr- "double *") out)
    ((-int-) len)
    #{  Torch::mxSub__(  $dp1  ,$dp2  ,$out  ,$len);  #} 
    ())


(de torch_mxZero__  (  dp len )
    
    ((-gptr- "double *") dp)
    ((-int-) len)
    #{  Torch::mxZero__(  $dp  ,$len);  #} 
    ())


(de torch_mxLUFactor  (  mat pivot )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Perm *") pivot)
    #{  Torch::mxLUFactor(  $mat  ,$pivot);  #} 
    ())


(de torch_mxLUSolve  (  mat pivot b x )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Perm *") pivot)
    ((-gptr- "Torch::Vec *") b)
    ((-gptr- "Torch::Vec *") x)
    #{  Torch::mxLUSolve(  $mat  ,$pivot  ,$b  ,$x);  #} 
    ())


(de torch_mxLUTSolve  (  mat pivot b x )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Perm *") pivot)
    ((-gptr- "Torch::Vec *") b)
    ((-gptr- "Torch::Vec *") x)
    #{  Torch::mxLUTSolve(  $mat  ,$pivot  ,$b  ,$x);  #} 
    ())


(de torch_mxInverse  (  mat out )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mxInverse(  $mat  ,$out);  #} 
    ())


(de torch_mxSolve  (  matrix b x )
    
    ((-gptr- "Torch::Mat *") matrix)
    ((-gptr- "Torch::Vec *") b)
    ((-gptr- "Torch::Vec *") x)
    #{  Torch::mxSolve(  $matrix  ,$b  ,$x);  #} 
    ())

(de torch_mxUSolve  (  matrix b out diag )
    
    ((-gptr- "Torch::Mat *") matrix)
    ((-gptr- "Torch::Vec *") b)
    ((-gptr- "Torch::Vec *") out)
    ((-double-) diag)
    #{  Torch::mxUSolve(  $matrix  ,$b  ,$out  ,$diag);  #} 
    ())


(de torch_mxLSolve  (  matrix b out diag )
    
    ((-gptr- "Torch::Mat *") matrix)
    ((-gptr- "Torch::Vec *") b)
    ((-gptr- "Torch::Vec *") out)
    ((-double-) diag)
    #{  Torch::mxLSolve(  $matrix  ,$b  ,$out  ,$diag);  #} 
    ())


(de torch_mxUTSolve  (  mat b out diag )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Vec *") b)
    ((-gptr- "Torch::Vec *") out)
    ((-double-) diag)
    #{  Torch::mxUTSolve(  $mat  ,$b  ,$out  ,$diag);  #} 
    ())


(de torch_mxDSolve  (  mat b x )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Vec *") b)
    ((-gptr- "Torch::Vec *") x)
    #{  Torch::mxDSolve(  $mat  ,$b  ,$x);  #} 
    ())


(de torch_mxLTSolve  (  mat b out diag )
    
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Vec *") b)
    ((-gptr- "Torch::Vec *") out)
    ((-double-) diag)
    #{  Torch::mxLTSolve(  $mat  ,$b  ,$out  ,$diag);  #} 
    ())


(de torch_mxTriEig  (  a b mat_q )
    
    ((-gptr- "Torch::Vec *") a)
    ((-gptr- "Torch::Vec *") b)
    ((-gptr- "Torch::Mat *") mat_q)
    #{  Torch::mxTriEig(  $a  ,$b  ,$mat_q);  #} 
    ())


(de torch_mxSymEig  (  mat_a mat_q out )
    
    ((-gptr- "Torch::Mat *") mat_a)
    ((-gptr- "Torch::Mat *") mat_q)
    ((-gptr- "Torch::Vec *") out)
    #{  Torch::mxSymEig(  $mat_a  ,$mat_q  ,$out);  #} 
    ())


(de torch_mxPermInv  (  px out )
    
    ((-gptr- "Torch::Perm *") px)
    ((-gptr- "Torch::Perm *") out)
    #{  Torch::mxPermInv(  $px  ,$out);  #} 
    ())


(de torch_mxPermMulPerm  (  px1 px2 out )
    
    ((-gptr- "Torch::Perm *") px1)
    ((-gptr- "Torch::Perm *") px2)
    ((-gptr- "Torch::Perm *") out)
    #{  Torch::mxPermMulPerm(  $px1  ,$px2  ,$out);  #} 
    ())


(de torch_mxPermVec  (  px vec out )
    
    ((-gptr- "Torch::Perm *") px)
    ((-gptr- "Torch::Vec *") vec)
    ((-gptr- "Torch::Vec *") out)
    #{  Torch::mxPermVec(  $px  ,$vec  ,$out);  #} 
    ())


(de torch_mxPermInvVec  (  px x out )
    
    ((-gptr- "Torch::Perm *") px)
    ((-gptr- "Torch::Vec *") x)
    ((-gptr- "Torch::Vec *") out)
    #{  Torch::mxPermInvVec(  $px  ,$x  ,$out);  #} 
    ())


(de torch_mxTrPerm  (  px i1 i2 )
    
    ((-gptr- "Torch::Perm *") px)
    ((-int-) i1)
    ((-int-) i2)
    #{  Torch::mxTrPerm(  $px  ,$i1  ,$i2);  #} 
    ())


(de torch_mxPermColsMat  (  px mat out )
    
    ((-gptr- "Torch::Perm *") px)
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mxPermColsMat(  $px  ,$mat  ,$out);  #} 
    ())


(de torch_mxPermRowsMat  (  px mat out )
    
    ((-gptr- "Torch::Perm *") px)
    ((-gptr- "Torch::Mat *") mat)
    ((-gptr- "Torch::Mat *") out)
    #{  Torch::mxPermRowsMat(  $px  ,$mat  ,$out);  #} 
    ())

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

(dhc-make-with-c++ () (list torch-libtorch) 
  dummy_matrix
  torch_mxmataddmat
  torch_mxmatsubmat
  torch_mxmatmulmat
  torch_mxmatmultrmat
  torch_mxtrmatmulmat
  torch_mxmatmulvec
  torch_mxrealmulmat
  torch_mxvecmulmat
  torch_mxtrmat
  torch_mxswaprowsmat
  torch_mxswapcolsmat
  torch_mxmataddrealmulmat
  torch_mxvecaddrealmulmatmulvec
  torch_mxvecaddrealmulvecmulmat
  torch_mx_givens
  torch_mx_rot_vec
  torch_mx_rot_rows
  torch_mx_rot_cols
  torch_mxhfactor
  torch_mxmakehq
  torch_mxmakeh
  torch_mxhhvec
  torch_mxhhtrvec
  torch_mxhhtrrows
  torch_mxhhtrcols
  torch_mxip__
  torch_mxrealmuladd__
  torch_mxrealmul__
  torch_mxadd__
  torch_mxsub__
  torch_mxzero__
  torch_mxlufactor
  torch_mxlusolve
  torch_mxlutsolve
  torch_mxinverse
  torch_mxsolve
  torch_mxusolve
  torch_mxlsolve
  torch_mxutsolve
  torch_mxdsolve
  torch_mxltsolve
  torch_mxtrieig
  torch_mxsymeig
  torch_mxperminv
  torch_mxpermmulperm
  torch_mxpermvec
  torch_mxperminvvec
  torch_mxtrperm
  torch_mxpermcolsmat
  torch_mxpermrowsmat
)
