text stringlengths 0 601k |
|---|
let sub ( src : t ) t start len = let src_len = src . len in if len < 0 || start > src_len - len then invalid_arg " Vec . sub " else { len ; arr = unsafe_sub src . arr start len } |
let iter f d = let arr = d . arr in for i = 0 to d . len - 1 do f ( Array . unsafe_get arr i ) i done |
let iteri f d = let arr = d . arr in for i = 0 to d . len - 1 do f i ( Array . unsafe_get arr i ) i done |
let iter_range ~ from ~ to_ f d = if from < 0 || to_ >= d . len then invalid_arg " Resize_array . iter_range " else let d_arr = d . arr in for i = from to to_ do f ( Array . unsafe_get d_arr i ) i done |
let iteri_range ~ from ~ to_ f d = if from < 0 || to_ >= d . len then invalid_arg " Resize_array . iteri_range " else let d_arr = d . arr in for i = from to to_ do f i ( Array . unsafe_get d_arr i ) i done |
let map_into_array f src = let src_len = src . len in let src_arr = src . arr in if src_len = 0 then [ ] || else let first_one = f ( Array . unsafe_get src_arr 0 ) 0 in let arr = Array . make src_len first_one in for i = 1 to src_len - 1 do Array . unsafe_set arr i ( f ( Array . unsafe_get src_arr i ) i ) i done ; arr |
let map_into_list f src = let src_len = src . len in let src_arr = src . arr in if src_len = 0 then [ ] else let acc = ref [ ] in for i = src_len - 1 downto 0 do acc := f ( Array . unsafe_get src_arr i ) i :: ! acc done ; ! acc |
let mapi f src = let len = src . len in if len = 0 then { len ; arr = [ | ] | } else let src_arr = src . arr in let arr = Array . make len ( Array . unsafe_get src_arr 0 ) 0 in for i = 1 to len - 1 do Array . unsafe_set arr i ( f i ( Array . unsafe_get src_arr i ) i ) i done ; { len ; arr ; } |
let fold_left f x a = let rec loop a_len ( a_arr : elt array ) array idx x = if idx >= a_len then x else loop a_len a_arr ( idx + 1 ) 1 ( f x ( Array . unsafe_get a_arr idx ) idx ) idx in loop a . len a . arr 0 x |
let fold_right f a x = let rec loop ( a_arr : elt array ) array idx x = if idx < 0 then x else loop a_arr ( idx - 1 ) 1 ( f ( Array . unsafe_get a_arr idx ) idx x ) x in loop a . arr ( a . len - 1 ) 1 x |
let filter f d = let new_d = copy d in let new_d_arr = new_d . arr in let d_arr = d . arr in let p = ref 0 in for i = 0 to d . len - 1 do let x = Array . unsafe_get d_arr i in if f x then begin Array . unsafe_set new_d_arr ! p x ; incr p ; end ; done ; new_d . len <- ! p ; new_d |
let equal eq x y : bool = if x . len <> y . len then false else let rec aux x_arr y_arr i = if i < 0 then true else if eq ( Array . unsafe_get x_arr i ) i ( Array . unsafe_get y_arr i ) i then aux x_arr y_arr ( i - 1 ) 1 else false in aux x . arr y . arr ( x . len - 1 ) 1 |
let get d i = if i < 0 || i >= d . len then invalid_arg " Resize_array . get " else Array . unsafe_get d . arr i |
let unsafe_get d i = Array . unsafe_get d . arr i |
let last d = if d . len <= 0 then invalid_arg " Resize_array . last " else Array . unsafe_get d . arr ( d . len - 1 ) 1 |
let capacity d = Array . length d . arr |
let exists p d = let a = d . arr in let n = d . len in let rec loop i = if i = n then false else if p ( Array . unsafe_get a i ) i then true else loop ( succ i ) i in loop 0 |
let map f src = let src_len = src . len in if src_len = 0 then { len = 0 ; arr = [ ] } || ] } ) * else let src_arr = src . arr in let first = f ( Array . unsafe_get src_arr 0 ) in let arr = Array . make src_len first in for i = 1 to src_len - 1 do Array . unsafe_set arr i ( f ( Array . unsafe_get src_arr i ) i ) i done... |
let init len f = if len < 0 then invalid_arg " Resize_array . init " else if len = 0 then { len = 0 ; arr = [ ] || } else let first = f 0 in let arr = Array . make len first in for i = 1 to len - 1 do Array . unsafe_set arr i ( f i ) i done ; { len ; arr } let make initsize : t = if initsize < 0 then invalid_arg " Resi... |
module Behavior = struct type t = | Grow_to_fill | Shrink_to_avoid_overflow | Grow_or_shrink_to_match_parent_size [ @@ deriving sexp , equal ] end |
module T = struct module Input = struct include Behavior let combine ( a : Behavior . t ) ( b : Behavior . t ) : Behavior . t = match a , b with | Grow_or_shrink_to_match_parent_size , _ | _ , Grow_or_shrink_to_match_parent_size | Grow_to_fill , Shrink_to_avoid_overflow | Shrink_to_avoid_overflow , Grow_to_fill -> Grow... |
module Hook = Vdom . Attr . Hooks . Make ( T ) |
let attr ( ? behavior = Behavior . Shrink_to_avoid_overflow ) ( ) = Vdom . Attr . many [ Vdom . Attr . create_hook " grow_to_fill " ( Hook . create behavior ) ; Vdom . Attr . style Css_gen . ( create ~ field " : transform - origin " ~ value " : left top " @> display ` Inline_block @> margin ~ top ( ` : Px 0 ) ~ bottom ... |
let attr_for_parent__recommended = Vdom . Attr . style ( Css_gen . overflow ` Hidden ) |
let conv2d ( ? padding = 1 ) ( ? ksize = 3 ) = Layer . conv2d_ ~ ksize ~ padding ~ use_bias : false |
let downsample vs ~ stride ~ input_dim output_dim = if stride <> 1 || input_dim <> output_dim then ( let conv = conv2d ( sub vs " 0 " ) ~ stride ~ ksize : 1 ~ padding : 0 ~ input_dim output_dim in let bn = Layer . batch_norm2d ( sub vs " 1 " ) output_dim in Layer . of_fn_ ( fun xs ~ is_training -> Layer . forward conv ... |
let basic_block vs ~ stride ~ input_dim output_dim = let conv1 = conv2d ( sub vs " conv1 " ) ~ stride ~ input_dim output_dim in let bn1 = Layer . batch_norm2d ( sub vs " bn1 " ) output_dim in let conv2 = conv2d ( sub vs " conv2 " ) ~ stride : 1 ~ input_dim : output_dim output_dim in let bn2 = Layer . batch_norm2d ( sub... |
let bottleneck_block vs ~ expansion ~ stride ~ input_dim output_dim = let expanded_dim = expansion * output_dim in let conv1 = conv2d ( sub vs " conv1 " ) ~ stride : 1 ~ padding : 0 ~ ksize : 1 ~ input_dim output_dim in let bn1 = Layer . batch_norm2d ( sub vs " bn1 " ) output_dim in let conv2 = conv2d ( sub vs " conv2 ... |
let resnet ? num_classes vs ~ block ~ layers ( : c1 , c2 , c3 , c4 ) = let block , e = match block with | ` basic -> basic_block , 1 | ` bottleneck -> bottleneck_block ~ expansion : 4 , 4 in let make_layer vs ~ stride ~ cnt ~ input_dim output_dim = List . init cnt ~ f ( : fun block_index -> let vs = sub vs ( Int . to_s... |
let resnet18 ? num_classes vs = resnet ? num_classes vs ~ block ` : basic ~ layers ( : 2 , 2 , 2 , 2 ) |
let resnet34 ? num_classes vs = resnet ? num_classes vs ~ block ` : basic ~ layers ( : 3 , 4 , 6 , 3 ) |
let resnet50 ? num_classes vs = resnet ? num_classes vs ~ block ` : bottleneck ~ layers ( : 3 , 4 , 6 , 3 ) |
let resnet101 ? num_classes vs = resnet ? num_classes vs ~ block ` : bottleneck ~ layers ( : 3 , 4 , 23 , 3 ) |
let resnet152 ? num_classes vs = resnet ? num_classes vs ~ block ` : bottleneck ~ layers ( : 3 , 8 , 36 , 3 ) |
type t = { global_resolution : GlobalResolution . t ; annotation_store : Refinement . Store . t ; type_variables : Type . Variable . Set . t ; resolve_expression : resolution : t -> Expression . t -> t * Annotation . t ; resolve_statement : resolution : t -> Statement . t -> resolve_statement_result_t ; parent : Refere... |
let create ~ global_resolution ~ annotation_store ~ resolve_expression ~ resolve_statement ? parent ( ) = { global_resolution ; annotation_store ; type_variables = Type . Variable . Set . empty ; resolve_expression ; resolve_statement ; parent ; } |
let pp format { annotation_store ; type_variables ; _ } = Type . Variable . Set . to_list type_variables |> List . map ~ f : Type . Variable . show |> String . concat ~ sep " , : " |> Format . fprintf format " Type variables : [ % s ] \ n " ; Format . fprintf format " % a " Refinement . Store . pp annotation_store |
let show resolution = Format . asprintf " % a " pp resolution |
let is_global { global_resolution ; _ } ~ reference = Reference . delocalize reference |> GlobalResolution . global global_resolution |> Option . is_some |
let resolve_expression ( { resolve_expression ; _ } as resolution ) expression = let resolution , annotation = resolve_expression ~ resolution expression in resolution , Annotation . annotation annotation |
let resolve_expression_to_type ( { resolve_expression ; _ } as resolution ) expression = resolve_expression ~ resolution expression |> snd |> Annotation . annotation |
let resolve_expression_to_annotation ( { resolve_expression ; _ } as resolution ) expression = resolve_expression ~ resolution expression |> snd |
let resolve_reference ( { resolve_expression ; _ } as resolution ) reference = Expression . from_reference ~ location : Location . any reference |> resolve_expression ~ resolution |> snd |> Annotation . annotation |
let resolve_statement ( { resolve_statement ; _ } as resolution ) statement = resolve_statement ~ resolution statement |
let resolve_assignment ( { resolve_statement ; _ } as resolution ) assign = Statement . Statement . Assign assign |> Ast . Node . create_with_default_location |> resolve_statement ~ resolution |> function | Unreachable -> resolution | Reachable { resolution ; _ } -> resolution |
let resolve_assertion ( { resolve_statement ; _ } as resolution ) ~ asserted_expression = Statement . Statement . Assert { Statement . Assert . test = asserted_expression ; message = None ; origin = Ast . Statement . Assert . Origin . Assertion ; } |> Ast . Node . create_with_default_location |> resolve_statement ~ res... |
let partition_name resolution ~ name = let identifiers = Reference . as_list ( Expression . name_to_reference_exn name ) in match identifiers with | head :: attributes -> let rec partition_attribute base attribute_list = let base_type = resolve_reference resolution base in if Type . is_untyped base_type then match attr... |
let has_nontemporary_annotation ~ reference resolution = Refinement . Store . has_nontemporary_annotation ~ name : reference resolution . annotation_store |
let new_local ( ? temporary = false ) resolution ~ reference ~ annotation = { resolution with annotation_store = resolution . annotation_store |> Refinement . Store . new_as_base ~ temporary ~ name : reference ~ base : annotation ; } |
let refine_local ( ? temporary = false ) resolution ~ reference ~ annotation = { resolution with annotation_store = resolution . annotation_store |> Refinement . Store . set_base ~ temporary ~ name : reference ~ base : annotation ; } |
let set_local_with_attributes ~ wipe_subtree ( ? temporary = false ) resolution ~ name ~ annotation = let name , attribute_path , base = partition_name resolution ~ name in { resolution with annotation_store = resolution . annotation_store |> Refinement . Store . set_annotation ~ temporary ~ wipe_subtree ~ name ~ attri... |
let new_local_with_attributes = set_local_with_attributes ~ wipe_subtree : true |
let refine_local_with_attributes = set_local_with_attributes ~ wipe_subtree : false |
let get_local ( ? global_fallback = true ) ~ reference { annotation_store ; global_resolution ; _ } = match Refinement . Store . get_base ~ name : reference annotation_store with | Some _ as result -> result | None when global_fallback -> let global = GlobalResolution . global global_resolution in Reference . delocaliz... |
let get_local_with_attributes ( ? global_fallback = true ) ~ name ( { annotation_store ; global_resolution ; _ } as resolution ) = let name , attribute_path , _ = partition_name resolution ~ name in match Refinement . Store . get_annotation ~ name ~ attribute_path annotation_store with | Some _ as result -> result | No... |
let unset_local ( { annotation_store = { annotations ; temporary_annotations } ; _ } as resolution ) ~ reference = { resolution with annotation_store = { annotations = Map . remove annotations reference ; temporary_annotations = Map . remove temporary_annotations reference ; } ; } |
let clear_temporary_annotations ( { annotation_store ; _ } as resolution ) = { resolution with annotation_store = { annotation_store with temporary_annotations = Reference . Map . empty } ; } |
let resolve_attribute_access resolution ~ base_type ~ attribute = let unique_name = Reference . create " $ n " in let resolution = new_local resolution ~ reference : unique_name ~ annotation ( : Annotation . create_mutable base_type ) in let expression_to_analyze = Expression . from_reference ~ location : Location . an... |
let resolve_expression_to_type_with_locals ( { resolve_expression ; _ } as resolution ) ~ locals expression = let new_local resolution ( reference , annotation ) = new_local resolution ~ reference ~ annotation in let resolution_with_locals = List . fold ~ init : resolution ~ f : new_local locals in resolve_expression ~... |
let add_type_variable ( { type_variables ; _ } as resolution ) ~ variable = { resolution with type_variables = Type . Variable . Set . add type_variables variable } |
let type_variable_exists { type_variables ; _ } ~ variable = Type . Variable . Set . mem type_variables variable |
let all_type_variables_in_scope { type_variables ; _ } = Type . Variable . Set . to_list type_variables |
let annotation_store { annotation_store ; _ } = annotation_store |
let refinements_equal left right = Refinement . Store . equal left . annotation_store right . annotation_store |
let meet_refinements left right = let global_resolution = left . global_resolution in { left with annotation_store = Refinement . Store . meet ~ global_resolution left . annotation_store right . annotation_store ; } |
let outer_join_refinements left right = let global_resolution = left . global_resolution in { left with annotation_store = Refinement . Store . outer_join ~ global_resolution left . annotation_store right . annotation_store ; } |
let outer_widen_refinements ~ iteration ~ widening_threshold left right = let global_resolution = left . global_resolution in { left with annotation_store = Refinement . Store . outer_widen ~ global_resolution ~ iteration ~ widening_threshold left . annotation_store right . annotation_store ; } |
let update_existing_refinements ~ old_resolution ~ new_resolution = { old_resolution with annotation_store = Refinement . Store . update_existing ~ old_store : old_resolution . annotation_store ~ new_store : new_resolution . annotation_store ; } |
let update_refinements_with_filter ~ old_resolution ~ new_resolution ~ filter = { old_resolution with annotation_store = Refinement . Store . update_with_filter ~ old_store : old_resolution . annotation_store ~ new_store : new_resolution . annotation_store ~ filter ; } |
let with_annotation_store resolution ~ annotation_store = { resolution with annotation_store } |
let parent { parent ; _ } = parent |
let with_parent resolution ~ parent = { resolution with parent } |
let is_consistent_with ( { global_resolution ; _ } as resolution ) = GlobalResolution . is_consistent_with global_resolution ~ resolve ( : resolve_expression_to_type resolution ) |
let global_resolution { global_resolution ; _ } = global_resolution |
let fallback_attribute ( ? accessed_through_class = false ) ( ? instantiated = None ) ~ resolution ~ name class_name = let class_name_reference = Reference . create class_name in let global_resolution = global_resolution resolution in let compound_backup = let name = match name with | " __iadd__ " -> Some " __add__ " |... |
let test_new_and_refine context = let create_name = Expression . create_name ~ location : Location . any in let assert_local ~ name ~ expected resolution = assert_equal ~ cmp ( : Option . equal Type . equal ) ( expected >>| parse_single_expression >>| Type . create ~ aliases : Type . empty_aliases ) ( Resolution . get_... |
let test_parse_annotation context = let assert_parse_annotation ~ validation ~ resolution ~ expected expression = assert_equal ~ cmp : Type . equal ~ printer : Type . show ( parse_single_expression expected |> Type . create ~ aliases : Type . empty_aliases ) ( GlobalResolution . parse_annotation ~ validation resolution... |
let make_resolution ~ context source = ScratchProject . setup ~ context [ " test . py " , source ] |> ScratchProject . build_resolution |
let test_parse_reference context = let resolution = make_resolution ~ context { | import typing class Foo : . . . MyType = int } | |> Resolution . global_resolution in let assert_parse_reference reference expected = assert_equal ~ printer : Type . show expected ( GlobalResolution . parse_reference resolution !& referen... |
let test_partition_name context = let resolution = make_resolution ~ context { | from dataclasses import dataclass from typing import Optional , Final @ dataclass ( frozen = True ) class InnerFrozenDataClass ( ) : x : Optional [ int ] @ dataclass ( frozen = True ) class FrozenDataClass ( ) : inner : InnerFrozenDataClas... |
let test_resolve_literal context = let resolution = make_resolution ~ context { | class C : def __init__ ( self ) -> None : pass T = typing . TypeVar ( " T " ) class G ( typing . Generic [ T ] ) : def __init__ ( self , x : T ) -> None : pass def foo ( ) -> int : . . . i = 1 j = foo ( ) s = ' asdf ' t = 1 , 1 . 0 none =... |
let test_resolve_exports context = let assert_resolve ~ sources name expected = let resolution = ScratchProject . setup ~ context sources |> ScratchProject . build_global_resolution in let reference = GlobalResolution . legacy_resolve_exports resolution ~ reference ( : Reference . create name ) in assert_equal ~ printe... |
let test_resolve_mutable_literals context = let resolution = make_resolution ~ context { | import enum class C : . . . class D ( C ) : . . . class Q : . . . class MyEnum ( enum . Enum ) : ONE = 1 TWO = 2 } | in let assert_resolve_mutable_literals ~ source ~ against expected_output = let parse_annotation annotation = an... |
let test_resolve_mutable_literal_to_complex_type context = let resolution = make_resolution ~ context { | class C : . . . class D ( C ) : . . . class Q : . . . } | in let assert_resolve_mutable_literals ~ source ~ against expected_output = let parse_annotation annotation = annotation |> parse_single_expression |> Globa... |
let test_resolve_mutable_literals_typed_dictionary context = let resolution = make_resolution ~ context { | import mypy_extensions class ClassBasedMovie ( mypy_extensions . TypedDict ) : name : str year : int class OuterTypedDict ( mypy_extensions . TypedDict ) : outer_foo : ClassBasedMovie outer_bar : ClassBasedMovie ... |
let test_distribute_union_over_parametric _ = let assert_distributed actual expected = assert_equal ~ cmp [ :% equal : Type . t option ] ~ printer [ :% show : Type . t option ] expected actual in assert_distributed ( distribute_union_over_parametric ~ parametric_name " : list " ~ number_of_parameters : 1 Type . integer... |
let test_resolve_mutable_literal_to_recursive_type context = let resolution = make_resolution ~ context { | from typing import Dict , List , Set , Union Tree = Union [ int , List [ " Tree " ] ] TreeSet = Union [ int , Set [ " TreeSet " ] ] JSON = Union [ int , str , List [ " JSON " ] , Dict [ str , " JSON " ] ] } | in ... |
let test_get_typed_dictionary context = let resolution = make_resolution ~ context { | import mypy_extensions class Movie ( mypy_extensions . TypedDict ) : name : str year : int class NonTotalMovie ( mypy_extensions . TypedDict , total = False ) : name : str year : int class Child ( Movie ) : rating : int class Regular... |
let test_function_definitions context = let assert_functions sources function_name expected = let project = ScratchProject . setup ~ context sources in let resolution = ScratchProject . build_resolution project in let resolution = Resolution . global_resolution resolution in let functions = GlobalResolution . function_... |
let test_source_is_unit_test context = let assert_is_unit_test ( ? expected = true ) ( ? extra_sources = [ ] ) source = let { ScratchProject . BuiltGlobalEnvironment . global_environment ; _ } = ScratchProject . setup ~ context ( [ " test . py " , source ] @ extra_sources ) |> ScratchProject . build_global_environment ... |
let test_fallback_attribute context = let assert_fallback_attribute ( ? instantiated = None ) ~ name source annotation = let { ScratchProject . BuiltGlobalEnvironment . global_environment ; _ } = ScratchProject . setup ~ context [ " test . py " , source ] |> ScratchProject . build_global_environment in let global_resol... |
let ( ) = " resolution " >::: [ " new_and_refine " >:: test_new_and_refine ; " parse_annotation " >:: test_parse_annotation ; " parse_reference " >:: test_parse_reference ; " partition_name " >:: test_partition_name ; " resolve_literal " >:: test_resolve_literal ; " resolve_exports " >:: test_resolve_exports ; " resolv... |
let raw_read_file filename = try done ; |
let whitespace = [ ' ' ; ' \ t ' ] |
let split ( txt : string ) ( pred : char -> bool ) : string list = let bits = Utils . split_string_on_char txt pred in let bits = List . map ( fun x -> Utils . implode ( Utils . trim ( Utils . explode x ) pred ) ) bits in List . filter ( fun x -> x <> " " ) bits |
let strip_comments x = match ( split x ( fun c -> c = ' ' # || c = ' ; ' ) ) with | [ ] -> " " | [ x ] -> x | ( x :: _ ) -> x |
let filter_blanks = List . filter ( fun line -> not ( List . fold_left ( ) && true ( List . map ( fun x -> List . mem x whitespace ) ( Utils . explode line ) ) ) ) |
module LookupValue = struct end |
module OptionsValue = struct try end |
module KeywordValue = struct end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.