1 import Base 2 import ./elementwise.bend as Elementwise 3 import ./loss_ops_LAWS.bend as Laws 4 5 def Laws.scalar_divide(left, right): 6 {==} 7 8 def Laws.scalar_exp_left(left, right): 9 {==} 10 11 def Laws.scalar_log_left(left, right): 12 {==} 13 14 def Laws.scalar_matches_same(left, right, same): 15 %Equal.sym(Bool, U32.is_eq(Elementwise.bits(left), Elementwise.bits(right)), True{}, same) : 16 {Elementwise.zero_if(Bool.not(_), 1.0) == 1.0 : F32} 17 {==} 18 19 def Laws.scalar_matches_other(left, right, other): 20 %Equal.sym(Bool, U32.is_eq(Elementwise.bits(left), Elementwise.bits(right)), False{}, other) : 21 {Elementwise.zero_if(Bool.not(_), 1.0) == 0.0 : F32} 22 {==} 23 24 def Laws.scalar_pick_negated_target(left, right, target): 25 %Equal.sym(Bool, Elementwise.is_one(right), True{}, target) : {Elementwise.zero_if(Bool.not(_), F32.neg(left)) == F32.neg(left) : F32} 26 {==} 27 28 def Laws.scalar_pick_negated_other(left, right, other): 29 %Equal.sym(Bool, Elementwise.is_one(right), False{}, other) : {Elementwise.zero_if(Bool.not(_), F32.neg(left)) == 0.0 : F32} 30 {==} 31 32 def Laws.scalar_mse_grad(scale, left, right): 33 {==} 34 35 def Laws.scalar_one_hot_grad_target(count, left, right, target): 36 %Equal.sym(Bool, Elementwise.is_one(right), True{}, target) : 37 {Elementwise.zero_if(Bool.not(_), Elementwise.target_gradient(left, count)) == F32.neg(F32.div(left, count)) : F32} 38 {==} 39 40 def Laws.scalar_one_hot_grad_other(count, left, right, other): 41 %Equal.sym(Bool, Elementwise.is_one(right), False{}, other) : 42 {Elementwise.zero_if(Bool.not(_), Elementwise.target_gradient(left, count)) == 0.0 : F32} 43 {==} 44 45 def Laws.scalar_softmax_grad_one_class(count, left, right): 46 {==} 47 48 def Laws.scalar_softmax_grad_classes(count, left, right): 49 {==}