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

Remove check for equal shapes in isAlmostEqual #367

Merged
merged 4 commits into from
Jul 29, 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
8 changes: 4 additions & 4 deletions Sources/TensorFlow/Operators/Comparison.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public extension Tensor where Scalar: Equatable {
public extension Tensor where Scalar: TensorFlowFloatingPoint & Equatable {
/// Returns a tensor of Boolean values indicating whether the elements of `self` are
/// approximately equal to those of `other`.
/// - Precondition: `self` and `other` must be of the same shape.
@inlinable
func elementsAlmostEqual(
_ other: Tensor,
Expand All @@ -229,14 +230,13 @@ public extension StringTensor {
}

public extension Tensor where Scalar: TensorFlowFloatingPoint {
/// Returns `true` if tensors are of equal shape and all pairs of scalars are approximately
/// equal.
/// Returns `true` if all elements of `self` are approximately equal to those of `other`.
/// - Precondition: `self` and `other` must be of the same shape.
@inlinable
func isAlmostEqual(
to other: Tensor,
tolerance: Scalar = Scalar.ulpOfOne.squareRoot()
) -> Bool {
return self.shape == other.shape &&
self.elementsAlmostEqual(other, tolerance: tolerance).all()
elementsAlmostEqual(other, tolerance: tolerance).all()
}
}