Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Made 'Tensor.gathering(where:alongAxis:)' differentiable. #271

Merged
merged 1 commit into from
Jun 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Sources/TensorFlow/Operators/Basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,10 @@ public extension Tensor {
/// - Returns: `(self.rank - K + 1)`-dimensional tensor populated by entries in this tensor
/// corresponding to `true` values in `mask`.
@inlinable
// @differentiable(wrt: self where Scalar: TensorFlowFloatingPoint)
@differentiable(wrt: self where Scalar: TensorFlowFloatingPoint)
func gathering(where mask: Tensor<Bool>, alongAxis axis: Int = 0) -> Tensor {
precondition(mask.rank != 0, "The boolean mask cannot be a scalar.")
// TODO: Remove once control flow AD is supported.
let rank = self.rank
let posAxis = { axis < 0 ? axis + rank : axis }()
let posAxis = Swift.withoutDerivative(at: self.rank) { r in axis < 0 ? axis + r : axis }
let leadingSize = shapeTensor[posAxis ..< posAxis + mask.rank].product().rankLifted()
let reshapedTensor = reshaped(
toShape: Tensor<Int32>(concatenating: [
Expand Down