22
33import  _Differentiation
44
5- extension  Sequence  where 
6-     Self:  Collection ,  // we constrain to conform to collection cause otherwise we can't access any values by index
5+ extension  Sequence 
6+ where 
7+     Self:  Collection ,   // we constrain to conform to collection cause otherwise we can't access any values by index
78    Self:  Differentiable , 
8-     Self. TangentVector:  RangeReplaceableCollection ,  // we constrain the tangentvector to be able to create a value and write to it
9+     Self. TangentVector:  RangeReplaceableCollection ,    // we constrain the tangentvector to be able to create a value and write to it
910    Self. TangentVector. Element ==  Element . TangentVector , 
1011    Element:  Differentiable , 
1112    Element:  Comparable 
@@ -19,29 +20,30 @@ extension Sequence where
1920        value:  Element ? , 
2021        pullback:  ( Element ? . TangentVector)  ->  ( Self . TangentVector ) 
2122    )  where  Self. Index ==  Self . TangentVector . Index  { 
22-         let  index  =  withoutDerivative ( at:  self . indices. max  {  self [ $0]  <  self [ $1]  } )  // we grab the index of the element with the max value
23+         let  index  =  withoutDerivative ( at:  self . indices. max  {  self [ $0]  <  self [ $1]  } )    // we grab the index of the element with the max value
2324        return  ( 
24-             value:  index. map  {  self [ $0]  } ,  // if the index is nil, we return nil otherwise we grab the value at the index
25+             value:  index. map  {  self [ $0]  } ,    // if the index is nil, we return nil otherwise we grab the value at the index
2526            pullback:  {  vector in 
26-                 var  dSelf  =  Self 
27+                 var  dSelf  = 
28+                     Self 
2729                    . TangentVector ( 
2830                        repeating:  . zero, 
2931                        count:  self 
3032                            . count
31-                     )  // we create a zero tangentvector we need `RangeReplaceableCollection` conformance in order to do this
33+                     )    // we create a zero tangentvector we need `RangeReplaceableCollection` conformance in order to do this
3234                if  let  vectorValue =  vector. value, 
33-                    let  index =  index
35+                      let  index =  index
3436                { 
3537                    // if an index was found and our tangentvector's value is non nil we set the value at index of our tangentvector to the
3638                    // provided tangentvector value
3739                    dSelf
3840                        . replaceSubrange ( 
3941                            index ..<  dSelf. index ( after:  index) , 
4042                            with:  [ vectorValue] 
41-                         )  // we use `RangeReplaceableCollection`'s method here in order to not have to also constrain our TangentVector to
43+                         )    // we use `RangeReplaceableCollection`'s method here in order to not have to also constrain our TangentVector to
4244                    // `MutableCollection`
4345                } 
44-                 return  dSelf // return the tangentvector
46+                 return  dSelf   // return the tangentvector
4547            } 
4648        ) 
4749    } 
@@ -55,19 +57,19 @@ extension Sequence where
5557        value:  Element ? , 
5658        pullback:  ( Element ? . TangentVector)  ->  ( Self . TangentVector ) 
5759    )  where  Self. Index ==  Self . TangentVector . Index  { 
58-         let  index  =  withoutDerivative ( at:  self . indices. min  {  self [ $0]  <  self [ $1]  } )  // we grab the index of the element with the max value
60+         let  index  =  withoutDerivative ( at:  self . indices. min  {  self [ $0]  <  self [ $1]  } )    // we grab the index of the element with the max value
5961        return  ( 
60-             value:  index. map  {  self [ $0]  } ,  // if the index is nil, we return nil otherwise we grab the value at the index
62+             value:  index. map  {  self [ $0]  } ,    // if the index is nil, we return nil otherwise we grab the value at the index
6163            pullback:  {  vector in 
62-                 var  dSelf  =  Self . TangentVector ( repeating:  . zero,  count:  self . count)  // we create a zero tangentvector
64+                 var  dSelf  =  Self . TangentVector ( repeating:  . zero,  count:  self . count)    // we create a zero tangentvector
6365                if  let  vectorValue =  vector. value, 
64-                    let  index =  index
66+                      let  index =  index
6567                { 
6668                    // if an index was found and our tangentvector's value is non nil we set the value at index of our tangentvector to the
6769                    // provided tangentvector value
6870                    dSelf. replaceSubrange ( index ..<  dSelf. index ( after:  index) ,  with:  [ vectorValue] ) 
6971                } 
70-                 return  dSelf // return the tangentvector
72+                 return  dSelf   // return the tangentvector
7173            } 
7274        ) 
7375    } 
0 commit comments