// Use a smooth robust regression objective and its bounded influence function with scale one. use graph_io; pub fn fd_pseudo_huber(rows: i64, width: i64) { println!("module {"); fd_line(" func.func @main(%x: tensor, %target: tensor) -> (tensor, tensor) {", rows, width); fd_line(" %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor", rows, width); fd_line(" %v1 = stablehlo.subtract %x, %target : tensor", rows, width); // r = x-target fd_line(" %v2 = stablehlo.constant dense<1.00000000000000000e+00> : tensor", rows, width); fd_line(" %v3 = stablehlo.multiply %v1, %v1 : tensor", rows, width); fd_line(" %v4 = stablehlo.add %v2, %v3 : tensor", rows, width); fd_line(" %v5 = stablehlo.sqrt %v4 : tensor", rows, width); // d = sqrt(1+r*r) fd_line(" %v6 = stablehlo.add %v5, %v2 : tensor", rows, width); fd_line(" %v7 = stablehlo.divide %v3, %v6 : tensor", rows, width); // loss = r*r/(d+1) fd_line(" %v8 = stablehlo.divide %v1, %v5 : tensor", rows, width); // grad = r/d fd_line(" return %v7, %v8 : tensor, tensor", rows, width); println!(" }"); println!("}"); }