@@ -148,6 +148,7 @@ type binop =
148148 | Mod
149149 | Cmplt
150150 | Cmpeq
151+ | Cmpne
151152 (* Waiting till we have a use-case to see how to sensibly introduce bitwise operations. *)
152153 (* | Shl *)
153154 (* | Shr *)
@@ -181,16 +182,18 @@ type op = Ternop of ternop | Binop of binop | Unop of unop [@@deriving sexp, com
181182(* * Either the left-neutral or right-neutral element of the operation. Unspecified if the operation
182183 does not have a neutral element. *)
183184let neutral_elem = function
184- | Add | Sub -> 0.
185- | Mul | Div -> 1.
185+ | Add -> 0.
186+ | Sub -> 0.
187+ | Mul -> 1.
188+ | Div -> 1.
186189 | ToPowOf -> 1.
187190 | Relu_gate -> 1.
188191 | Satur01_gate -> 0.5
189192 | Max -> Float. neg_infinity
190193 | Min -> Float. infinity
191194 | And -> 1.
192195 | Or -> 0.
193- | Arg2 | Arg1 | Mod | Cmplt | Cmpeq (* | Shl | Shr * ) -> 0.
196+ | Arg2 | Arg1 | Mod | Cmplt | Cmpeq | Cmpne (* | Shl | Shr * ) -> 0.
194197
195198let interpret_binop op v1 v2 =
196199 let open Float in
@@ -210,6 +213,7 @@ let interpret_binop op v1 v2 =
210213 | Mod -> v1 % v2
211214 | Cmplt -> if v1 < v2 then 1. else 0.
212215 | Cmpeq -> if v1 = v2 then 1. else 0.
216+ | Cmpne -> if v1 <> v2 then 1. else 0.
213217 (* | Shl -> v1 * (int_pow 2. @@ to_int v2) *)
214218 (* | Shr -> v1 / (int_pow 2. @@ to_int v2) *)
215219 | Or -> if v1 <> 0. || v2 <> 0. then 1. else 0.
@@ -260,6 +264,7 @@ let binop_cd_syntax = function
260264 | Satur01_gate -> " -?^"
261265 | Cmplt -> " <"
262266 | Cmpeq -> " ="
267+ | Cmpne -> " <>"
263268 | Or -> " ||"
264269 | And -> " &&"
265270 | Mod -> " %"
@@ -282,6 +287,7 @@ let binop_cd_fallback_syntax = function
282287 | Satur01_gate -> " sat01_gate"
283288 | Cmplt -> " lt"
284289 | Cmpeq -> " eq"
290+ | Cmpne -> " ne"
285291 | Or -> " or_"
286292 | And -> " and_"
287293 | Mod -> " mod_"
@@ -315,6 +321,7 @@ let binop_c_syntax prec v =
315321 | Mod , _ -> (" (" , " %" , " )" )
316322 | Cmplt , _ -> (" (" , " <" , " )" )
317323 | Cmpeq , _ -> (" (" , " ==" , " )" )
324+ | Cmpne , _ -> (" (" , " !=" , " )" )
318325 (* | Shl, Byte_prec _ -> ("(", " <<", ")") *)
319326 (* | Shl, _ -> ("((", ") * exp2(", "))") *)
320327 (* | Shr, Byte_prec _ -> ("(", " >>", ")") *)
@@ -323,7 +330,7 @@ let binop_c_syntax prec v =
323330 | And , _ -> (" (" , " &&" , " )" )
324331
325332let is_assign_op = function
326- | Arg1 | Mod (* | Shl | Shr * ) | Cmplt | Cmpeq -> false
333+ | Arg1 | Mod (* | Shl | Shr * ) | Cmplt | Cmpeq | Cmpne -> false
327334 | Add | Sub | Mul | Div | ToPowOf | Relu_gate | Satur01_gate | Arg2 | Max | Min | Or | And -> true
328335
329336let assign_op_cd_syntax ~initialize_neutral = function
@@ -350,7 +357,7 @@ let assign_op_cd_syntax ~initialize_neutral = function
350357 | Min -> " =^^"
351358 | Or -> " =||"
352359 | And -> " =&&"
353- | Arg1 | Mod (* | Shl | Shr * ) | Cmplt | Cmpeq ->
360+ | Arg1 | Mod (* | Shl | Shr * ) | Cmplt | Cmpeq | Cmpne ->
354361 invalid_arg " Ops.assign_op_cd_syntax: not an assignment op"
355362
356363(* * Note: currently we do not support unary prefix symbols. *)
0 commit comments