text
stringlengths
12
786k
let drawMode = ref 0
let maxVertices = ref 0
let maxIndices = ref 0
let ( += ) a b = ( a := ! a . + b ) ; ;
let vertices = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 1 . ; 1 . ; 1 . ; - 1 . ; 1 . ; 1 . ; - 1 . ; - 1 . ; 1 . ; 1 . ; - 1 . ; 1 . ; 1 . ; 1 . ; 1 . ; 1 . ; - 1 . ; 1 . ; 1 . ;...
let normals = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 ...
let colors = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 1 . ; 1 . ; 1 . ; 1 . ; 1 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 1 . ; 1 . ; 1 . ; 1 . ; 1 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 ...
let indices = Bigarray . Array1 . of_array Bigarray . int16_unsigned Bigarray . c_layout [ | 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 ; 11 ; 12 ; 13 ; 14 ; 15 ; 16 ; 17 ; 18 ; 19 ; 20 ; 21 ; 22 ; 23 ] |
let draw1 ( ) = glPushMatrix ( ) ; glTranslate ( - 2 . ) ( 2 . ) ( 0 . ) ; glBegin GL_QUADS ; glNormal3 0 . 0 . 1 . ; glColor3 1 . 1 . 1 . ; glVertex3 1 . 1 . 1 . ; glColor3 1 . 1 . 0 . ; glVertex3 ( - 1 . ) 1 . 1 . ; glCol...
let draw2 ( ) = glEnableClientState GL_NORMAL_ARRAY ; glEnableClientState GL_COLOR_ARRAY ; glEnableClientState GL_VERTEX_ARRAY ; glNormalPointer Norm . GL_FLOAT 0 normals ; glColorPointer 3 Color . GL_FLOAT 0 colors ; glVertexPointer 3 Coord . GL_FLOAT 0 vertices ; glPushMatrix ( ) ; g...
let draw3 ( ) = glEnableClientState GL_NORMAL_ARRAY ; glEnableClientState GL_COLOR_ARRAY ; glEnableClientState GL_VERTEX_ARRAY ; glNormalPointer Norm . GL_FLOAT 0 normals ; glColorPointer 3 Color . GL_FLOAT 0 colors ; glVertexPointer 3 Coord . GL_FLOAT 0 vertices ; glPushMatrix ( ) ; g...
let draw4 ( ) = glEnableClientState GL_NORMAL_ARRAY ; glEnableClientState GL_COLOR_ARRAY ; glEnableClientState GL_VERTEX_ARRAY ; glNormalPointer Norm . GL_FLOAT 0 normals ; glColorPointer 3 Color . GL_FLOAT 0 colors ; glVertexPointer 3 Coord . GL_FLOAT 0 vertices ; glPushMatrix ( ) ; g...
let draw_string str x y ( r , g , b , a ) font = glPushAttrib [ Attrib . GL_LIGHTING_BIT ; Attrib . GL_CURRENT_BIT ] ; glDisable GL_LIGHTING ; glColor4 r g b a ; glRasterPos2 ( float x ) ( float y ) ; let len = String . length str in for i = 0 to pred len do glutBitmapCharacter...
let draw_string_3D str ( x , y , z ) ( r , g , b , a ) font = glPushAttrib [ Attrib . GL_LIGHTING_BIT ; Attrib . GL_CURRENT_BIT ] ; glDisable GL_LIGHTING ; glColor4 r g b a ; glRasterPos3 x y z ; let len = String . length str in for i = 0 to pred len do glutBitmapCharacter font...
let show_info ( ) = glPushMatrix ( ) ; glLoadIdentity ( ) ; glMatrixMode GL_PROJECTION ; glPushMatrix ( ) ; glLoadIdentity ( ) ; gluOrtho2D 0 . 400 . 0 . 300 . ; let color = ( 1 . , 1 . , 1 . , 1 . ) in let str = Printf . sprintf " Max Elements Ve...
let display ( ) = glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ; GL_STENCIL_BUFFER_BIT ] ; glPushMatrix ( ) ; glTranslate 0 . 0 . ! cameraDistance ; glRotate ! cameraAngleX 1 . 0 . 0 . ; glRotate ! cameraAngleY 0 . 1 . 0 . ; draw1 ( ) ; draw2 ( ) ; ...
let reshape ~ width : w ~ height : h = glViewport 0 0 w h ; let aspect = ( float w ) . / ( float h ) in glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; ) * gluPerspective ~ fovy : 60 . 0 ~ aspect ~ zNear : 0 . 5 ~ zFar : 80 . 0 ; glMatrixMode GL_MODELVIEW ; ; ;...
let rec timer ~ value : millisec = glutTimerFunc ~ msecs : millisec ~ timer ~ value : millisec ; glutPostRedisplay ( ) ; ; ;
let motion ~ x ~ y = if ( ! mouseLeftDown ) then begin cameraAngleY += ( float x . - ! mouseX ) ; cameraAngleX += ( float y . - ! mouseY ) ; mouseX := float x ; mouseY := float y ; end ; if ( ! mouseRightDown ) then begin cameraDistance += ( float y . - ! mouseY ) . ...
let mouse ~ button ~ state ~ x ~ y = mouseX := float x ; mouseY := float y ; match button , state with | GLUT_LEFT_BUTTON , GLUT_DOWN -> mouseLeftDown := true ; | GLUT_LEFT_BUTTON , GLUT_UP -> mouseLeftDown := false ; | GLUT_RIGHT_BUTTON , GLUT_DOWN -> mouseRightDown := true ; | GLUT_...
let keyboard ~ key ~ x ~ y = begin match key with | ' \ 027 ' -> exit 0 ; | ' D ' | ' d ' -> drawMode := ( ! drawMode + 1 ) mod 3 ; if ( ! drawMode = 0 ) then begin glPolygonMode GL_FRONT_AND_BACK GL_FILL ; glEnable GL_DEPTH_TEST ; glEnable GL_CULL_FACE ; end else if ( ...
let init_lights ( ) = let lightKa = ( 0 . 2 , 0 . 2 , 0 . 2 , 1 . 0 ) and lightKd = ( 0 . 7 , 0 . 7 , 0 . 7 , 1 . 0 ) and lightKs = ( 1 . 0 , 1 . 0 , 1 . 0 , 1 . 0 ) in glLight ( GL_LIGHT 0 ) ( Light . GL_AMBIENT lightKa ) ...
let set_camera ~ posX ~ posY ~ posZ ~ targetX ~ targetY ~ targetZ = glMatrixMode GL_MODELVIEW ; glLoadIdentity ( ) ; gluLookAt posX posY posZ targetX targetY targetZ 0 . 1 . 0 . ; ; ;
let initGLUT ( ) = ignore ( glutInit Sys . argv ) ; glutInitDisplayMode [ GLUT_RGB ; GLUT_DOUBLE ; GLUT_DEPTH ; GLUT_STENCIL ] ; glutInitWindowSize 400 300 ; glutInitWindowPosition 100 100 ; let handle = glutCreateWindow Sys . argv . ( 0 ) in glutDisplayFunc ~ display ; glu...
let initGL ( ) = glShadeModel GL_SMOOTH ; glPixelStorei GL_UNPACK_ALIGNMENT 4 ; glHint GL_PERSPECTIVE_CORRECTION_HINT GL_NICEST ; glEnable GL_DEPTH_TEST ; glEnable GL_LIGHTING ; glEnable GL_TEXTURE_2D ; glEnable GL_CULL_FACE ; glColorMaterial GL_FRONT_AND_BACK GL_AMBIENT_AND_DIFFUSE ; glEnable GL_...
let ( ) = let _ = initGLUT ( ) in initGL ( ) ; maxVertices := glGetInteger1 Get . GL_MAX_ELEMENTS_VERTICES ; maxIndices := glGetInteger1 Get . GL_MAX_ELEMENTS_INDICES ; glutMainLoop ( ) ; ; ;
module Bigint = struct module R = struct include Field . Bigint let of_data _ = failwith __LOC__ let to_field = Field . of_bigint let of_field = Field . to_bigint end end
let field_size : Bigint . R . t = Field . size
module Verification_key = struct type t = ( Pasta_bindings . Fp . t , Kimchi_bindings . Protocol . SRS . Fp . t , Pasta_bindings . Fq . t Kimchi_types . or_infinity Kimchi_types . poly_comm ) Kimchi_types . VerifierIndex . verifier_index let to_string _ = failwith __LOC__ let of_string _ = failwith...
module R1CS_constraint_system = Plonk_constraint_system . Make ( Field ) Field ( Kimchi_bindings . Protocol . Gates . Vector . Fp ) Fp ( struct let params = Sponge . Params ( . map pasta_p_kimchi ~ f ( : fun x -> Field . of_bigint ( Bigint256 . of_decimal_string x ) x ) ) end ...
let lagrange : int -> _ Kimchi_types . poly_comm array = Memo . general ~ hashable : Int . hashable ( fun domain_log2 -> Array . map Precomputed . Lagrange_precomputations ( . vesta ( . index_of_domain_log2 domain_log2 ) domain_log2 ) domain_log2 ~ f ( : fun unshifted -> { Kimchi_type...
let with_lagrange f ( vk : Verification_key . t ) t = f ( lagrange vk . domain . log_size_of_group ) log_size_of_group vk
let with_lagranges f ( vks : Verification_key . t array ) array = let lgrs = Array . map vks ~ f ( : fun vk -> lagrange vk . domain . log_size_of_group ) log_size_of_group in f lgrs vks
module Keypair = Dlog_plonk_based_keypair . Make ( struct let name = " vesta " module Rounds = Rounds module Urs = Kimchi_bindings . Protocol . SRS . Fp module Index = Kimchi_bindings . Protocol . Index . Fp module Curve = Curve module Poly_comm = Fp_poly_comm module Scalar_field = Field module Verifie...
module Proof = Plonk_dlog_proof . Make ( struct let id = " pasta_vesta " module Scalar_field = Field module Base_field = Fq module Backend = struct type t = ( Pasta_bindings . Fq . t Kimchi_types . or_infinity , Pasta_bindings . Fp . t ) Kimchi_types . prover_proof include Kimchi_bindings . Proto...
module Proving_key = struct type t = Keypair . t include Core_kernel . Binable . Of_binable ( Core_kernel . Unit ) Unit ( struct type nonrec t = t let to_binable _ = ( ) let of_binable ( ) = failwith " TODO " end ) end let is_initialized _ = ` Yes let set_constraint_system _ _ = ( ...
module Oracles = Plonk_dlog_oracles . Make ( struct module Verifier_index = Verification_key module Field = Field module Proof = Proof module Backend = struct include Kimchi_bindings . Protocol . Oracles . Fp let create = with_lagrange create end end ) end
let relu = Layer . of_fn_ ( fun xs ~ is_training : _ -> Tensor . relu xs )
let relu_ = Layer . of_fn_ ( fun xs ~ is_training : _ -> Tensor . relu_ xs )
type t = | C of int | M
let layers_cfg = function | ` A -> [ C 64 ; M ; C 128 ; M ; C 256 ; C 256 ; M ; C 512 ; C 512 ; M ; C 512 ; C 512 ; M ] | ` B -> [ C 64 ; C 64 ; M ; C 128 ; C 128 ; M ; C 256 ; C 256 ; M ; C 512 ; C 512 ; M ; C 512 ; C 512 ; M ] | `...
let make_layers vs cfg ~ batch_norm ~ in_place_relu = let relu = if in_place_relu then relu_ else relu in let sub_vs index = Var_store . sub vs ( Int . to_string index ) in let ( _output_dim , _output_idx ) , layers = List . fold_map ( layers_cfg cfg ) ~ init ( : 3 , 0 ) ~ f ( ...
let vgg ~ num_classes vs cfg ~ batch_norm = let cls_vs i = Var_store . ( vs / " classifier " / Int . to_string i ) in let layers = make_layers ( Var_store . sub vs " features " ) cfg ~ batch_norm ~ in_place_relu : true |> Layer . sequential_ in let fc1 = Layer . linear ( cls_vs 0...
let vgg11 vs ~ num_classes = vgg ~ num_classes vs ` A ~ batch_norm : false
let vgg11_bn vs ~ num_classes = vgg ~ num_classes vs ` A ~ batch_norm : true
let vgg13 vs ~ num_classes = vgg ~ num_classes vs ` B ~ batch_norm : false
let vgg13_bn vs ~ num_classes = vgg ~ num_classes vs ` B ~ batch_norm : true
let vgg16 vs ~ num_classes = vgg ~ num_classes vs ` D ~ batch_norm : false
let vgg16_bn vs ~ num_classes = vgg ~ num_classes vs ` D ~ batch_norm : true
let vgg19 vs ~ num_classes = vgg ~ num_classes vs ` E ~ batch_norm : false
let vgg19_bn vs ~ num_classes = vgg ~ num_classes vs ` E ~ batch_norm : true
let vgg16_layers ( ? max_layer = Int . max_value ) vs ~ batch_norm = let layers = List . take ( make_layers ( Var_store . sub vs " features " ) ` D ~ batch_norm ~ in_place_relu : false ) max_layer in Staged . stage ( fun xs -> List . fold_mapi layers ~ init : xs ~ f ( : fun ...
let vgg19 ( ) = let block iter ~ block_idx ~ out_channels x = List . init iter ~ f : Fn . id |> List . fold ~ init : x ~ f ( : fun acc idx -> Fnn . conv2d ( ) acc ~ name ( : Printf . sprintf " conv % d_ % d " block_idx ( idx + 1 ) 1 ) 1 ~ w_init ( ` : normal 0 . 1...
let ( ) = let { Image . tensor ; _ } = Image . load " input . jpg " in let input_id , model = vgg19 ( ) in Fnn . Model . load model ~ filename ( : Caml . Sys . getcwd ( ) ^ " / vgg19 . cpkt ) " ; let results = Fnn . Model . predict model [ input_id , tensor ] in...
module type Image = sig type t val create : int -> int -> t val size : t -> int val blit_all : t -> t -> unit val copy : t -> t val blank : t -> unit val randomize : t -> unit end
module Image = struct include Mm_image . Image . YUV420 let create w h = create w h let scale = scale ~ proportional : false end
module Make ( Image : Image ) = struct module I = Image type t = Image . t array type buffer = t let make len width height = Array . init len ( fun _ -> Image . create width height ) let single img = [ | img ] | let blit sbuf sofs dbuf dofs len = for i = 0 to len - 1 do Image . blit_...
module Canvas = struct module Image = Mm_image . Image . Canvas ( Image ) type image = Image . t type t = Image . t array let make len ( width , height ) : t = Array . init len ( fun _ -> Image . create width height ) let single img = [ | img ] | let single_image img = single (...
module FPS = struct type t = float let to_frac f = let n = floor ( ( f . * 100 . ) . + 0 . 5 ) in let n = int_of_float n in if n mod 100 = 0 then ( n / 100 , 1 ) else ( n , 100 ) end
module AVI = struct module Writer = struct let word n = let s = Bytes . create 2 in Bytes . set_int16_le s 0 n ; Bytes . unsafe_to_string s let dword n = let s = Bytes . create 4 in Bytes . set_int32_le s 0 ( Int32 . of_int n ) ; Bytes . unsafe_to_string s module Chunk = struct let crea...
module IO = struct exception Invalid_file module Reader = struct class type t = object method width : int method height : int method frame_rate : float method read : buffer -> int -> int -> int method close : unit end end module Writer = struct class type t = object method write : buffer -> int -> int ...
type t = { duration : int option ; h : int option ; w : int option ; mimetype : string option ; size : int option ; thumbnail_url : string option ; thumbnail_file : Encrypted_file . t option ; thumbnail_info : Thumbnail_info . t option ; }
let encoding = let to_tuple t = ( t . duration , t . h , t . w , t . mimetype , t . size , t . thumbnail_url , t . thumbnail_file , t . thumbnail_info ) in let of_tuple v = let ( duration , h , w , mimetype , size , thumbnail_url , thumbnail_file , thumbnail_info ) ...
module Make ( Node_id : S . NODE_ID ) ( Node : S . NODE with type nid := Node_id . t ) : S . VIEW with type nid := Node_id . t and type node := Node . t = struct let min x y = if x < y then x else y let max x y = if x < y then y else x module I = struct type t = int let compare ( a :...
let list_modules ~ path = List . fold_left path ~ init [ ] : ~ f : begin fun modules dir -> let l = List . filter ( Useunix . get_files_in_directory dir ) ~ f ( : fun x -> Filename . check_suffix x " . cmi " ) in let l = List . map l ~ f : begin fun x -> String . capitalize ...
let reset_modules box = Listbox . delete box ~ first ( ` : Num 0 ) ~ last ` : End ; module_list := Sort . list ( Jg_completion . lt_string ~ nocase : true ) ( list_modules ~ path :! Config . load_path ) ; Listbox . insert box ~ index ` : End ~ texts :! module_list ; Jg_b...
let view_symbol ~ kind ~ env ? path id = let name = match id with Lident x -> x | Ldot ( _ , x ) -> x | _ -> match kind with Pvalue | Ptype | Plabel -> " z " | _ -> " Z " in match kind with Pvalue -> let path , vd = lookup_value id env in view_signature_item ~ path ~ env [ Tsig_v...
let choose_symbol ~ title ~ env ? signature ? path l = if match path with None -> false | Some path -> is_shown_module path then ( ) else let tl = Jg_toplevel . titled title in Jg_bind . escape_destroy tl ; top_widgets := coe tl :: ! top_widgets ; let buttons = Frame . create tl in let all =...
let choose_symbol_ref = ref choose_symbol
let guess_search_mode s : [ ` Type | ` Long | ` Pattern ] = let is_type = ref false and is_long = ref false in for i = 0 to String . length s - 2 do if s . [ i ] = ' ' - && s . [ i + 1 ] = ' ' > then is_type := true ; if s . [ i ] = ' . ' then is_long :=...
let search_string ( ? mode " = symbol " ) ew = let text = Entry . get ew in try if text = " " then ( ) else let l = match mode with " Name " -> begin match guess_search_mode text with ` Long -> search_string_symbol text | ` Pattern -> search_pattern_symbol text | ` Type -> search...
let search_which = ref " Name "
let search_symbol ( ) = if ! module_list = [ ] then module_list := List . sort ~ cmp : compare ( list_modules ~ path :! Config . load_path ) ; let tl = Jg_toplevel . titled " Search symbol " in Jg_bind . escape_destroy tl ; let ew = Entry . create tl ~ width : 30 in let choice...
let ident_of_decl ~ modlid = function Tsig_value ( id , _ ) -> Lident ( Ident . name id ) , Pvalue | Tsig_type ( id , _ , _ ) -> Lident ( Ident . name id ) , Ptype | Tsig_exception ( id , _ ) -> Ldot ( modlid , Ident . name id ) , Pconstructor | Tsig_module ( ...
let view_defined ~ env ( ? show_all = false ) modlid = try match lookup_module modlid env with path , Tmty_signature sign -> let rec iter_sign sign idents = match sign with [ ] -> List . rev idents | decl :: rem -> let rem = match decl , rem with Tsig_class _ , cty :: ty1 :: ty2 :: rem -...
let close_all_views ( ) = List . iter ! top_widgets ~ f ( : fun tl -> try destroy tl with Protocol . TkError _ -> ( ) ) ; top_widgets := [ ]
let shell_counter = ref 1
let default_shell = ref " ocaml "
let start_shell master = let tl = Jg_toplevel . titled " Start New Shell " in Wm . transient_set tl ~ master ; let input = Frame . create tl and buttons = Frame . create tl in let ok = Button . create buttons ~ text " : Ok " and cancel = Jg_button . create_destroyer tl ~ parent : button...
let show_help ( ) = let tl = Jg_toplevel . titled " OCamlBrowser Help " in Jg_bind . escape_destroy tl ; let fw , tw , sb = Jg_text . create_with_scrollbar tl in let ok = Jg_button . create_destroyer ~ parent : tl ~ text " : Ok " tl in Text . insert tw ~ index : tend ~ text : Hel...
let f ( ? dir = Unix . getcwd ( ) ) ? on ( ) = let ( top , tl ) = match on with None -> let tl = Jg_toplevel . titled " Module viewer " in ignore ( Jg_bind . escape_destroy tl ) ; ( tl , coe tl ) | Some top -> Wm . title_set top " OCamlBrowser " ; Wm . iconname...
let st_viewer ? dir ? on ( ) = let viewer = new st_viewer ? dir ? on ( ) in choose_symbol_ref := viewer # choose_symbol
let pi = 4 . . * atan 1 .
module F ( M : sig type font type color type text val white : color type ctx val save : ctx -> unit val restore : ctx -> unit val scale : ctx -> sx : float -> sy : float -> unit val translate : ctx -> tx : float -> ty : float -> unit val begin_path : ctx -> unit val close_path : ctx -> unit val ...
type rect = { x : int ; y : int ; width : int ; height : int }
let create_canvas w h = let c = Html . createCanvas Html . document in c . ## width := w ; c . ## height := h ; c
module Common = Viewer_common . F ( struct type font = Js . js_string Js . t type color = Js . js_string Js . t type text = Js . js_string Js . t let white = Js . string " white " type ctx = Html . canvasRenderingContext2D Js . t let save ctx = ctx ## save let restore ctx = ctx ## re...
let redraw st s h v ( canvas : Html . canvasElement Js . t ) = let width = canvas . ## width in let height = canvas . ## height in redraw st s h v canvas { x = 0 ; y = 0 ; width ; height } 0 0 width height
let json : < parse : Js . js_string Js . t -> ' a > Js . t = Js . Unsafe . pure_js_expr " JSON "
let ( >>= ) = Lwt . bind
let http_get url = XmlHttpRequest . get url >>= fun { XmlHttpRequest . code = cod ; content = msg ; _ } -> if cod = 0 || cod = 200 then Lwt . return msg else fst ( Lwt . wait ( ) )
let getfile f = try Lwt . return ( Sys_js . read_file ~ name : f ) with Not_found -> http_get f ( ? value = 0 . ) ( ? lower = 0 . ) ( ? upper = 100 . ) ( ? step_incr = 1 . ) ( ? page_incr = 10 . ) ( ? page_size = 10 . ) ( ) = object val mutable _val...
let handle_drag element f = let mx = ref 0 in let my = ref 0 in element . ## onmousedown := Html . handler ( fun ev -> mx := ev . ## clientX ; my := ev . ## clientY ; element . ## style . ## cursor := Js . string " move " ; let c1 = Html . addEventListener Html . document H...
let start ( ) = let doc = Html . document in let page = doc . ## documentElement in page . ## style . ## overflow := Js . string " hidden " ; doc . ## body . ## style . ## overflow := Js . string " hidden " ; doc . ## body . ## style . ## margin := Js . string " ...
let _ = Html . window . ## onload := Html . handler ( fun _ -> ignore ( start ( ) ) ; Js . _false )
type t_point = float * float
type t_coord = t_point * t_point
type t_shape = Srect | Sellipse
type t_gtk_obj = GnomeCanvas . re_p GnoCanvas . item
module Node = struct type t = string * ( t_shape * t_coord * t_gtk_obj ) option let id n = fst n let coord n = match snd n with None -> None | Some ( _ , c , _ ) -> Some c let item n = match snd n with None -> None | Some ( _ , _ , r ) -> Some r end