Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 2 additions & 7 deletions stdlib/public/TensorFlow/CompilerRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ func _TFCOpSetAttrTensorShapeArray(_ op: CTFEOp,
_ value: Array<TensorShape>,
_ status: CTFStatus) {
let flattenedDims = value.flatMap { $0.dimensions.map(Int64.init) }
let ranks = value.map { $0.rank }
let ranks = value.map { Int32($0.rank) }
setAttrShapeList(op: op, attrName: attrName, flattenedDims: flattenedDims,
ranks: ranks, status: status)
}
Expand All @@ -1927,12 +1927,7 @@ func _TFCOpSetAttrOptionalTensorShapeArray(_ op: CTFEOp,
}
return []
}
let ranks = value.map { tensorShapeOpt -> Int32 in
if let tensorShape = tensorShapeOpt {
return tensorShape.rank
}
return -1
}
let ranks = value.map { shape in (shape?.rank).map(Int32.init) ?? -1 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the parentheses necessary?

setAttrShapeList(op: op, attrName: attrName, flattenedDims: flattenedDims,
ranks: ranks, status: status)
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/TensorFlow/CompositeMath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public func softmax<T : FloatingPoint>(_ x: Tensor<T>) -> Tensor<T> {
/// Specifically, computes `exp(x) / exp(x).sum(alongAxes: axis)`.
@inlinable @inline(__always)
public func softmax<T : TensorFlowFloatingPoint>(
_ x: Tensor<T>, alongAxis axis: Int32
_ x: Tensor<T>, alongAxis axis: Int
) -> Tensor<T> {
let expx = exp(x)
return expx / expx.sum(alongAxes: axis)
Expand Down
17 changes: 13 additions & 4 deletions stdlib/public/TensorFlow/Gradients.swift
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,15 @@ extension Tensor where Scalar : TensorFlowFloatingPoint {

@inlinable
func _vjpTransposed(
withPermutations permutations: [Int32]
withPermutations permutations: [Int]
) -> (Tensor, (Tensor) -> Tensor) {
let value = transposed(withPermutations: permutations)
return (value, { $0.transposed(withPermutations: permutations) })
}

@inlinable
func _vjpTransposed(
withPermutations permutations: Int32...
withPermutations permutations: Int...
) -> (Tensor, (Tensor) -> Tensor) {
let value = transposed(withPermutations: permutations)
return (value, { $0.transposed(withPermutations: permutations) })
Expand Down Expand Up @@ -545,7 +545,7 @@ extension Tensor where Scalar : TensorFlowFloatingPoint {
}

@inlinable
func _vjpSqueezingShape(at axes: [Int32]) -> (Tensor, (Tensor) -> Tensor) {
func _vjpSqueezingShape(at axes: [Int]) -> (Tensor, (Tensor) -> Tensor) {
let value = squeezingShape(at: axes)
return (value, { [shape = shapeTensor] v in
v.reshaped(toShape: shape)
Expand All @@ -554,7 +554,7 @@ extension Tensor where Scalar : TensorFlowFloatingPoint {

@inlinable
func _vjpExpandingShape(
at shapeIndex: Int32
at shapeIndex: Int
) -> (Tensor, (Tensor) -> Tensor) {
let value = expandingShape(at: shapeIndex)
return (value, { v in
Expand Down Expand Up @@ -591,6 +591,15 @@ extension Tensor where Scalar : TensorFlowFloatingPoint {
})
}

@inlinable
func _vjpMean(squeezingAxes axes: [Int]) -> (Tensor, (Tensor) -> Tensor) {
let value = mean(squeezingAxes: axes)
return (value, { [shape = shapeTensor,
count = axes.map { shape[$0] }.reduce(1, *)] in
$0.broadcast(toShape: shape) / Tensor(Scalar(count))
})
}

@inlinable
func _vjpMean(
squeezingAxes axes: Tensor<Int32>
Expand Down
Loading