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

added more precondition #614

Merged
merged 5 commits into from
Jan 14, 2020
Merged

Conversation

SumanSudhir
Copy link
Contributor

@SumanSudhir SumanSudhir commented Jan 11, 2020

#517
Precondiiton for function:

  • replacing
  • all
  • any
  • max
  • min
  • argmax
  • argmin
  • sum
  • product
  • mean
  • variance
  • cumulativeSum
  • cumulativeProduct

@SumanSudhir
Copy link
Contributor Author

SumanSudhir commented Jan 11, 2020

@dan-zheng I have change precondition of areAxesInRange() as it is not necessary that the input axes tensor must have rank 1. Eg: cumlativeSum() and moments the former require rank 0 tensor while later takes rank 1 tensor as input

@@ -2229,7 +2248,9 @@ public extension Tensor where Scalar: Numeric {
exclusive: Bool = false,
reverse: Bool = false
) -> Tensor {
_Raw.cumsum(self, axis: axis, exclusive: exclusive, reverse: reverse)
precondition(axis.rank == 0, "Axis must have rank 0.")
precondition(areAxesInRange(axis), "All axis must be in the range `[-rank, rank)`.")
Copy link
Contributor

Choose a reason for hiding this comment

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

In cumprod and cumsum, if the axis is plural then I think the documentation must read, All axes must be in range ..., Like the previous conditions.
If it's a singular value, is calling the function necessary instead of just doing the check locally ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously it was given axis instead of axes and also the same comment was written above that axis must be in the range -rank..<rank. So I followed the same pattern in writing the precondition. Changing the input variable from axis to axes may conflict with some written test cases.

Copy link
Contributor

@Shashi456 Shashi456 Jan 11, 2020

Choose a reason for hiding this comment

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

You don't have to write all axis, it's just referring to a singular axis. You can start the statement with Axis must be in range...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think rank 0 tensor means that there is only one value in axis tensor. So previously it was written as singular.
var input: Tensor<Int32> = Tensor(5)
input.rank is giving 0 as output

@SumanSudhir
Copy link
Contributor Author

@dan-zheng can you please review it?

@@ -2229,7 +2248,9 @@ public extension Tensor where Scalar: Numeric {
exclusive: Bool = false,
reverse: Bool = false
) -> Tensor {
_Raw.cumsum(self, axis: axis, exclusive: exclusive, reverse: reverse)
precondition(axis.rank == 0, "Axis must have rank 0.")
precondition(areAxesInRange(axis), "Axis must be in the range `[-rank, rank)`.")
Copy link
Member

@dan-zheng dan-zheng Jan 12, 2020

Choose a reason for hiding this comment

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

@dan-zheng I have change precondition of areAxesInRange() as it is not necessary that the input axes tensor must have rank 1. Eg: cumlativeSum() and moments the former require rank 0 tensor while later takes rank 1 tensor as input

Thanks for the clarification!

The correct fix is actually to add another precondition helper method called isAxisInRange taking a Tensor<Int32>, not to call areAxesInRange(_: Tensor<Int32>) on a scalar Tensor<Int32> representing a single axis.

Tensor.isAxisInRange(_: Tensor<Int32>) should have a precondition:

precondition(axis.rank == 0, "Axis must have rank 0.")

And Tensor.areAxesInRange(_: Tensor<Int32>) should have the old precondition:

precondition(axes.rank == 1, "Axis must have rank 1.")
Suggested change
precondition(areAxesInRange(axis), "Axis must be in the range `[-rank, rank)`.")
precondition(isAxisInRange(axis), "Axis must be in the range `[-rank, rank)`.")

@SumanSudhir SumanSudhir requested a review from dan-zheng January 13, 2020 08:41
Copy link
Member

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

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

Nice!

@dan-zheng
Copy link
Member

Weirdly, there's a test failure:

/swift-apis/Tests/TensorFlowTests/OperatorTests/LinearAlgebraTests.swift:77: error: LinearAlgebraTests.testSVD : XCTAssertEqual failed: ("-3.0785367") is not equal to ("-3.0785267") +/- ("1e-05") -
/swift-apis/Tests/TensorFlowTests/OperatorTests/LinearAlgebraTests.swift:89: error: LinearAlgebraTests.testSVD : XCTAssertEqual failed: ("-3.0785367") is not equal to ("-3.0785267") +/- ("1e-05") -
Test Case 'LinearAlgebraTests.testSVD' failed (0.012 seconds)

Is this a flaky test? Rerunning tests now.

@dan-zheng dan-zheng merged commit 723d17a into tensorflow:master Jan 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants