Uploaded image for project: ' Swift for TensorFlow'
  1. Swift for TensorFlow
  2. TF-1134

Define derivatives for Float and Double maximum and minimum methods

    XMLWordPrintable

    Details

      Description

      Type Methods (maximum and minimum) for Float and Double  have not been marked '@differentiable'.

      The following sample code will fail to compile:

      
       // Custom differentiable type.
      struct Model: Differentiable {
       var w: Float
       var b: Float
       func applied(to input: Float) -> Float {
       return Float.maximum(w * input + b, 0.0)
       }
      }
      
      // Differentiate using `gradient(at:_:in:)`.
      let model = Model(w: 4, b: 3)
      let input: Float = 2
      let (g_model, g_input) = gradient(at: model, input) { model, input in
       model.applied(to: input)
      }
      
      print(g_model) // Model.TangentVector(w: 2.0, b: 1.0)
      print(g_input) // 4.0
      
       
      
       
      
      

       

      Error:

      error: <Cell 5>:8:22: error: expression is not differentiable
      return Float.maximum(w * input + b, 0.0)
      ^

      <Cell 5>:8:22: note: cannot differentiate functions that have not been marked '@differentiable' and that are defined in other files
      return Float.maximum(w * input + b, 0.0)

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              pnrodriguez Pedro N. Rodriguez
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: