Skip to content

Instantly share code, notes, and snippets.

@rxwei
Created September 24, 2019 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rxwei/4b1091cacbb07008c234e55201cb22be to your computer and use it in GitHub Desktop.
Save rxwei/4b1091cacbb07008c234e55201cb22be to your computer and use it in GitHub Desktop.
Zero initialization considered harmful!
// AD__dot__pullback_src_0_wrt_0_1
sil hidden [ossa] @AD__dot__pullback_src_0_wrt_0_1 : $@convention(thin) (@in_guaranteed Float, @owned _AD__dot_bb0__PB__src_0_wrt_0_1) -> (@out Vector, @out Vector) {
// %0 // user: %202
// %1 // user: %203
// %2 // user: %65
// %3 // user: %66
bb0(%0 : $*Vector, %1 : $*Vector, %2 : $*Float, %3 : @owned $_AD__dot_bb0__PB__src_0_wrt_0_1):
%4 = alloc_stack $Tracked<Float> // users: %233, %232, %196, %188, %7
%5 = witness_method $Tracked<Float>, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %7
%6 = metatype $@thick Tracked<Float>.Type // user: %7
%7 = apply %5<Tracked<Float>>(%4, %6) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%8 = alloc_stack $Tracked<Float> // users: %231, %230, %180, %172, %11
%9 = witness_method $Tracked<Float>, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %11
%10 = metatype $@thick Tracked<Float>.Type // user: %11
%11 = apply %9<Tracked<Float>>(%8, %10) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%12 = alloc_stack $Tracked<Float> // users: %229, %228, %172, %166, %15
%13 = witness_method $Tracked<Float>, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %15
%14 = metatype $@thick Tracked<Float>.Type // user: %15
%15 = apply %13<Tracked<Float>>(%12, %14) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%16 = alloc_stack $Tracked<Float> // users: %227, %226, %188, %162, %19
%17 = witness_method $Tracked<Float>, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %19
%18 = metatype $@thick Tracked<Float>.Type // user: %19
%19 = apply %17<Tracked<Float>>(%16, %18) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%20 = alloc_stack $Vector // users: %225, %202, %199, %150, %23
%21 = witness_method $Vector, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %23
%22 = metatype $@thick Vector.Type // user: %23
%23 = apply %21<Vector>(%20, %22) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%24 = alloc_stack $Tracked<Float> // users: %224, %223, %147, %139, %27
%25 = witness_method $Tracked<Float>, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %27
%26 = metatype $@thick Tracked<Float>.Type // user: %27
%27 = apply %25<Tracked<Float>>(%24, %26) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%28 = alloc_stack $Vector // users: %222, %203, %183, %134, %31
%29 = witness_method $Vector, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %31
%30 = metatype $@thick Vector.Type // user: %31
%31 = apply %29<Vector>(%28, %30) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%32 = alloc_stack $Tracked<Float> // users: %221, %220, %131, %123, %35
%33 = witness_method $Tracked<Float>, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %35
%34 = metatype $@thick Tracked<Float>.Type // user: %35
%35 = apply %33<Tracked<Float>>(%32, %34) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%36 = alloc_stack $Tracked<Float> // users: %219, %218, %123, %117, %39
%37 = witness_method $Tracked<Float>, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %39
%38 = metatype $@thick Tracked<Float>.Type // user: %39
%39 = apply %37<Tracked<Float>>(%36, %38) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%40 = alloc_stack $Tracked<Float> // users: %217, %216, %139, %113, %43
%41 = witness_method $Tracked<Float>, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %43
%42 = metatype $@thick Tracked<Float>.Type // user: %43
%43 = apply %41<Tracked<Float>>(%40, %42) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%44 = alloc_stack $Tracked<Float> // users: %215, %214, %108, %100, %47
%45 = witness_method $Tracked<Float>, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %47
%46 = metatype $@thick Tracked<Float>.Type // user: %47
%47 = apply %45<Tracked<Float>>(%44, %46) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%48 = alloc_stack $Tracked<Float> // users: %213, %212, %157, %96, %51
%49 = witness_method $Tracked<Float>, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %51
%50 = metatype $@thick Tracked<Float>.Type // user: %51
%51 = apply %49<Tracked<Float>>(%48, %50) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%52 = alloc_stack $Tracked<Float> // users: %211, %210, %91, %86, %55
%53 = witness_method $Tracked<Float>, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %55
%54 = metatype $@thick Tracked<Float>.Type // user: %55
%55 = apply %53<Tracked<Float>>(%52, %54) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%56 = alloc_stack $Tracked<Float> // users: %209, %208, %86, %81, %59
%57 = witness_method $Tracked<Float>, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %59
%58 = metatype $@thick Tracked<Float>.Type // user: %59
%59 = apply %57<Tracked<Float>>(%56, %58) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%60 = alloc_stack $Float // users: %207, %206, %76, %72, %63
%61 = witness_method $Float, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %63
%62 = metatype $@thick Float.Type // user: %63
%63 = apply %61<Float>(%60, %62) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%64 = alloc_stack $Float // users: %205, %204, %72, %65
copy_addr %2 to [initialization] %64 : $*Float // id: %65
(%66, %67, %68, %69) = destructure_struct %3 : $_AD__dot_bb0__PB__src_0_wrt_0_1 // users: %156, %107, %90, %75
%70 = witness_method $Float, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %72
%71 = metatype $@thick Float.Type // user: %72
%72 = apply %70<Float>(%60, %64, %71) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
%73 = alloc_stack $Tracked<Float> // users: %83, %82, %81, %76
// function_ref thunk for @escaping @callee_guaranteed (@unowned Float) -> (@owned Tracked<Float>)
%74 = function_ref @$sSf4null7TrackedVySfGIegyo_SfADIegnr_TR : $@convention(thin) (@in_guaranteed Float, @guaranteed @callee_guaranteed (Float) -> @owned Tracked<Float>) -> @out Tracked<Float> // user: %75
%75 = partial_apply [callee_guaranteed] %74(%69) : $@convention(thin) (@in_guaranteed Float, @guaranteed @callee_guaranteed (Float) -> @owned Tracked<Float>) -> @out Tracked<Float> // users: %77, %76
%76 = apply %75(%73, %60) : $@callee_guaranteed (@in_guaranteed Float) -> @out Tracked<Float> // user: %78
destroy_value %75 : $@callee_guaranteed (@in_guaranteed Float) -> @out Tracked<Float> // id: %77
destructure_tuple %76 : $() // id: %78
%79 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %81
%80 = metatype $@thick Tracked<Float>.Type // user: %81
%81 = apply %79<Tracked<Float>>(%56, %73, %80) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
destroy_addr %73 : $*Tracked<Float> // id: %82
dealloc_stack %73 : $*Tracked<Float> // id: %83
%84 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %86
%85 = metatype $@thick Tracked<Float>.Type // user: %86
%86 = apply %84<Tracked<Float>>(%52, %56, %85) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
%87 = alloc_stack $Tracked<Float> // users: %103, %97, %96, %91
%88 = alloc_stack $Tracked<Float> // users: %102, %101, %100, %91
// function_ref thunk for @escaping @callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>)
%89 = function_ref @$s4null7TrackedVySfGA2DIeggoo_A3DIegnrr_TR : $@convention(thin) (@in_guaranteed Tracked<Float>, @guaranteed @callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>)) -> (@out Tracked<Float>, @out Tracked<Float>) // user: %90
%90 = partial_apply [callee_guaranteed] %89(%68) : $@convention(thin) (@in_guaranteed Tracked<Float>, @guaranteed @callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>)) -> (@out Tracked<Float>, @out Tracked<Float>) // users: %92, %91
%91 = apply %90(%87, %88, %52) : $@callee_guaranteed (@in_guaranteed Tracked<Float>) -> (@out Tracked<Float>, @out Tracked<Float>) // user: %93
destroy_value %90 : $@callee_guaranteed (@in_guaranteed Tracked<Float>) -> (@out Tracked<Float>, @out Tracked<Float>) // id: %92
destructure_tuple %91 : $() // id: %93
%94 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %96
%95 = metatype $@thick Tracked<Float>.Type // user: %96
%96 = apply %94<Tracked<Float>>(%48, %87, %95) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
destroy_addr %87 : $*Tracked<Float> // id: %97
%98 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %100
%99 = metatype $@thick Tracked<Float>.Type // user: %100
%100 = apply %98<Tracked<Float>>(%44, %88, %99) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
destroy_addr %88 : $*Tracked<Float> // id: %101
dealloc_stack %88 : $*Tracked<Float> // id: %102
dealloc_stack %87 : $*Tracked<Float> // id: %103
%104 = alloc_stack $Tracked<Float> // users: %120, %114, %113, %108
%105 = alloc_stack $Tracked<Float> // users: %119, %118, %117, %108
// function_ref thunk for @escaping @callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>)
%106 = function_ref @$s4null7TrackedVySfGA2DIeggoo_A3DIegnrr_TR : $@convention(thin) (@in_guaranteed Tracked<Float>, @guaranteed @callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>)) -> (@out Tracked<Float>, @out Tracked<Float>) // user: %107
%107 = partial_apply [callee_guaranteed] %106(%67) : $@convention(thin) (@in_guaranteed Tracked<Float>, @guaranteed @callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>)) -> (@out Tracked<Float>, @out Tracked<Float>) // users: %109, %108
%108 = apply %107(%104, %105, %44) : $@callee_guaranteed (@in_guaranteed Tracked<Float>) -> (@out Tracked<Float>, @out Tracked<Float>) // user: %110
destroy_value %107 : $@callee_guaranteed (@in_guaranteed Tracked<Float>) -> (@out Tracked<Float>, @out Tracked<Float>) // id: %109
destructure_tuple %108 : $() // id: %110
%111 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %113
%112 = metatype $@thick Tracked<Float>.Type // user: %113
%113 = apply %111<Tracked<Float>>(%40, %104, %112) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
destroy_addr %104 : $*Tracked<Float> // id: %114
%115 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %117
%116 = metatype $@thick Tracked<Float>.Type // user: %117
%117 = apply %115<Tracked<Float>>(%36, %105, %116) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
destroy_addr %105 : $*Tracked<Float> // id: %118
dealloc_stack %105 : $*Tracked<Float> // id: %119
dealloc_stack %104 : $*Tracked<Float> // id: %120
%121 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %123
%122 = metatype $@thick Tracked<Float>.Type // user: %123
%123 = apply %121<Tracked<Float>>(%32, %36, %122) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
%124 = alloc_stack $Vector // users: %136, %135, %134, %128, %127
%125 = witness_method $Vector, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %127
%126 = metatype $@thick Vector.Type // user: %127
%127 = apply %125<Vector>(%124, %126) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%128 = struct_element_addr %124 : $*Vector, #Vector.y // user: %131
%129 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %131
%130 = metatype $@thick Tracked<Float>.Type // user: %131
%131 = apply %129<Tracked<Float>>(%128, %32, %130) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
%132 = witness_method $Vector, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %134
%133 = metatype $@thick Vector.Type // user: %134
%134 = apply %132<Vector>(%28, %124, %133) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
destroy_addr %124 : $*Vector // id: %135
dealloc_stack %124 : $*Vector // id: %136
%137 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %139
%138 = metatype $@thick Tracked<Float>.Type // user: %139
%139 = apply %137<Tracked<Float>>(%24, %40, %138) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
%140 = alloc_stack $Vector // users: %152, %151, %150, %144, %143
%141 = witness_method $Vector, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %143
%142 = metatype $@thick Vector.Type // user: %143
%143 = apply %141<Vector>(%140, %142) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%144 = struct_element_addr %140 : $*Vector, #Vector.y // user: %147
%145 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %147
%146 = metatype $@thick Tracked<Float>.Type // user: %147
%147 = apply %145<Tracked<Float>>(%144, %24, %146) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
%148 = witness_method $Vector, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %150
%149 = metatype $@thick Vector.Type // user: %150
%150 = apply %148<Vector>(%20, %140, %149) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
destroy_addr %140 : $*Vector // id: %151
dealloc_stack %140 : $*Vector // id: %152
%153 = alloc_stack $Tracked<Float> // users: %169, %163, %162, %157
%154 = alloc_stack $Tracked<Float> // users: %168, %167, %166, %157
// function_ref thunk for @escaping @callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>)
%155 = function_ref @$s4null7TrackedVySfGA2DIeggoo_A3DIegnrr_TR : $@convention(thin) (@in_guaranteed Tracked<Float>, @guaranteed @callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>)) -> (@out Tracked<Float>, @out Tracked<Float>) // user: %156
%156 = partial_apply [callee_guaranteed] %155(%66) : $@convention(thin) (@in_guaranteed Tracked<Float>, @guaranteed @callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>)) -> (@out Tracked<Float>, @out Tracked<Float>) // users: %158, %157
%157 = apply %156(%153, %154, %48) : $@callee_guaranteed (@in_guaranteed Tracked<Float>) -> (@out Tracked<Float>, @out Tracked<Float>) // user: %159
destroy_value %156 : $@callee_guaranteed (@in_guaranteed Tracked<Float>) -> (@out Tracked<Float>, @out Tracked<Float>) // id: %158
destructure_tuple %157 : $() // id: %159
%160 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %162
%161 = metatype $@thick Tracked<Float>.Type // user: %162
%162 = apply %160<Tracked<Float>>(%16, %153, %161) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
destroy_addr %153 : $*Tracked<Float> // id: %163
%164 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %166
%165 = metatype $@thick Tracked<Float>.Type // user: %166
%166 = apply %164<Tracked<Float>>(%12, %154, %165) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
destroy_addr %154 : $*Tracked<Float> // id: %167
dealloc_stack %154 : $*Tracked<Float> // id: %168
dealloc_stack %153 : $*Tracked<Float> // id: %169
%170 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %172
%171 = metatype $@thick Tracked<Float>.Type // user: %172
%172 = apply %170<Tracked<Float>>(%8, %12, %171) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
%173 = alloc_stack $Vector // users: %185, %184, %183, %177, %176
%174 = witness_method $Vector, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %176
%175 = metatype $@thick Vector.Type // user: %176
%176 = apply %174<Vector>(%173, %175) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%177 = struct_element_addr %173 : $*Vector, #Vector.x // user: %180
%178 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %180
%179 = metatype $@thick Tracked<Float>.Type // user: %180
%180 = apply %178<Tracked<Float>>(%177, %8, %179) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
%181 = witness_method $Vector, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %183
%182 = metatype $@thick Vector.Type // user: %183
%183 = apply %181<Vector>(%28, %173, %182) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
destroy_addr %173 : $*Vector // id: %184
dealloc_stack %173 : $*Vector // id: %185
%186 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %188
%187 = metatype $@thick Tracked<Float>.Type // user: %188
%188 = apply %186<Tracked<Float>>(%4, %16, %187) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
%189 = alloc_stack $Vector // users: %201, %200, %199, %193, %192
%190 = witness_method $Vector, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %192
%191 = metatype $@thick Vector.Type // user: %192
%192 = apply %190<Vector>(%189, %191) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
%193 = struct_element_addr %189 : $*Vector, #Vector.x // user: %196
%194 = witness_method $Tracked<Float>, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %196
%195 = metatype $@thick Tracked<Float>.Type // user: %196
%196 = apply %194<Tracked<Float>>(%193, %4, %195) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
%197 = witness_method $Vector, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %199
%198 = metatype $@thick Vector.Type // user: %199
%199 = apply %197<Vector>(%20, %189, %198) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
destroy_addr %189 : $*Vector // id: %200
dealloc_stack %189 : $*Vector // id: %201
copy_addr [take] %20 to [initialization] %0 : $*Vector // id: %202
copy_addr [take] %28 to [initialization] %1 : $*Vector // id: %203
destroy_addr %64 : $*Float // id: %204
dealloc_stack %64 : $*Float // id: %205
destroy_addr %60 : $*Float // id: %206
dealloc_stack %60 : $*Float // id: %207
destroy_addr %56 : $*Tracked<Float> // id: %208
dealloc_stack %56 : $*Tracked<Float> // id: %209
destroy_addr %52 : $*Tracked<Float> // id: %210
dealloc_stack %52 : $*Tracked<Float> // id: %211
destroy_addr %48 : $*Tracked<Float> // id: %212
dealloc_stack %48 : $*Tracked<Float> // id: %213
destroy_addr %44 : $*Tracked<Float> // id: %214
dealloc_stack %44 : $*Tracked<Float> // id: %215
destroy_addr %40 : $*Tracked<Float> // id: %216
dealloc_stack %40 : $*Tracked<Float> // id: %217
destroy_addr %36 : $*Tracked<Float> // id: %218
dealloc_stack %36 : $*Tracked<Float> // id: %219
destroy_addr %32 : $*Tracked<Float> // id: %220
dealloc_stack %32 : $*Tracked<Float> // id: %221
dealloc_stack %28 : $*Vector // id: %222
destroy_addr %24 : $*Tracked<Float> // id: %223
dealloc_stack %24 : $*Tracked<Float> // id: %224
dealloc_stack %20 : $*Vector // id: %225
destroy_addr %16 : $*Tracked<Float> // id: %226
dealloc_stack %16 : $*Tracked<Float> // id: %227
destroy_addr %12 : $*Tracked<Float> // id: %228
dealloc_stack %12 : $*Tracked<Float> // id: %229
destroy_addr %8 : $*Tracked<Float> // id: %230
dealloc_stack %8 : $*Tracked<Float> // id: %231
destroy_addr %4 : $*Tracked<Float> // id: %232
dealloc_stack %4 : $*Tracked<Float> // id: %233
%234 = tuple () // user: %235
return %234 : $() // id: %235
} // end sil function 'AD__dot__pullback_src_0_wrt_0_1'
// AD__dot__pullback_src_0_wrt_0_1
sil hidden [ossa] @AD__dot__pullback_src_0_wrt_0_1 : $@convention(thin) (Float, @owned _AD__dot_bb0__PB__src_0_wrt_0_1) -> (@owned Vector, @owned Vector) {
// %0 // user: %11
// %1 // user: %6
bb0(%0 : $Float, %1 : @owned $_AD__dot_bb0__PB__src_0_wrt_0_1):
%2 = alloc_stack $Float // users: %51, %50, %19, %14, %5
%3 = witness_method $Float, #AdditiveArithmetic.zero!getter.1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %5
%4 = metatype $@thick Float.Type // user: %5
%5 = apply %3<Float>(%2, %4) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
(%6, %7, %8, %9) = destructure_struct %1 : $_AD__dot_bb0__PB__src_0_wrt_0_1 // users: %30, %29, %26, %25, %22, %21, %18
%10 = alloc_stack $Float // users: %16, %15, %14, %11
store %0 to [trivial] %10 : $*Float // id: %11
%12 = witness_method $Float, #AdditiveArithmetic."+="!1 : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %14
%13 = metatype $@thick Float.Type // user: %14
%14 = apply %12<Float>(%2, %10, %13) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
destroy_addr %10 : $*Float // id: %15
dealloc_stack %10 : $*Float // id: %16
// function_ref thunk for @escaping @callee_guaranteed (@unowned Float) -> (@owned Tracked<Float>)
%17 = function_ref @$sSf4null7TrackedVySfGIegyo_SfADIegno_TR : $@convention(thin) (@in_guaranteed Float, @guaranteed @callee_guaranteed (Float) -> @owned Tracked<Float>) -> @owned Tracked<Float> // user: %18
%18 = partial_apply [callee_guaranteed] %17(%9) : $@convention(thin) (@in_guaranteed Float, @guaranteed @callee_guaranteed (Float) -> @owned Tracked<Float>) -> @owned Tracked<Float> // users: %20, %19
%19 = apply %18(%2) : $@callee_guaranteed (@in_guaranteed Float) -> @owned Tracked<Float> // users: %41, %21
destroy_value %18 : $@callee_guaranteed (@in_guaranteed Float) -> @owned Tracked<Float> // id: %20
%21 = apply %8(%19) : $@callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>) // user: %23
destroy_value %8 : $@callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>) // id: %22
(%23, %24) = destructure_tuple %21 : $(Tracked<Float>, Tracked<Float>) // users: %42, %29, %43, %25
%25 = apply %7(%24) : $@callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>) // user: %27
destroy_value %7 : $@callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>) // id: %26
(%27, %28) = destructure_tuple %25 : $(Tracked<Float>, Tracked<Float>) // users: %44, %34, %45, %38
%29 = apply %6(%23) : $@callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>) // user: %31
destroy_value %6 : $@callee_guaranteed (@guaranteed Tracked<Float>) -> (@owned Tracked<Float>, @owned Tracked<Float>) // id: %30
(%31, %32) = destructure_tuple %29 : $(Tracked<Float>, Tracked<Float>) // users: %46, %33, %47, %37
%33 = copy_value %31 : $Tracked<Float> // user: %35
%34 = copy_value %27 : $Tracked<Float> // user: %35
%35 = struct $Vector (%33 : $Tracked<Float>, %34 : $Tracked<Float>) // users: %48, %36
%36 = copy_value %35 : $Vector // user: %52
%37 = copy_value %32 : $Tracked<Float> // user: %39
%38 = copy_value %28 : $Tracked<Float> // user: %39
%39 = struct $Vector (%37 : $Tracked<Float>, %38 : $Tracked<Float>) // users: %49, %40
%40 = copy_value %39 : $Vector // user: %52
destroy_value %19 : $Tracked<Float> // id: %41
destroy_value %23 : $Tracked<Float> // id: %42
destroy_value %24 : $Tracked<Float> // id: %43
destroy_value %27 : $Tracked<Float> // id: %44
destroy_value %28 : $Tracked<Float> // id: %45
destroy_value %31 : $Tracked<Float> // id: %46
destroy_value %32 : $Tracked<Float> // id: %47
destroy_value %35 : $Vector // id: %48
destroy_value %39 : $Vector // id: %49
destroy_addr %2 : $*Float // id: %50
dealloc_stack %2 : $*Float // id: %51
%52 = tuple (%36 : $Vector, %40 : $Vector) // user: %53
return %52 : $(Vector, Vector) // id: %53
} // end sil function 'AD__dot__pullback_src_0_wrt_0_1'
public enum _GlobalLeakCount {
public static var count = 0
}
/// A type that tracks the number of live instances of a wrapped value type.
///
/// `Tracked<T>` is used to check for memory leaks in functions created via
/// automatic differentiation.
public struct Tracked<T> {
fileprivate class Box {
fileprivate var value : T
init(_ value: T) {
self.value = value
_GlobalLeakCount.count += 1
}
deinit {
_GlobalLeakCount.count -= 1
}
}
private var handle: Box
@differentiable(jvp: _jvpInit, vjp: _vjpInit where T : Differentiable, T == T.TangentVector)
public init(_ value: T) {
self.handle = Box(value)
}
@differentiable(jvp: _jvpValue, vjp: _vjpValue where T : Differentiable, T == T.TangentVector)
public var value: T {
get { handle.value }
set { handle.value = newValue }
}
}
extension Tracked : ExpressibleByFloatLiteral where T : ExpressibleByFloatLiteral {
public init(floatLiteral value: T.FloatLiteralType) {
self.handle = Box(T(floatLiteral: value))
}
}
extension Tracked : CustomStringConvertible {
public var description: String { return "Tracked(\(value))" }
}
extension Tracked : ExpressibleByIntegerLiteral where T : ExpressibleByIntegerLiteral {
public init(integerLiteral value: T.IntegerLiteralType) {
self.handle = Box(T(integerLiteral: value))
}
}
extension Tracked : Comparable where T : Comparable {
public static func < (lhs: Tracked, rhs: Tracked) -> Bool {
return lhs.value < rhs.value
}
public static func <= (lhs: Tracked, rhs: Tracked) -> Bool {
return lhs.value <= rhs.value
}
public static func > (lhs: Tracked, rhs: Tracked) -> Bool {
return lhs.value > rhs.value
}
public static func >= (lhs: Tracked, rhs: Tracked) -> Bool {
return lhs.value >= rhs.value
}
}
extension Tracked : AdditiveArithmetic where T : AdditiveArithmetic {
public static var zero: Tracked { return Tracked(T.zero) }
public static func + (lhs: Tracked, rhs: Tracked) -> Tracked {
return Tracked(lhs.value + rhs.value)
}
public static func - (lhs: Tracked, rhs: Tracked) -> Tracked {
return Tracked(lhs.value - rhs.value)
}
}
extension Tracked : Equatable where T : Equatable {
public static func == (lhs: Tracked, rhs: Tracked) -> Bool {
return lhs.value == rhs.value
}
}
extension Tracked : SignedNumeric & Numeric where T : SignedNumeric, T == T.Magnitude {
public typealias Magnitude = Tracked<T.Magnitude>
public init?<U>(exactly source: U) where U : BinaryInteger {
if let t = T(exactly: source) {
self.init(t)
}
return nil
}
public var magnitude: Magnitude { return Magnitude(value.magnitude) }
public static func * (lhs: Tracked, rhs: Tracked) -> Tracked {
return Tracked(lhs.value * rhs.value)
}
public static func *= (lhs: inout Tracked, rhs: Tracked) {
lhs = lhs * rhs
}
}
extension Tracked where T : FloatingPoint {
public static func / (lhs: Tracked, rhs: Tracked) -> Tracked {
return Tracked(lhs.value / rhs.value)
}
public static func /= (lhs: inout Tracked, rhs: Tracked) {
lhs = lhs / rhs
}
}
extension Tracked : Strideable where T : Strideable, T.Stride == T.Stride.Magnitude {
public typealias Stride = Tracked<T.Stride>
public func distance(to other: Tracked) -> Stride {
return Stride(value.distance(to: other.value))
}
public func advanced(by n: Stride) -> Tracked {
return Tracked(value.advanced(by: n.value))
}
}
// For now, `T` must be restricted to trivial types (like `Float` or `Tensor`).
extension Tracked : Differentiable where T : Differentiable, T == T.TangentVector {
public typealias TangentVector = Tracked<T.TangentVector>
}
extension Tracked where T : Differentiable, T == T.TangentVector {
@usableFromInline
internal static func _vjpInit(_ value: T)
-> (value: Self, pullback: (Self.TangentVector) -> (T.TangentVector)) {
return (Tracked(value), { v in v.value })
}
@usableFromInline
internal static func _jvpInit(_ value: T)
-> (value: Self, differential: (T.TangentVector) -> (Self.TangentVector)) {
return (Tracked(value), { v in Tracked(v) })
}
@usableFromInline
internal func _vjpValue() -> (T, (T.TangentVector) -> Self.TangentVector) {
return (value, { v in Tracked(v) })
}
@usableFromInline
internal func _jvpValue() -> (T, (Self.TangentVector) -> T.TangentVector) {
return (value, { v in v.value })
}
}
extension Tracked where T : Differentiable, T == T.TangentVector {
@usableFromInline
@differentiating(+)
internal static func _vjpAdd(lhs: Self, rhs: Self)
-> (value: Self, pullback: (Self) -> (Self, Self)) {
return (lhs + rhs, { v in (v, v) })
}
@usableFromInline
@differentiating(+)
internal static func _jvpAdd(lhs: Self, rhs: Self)
-> (value: Self, differential: (Self, Self) -> Self) {
return (lhs + rhs, { $0 + $1 })
}
@usableFromInline
@differentiating(-)
internal static func _vjpSubtract(lhs: Self, rhs: Self)
-> (value: Self, pullback: (Self) -> (Self, Self)) {
return (lhs - rhs, { v in (v, .zero - v) })
}
@usableFromInline
@differentiating(-)
internal static func _jvpSubtract(lhs: Self, rhs: Self)
-> (value: Self, differential: (Self, Self) -> Self) {
return (lhs - rhs, { $0 - $1 })
}
}
extension Tracked where T : Differentiable & SignedNumeric, T == T.Magnitude,
T == T.TangentVector {
@usableFromInline
@differentiating(*)
internal static func _vjpMultiply(lhs: Self, rhs: Self)
-> (value: Self, pullback: (Self) -> (Self, Self)) {
return (lhs * rhs, { v in (v * rhs, v * lhs) })
}
@usableFromInline
@differentiating(*)
internal static func _jvpMultiply(lhs: Self, rhs: Self)
-> (value: Self, differential: (Self, Self) -> (Self)) {
return (lhs * rhs, { (dx, dy) in dx * rhs + dy * lhs })
}
}
extension Tracked where T : Differentiable & FloatingPoint, T == T.TangentVector {
@usableFromInline
@differentiating(/)
internal static func _vjpDivide(lhs: Self, rhs: Self)
-> (value: Self, pullback: (Self) -> (Self, Self)) {
return (lhs / rhs, { v in (v / rhs, -lhs / (rhs * rhs) * v) })
}
@usableFromInline
@differentiating(/)
internal static func _jvpDivide(lhs: Self, rhs: Self)
-> (value: Self, differential: (Self, Self) -> (Self)) {
return (lhs / rhs, { (dx, dy) in dx / rhs - lhs / (rhs * rhs) * dy })
}
}
struct Vector: Differentiable, AdditiveArithmetic {
var x: Tracked<Float>
var y: Tracked<Float>
}
import Dispatch
func time(_ body: () -> Void) {
let divisor: Float = 1_000_000_000
let start = Float(DispatchTime.now().uptimeNanoseconds) / divisor
print("Start: \(start)s")
body()
let end = Float(DispatchTime.now().uptimeNanoseconds) / divisor
print("End: \(end)s")
let elapsed = end - start
print("Elapsed: \(elapsed)s")
}
@differentiable
@_silgen_name("dot")
func dot(_ a: Vector, _ b: Vector) -> Float {
(a.x * b.x + a.y * b.y).value
}
time {
for i in 0...100000 {
let x = Vector.zero
let y = Vector.zero
if i.isMultiple(of: 1000) { print("\(i)...") }
_ = gradient(of: dot)(x, y)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment