Blyx Nest Blyx language
Registry / Framework
framework · v0.1.1

Flightdeck cosine-fit

Train an embedding direction against a target row. A squared-norm epsilon stabilizes empty signal.

Source repository · Package JSON

Use Flightdeck cosine-fit

use vendor::fd_cosine_fit::cosine_fit;

Run the example

nest demo fd_cosine_fit@0.1.1
blyxc native-run fd_cosine_fit-demo/main.blyx
Example source and expected output
use vendor::fd_cosine_fit::cosine_fit;
fn main() { fd_cosine_fit(2, 7); }

Expected output

module {
  func.func @main(%x: tensor<2x7xf32>, %target: tensor<2x7xf32>) -> (tensor<2x7xf32>, tensor<2x7xf32>) {
    %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor<2x7xf32>
    %v1 = stablehlo.multiply %x, %x : tensor<2x7xf32>
    %v2 = stablehlo.constant dense<0.00000000000000000e+00> : tensor<f32>
    %v3 = stablehlo.reduce(%v1 init: %v2) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
    %v4 = stablehlo.broadcast_in_dim %v3, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
    %v5 = stablehlo.constant dense<9.99999999999999955e-07> : tensor<2x7xf32>
    %v6 = stablehlo.add %v4, %v5 : tensor<2x7xf32>
    %v7 = stablehlo.sqrt %v6 : tensor<2x7xf32>
    %v8 = stablehlo.multiply %target, %target : tensor<2x7xf32>
    %v9 = stablehlo.reduce(%v8 init: %v2) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
    %v10 = stablehlo.broadcast_in_dim %v9, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
    %v11 = stablehlo.add %v10, %v5 : tensor<2x7xf32>
    %v12 = stablehlo.sqrt %v11 : tensor<2x7xf32>
    %v13 = stablehlo.multiply %x, %target : tensor<2x7xf32>
    %v14 = stablehlo.reduce(%v13 init: %v2) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
    %v15 = stablehlo.broadcast_in_dim %v14, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
    %v16 = stablehlo.multiply %v7, %v12 : tensor<2x7xf32>
    %v17 = stablehlo.divide %v15, %v16 : tensor<2x7xf32>
    %v18 = stablehlo.constant dense<1.00000000000000000e+00> : tensor<2x7xf32>
    %v19 = stablehlo.subtract %v18, %v17 : tensor<2x7xf32>
    %v20 = stablehlo.multiply %v17, %x : tensor<2x7xf32>
    %v21 = stablehlo.multiply %v7, %v7 : tensor<2x7xf32>
    %v22 = stablehlo.divide %v20, %v21 : tensor<2x7xf32>
    %v23 = stablehlo.divide %target, %v16 : tensor<2x7xf32>
    %v24 = stablehlo.subtract %v22, %v23 : tensor<2x7xf32>
    return %v19, %v24 : tensor<2x7xf32>, tensor<2x7xf32>
  }
}

Published versions

VersionPackageSource commitSHA-256
0.1.1Download ZIP · Browse filesbf9c3d5003180834f890d8488b14b8722d5c39bd1fbb35e0289bbb37fd2240b2d3503819d8
0.1.0Download ZIP · Browse filesd5835c510937075a18b86fd43802cd764c0b34e6ad6a97f68abdd15d837a64a6bc2855e155