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

Add a 'clipped(min:max:)' method. #198

Merged
merged 10 commits into from
Jun 16, 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
10 changes: 10 additions & 0 deletions Sources/TensorFlow/Operators/Basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,16 @@ public extension Tensor {
}
}

public extension Tensor where Scalar: Numeric {
/// Returns a tensor by clipping scalars to a specified minimum and maximum.
// FIXME: Define a derivative function.
// @differentiable(wrt: self where Scalar: TensorFlowFloatingPoint)
@inlinable
func clipped(min: Tensor, max: Tensor) -> Tensor {
Raw.clipByValue(t: self, clipValueMin: min, clipValueMax: max)
}
}

//===------------------------------------------------------------------------------------------===//
// Broadcasting
//===------------------------------------------------------------------------------------------===//
Expand Down