text stringlengths 0 601k |
|---|
let of_int_ms i = Int63 . ( of_int i * millisecond ) |
let of_int_sec i = Int63 . ( of_int i * second ) |
let of_us f = round_nearest ( f . * float microsecond ) |
let of_ms f = round_nearest ( f . * float millisecond ) |
let of_sec f = round_nearest ( f . * float second ) |
let of_min f = round_nearest ( f . * float minute ) |
let of_hr f = round_nearest ( f . * float hour ) |
let of_day f = round_nearest ( f . * float day ) |
let of_sec_with_microsecond_precision sec = let us = round_nearest ( sec . * 1e6 ) in of_int63_ns Int63 . ( us * of_int 1000 ) ; ; |
let of_int63_seconds x = x * second |
let of_int32_seconds x = of_int63_seconds ( Int63 . of_int32 x ) |
let to_ns t = float t |
let to_int63_ns t = t |
let to_us t = float t . / float microsecond |
let to_ms t = float t . / float millisecond |
let to_sec t = float t . / float second |
let to_min t = float t . / float minute |
let to_hr t = float t . / float hour |
let to_day t = float t . / float day |
let to_int_us t = Int63 . ( to_int_exn ( t / microsecond ) ) |
let to_int_ms t = Int63 . ( to_int_exn ( t / millisecond ) ) |
let to_int_sec t = Int63 . ( to_int_exn ( t / second ) ) |
let to_int63_seconds_round_down_exn t = t /% second |
let of_int_ns i = of_int63_ns ( Int63 . of_int i ) |
let to_int_ns = if arch_sixtyfour then fun t -> Int63 . to_int_exn ( to_int63_ns t ) else fun _ -> failwith " Time_ns . Span . to_int_ns : unsupported on 32bit machines " ; ; |
let ( + ) t u = Int63 . ( + ) t u |
let ( - ) t u = Int63 . ( - ) t u |
let scale t f = round_nearest ( float t . * f ) |
let scale_int63 t i = Int63 . ( * ) t i |
let scale_int t i = scale_int63 t ( Int63 . of_int i ) |
let div = Int63 . ( /% ) |
let ( / ) t f = round_nearest ( float t . / f ) |
let ( // ) = Int63 . ( // ) |
let to_proportional_float t = Int63 . to_float t |
let of_unit_of_time u = match ( u : Unit_of_time . t ) with | Nanosecond -> nanosecond | Microsecond -> microsecond | Millisecond -> millisecond | Second -> second | Minute -> minute | Hour -> hour | Day -> day ; ; |
let to_unit_of_time t : Unit_of_time . t = let abs_t = abs t in if abs_t >= day then Day else if abs_t >= hour then Hour else if abs_t >= minute then Minute else if abs_t >= second then Second else if abs_t >= millisecond then Millisecond else if abs_t >= microsecond then Microsecond else Nanosecond ; ; |
module Stable = struct module V2 = struct module T = struct module T0 = struct type nonrec t = t [ @@ deriving bin_io , compare , hash ] let of_int63_exn t = of_int63_ns t let to_int63 t = to_int63_ns t module To_string = struct let number_of_digits_to_write ~ span_part_magnitude = let open Int . O in if span_part_magn... |
module Alternate_sexp = struct type nonrec t = t [ @@ deriving sexp ] end type nonrec t = t [ @@ deriving compare , sexp ] let zero = zero end ) |
let ( . >= ) t u = t >= Int63 . ( u - robust_comparison_tolerance ) |
let ( . <= ) t u = t <= Int63 . ( u + robust_comparison_tolerance ) |
let ( . = ) t u = Int63 . ( abs ( t - u ) ) <= robust_comparison_tolerance |
let ( . > ) t u = t > Int63 . ( u + robust_comparison_tolerance ) |
let ( . < ) t u = t < Int63 . ( u - robust_comparison_tolerance ) |
let ( . <> ) t u = Int63 . ( abs ( t - u ) ) > robust_comparison_tolerance |
let robustly_compare t u = if t . < u then - 1 else if t . > u then 1 else 0 |
let to_string_hum ( ? delimiter = ' _ ' ) ( ? decimals = 3 ) ( ? align_decimal = false ) ? unit_of_time t = let float , suffix = match Option . value unit_of_time ~ default ( : to_unit_of_time t ) with | Day -> to_day t , " d " | Hour -> to_hr t , " h " | Minute -> to_min t , " m " | Second -> to_sec t , " s " | Millis... |
let since_unix_epoch ( ) = Time_now . nanoseconds_since_unix_epoch ( ) |> of_int63_ns |
let random ? state ( ) = Int63 . random ? state ( max_value_for_1us_rounding + Int63 . one ) - Int63 . random ? state ( neg min_value_for_1us_rounding + Int63 . one ) ; ; |
let randomize t ~ percent = Span_helpers . randomize t ~ percent ~ scale |
let to_short_string t = let ( { sign ; hr ; min ; sec ; ms ; us ; ns } : Parts . t ) = to_parts t in Span_helpers . short_string ~ sign ~ hr ~ min ~ sec ~ ms ~ us ~ ns ; ; |
let gen_uniform_incl = Int63 . gen_uniform_incl type nonrec t = t let to_string = to_string let module_name = module_name end ) type nonrec t = t [ @@ deriving bin_io , compare , hash , sexp ] end ) |
type comparator_witness = Stable . V2 . comparator_witness type nonrec t = t [ @@ deriving bin_io , compare , sexp ] type nonrec comparator_witness = comparator_witness let comparator = Stable . V2 . comparator end ) |
let to_span_float_round_nearest t = Span_float . of_sec ( to_sec t ) |
let of_span_float_round_nearest s = of_sec ( Span_float . to_sec s ) |
let half_microsecond = Int63 . of_int 500 |
let nearest_microsecond t = Int63 . ( ( to_int63_ns t + half_microsecond ) /% of_int 1000 ) raise_s [ % message " Span . t exceeds limits " ( t : t ) ( min_value_for_1us_rounding : t ) ( max_value_for_1us_rounding : t ) ] ; ; |
let check_range_for_1us_rounding t = if t < min_value_for_1us_rounding || t > max_value_for_1us_rounding then invalid_range_for_1us_rounding t else t ; ; |
let to_span_float_round_nearest_microsecond t = Span_float . of_us ( Int63 . to_float ( nearest_microsecond ( check_range_for_1us_rounding t ) ) ) ; ; |
let min_span_float_value_for_1us_rounding = to_span_float_round_nearest min_value_for_1us_rounding ; ; |
let max_span_float_value_for_1us_rounding = to_span_float_round_nearest max_value_for_1us_rounding ; ; |
let of_span_float_round_nearest_microsecond s = if Span_float . ( > ) s max_span_float_value_for_1us_rounding || Span_float . ( < ) s min_span_float_value_for_1us_rounding then failwiths ~ here [ :% here ] " Time_ns . Span does not support this span " s [ % sexp_of : Span_float . t ] ; of_sec_with_microsecond_precision... |
let min_value_representable = of_int63_ns Int63 . min_value |
let max_value_representable = of_int63_ns Int63 . max_value |
module Private = struct module Parts = Parts let of_parts = of_parts let to_parts = to_parts end |
let span_set_full : Span_set . t = Span_set . add ( Span_set . Interval . make Timedesc . Timestamp . min_val ( Timedesc . Span . pred Timedesc . Timestamp . max_val ) ) Span_set . empty |
let span_set_map ( f : Time . Interval ' . t -> Time . Interval ' . t ) ( set : Span_set . t ) : Span_set . t = Span_set . fold ( fun interval acc -> let x , y = Span_set . Interval . ( x interval , y interval ) in let y = Timedesc . Span . succ y in let x , y = f ( x , y ) in let y = Timedesc . Span . pred y in Span_s... |
let intervals_of_int64s ( s : int64 Seq . t ) : Time . Interval ' . t Seq . t = let rec aux acc s = match s ( ) with | Seq . Nil -> ( match acc with None -> Seq . empty | Some x -> Seq . return x ) | Seq . Cons ( x , rest ) -> ( match acc with | None -> aux ( Some ( x , Int64 . succ x ) ) rest | Some ( x ' , y ' ) -> i... |
let span_set_of_intervals ( s : Time . Interval ' . t Seq . t ) : Span_set . t = Seq . fold_left ( fun ( count , acc ) ( x , y ) -> if count >= span_set_max_interval_count then Crowbar . bad_test ( ) else if Timedesc . Span . ( x = y ) then ( count , acc ) else ( succ count , Span_set . ( add ( Interval . make x ( Time... |
let intervals_of_span_set ( set : Span_set . t ) : Time . Interval ' . t Seq . t = let rec aux set = match Span_set . min_elt set with | i -> fun ( ) -> Seq . Cons ( Span_set . Interval . ( x i , Timedesc . Span . succ ( y i ) ) , aux ( Span_set . remove i set ) ) | exception Not_found -> Seq . empty in aux set |
module Alco = struct let lt_case0 ( ) = Alcotest . ( check bool ) " less than " true Timedesc . Span . ( lt ( Timedesc . Span . make ~ ns : 1 ( ) ) ( Timedesc . Span . make ~ ns : 2 ( ) ) ) let lt_case1 ( ) = Alcotest . ( check bool ) " less than " false Timedesc . Span . ( lt ( Timedesc . Span . make ~ ns : 1 ( ) ) ( ... |
let normalize ( x : Timedesc . Span . t ) : Timedesc . Span . t = let s , ns = Timedesc . Span . to_s_ns x in Timedesc . Span . make ~ s ~ ns ( ) |
module Qc = struct let make_is_lossless = QCheck . Test . make ~ count : 100_000 ~ name " : make_is_lossless " QCheck . ( pair int64 int ) ( fun ( s , ns ) -> let span = Timedesc . Span . make ~ s ~ ns ( ) in Int64 . add ( Int64 . mul s 1_000_000_000L ) ( Int64 . of_int ns ) = Int64 . add ( Int64 . mul ( Timedesc . Spa... |
let print_mat out mat = let m , n = S . size mat in let nnz , _ = S . dims mat in fprintf out " [ @< v > matrix ( M =% d , N =% d , NNZ =% d ) :@\ n " m n nnz ; for i = 0 to n - 1 do fprintf out " col % d " : i ; for j = S . get_col mat i to ( S . get_col mat ( i + 1 ) ) - 1 do let r , v = S . get mat j in printf " ( %... |
let print_vec out m = let nr = Array1 . dim m in fprintf out " [ @< h " ; > for i = 0 to nr - 1 do fprintf out " @ % e " m . { i } done ; fprintf out " ] " @ |
let nrows , ncols , nzeros = 3 , 3 , 5 ; ; |
let main ( ) = let da = D . create nrows ncols in let b = S . ( make CSC nrows ncols 2 ) in let zero = S . ( make CSC nrows ncols 0 ) in let x = Sundials . RealArray . of_list [ 2 . 0 ; 3 . 0 ; 4 . 0 ] in let y = Sundials . RealArray . create nrows in D . set da 0 0 ( 0 . 0 ) ; D . set da 0 1 ( 2 . 0 ) ; D . set da 0 2... |
type t = | N | C of int * A . t * t |
let is_empty = function | N -> true | C _ -> false |
let rec add base offset s = match s with | N -> C ( base , A . singleton offset , N ) | C ( addr , ss , qs ) -> if base < addr then C ( base , A . singleton offset , s ) else if base = addr then let ss ' = A . add offset ss in if A . equal ss ' ss then s else C ( addr , ss ' , qs ) else let qs ' = add base offset qs in... |
let add i s = let offset = i mod A . bound in let base = i - offset in add base offset s |
let singleton i = let offset = i mod A . bound in let base = i - offset in C ( base , A . singleton offset , N ) |
let rec remove base offset s = match s with | N -> N | C ( addr , ss , qs ) -> if base < addr then s else if base = addr then let ss ' = A . remove offset ss in if A . is_empty ss ' then qs else if A . equal ss ' ss then s else C ( addr , ss ' , qs ) else let qs ' = remove base offset qs in if qs == qs ' then s else C ... |
let remove i s = let offset = i mod A . bound in let base = i - offset in remove base offset s |
let rec mem base offset s = match s with | N -> false | C ( addr , ss , qs ) -> if base < addr then false else if base = addr then A . mem offset ss else mem base offset qs |
let mem i s = let offset = i mod A . bound in let base = i - offset in mem base offset s |
let rec fold f s accu = match s with | N -> accu | C ( addr , ss , qs ) -> let accu = A . fold_delta addr f ss accu in fold f qs accu |
let rec iter f s = match s with | N -> ( ) | C ( addr , ss , qs ) -> A . iter_delta addr f ss ; iter f qs |
let is_singleton s = match s with | C ( _ , ss , N ) -> A . is_singleton ss | C ( _ , _ , C _ ) | N -> false |
let rec cardinal accu s = match s with | C ( _ , ss , qs ) -> let accu = accu + A . cardinal ss in cardinal accu qs | N -> accu |
let cardinal s = cardinal 0 s |
let elements s = fold ( fun tl hd -> tl :: hd ) s [ ] |
let rec subset s1 s2 = match s1 , s2 with | N , _ -> true | _ , N -> false | C ( addr1 , ss1 , qs1 ) , C ( addr2 , ss2 , qs2 ) -> if addr1 < addr2 then false else if addr1 = addr2 then A . subset ss1 ss2 && subset qs1 qs2 else subset s1 qs2 |
let rec union s1 s2 = match s1 , s2 with | N , s | s , N -> s | C ( addr1 , ss1 , qs1 ) , C ( addr2 , ss2 , qs2 ) -> if addr1 < addr2 then C ( addr1 , ss1 , union qs1 s2 ) else if addr1 > addr2 then let s = union s1 qs2 in if s == qs2 then s2 else C ( addr2 , ss2 , s ) else let ss = A . union ss1 ss2 in let s = union q... |
let rec inter s1 s2 = match s1 , s2 with | N , _ | _ , N -> N | C ( addr1 , ss1 , qs1 ) , C ( addr2 , ss2 , qs2 ) -> if addr1 < addr2 then inter qs1 s2 else if addr1 > addr2 then inter s1 qs2 else let ss = A . inter ss1 ss2 in let s = inter qs1 qs2 in if A . is_empty ss then s else if A . equal ss ss1 && s == qs1 then ... |
let choose s = match s with | N -> raise Not_found | C ( addr , ss , _ ) -> assert ( not ( A . is_empty ss ) ) ; addr + A . choose ss |
let rec compare x y = if x == y then 0 else match x , y with | C ( a1 , ss1 , qs1 ) , C ( a2 , ss2 , qs2 ) -> begin match Generic . compare a1 a2 with | 0 -> begin match A . compare ss1 ss2 with | 0 -> compare qs1 qs2 | n -> n end | n -> n end | N , N -> 0 | C _ , N -> 1 | N , C _ -> - 1 |
let rec equal x y = ( x == y ) || match x , y with | C ( a1 , ss1 , qs1 ) , C ( a2 , ss2 , qs2 ) -> a1 = a2 && A . equal ss1 ss2 && equal qs1 qs2 | N , N -> true | C _ , N | N , C _ -> false |
let rec disjoint s1 s2 = match s1 , s2 with | N , _ | _ , N -> true | C ( addr1 , ss1 , qs1 ) , C ( addr2 , ss2 , qs2 ) -> if addr1 = addr2 then A . disjoint ss1 ss2 && disjoint qs1 qs2 else if addr1 < addr2 then disjoint qs1 s2 else disjoint s1 qs2 |
let rec quick_subset a1 ss1 = function | N -> false | C ( a2 , ss2 , qs2 ) -> if a1 = a2 then AtomicBitSet . quick_subset ss1 ss2 else ( a1 > a2 && quick_subset a1 ss1 qs2 ) |
let quick_subset s1 s2 = match s1 with | N -> true | C ( a1 , ss1 , _ ) -> quick_subset a1 ss1 s2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.