text stringlengths 0 601k |
|---|
module ArrayLike ( A : ArrayBaseOps ) = struct include A let make n x = let a = create n in for i = 0 to n - 1 do set a i x done ; a let copy a = let n = length a in let b = create n in for i = 0 to n - 1 do set b i ( get a i ) done ; b let fold_right f a x = let rec go x i = if i < 0 then x else go ( f ( get a i ) x )... |
module Roots = struct open Bigarray type t = ( int32 , int32_elt , c_layout ) Array1 . t type r = | NoRoot | Rising | Falling let root_of_int32 = function | 1l -> Rising | - 1l -> Falling | 0l -> NoRoot | n -> failwith ( Printf . sprintf " Roots . root_of_int32 : invalid root event % ld " n ) let int32_of_root x = matc... |
module RootDirs = struct open Bigarray type t = ( int32 , int32_elt , c_layout ) Array1 . t type d = | Increasing | Decreasing | IncreasingOrDecreasing let int32_of_rootdir x = match x with | Increasing -> 1l | Decreasing -> - 1l | IncreasingOrDecreasing -> 0l let rootdir_of_int32 x = match x with | 1l -> Increasing | ... |
module Constraint = struct let unconstrained = 0 . 0 let geq_zero = 1 . 0 let leq_zero = - 1 . 0 let gt_zero = 2 . 0 let lt_zero = - 2 . 0 type t = | Unconstrained | GeqZero | LeqZero | GtZero | LtZero let of_float = function | 0 . 0 -> Unconstrained | 1 . 0 -> GeqZero | - 1 . 0 -> LeqZero | 2 . 0 -> GtZero | - 2 . 0 -... |
module Util = struct type error_details = { error_code : int ; module_name : string ; function_name : string ; error_message : string ; } external format_float : string -> float -> string = " caml_format_float " let floata = format_float " % a " external c_compare_float : float -> float -> float -> int = " sunml_sundia... |
let warn_discarded_exn exn context = Printf . fprintf stderr ( " WARNING : discarding exception % s raised in % s . \ n % s " ) ( Printexc . to_string exn ) context ( Printexc . get_backtrace ( ) ) ; flush stderr |
let ( ) = c_init_module warn_discarded_exn Weak . get [ | RecoverableFailure ; NonPositiveEwt ; Config . NotImplementedBySundialsVersion ] | |
module Vptr : sig type ' a vptr val make : ' a -> ' a vptr val unwrap : ' a vptr -> ' a type ' a vcptr type ' a vptr = ' a * ' a vcptr external make : ' a -> ' a vptr = " sunml_make_vptr " let unwrap ( x , _ ) = x end |
module Callback = struct type ' f cfunptr type ' f cfun = { cptr : ' f cfunptr ; call : ' f ; } let invoke { call ; _ } = call end |
let in_compat_mode2 = match Sundials_configuration . sundials_version with | 2 , _ , _ -> true | _ -> false |
let in_compat_mode2_3 = match Sundials_configuration . sundials_version with | 2 , _ , _ -> true | 3 , _ , _ -> true | _ -> false |
let lt400 = match Sundials_configuration . sundials_version with | 2 , _ , _ -> true | 3 , _ , _ -> true | _ -> false |
let lt500 = let m , _ , _ = Sundials_configuration . sundials_version in m < 5 |
let lt530 = let m , n , _ = Sundials_configuration . sundials_version in m < 5 || ( m = 5 && n < 3 ) |
let lt540 = let m , n , _ = Sundials_configuration . sundials_version in m < 5 || ( m = 5 && n < 4 ) |
let lt580 = let m , n , _ = Sundials_configuration . sundials_version in m < 5 || ( m = 5 && n < 8 ) |
let lt600 = let m , _ , _ = Sundials_configuration . sundials_version in m < 6 |
let has_nvector_get_id = match Sundials_configuration . sundials_version with | 2 , n , _ -> n >= 9 | _ -> true end |
module Logfile = struct type t external c_stderr : unit -> t = " sunml_sundials_stderr " external c_stdout : unit -> t = " sunml_sundials_stdout " external fopen : string -> bool -> t = " sunml_sundials_fopen " let stderr = c_stderr ( ) let stdout = c_stdout ( ) let openfile ( ? trunc = false ) fpath = fopen fpath trun... |
module Profiler = struct type t external make : string -> t = " sunml_profiler_make " end |
module Context = struct type cptr type t = { cptr : cptr ; mutable profiler : Profiler . t option ; } exception ExternalProfilerInUse external c_make : unit -> cptr = " sunml_context_make " external c_set_profiler : cptr -> Profiler . t -> unit = " sunml_context_set_profiler " let set_profiler ( { cptr ; _ } as context... |
type ( ' mat , ' data , ' kind , ' tag ) t = ( ' mat , ' data , ' kind , ' tag ) linear_solver |
type ( ' mat , ' kind , ' tag ) serial_t = ( ' mat , Nvector_serial . data , [ > Nvector_serial . kind ] as ' kind , ' tag ) linear_solver |
type linear_solver_type = LSI . linear_solver_type = | Direct | Iterative | MatrixIterative | MatrixEmbedded |
type linear_solver_id = LSI . linear_solver_id = | Band | Dense | Klu | LapackBand | LapackDense | Pcg | Spbcgs | Spfgmr | Spgmr | Sptfqmr | Superludist | Superlumt | Custom |
type ' d atimesfn = ' d LSI . atimesfn |
type ' d psolvefn = ' d LSI . psolvefn |
module Direct = struct external c_dense : ' k Nvector . serial -> ' k Matrix . dense -> Sundials . Context . t -> ( Matrix . Dense . t , Nvector_serial . data , ' k ) cptr = " sunml_lsolver_dense " let dense ? context nvec mat = let ctx = Sundials_impl . Context . get context in LS { rawptr = c_dense nvec mat ctx ; sol... |
module Iterative = struct include LSI . Iterative external c_set_maxl : ( ' m , ' nd , ' nk ) cptr -> ( ' m , ' nd , ' nk , [ < ` Iter ` | Spbcgs ` | Sptfqmr ` | Pcg ] ) solver_data -> int -> unit = " sunml_lsolver_set_maxl " external c_set_gs_type : ( ' m , ' nd , ' nk ) cptr -> ( ' m , ' nd , ' nk , [ < ` Iter ` | Sp... |
module Custom = struct type ( ' d , ' k ) atimesfn = ( ' d , ' k ) Nvector . t -> ( ' d , ' k ) Nvector . t -> unit type psetupfn = unit -> unit type ( ' d , ' k ) psolvefn = ( ' d , ' k ) Nvector . t -> ( ' d , ' k ) Nvector . t -> float -> bool -> unit type ( ' matrix , ' data , ' kind , ' lsolver ) ops = { solver_ty... |
let get_type ( LS { rawptr } ) = c_get_type rawptr = " sunml_lsolver_get_id " |
let get_id ( LS { rawptr } ) = c_get_id rawptr : ( ' m , ' d , ' k ) cptr -> ( ' d , ' k ) ocaml_callbacks Sundials_impl . Vptr . vptr -> unit = " sunml_lsolver_set_atimes " |
let set_atimes ( LS { rawptr ; ocaml_callbacks } ) fn = ( Sundials_impl . Vptr . unwrap ocaml_callbacks ) . ocaml_atimes <- fn ; c_set_atimes rawptr ocaml_callbacks : ( ' m , ' d , ' k ) cptr -> ( ' d , ' k ) ocaml_callbacks Sundials_impl . Vptr . vptr -> unit = " sunml_lsolver_set_preconditioner " |
let set_preconditioner ( LS { rawptr ; ocaml_callbacks } ) psetupf psolvef = let cb = Sundials_impl . Vptr . unwrap ocaml_callbacks in cb . ocaml_psetup <- psetupf ; cb . ocaml_psolve <- psolvef ; c_set_preconditioner rawptr ocaml_callbacks : ( ' m , ' d , ' k ) cptr -> ( ' d , ' k ) Nvector . t -> ( ' d , ' k ) Nvecto... |
let set_scaling_vectors ( LS { rawptr ; ocaml_callbacks } ) s1 s2 = let cb = Sundials_impl . Vptr . unwrap ocaml_callbacks in cb . scaling_vector1 <- Some s1 ; cb . scaling_vector2 <- Some s2 ; c_set_scaling_vectors rawptr s1 s2 : ( ' m , ' d , ' k ) cptr -> bool -> unit = " sunml_lsolver_set_zero_guess " |
let set_zero_guess ( LS { rawptr ; _ } ) onoff = c_set_zero_guess rawptr onoff = " sunml_lsolver_initialize " |
let init ( LS { rawptr } ) = c_initialize rawptr = " sunml_lsolver_setup " |
let setup ( LS { rawptr } ) = c_setup rawptr ( ' m , ' d , ' k ) cptr -> ( ' a , ' m , ' d , ' k ) Matrix . t -> ( ' d , ' k ) Nvector . t -> ( ' d , ' k ) Nvector . t -> float -> unit = " sunml_lsolver_solve " |
let solve ( LS { rawptr } ) = c_solve rawptr = " sunml_lsolver_iters " |
let get_num_iters ( LS { rawptr } ) = c_iters rawptr = " sunml_lsolver_res_norm " |
let get_res_norm ( LS { rawptr } ) = c_res_norm rawptr = " sunml_lsolver_res_id " |
let get_res_id ( LS { rawptr } ) = c_res_id rawptr = " sunml_lsolver_last_flag " |
let get_last_flag ( LS { rawptr } ) = c_last_flag rawptr = " sunml_lsolver_space " |
let get_work_space ( LS { rawptr } ) = c_space rawptr " sunml_lsolver_init_module " |
let _ = c_init_module [ | InvalidLinearSolver ; UnrecoverableFailure false ; MatrixNotSquare ; MatrixVectorMismatch ; InsufficientStorageUpperBandwidth ; Invalid_argument " " ; ATimesFailure false ; PSetFailure false ; PSolveFailure false ; GSFailure ; QRSolFailure ; VectorOpError ; ResReduced ; ConvFailure ; QRfactFai... |
type linear_solver_type = | Direct | Iterative | MatrixIterative | MatrixEmbedded |
type linear_solver_id = | Band | Dense | Klu | LapackBand | LapackDense | Pcg | Spbcgs | Spfgmr | Spgmr | Sptfqmr | Superludist | Superlumt | Custom |
module Klu = struct type ordering = Amd | ColAmd | Natural type info = { mutable ordering : ordering option ; mutable reinit : int -> int option -> unit ; mutable set_ordering : ordering -> unit ; } let info ( ) = { ordering = None ; reinit = ( fun _ _ -> ( ) ) ; set_ordering = ( fun _ -> ( ) ) ; } |
module Superlumt = struct type ordering = Natural | MinDegreeProd | MinDegreeSum | ColAmd type info = { mutable ordering : ordering option ; mutable set_ordering : ordering -> unit ; num_threads : int ; } let info num_threads = { ordering = None ; set_ordering = ( fun _ -> ( ) ) ; num_threads = num_threads ; } |
module Iterative = struct type gramschmidt_type = | ModifiedGS | ClassicalGS type preconditioning_type = | PrecNone | PrecLeft | PrecRight | PrecBoth type info = { mutable maxl : int ; mutable gs_type : gramschmidt_type option ; mutable max_restarts : int option ; mutable set_maxl : int -> unit ; mutable set_gs_type : ... |
module Custom = struct type ( ' data , ' kind ) atimes_with_data external call_atimes : ( ' data , ' kind ) atimes_with_data -> ( ' data , ' kind ) Nvector . t -> ( ' data , ' kind ) Nvector . t -> unit = " sunml_lsolver_call_atimes " type ( ' data , ' kind ) precond_with_data external call_psetup : ( ' data , ' kind )... |
type ( ' m , ' nd , ' nk ) cptr |
type ( _ , ' nd , ' nk , _ ) solver_data = | Spbcgs : ( ' m , ' nd , ' nk , [ ` > Spbcgs ] ) solver_data | Spfgmr : ( ' m , ' nd , ' nk , [ ` > Spfgmr ] ) solver_data | Spgmr : ( ' m , ' nd , ' nk , [ ` > Spgmr ] ) solver_data | Sptfqmr : ( ' m , ' nd , ' nk , [ ` > Sptfqmr ] ) solver_data | Pcg : ( ' m , ' nd , ' nk ,... |
type ' d atimesfn = ' d -> ' d -> unit |
type psetupfn = unit -> unit |
type ' d psolvefn = ' d -> ' d -> float -> bool -> unit |
type ( ' d , ' k ) ocaml_callbacks = { mutable ocaml_atimes : ' d atimesfn ; mutable ocaml_psetup : psetupfn ; mutable ocaml_psolve : ' d psolvefn ; mutable scaling_vector1 : ( ' d , ' k ) Nvector . t option ; mutable scaling_vector2 : ( ' d , ' k ) Nvector . t option ; } |
type ( ' m , ' mk , ' nd , ' nk , ' t ) linear_solver_data = { rawptr : ( ' m , ' nd , ' nk ) cptr ; solver : ( ' m , ' nd , ' nk , ' t ) solver_data ; matrix : ( ' mk , ' m , ' nd , ' nk ) Matrix . t option ; compat : Iterative . info ; context : Sundials . Context . t ; mutable check_prec_type : Iterative . precondit... |
let empty_ocaml_callbacks ( ) = Sundials_impl . Vptr . make ( { ocaml_atimes = ( fun _ _ -> failwith " internal error : ocaml_atimes " ) ; ocaml_psetup = ( fun _ -> failwith " internal error : ocaml_psetup " ) ; ocaml_psolve = ( fun _ _ _ _ -> failwith " internal error : ocaml_psolve " ) ; scaling_vector1 = None ; scal... |
type ( ' m , ' nd , ' nk , ' t ) linear_solver = LS : ( ' m , ' mk , ' nd , ' nk , ' t ) linear_solver_data -> ( ' m , ' nd , ' nk , ' t ) linear_solver |
type held_linear_solver = | HLS : ( ' m , ' mk , ' nd , ' nk , ' t ) linear_solver_data -> held_linear_solver | NoHLS : held_linear_solver |
type ( ' nd , ' nk ) solver = S : ( ' m , ' nd , ' nk , ' t ) solver_data -> ( ' nd , ' nk ) solver |
let attach ( LS ( { attached } as s ) ) = if attached then raise LinearSolverInUse ; s . attached <- true : ( ' m , ' nd , ' nk ) cptr -> ( ' m , ' nd , ' nk , ' t ) solver_data -> Iterative . preconditioning_type -> bool -> unit = " sunml_lsolver_set_prec_type " |
let impl_set_prec_type ( type t ) rawptr solver prec_type docheck = match ( solver : ( ' m , ' nd , ' nk , t ) solver_data ) with | Custom ( ldata , { Custom . set_prec_type = f } ) -> f ldata prec_type | _ -> c_set_prec_type rawptr solver prec_type docheck : linear_solver_type -> ( ' t * ( ' m , ' nd , ' nk , ' t ) Cu... |
type t = ( int , int_elt , c_layout ) Array1 . t |
let create = Array1 . create int c_layout |
let make n x = let v = create n in Array1 . fill v x ; v |
let empty = create 0 |
let pp fmt a = Format . pp_print_string fmt " [ " ; Format . pp_open_hovbox fmt 0 ; for i = 0 to Array1 . dim a - 1 do if i > 0 then ( Format . pp_print_string fmt " ; " ; Format . pp_print_space fmt ( ) ; ) ; Format . fprintf fmt " % 6d " a . { i } done ; Format . pp_close_box fmt ( ) ; Format . pp_print_string fmt " ... |
let ppi ( ? start " [ " ) = ( ? stop " ] " ) = ( ? sep " ; " ) = ( ? item = fun fmt -> Format . fprintf fmt " % 2d =% 6d " ) ( ) fmt a = Format . pp_print_string fmt start ; Format . pp_open_hovbox fmt 0 ; for i = 0 to Array1 . dim a - 1 do if i > 0 then ( Format . pp_print_string fmt sep ; Format . pp_print_space fmt ... |
let check_valid = match Config . sundials_version with | 2 , _ , _ -> Sundials_configuration . safe | _ -> false |
type [ @ warning " - 69 " ] ( ' data , ' cptr ) matrix_content = { mutable payload : ' data ; rawptr : ' cptr ; mutable valid : bool ; } |
type ( ' m , ' d ) matrix_ops = { m_clone : ' m -> ' m ; m_zero : ' m -> unit ; m_copy : ' m -> ' m -> unit ; m_scale_add : float -> ' m -> ' m -> unit ; m_scale_addi : float -> ' m -> unit ; m_matvec_setup : ( ' m -> unit ) option ; m_matvec : ' m -> ' d -> ' d -> unit ; m_space : ' m -> int * int ; } |
module Dense = struct type data = RealArray2 . data type cptr type t = ( data , cptr ) matrix_content external c_create : int -> int -> t = " sunml_matrix_dense_create " let create i j = if Sundials_configuration . safe then begin if i <= 0 then invalid_arg " i " ; if j <= 0 then invalid_arg " j " end ; c_create i j le... |
module Band = struct type dimensions = { n : int ; mu : int ; smu : int ; ml : int ; } type data = { data : RealArray2 . data ; dims : dimensions ; } type cptr type t = ( data , cptr ) matrix_content external c_create : dimensions -> t = " sunml_matrix_band_create " let create ( { n ; smu ; ml ; _ } as dimensions ) = i... |
module Sparse = struct type csc type csr type _ sformat = | CSC : csc sformat | CSR : csr sformat let unsafe_content = match Config . sundials_version with | 2 , _ , _ -> true | _ -> false type index_array = ( Index . t , Index . index_elt , Bigarray . c_layout ) Bigarray . Array1 . t type ' s data = { idxvals : index_... |
module ArrayDense = struct type t = RealArray2 . t let make = RealArray2 . make let create = RealArray2 . create let size = RealArray2 . size let pp = RealArray2 . pp let unwrap = RealArray2 . unwrap let get = RealArray2 . get let set = RealArray2 . set let update a i j f = set a i j ( f ( get a i j ) ) let set_to_zero... |
module ArrayBand = struct type smu = int type mu = int type ml = int type t = RealArray2 . t * ( smu * mu * ml ) let make ( ( smu , _ , ml ) as dims ) n v = ( RealArray2 . make ( smu + ml + 1 ) n v , dims ) let create ( ( smu , _ , ml ) as dims ) n = ( RealArray2 . create ( smu + ml + 1 ) n , dims ) let size ( a , _ ) ... |
type ( _ , _ , _ , _ ) id = | Dense : ( standard , Dense . t , Nvector_serial . data , [ > Nvector_serial . kind ] ) id | Band : ( standard , Band . t , Nvector_serial . data , [ > Nvector_serial . kind ] ) id | Sparse : ( standard , ' s Sparse . t , Nvector_serial . data , [ > Nvector_serial . kind ] ) id | Custom : (... |
type [ @ warning " - 69 " ] ( ' k , ' m , ' nd , ' nk ) t = { payload : ' m ; rawptr : cmat ; context : Context . t ; id : ( ' k , ' m , ' nd , ' nk ) id ; mat_ops : ( ' m , ' nd ) matrix_ops ; } |
type ' nk dense = ( standard , Dense . t , Nvector_serial . data , [ > Nvector_serial . kind ] as ' nk ) t |
type ' nk band = ( standard , Band . t , Nvector_serial . data , [ > Nvector_serial . kind ] as ' nk ) t |
type ( ' s , ' nk ) sparse = ( standard , ' s Sparse . t , Nvector_serial . data , [ > Nvector_serial . kind ] as ' nk ) t |
type ' nk arraydense = ( custom , ArrayDense . t , RealArray . t , ' nk ) t |
type ' nk arrayband = ( custom , ArrayBand . t , RealArray . t , ' nk ) t ( ' k , ' m , ' nd , ' nk ) id -> ' content_cptr -> ' m -> bool -> Context . t -> cmat = " sunml_matrix_wrap " |
let wrap_dense ? context ( data : Dense . t ) = let ctx = Sundials_impl . Context . get context in { payload = data ; rawptr = c_wrap Dense data . rawptr data false ctx ; context = ctx ; id = Dense ; mat_ops = Dense . ops ; } |
let dense ? context ? m ( ? i = 0 . 0 ) n = let m = match m with Some m -> m | None -> n in wrap_dense ? context ( Dense . make m n i ) |
let wrap_band ? context ( data : Band . t ) = let ctx = Sundials_impl . Context . get context in { payload = data ; rawptr = c_wrap Band data . rawptr data false ctx ; context = ctx ; id = Band ; mat_ops = Band . ops ; } |
let band ? context ( ? mu = 2 ) ? smu ? ml ( ? i = 0 . 0 ) n = let ml = match ml with Some ml -> ml | None -> mu in let smu = match smu with Some smu -> smu | None -> mu + ml in wrap_band ? context ( Band . ( make { n ; mu ; smu ; ml } i ) ) |
let wrap_sparse ? context ( data : ' f Sparse . t ) = ( match Config . sundials_version with | ( 2 , v , _ ) when v < 6 -> raise Config . NotImplementedBySundialsVersion | _ -> ( ) ) ; let ctx = Sundials_impl . Context . get context in { payload = data ; rawptr = c_wrap Sparse data . rawptr data false ctx ; context = c... |
let sparse_csc ? context ? m ? nnz n = let m = match m with Some m -> m | None -> n in let nnz = match nnz with Some nnz -> nnz | None -> n / 10 in wrap_sparse ? context Sparse . ( make CSC m n nnz ) |
let sparse_csr ? context ? m ? nnz n = let m = match m with Some m -> m | None -> n in let nnz = match nnz with Some nnz -> nnz | None -> n / 10 in wrap_sparse ? context Sparse . ( make CSR m n nnz ) |
let wrap_custom ops ? context data = let ctx = Sundials_impl . Context . get context in { payload = data ; rawptr = c_wrap Custom ops data ( ops . m_matvec_setup <> None ) ctx ; context = ctx ; id = Custom ; mat_ops = ops ; } |
let wrap_arraydense ? context data = let ctx = Sundials_impl . Context . get context in { payload = data ; rawptr = c_wrap ArrayDense ArrayDense . ops data false ctx ; context = ctx ; id = ArrayDense ; mat_ops = ArrayDense . ops ; } |
let arraydense ? context ? m ( ? i = 0 . 0 ) n = let m = match m with Some m -> m | None -> n in wrap_arraydense ? context ( ArrayDense . make m n i ) |
let wrap_arrayband ? context data = let ctx = Sundials_impl . Context . get context in { payload = data ; rawptr = c_wrap ArrayBand ArrayBand . ops data false ctx ; context = ctx ; id = ArrayBand ; mat_ops = ArrayBand . ops ; } |
let arrayband ? context ? mu ? smu ? ml ( ? i = 0 . 0 ) n = let mu = match mu , smu with | None , None -> 2 | Some mu , _ -> mu | _ , Some smu -> smu in let ml = match ml with Some ml -> ml | None -> mu in let smu = match smu with Some smu -> smu | None -> mu + ml in wrap_arrayband ? context ( ArrayBand . make ( smu , ... |
let get_ops { mat_ops } = mat_ops |
let get_id { id } = id |
let unwrap { payload } = payload : float -> ( ' k , ' m , ' nd , ' nk ) t -> ( ' k , ' m , ' nd , ' nk ) t -> unit = " sunml_matrix_scale_add " |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.