text stringlengths 0 601k |
|---|
let print_roots vs = Sundials . Roots . iter ( fun x -> Printf . printf " \ t % s " ( string_of_root x ) ) vs ; print_newline ( ) |
let f _ y yd = yd . { 0 } <- cos ( y . { 1 } ) ; yd . { 1 } <- 1 . 0 ; yd . { 2 } <- 0 . 0 |
let g _ y gout = gout . { 0 } <- y . { 0 } ; gout . { 1 } <- y . { 1 } |
let y = Sundials . RealArray . of_array [ | 0 . 0 ; 0 . 0 ; 0 . 0 ] | |
let s = Cvode . init Cvode . Adams Cvode . default_tolerances f 0 . 0 ~ roots ( : 2 , g ) y_nvec |
let rootdata = Sundials . Roots . create 2 |
let _ = print_with_time 0 . 0 y ; let t = ref 0 . 1 in let keep_going = ref true in while ! keep_going do let ( t ' , result ) = Cvode . solve_normal s ! t y_nvec in print_with_time t ' y ; t := t ' . + 0 . 1 ; match result with | Cvode . RootsFound -> begin Cvode . get_root_info s rootdata ; Printf . printf " R : % e ... |
let f _ y yd = yd . ( 0 ) <- cos ( y . ( 1 ) ) ; yd . ( 1 ) <- 1 . 0 ; yd . ( 2 ) <- 0 . 0 |
let g _ y gout = gout . { 0 } <- y . ( 0 ) ; gout . { 1 } <- y . ( 1 ) |
let y = [ | 0 . 0 ; 0 . 0 ; 0 . 0 ] | |
let y_nvec = Nvector_array . wrap y |
let s = Cvode . init Cvode . Adams Cvode . default_tolerances f ~ roots ( : 2 , g ) 0 . 0 y_nvec |
let rootdata = Sundials . Roots . create 2 |
let print_with_time t v = Printf . printf " % e " t ; Array . iter ( Printf . printf " \ t % . 8f " ) v ; print_newline ( ) |
let string_of_root x = match x with | Sundials . Roots . Rising -> " rising " | Sundials . Roots . Falling -> " falling " | Sundials . Roots . NoRoot -> " noroot " |
let print_roots vs = Sundials . Roots . iter ( fun x -> Printf . printf " \ t % s " ( string_of_root x ) ) vs ; print_newline ( ) |
let _ = print_with_time 0 . 0 y ; let t = ref 0 . 1 in let keep_going = ref true in while ! keep_going do let ( t ' , result ) = Cvode . solve_normal s ! t y_nvec in print_with_time t ' y ; t := t ' . + 0 . 1 ; match result with | Cvode . RootsFound -> begin Cvode . get_root_info s rootdata ; Printf . printf " R : % e ... |
let root_dir = ref Sundials . RootDirs . Increasing |
let args = [ ( " - e " , Arg . Unit ( fun ( ) -> root_dir := Sundials . RootDirs . IncreasingOrDecreasing ) , " Use either instead of up ( ) " ) ; ] |
let _ = Arg . parse args ( fun _ -> ( ) ) " sinezero : different types of root detection on a sine wave " |
let pi = 4 . 0 . * atan 1 . 0 |
let max_sim_t = 4 . 0 . * pi . + 1 . 0 |
let print_with_time t v = Printf . printf " % e " t ; Sundials . RealArray . iter ( Printf . printf " \ t % e " ) v ; print_newline ( ) |
let f t_s y yd = yd . { x } <- cos ( t_s ) ; Printf . printf " f ( % e , [ % e ] ) = [ % e ] \ n " t_s y . { x } yd . { x } |
let g t_s y gout = gout . { 0 } <- y . { x } ; Printf . printf " g ( % e , [ % e ] ) = [ % e ] \ n " t_s y . { x } gout . { 0 } |
let y = Sundials . RealArray . of_array [ | x_i ] | |
let y_nvec = Nvector_serial . wrap y |
let s = Cvode . ( init Adams default_tolerances f ~ roots ( : 1 , g ) 0 . y_nvec ) |
let rootdata = Sundials . Roots . create 1 |
let _ = Cvode . set_all_root_directions s ! root_dir |
let _ = Cvode . set_stop_time s max_sim_t |
let _ = Cvode . set_max_step s 5 . 0 |
let _ = Printf . printf " time \ t \ t t \ n " ; Printf . printf " ------------------------------------\ n " ; print_with_time 0 . 0 y ; try let i = ref 0 in while true do let ( t ' , result ) = Cvode . solve_one_step s max_sim_t y_nvec in Printf . printf " \ nstep % 3d . \ n " ! i ; incr i ; print_with_time t ' y ; Pr... |
module type S = S |
module type Item = Item |
module Make ( Item : Item ) = struct module Searcher = struct module T = struct module Input = Item . Set module Result = struct type t = { items_matching_search : Item . Set . t ; update_search : string -> unit Bonsai . Effect . t ; current_search : string } end module Model = String module Action = String let apply_a... |
module type Item = sig type t [ @@ deriving equal , sexp ] include Comparable . S with type t := t val to_string : t -> string end |
module type S = sig module Item : Item module View_config : sig type t = { header : Vdom . Node . t ; autofocus_search_box : bool ; search_box_id : string option ; extra_row_attrs : ( is_focused : bool -> Vdom . Attr . t ) option } val create : ? extra_row_attrs ( : is_focused : bool -> Vdom . Attr . t ) -> ? autofocus... |
module type Single_factor = sig module type Item = Item module type S = S module Make ( Item : Item ) : S with module Item := Item end |
type ( ' a , ' b ) t = ( ' a , ' b ) sink = | Sink : { init : unit -> ' acc ; push : ' acc -> ' a -> ' acc ; full : ' acc -> bool ; stop : ' acc -> ' b ; } -> ( ' a , ' b ) t |
let make ~ init ~ push ( ? full = fun _ -> false ) ~ stop ( ) = Sink { init ; push ; full ; stop } |
let fill b = Sink { init = ( fun ( ) -> ( ) ) ; push = ( fun ( ) _ -> ( ) ) ; full = ( fun ( ) -> true ) ; stop = ( fun ( ) -> b ) ; } |
let map f ( Sink k ) = Sink { k with stop = ( fun x -> f ( k . stop x ) ) } |
let ( <@> ) = map |
let premap f ( Sink k ) = Sink { k with push = ( fun acc x -> k . push acc ( f x ) ) } |
let prefilter f ( Sink k ) = Sink { k with push = ( fun acc x -> if f x then k . push acc x else acc ) } |
let prefilter_map f ( Sink k ) = Sink { k with push = ( fun acc x -> match f x with | Some y -> k . push acc y | None -> acc ) ; } |
let zip ( Sink l ) ( Sink r ) = let init ( ) = ( l . init ( ) , r . init ( ) ) in let push ( l_acc , r_acc ) x = ( l . push l_acc x , r . push r_acc x ) in let full ( l_acc , r_acc ) = l . full l_acc || r . full r_acc in let stop ( l_acc , r_acc ) = ( l . stop l_acc , r . stop r_acc ) in Sink { init ; push ; full ; sto... |
let zip_left ( Sink l ) ( Sink r ) = let init ( ) = ( l . init ( ) , r . init ( ) ) in let push ( l_acc , r_acc ) x = ( l . push l_acc x , r . push r_acc x ) in let full ( l_acc , r_acc ) = l . full l_acc || r . full r_acc in let stop ( l_acc , r_acc ) = let l = l . stop l_acc in let _r = r . stop r_acc in l in Sink { ... |
let zip_right ( Sink l ) ( Sink r ) = let init ( ) = ( l . init ( ) , r . init ( ) ) in let push ( l_acc , r_acc ) x = ( l . push l_acc x , r . push r_acc x ) in let full ( l_acc , r_acc ) = l . full l_acc || r . full r_acc in let stop ( l_acc , r_acc ) = let _l = l . stop l_acc in let r = r . stop r_acc in r in Sink {... |
let zip_with f ( Sink l ) ( Sink r ) = let init ( ) = ( l . init ( ) , r . init ( ) ) in let push ( l_acc , r_acc ) x = ( l . push l_acc x , r . push r_acc x ) in let full ( l_acc , r_acc ) = l . full l_acc || r . full r_acc in let stop ( l_acc , r_acc ) = let l = l . stop l_acc in let r = r . stop r_acc in f l r in Si... |
let ( <&> ) = zip |
let ( <& ) = zip_left |
let ( &> ) = zip_right |
type ( ' a , ' r ) many = | Many : { acc : ' acc ; push : ' acc -> ' a -> ' acc ; full : ' acc -> bool ; stop : ' acc -> ' r ; } -> ( ' a , ' r ) many |
let many sinks = match sinks with | [ ] -> fill [ ] | sinks -> let init ( ) = List . map ( fun ( Sink k ) -> Many { acc = k . init ( ) ; push = k . push ; full = k . full ; stop = k . stop } ) sinks in let push sinks x = List . map ( fun ( Many k ) -> let acc = if k . full k . acc then k . acc else k . push k . acc x i... |
let unzip ( Sink l ) ( Sink r ) = let init ( ) = ( l . init ( ) , r . init ( ) ) in let push ( l_acc , r_acc ) ( x , y ) = ( l . push l_acc x , r . push r_acc y ) in let full ( l_acc , r_acc ) = l . full l_acc || r . full r_acc in let stop ( l_acc , r_acc ) = ( l . stop l_acc , r . stop r_acc ) in Sink { init ; push ; ... |
let unzip_left ( Sink l ) ( Sink r ) = let init ( ) = ( l . init ( ) , r . init ( ) ) in let push ( l_acc , r_acc ) ( x , y ) = ( l . push l_acc x , r . push r_acc y ) in let full ( l_acc , r_acc ) = l . full l_acc || r . full r_acc in let stop ( l_acc , r_acc ) = let l = l . stop l_acc in let _r = r . stop r_acc in l ... |
let unzip_right ( Sink l ) ( Sink r ) = let init ( ) = ( l . init ( ) , r . init ( ) ) in let push ( l_acc , r_acc ) ( x , y ) = ( l . push l_acc x , r . push r_acc y ) in let full ( l_acc , r_acc ) = l . full l_acc || r . full r_acc in let stop ( l_acc , r_acc ) = let _l = l . stop l_acc in let r = r . stop r_acc in r... |
let unzip_with f ( Sink l ) ( Sink r ) = let init ( ) = ( l . init ( ) , r . init ( ) ) in let push ( l_acc , r_acc ) ( x , y ) = ( l . push l_acc x , r . push r_acc y ) in let full ( l_acc , r_acc ) = l . full l_acc || r . full r_acc in let stop ( l_acc , r_acc ) = let l = l . stop l_acc in let r = r . stop r_acc in f... |
let ( <*> ) = unzip |
let ( <* ) = unzip_left |
let ( *> ) = unzip_right |
let distribute ( Sink l ) ( Sink r ) = let init ( ) = ( l . init ( ) , r . init ( ) , true ) in let push ( l_acc , r_acc , flag ) x = if flag then ( l . push l_acc x , r_acc , not flag ) else ( l_acc , r . push r_acc x , not flag ) in let full ( l_acc , r_acc , _ ) = l . full l_acc || r . full r_acc in let stop ( l_acc... |
type ( ' a , ' b ) race = Left of ' a | Right of ' b | Both of ' a * ' b |
let race ( Sink l ) ( Sink r ) = let init ( ) = Both ( l . init ( ) , r . init ( ) ) in let push state x = match state with | Both ( l_acc , r_acc ) -> let l_acc ' = l . push l_acc x in let r_acc ' = r . push r_acc x in if l . full l_acc ' then Left l_acc ' else if r . full r_acc ' then Right r_acc ' else Both ( l_acc ... |
let ( <|> ) = race |
let seq ( Sink l ) ( Sink r ) = let init ( ) = ` L ( l . init ( ) ) in let push state x = match state with | ` L l_acc -> let l_acc ' = l . push l_acc x in if l . full l_acc ' then ` R ( l . stop l_acc ' , r . init ( ) ) else ` L l_acc | ` R ( l_r , r_acc ) -> ` R ( l_r , r . push r_acc x ) in let full = function | ` L... |
let seq_left ( Sink l ) ( Sink r ) = let init ( ) = ` L ( l . init ( ) ) in let push state x = match state with | ` L l_acc -> let l_acc ' = l . push l_acc x in if l . full l_acc ' then ` R ( l . stop l_acc ' , r . init ( ) ) else ` L l_acc | ` R ( l_r , r_acc ) -> ` R ( l_r , r . push r_acc x ) in let full = function ... |
let seq_right ( Sink l ) ( Sink r ) = let init ( ) = ` L ( l . init ( ) ) in let push state x = match state with | ` L l_acc -> let l_acc ' = l . push l_acc x in if l . full l_acc ' then ( ignore ( l . stop l_acc ' ) ; ` R ( r . init ( ) ) ) else ` L l_acc | ` R r_acc -> ` R ( r . push r_acc x ) in let full = function ... |
let ( <+> ) = seq |
let ( <+ ) = seq_left |
let ( +> ) = seq_right |
type ( ' top , ' a , ' b ) flat_map = | Flat_map_top : ' top -> ( ' top , ' a , ' b ) flat_map | Flat_map_sub : { init : ' sub ; push : ' sub -> ' a -> ' sub ; full : ' sub -> bool ; stop : ' sub -> ' b ; } -> ( ' top , ' a , ' b ) flat_map |
let flat_map f ( Sink top ) = let init ( ) = Flat_map_top ( top . init ( ) ) in let push s x = match s with | Flat_map_top acc -> let acc ' = top . push acc x in if top . full acc ' then let r = top . stop acc ' in let ( Sink sub ) = f r in Flat_map_sub { init = sub . init ( ) ; push = sub . push ; full = sub . full ; ... |
let ( >>= ) m f = flat_map f m |
let fold f z = Sink { init = ( fun ( ) -> z ) ; push = f ; full = ( fun _ -> false ) ; stop = ( fun r -> r ) ; } |
let fold_while full f z = Sink { init = ( fun ( ) -> z ) ; push = f ; full ; stop = ( fun r -> r ) } |
let full = Sink { init = ( fun ( ) -> ( ) ) ; push = ( fun ( ) _ -> invalid_arg " push to full sink " ) ; full = ( fun ( ) -> true ) ; stop = ( fun ( ) -> ( ) ) ; } |
let drain = Sink { init = ( fun ( ) -> ( ) ) ; push = ( fun ( ) _ -> ( ) ) ; full = ( fun ( ) -> false ) ; stop = ( fun ( ) -> ( ) ) ; } |
let each f = Sink { init = ( fun ( ) -> ( ) ) ; push = ( fun ( ) x -> f x ) ; full = ( fun ( ) -> false ) ; stop = ( fun ( ) -> ( ) ) ; } |
let len = Sink { init = ( fun ( ) -> 0 ) ; push = ( fun acc _ -> acc + 1 ) ; full = ( fun _ -> false ) ; stop = ( fun acc -> acc ) ; } |
let mean = let init ( ) = ( 0 . 0 , 0 . 0 ) in let push ( r , n ) x = let n ' = n . + 1 . 0 in ( r . + ( ( x . - r ) . / n ' ) , n ' ) in let stop ( r , _ ) = r in let full _ = false in Sink { init ; push ; full ; stop } |
let nth_pure n = let init ( ) = ` Searching 0 in let push s x = match s with | ` Searching i when eq_int i n -> ` Found x | ` Searching i -> ` Searching ( i + 1 ) | ` Found x -> ` Found x in let full s = match s with | ` Searching _ -> false | ` Found _ -> true in let stop s = match s with | ` Searching _ -> None | ` F... |
let nth n = let i = ref 0 in let init ( ) = None in let push r x = let r ' = if ! i = n then Some x else r in incr i ; r ' in let full = function | None -> false | Some _ -> true in let stop x = x in Sink { init ; push ; full ; stop } |
let first = Sink { init = ( fun ( ) -> None ) ; push = ( fun _ x -> Some x ) ; full = ( function | None -> false | _ -> true ) ; stop = ( fun acc -> acc ) ; } |
let last = Sink { init = ( fun ( ) -> None ) ; push = ( fun _ x -> Some x ) ; full = ( fun _ -> false ) ; stop = ( fun acc -> acc ) ; } |
let contains ~ where : pred = Sink { init = ( fun ( ) -> false ) ; push = ( fun found x -> if pred x then true else found ) ; full = ( fun found -> found ) ; stop = ( fun found -> found ) ; } |
let find ~ where : pred = Sink { init = ( fun ( ) -> None ) ; push = ( fun none x -> if pred x then Some x else none ) ; full = ( function | None -> false | _ -> true ) ; stop = ( fun acc -> acc ) ; } |
let index ~ where : pred = let i = ref 0 in Sink { init = ( fun ( ) -> false ) ; push = ( fun acc x -> if pred x then true else ( incr i ; acc ) ) ; full = ( fun found -> found ) ; stop = ( fun found -> if found then Some ! i else None ) ; } |
let maximum ~ by ( : > ) = let push state x = match state with | Some y when y > x -> Some y | _ -> Some x in Sink { init = ( fun ( ) -> None ) ; push ; full = ( fun _ -> false ) ; stop = ( fun acc -> acc ) ; } |
let minimum ~ by ( : < ) = let push state x = match state with | Some y when y < x -> Some y | _ -> Some x in Sink { init = ( fun ( ) -> None ) ; push ; full = ( fun _ -> false ) ; stop = ( fun acc -> acc ) ; } |
let is_empty = Sink { init = ( fun ( ) -> true ) ; push = ( fun _ _ -> false ) ; full = ( fun _ -> false ) ; stop = ( fun acc -> acc ) ; } |
let is_full ( Sink k ) = k . full ( k . init ( ) ) |
let push x ( Sink k ) = Sink { k with init = ( fun ( ) -> k . push ( k . init ( ) ) x ) } |
let all ~ where : pred = Sink { init = ( fun ( ) -> true ) ; push = ( fun acc x -> pred x && acc ) ; full = ( fun acc -> not acc ) ; stop = ( fun acc -> acc ) ; } |
let any ~ where : pred = Sink { init = ( fun ( ) -> false ) ; push = ( fun acc x -> pred x || acc ) ; full = ( fun acc -> acc ) ; stop = ( fun acc -> acc ) ; } |
let print = each print_endline |
let list = Sink { init = ( fun ( ) -> [ ] ) ; push = ( fun acc x -> x :: acc ) ; full = ( fun _ -> false ) ; stop = ( fun acc -> List . rev acc ) ; } |
let list_rev = Sink { init = ( fun ( ) -> [ ] ) ; push = ( fun acc x -> x :: acc ) ; full = ( fun _ -> false ) ; stop = ( fun acc -> acc ) ; } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.