;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; 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")



#? *** level0

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

#? * torch_allocator
;;.TYPE CLASS
#? (==> <torch_allocator> attach_cpp_object <s>)
#? (==> <torch_allocator> get_ptrs)
#? (==> <torch_allocator> set_ptrs <s>)
#? (new torch_allocator <flag>>
#? (==> <torch_allocator> alloc <size> <object_style>)
#? (==> <torch_allocator> realloc <ptr> <size>)
#? (==> <torch_allocator> free <ptr>)
#? (==> <torch_allocator> retain <ptr> <object_style>)
#? (==> <torch_allocator> release <ptr>)
#? (==> <torch_allocator> steal_2 <ptr> <allocator>)
#? (==> <torch_allocator> steal_1 <allocator>)
#? (==> <torch_allocator> ismine <ptr>)
#? (==> <torch_allocator> freeall)
#? (==> <torch_allocator> sysalloc <size>)
#? (==> <torch_allocator> sysrealloc <ptr> <size>)
#? (==> <torch_allocator> -destructor)

#? * torch_object
;;.TYPE CLASS
#? (==> <torch_object> get_n_options)
#? (==> <torch_object> set_n_options <s>)
#? (==> <torch_object> get_options)
#? (==> <torch_object> set_options <s>)
#? (==> <torch_object> get_allocator)
#? (==> <torch_object> set_allocator <s>)
#? (new torch_object <flag>>
#? (==> <torch_object> attach_cpp_object <s>)
#? (==> <torch_object> addoption <name> <size> <ptr> <help>)
#? (==> <torch_object> addioption <name> <ptr> <init_value> <help>)
#? (==> <torch_object> addroption <name> <ptr> <init_value> <help>)
#? (==> <torch_object> addboption <name> <ptr> <init_value> <help>)
#? (==> <torch_object> addooption <name> <ptr> <init_value> <help>)
#? (==> <torch_object> setoption <name> <ptr>)
#? (==> <torch_object> setioption <name> <option>)
#? (==> <torch_object> setroption <name> <option>)
#? (==> <torch_object> setboption <name> <option>)
#? (==> <torch_object> setooption <name> <option>)
#? (==> <torch_object> loadxfile <file>)
#? (==> <torch_object> savexfile <file>)
#? (==> <torch_object> load <filename>)
#? (==> <torch_object> save <filename>)
#? (==> <torch_object> -destructor)

#? * torch_random
;;.TYPE CLASS
#? (new torch_random>
#? (==> <torch_random> -destructor)
#? (==> <torch_random> get_the_initial_seed)
#? (==> <torch_random> set_the_initial_seed <s>)
#? (==> <torch_random> get_n)
#? (==> <torch_random> set_n <s>)
#? (==> <torch_random> get_m)
#? (==> <torch_random> set_m <s>)
#? (==> <torch_random> get_state)
#? (==> <torch_random> set_state <s>)
#? (==> <torch_random> get_left)
#? (==> <torch_random> set_left <s>)
#? (==> <torch_random> get_initf)
#? (==> <torch_random> set_initf <s>)
#? (==> <torch_random> get_next)
#? (==> <torch_random> set_next <s>)
#? (==> <torch_random> get_normal_x)
#? (==> <torch_random> set_normal_x <s>)
#? (==> <torch_random> get_normal_y)
#? (==> <torch_random> set_normal_y <s>)
#? (==> <torch_random> get_normal_rho)
#? (==> <torch_random> set_normal_rho <s>)
#? (==> <torch_random> get_normal_is_valid)
#? (==> <torch_random> set_normal_is_valid <s>)
#? (==> <torch_random> nextstate)
#? (==> <torch_random> seed)
#? (==> <torch_random> manualseed <the_seed_>)
#? (==> <torch_random> getinitialseed)
#? (==> <torch_random> random)
#? (==> <torch_random> uniform)
#? (==> <torch_random> getshuffledindices <indices> <n_indices>)
#? (==> <torch_random> shuffle <tabular> <size_elem> <n_elems>)
#? (==> <torch_random> boundeduniform <a> <b>)
#? (==> <torch_random> normal <mean> <stdv>)
#? (==> <torch_random> exponential <lambda>)
#? (==> <torch_random> cauchy <median> <sigma>)
#? (==> <torch_random> lognormal <mean> <stdv>)
#? (==> <torch_random> geometric <p>)
#? (==> <torch_random> bernouilli <p>)

#? * (dummy_level0)

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

;;class Allocator

(defclass  torch_Allocator object
  ((-gptr-) p)
  ((-bool-) shell_flag))

(defmethod torch_Allocator  attach_cpp_object ( s )
  ((-gptr-) s)
  #{ $p = $s ; #}
  ())

(defmethod  torch_Allocator  get_ptrs ()
  
  (gptr #{ ((Torch::Allocator *)$p)->ptrs   #} ))        ;; AllocatorNode *  -> gptr

(defmethod  torch_Allocator  set_ptrs (s )
  
  ((-gptr- "Torch::AllocatorNode *") s)
  #{ ((Torch::Allocator *)$p)->ptrs = $s;  #} 
  ())

(defmethod  torch_Allocator  torch_Allocator ( flag )
  ((-bool-) flag)
  
  #{ if($flag == false) {
            $shell_flag = false;
            $p = new Torch::Allocator(); 
     }
     else 
            $shell_flag = true; 
  #} 
  ())

(defmethod  torch_Allocator  alloc (size  object_style )
  
  ((-int-) size)   ;; size_t -> int
  ((-int-) object_style)  
  (gptr #{ ((Torch::Allocator *)$p)->alloc($size  ,$object_style)  #} ))        ;; void *  -> gptr

(defmethod  torch_Allocator  realloc (ptr  size )
  
  ((-gptr-) ptr)  
  ((-int-) size)   ;; size_t -> int 
  (gptr #{ ((Torch::Allocator *)$p)->realloc($ptr  ,$size)  #} ))        ;; void *  -> gptr

(defmethod  torch_Allocator  free (ptr )
  
  ((-gptr-) ptr)  
  #{ ((Torch::Allocator *)$p)->free($ptr)  ; #} 
  ())

(defmethod  torch_Allocator  retain (ptr  object_style )
  
  ((-gptr-) ptr)  
  ((-int-) object_style)  
  #{ ((Torch::Allocator *)$p)->retain($ptr  ,$object_style)  ; #} 
  ())

(defmethod  torch_Allocator  release (ptr )
  
  ((-gptr-) ptr)  
  (int #{ ((Torch::Allocator *)$p)->release($ptr)  #} ))

(defmethod  torch_Allocator  steal_2 (ptr  allocator )
  
  ((-gptr-) ptr)  
  ((-gptr- "Torch::Allocator *") allocator)  
  #{ ((Torch::Allocator *)$p)->steal($ptr  ,$allocator)  ; #} 
  ())

(defmethod  torch_Allocator  steal_1 (allocator )
  
  ((-gptr- "Torch::Allocator *") allocator)  
  #{ ((Torch::Allocator *)$p)->steal($allocator)  ; #} 
  ())

(defmethod  torch_Allocator  isMine (ptr )
  
  ((-gptr-) ptr)  
  (gptr #{ ((Torch::Allocator *)$p)->isMine($ptr)  #} ))        ;; AllocatorNode *  -> gptr

(defmethod  torch_Allocator  freeAll ()
  
  #{ ((Torch::Allocator *)$p)->freeAll()  ; #} 
  ())

(defmethod  torch_Allocator  sysAlloc (size )
  
  ((-int-) size)  
  (gptr #{ Torch::Allocator::sysAlloc($size)  #} ))        ;; void *  -> gptr

(defmethod  torch_Allocator  sysRealloc (ptr  size )
  
  ((-gptr-) ptr)  
  ((-int-) size)  
  (gptr #{ Torch::Allocator::sysRealloc($ptr  ,$size)  #} ))        ;; void *  -> gptr

(defmethod  torch_Allocator  -destructor ()
  
 #{  if( $shell_flag == false ) {
             delete  ((Torch::Allocator *)$p);  
             $p = NULL; 
             $shell_flag = true; 
     }
  #} 
  ())




;;class Object
(defclass torch_Object  object 
  ((-gptr-) p)
  ((-bool-) shell_flag))

(defmethod  torch_Object  get_n_options ()
  
  (int #{ ((Torch::Object *)$p)->n_options   #} ))

(defmethod  torch_Object  set_n_options (s )
  
  ((-int-) s)  
  #{ ((Torch::Object *)$p)->n_options = $s  ; #} 
  ())

(defmethod  torch_Object  get_options ()
  
  (gptr #{ ((Torch::Object *)$p)->options   #} ))        ;; Option *  -> gptr

(defmethod  torch_Object  set_options (s )
  
  ((-gptr- "Torch::Option *") s)  
  #{ ((Torch::Object *)$p)->options = $s  ; #} 
  ())

(defmethod  torch_Object  get_allocator ()
  
  (gptr #{ ((Torch::Object *)$p)->allocator   #} ))        ;; Allocator *  -> gptr

(defmethod  torch_Object  set_allocator (s )
  
  ((-gptr- "Torch::Allocator *") s)  
  #{ ((Torch::Object *)$p)->allocator = $s  ; #} 
  ())

(defmethod  torch_Object  torch_Object ( flag )
  ((-bool-) flag)
  
  #{ if($flag == false) {
            $p = new Torch::Object(); 
            $shell_flag = false;
     }
     else 
            $shell_flag = true; 
  #} 
  ())

(defmethod torch_Object  attach_cpp_object ( s )
  ((-gptr-) s)
  (if (= shell_flag ())
      (error "there's a C++ object attached already. call failed.")
    (setq shell_flag ())
    #{ $p = $s; #})
  ())

(defmethod  torch_Object  addOption (name  size  ptr  help )
  
  ((-str-) name)  
  ((-int-) size)  
  ((-gptr-) ptr)  
  ((-str-) help)  
  #{ ((Torch::Object *)$p)->addOption((const char *)$name->data  ,$size  ,$ptr  ,(const char *)$help->data)  ; #} 
  ())

(defmethod  torch_Object  addIOption (name  ptr  init_value  help )
  
  ((-str-) name)  
  ((-gptr- "int *") ptr)  
  ((-int-) init_value)  
  ((-str-) help)  
  #{ ((Torch::Object *)$p)->addIOption((const char *)$name->data ,$ptr  ,$init_value  ,(const char *)$help->data)  ; #} 
  ())

(defmethod  torch_Object  addROption (name  ptr  init_value  help )
  
  ((-str-) name)  
  ((-gptr- "double *") ptr)  
  ((-double-) init_value)  
  ((-str-) help)  
  #{ ((Torch::Object *)$p)->addROption((const char *)$name->data  ,$ptr  ,$init_value  ,(const char *)$help->data)  ; #} 
  ())

(defmethod  torch_Object  addBOption (name  ptr  init_value  help )
  
  ((-str-) name)  
  ((-gptr- "bool *") ptr)  
  ((-bool-) init_value)  
  ((-str-) help)  
  #{ ((Torch::Object *)$p)->addBOption((const char *)$name->data  ,$ptr  ,$init_value  ,(const char *)$help->data)  ; #} 
  ())

(defmethod  torch_Object  addOOption (name  ptr  init_value  help )
  
  ((-str-) name)  
  ((-gptr- "Torch::Object **") ptr)  
  ((-gptr- "Torch::Object *") init_value)  
  ((-str-) help)  
  #{ ((Torch::Object *)$p)->addOOption((const char *)$name->data ,$ptr  ,$init_value  ,(const char *)$help->data)  ; #} 
  ())

(defmethod  torch_Object  setOption (name  ptr )
  
  ((-str-) name)  
  ((-gptr-) ptr)  
  #{ ((Torch::Object *)$p)->setOption((const char *)$name->data  ,$ptr)  ; #} 
  ())

(defmethod  torch_Object  setIOption (name  option )
  
  ((-str-) name)  
  ((-int-) option)  
  #{ ((Torch::Object *)$p)->setIOption((const char *)$name->data,$option)  ; #} 
  ())

(defmethod  torch_Object  setROption (name  option )
  
  ((-str-) name)  
  ((-double-) option)  
  #{ ((Torch::Object *)$p)->setROption((const char *)$name->data,$option)  ; #} 
  ())

(defmethod  torch_Object  setBOption (name  option )
  
  ((-str-) name)  
  ((-bool-) option)  
  #{ ((Torch::Object *)$p)->setBOption((const char *)$name->data,$option)  ; #} 
  ())

(defmethod  torch_Object  setOOption (name  option )
  
  ((-str-) name)  
  ((-gptr- "Torch::Object *") option)  
  #{ ((Torch::Object *)$p)->setOOption((const char *)$name->data,$option)  ; #} 
  ())

(defmethod  torch_Object  loadXFile (file )
  
  ((-gptr- "Torch::XFile *") file)  
  #{ ((Torch::Object *)$p)->loadXFile($file)  ; #} 
  ())

(defmethod  torch_Object  saveXFile (file )
  
  ((-gptr- "Torch::XFile *") file)  
  #{ ((Torch::Object *)$p)->saveXFile($file)  ; #} 
  ())

(defmethod  torch_Object  load (filename )
  
  ((-str-) filename)  
  #{ ((Torch::Object *)$p)->load((const char *)$filename->data)  ; #} 
  ())

(defmethod  torch_Object  save (filename )
  
  ((-str-) filename)  
  #{ ((Torch::Object *)$p)->save((const char *)$filename->data)  ; #} 
  ())

(defmethod  torch_Object  -destructor ()
  
  #{ 
       if ( $shell_flag == false )  {
            delete  ((Torch::Object *)$p);
            $p = NULL;
            $shell_flag = true; 
       }
  #} 
  ())


;;class Random
(defclass  torch_Random object)

(defmethod  torch_Random torch_Random ()
  ())

(defmethod  torch_Random -destructor ()
  ())

(defmethod  torch_Random  get_the_initial_seed ()
  
  (int #{ Torch::Random::the_initial_seed   #} ))  ;; unsigned long -> int

(defmethod  torch_Random  set_the_initial_seed (s )
  
  ((-int-) s)  
  #{ Torch::Random::the_initial_seed = $s  ; #} 
  ())

(defmethod  torch_Random  get_n ()
  
  (int #{ Torch::Random::n   #} ))


(defmethod  torch_Random  get_m ()
  
  (int #{ Torch::Random::m   #} ))


(defmethod  torch_Random  get_state ()
  
  (gptr #{ Torch::Random::state   #} ))        ;; unsigned long *  -> gptr

(defmethod  torch_Random  set_state ( ind s )
  
  ((-int-) ind)
  ((-int-) s)          ;; unsigned long -> int
  #{ Torch::Random::state[$ind] = $s; #} 
  ())

(defmethod  torch_Random  get_left ()
  
  (int #{ Torch::Random::left   #} ))

(defmethod  torch_Random  set_left (s )
  
  ((-int-) s)  
  #{ Torch::Random::left = $s  ; #} 
  ())

(defmethod  torch_Random  get_initf ()
  
  (int #{ Torch::Random::initf   #} ))

(defmethod  torch_Random  set_initf (s )
  
  ((-int-) s)  
  #{ Torch::Random::initf = $s  ; #} 
  ())

(defmethod  torch_Random  get_next ()
  
  (gptr #{ Torch::Random::next   #} ))        ;; unsigned long *  -> gptr

(defmethod  torch_Random  set_next (s )
  
  ((-gptr- "unsigned long *") s)  
  #{ Torch::Random::next = $s  ; #} 
  ())

(defmethod  torch_Random  get_normal_x ()
  
  (double #{ Torch::Random::normal_x   #} ))

(defmethod  torch_Random  set_normal_x (s )
  
  ((-double-) s)  
  #{ Torch::Random::normal_x = $s  ; #} 
  ())

(defmethod  torch_Random  get_normal_y ()
  
  (double #{ Torch::Random::normal_y   #} ))

(defmethod  torch_Random  set_normal_y (s )
  
  ((-double-) s)  
  #{ Torch::Random::normal_y = $s  ; #} 
  ())

(defmethod  torch_Random  get_normal_rho ()
  
  (double #{ Torch::Random::normal_rho   #} ))

(defmethod  torch_Random  set_normal_rho (s )
  
  ((-double-) s)  
  #{ Torch::Random::normal_rho = $s  ; #} 
  ())

(defmethod  torch_Random  get_normal_is_valid ()
  
  (bool #{ Torch::Random::normal_is_valid   #} ))

(defmethod  torch_Random  set_normal_is_valid (s )
  
  ((-bool-) s)  
  #{ Torch::Random::normal_is_valid = $s  ; #} 
  ())

(defmethod  torch_Random  nextState ()
  
  #{ Torch::Random::nextState()  ; #} 
  ())

(defmethod  torch_Random  seed ()
  
  #{ Torch::Random::seed()  ; #} 
  ())

(defmethod  torch_Random  manualSeed (the_seed_ )
  
  ((-int-) the_seed_)      ;; unsigned long -> int
  #{ Torch::Random::manualSeed($the_seed_)  ; #} 
  ())

(defmethod  torch_Random  getInitialSeed ()
  
  (int #{ Torch::Random::getInitialSeed()  #} ))    ;; unsigned long -> int

(defmethod  torch_Random  random ()
  
  (int #{ Torch::Random::random()  #} ))      ;; unsigned long -> int

(defmethod  torch_Random  uniform ()
  
  (double #{ Torch::Random::uniform()  #} ))

(defmethod  torch_Random  getShuffledIndices (indices  n_indices )
  
  ((-gptr- "int *") indices)  
  ((-int-) n_indices)  
  #{ Torch::Random::getShuffledIndices($indices  ,$n_indices)  ; #} 
  ())

(defmethod  torch_Random  shuffle (tabular  size_elem  n_elems )
  
  ((-gptr-) tabular)  
  ((-int-) size_elem)  
  ((-int-) n_elems)  
  #{ Torch::Random::shuffle($tabular  ,$size_elem  ,$n_elems)  ; #} 
  ())

(defmethod  torch_Random  boundedUniform (a  b )
  
  ((-double-) a)  
  ((-double-) b)  
  (double #{ Torch::Random::boundedUniform($a  ,$b)  #} ))

(defmethod  torch_Random  normal (mean  stdv )
  
  ((-double-) mean)  
  ((-double-) stdv)  
  (double #{ Torch::Random::normal($mean  ,$stdv)  #} ))

(defmethod  torch_Random  exponential (lambda )
  
  ((-double-) lambda)  
  (double #{ Torch::Random::exponential($lambda)  #} ))

(defmethod  torch_Random  cauchy (median  sigma )
  
  ((-double-) median)  
  ((-double-) sigma)  
  (double #{ Torch::Random::cauchy($median  ,$sigma)  #} ))

(defmethod  torch_Random  logNormal (mean  stdv )
  
  ((-double-) mean)  
  ((-double-) stdv)  
  (double #{ Torch::Random::logNormal($mean  ,$stdv)  #} ))

(defmethod  torch_Random  geometric (p )
  
  ((-double-) p)  
  (int #{ Torch::Random::geometric($p)  #} ))

(defmethod  torch_Random  bernouilli (p )
  
  ((-double-) p)  
  (bool #{ Torch::Random::bernouilli($p)  #} ))


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

(dhc-make-with-c++ () (list torch-libtorch) 
  dummy_level0
  (torch_allocator  -destructor  sysrealloc  sysalloc  freeall  ismine  steal_1  steal_2  release  retain  free  realloc  alloc  torch_allocator  set_ptrs  get_ptrs  attach_cpp_object)
  (torch_object  -destructor save  load  savexfile  loadxfile  setooption  setboption  setroption  setioption  setoption  addooption  addboption  addroption  addioption  addoption  attach_cpp_object  torch_object  set_allocator  get_allocator  set_options  get_options  set_n_options  get_n_options)
  (torch_random  bernouilli  geometric  lognormal  cauchy  exponential  normal  boundeduniform  shuffle  getshuffledindices  uniform  random  getinitialseed  manualseed  seed  nextstate  set_normal_is_valid  get_normal_is_valid  set_normal_rho  get_normal_rho  set_normal_y  get_normal_y  set_normal_x  get_normal_x  set_next  get_next  set_initf  get_initf  set_left  get_left  set_state  get_state  get_m  get_n  set_the_initial_seed  get_the_initial_seed  -destructor  torch_random)
)
