- When doing *exact* floating point comparisons, print out enough digits of the
floating point number to unambiguously round trip to the float in question.
- The exhaustive op test had an off-by-one for precision when printing a float.
PiperOrigin-RevId: 277988562
Change-Id: I9d30190a754d698e009fd51aa7fe6ca5661e2bc0
literal_comparison::Near will now make a call to miscompare_callback when non
floating/complex types fail the check.
literal_comparison::Near may now accept nullptr as a miscompare_callback. In
this case, it will return on the first failed comparison.
MiscompareCallback functions now have the ShapeIndex of the LiteralSlice being
compared as a parameter.
PiperOrigin-RevId: 251722837
In partcular, templated function FpAbsoluteValue is used to compute the abs of
a value and previously, it returns a float. Change this function to return
a double instead to avoid cast overfloat for inputs with types double and
complex128.
Add a test case.
PiperOrigin-RevId: 240984454
Literal comparison has the option of displaying a "detailed breakdown", which
includes things like the distribution of errors. Previously, you'd only get
this breakdown if you asked for it, but there are many routines that don't
expose this knob. We could expose it piecemeal, but I think in general if
you're comparing a "large" literal and you have mismatches, you probably want
this breakdown. At least, it's not going to be a lot of noise. So this patch
makes us show the default breakdown by default when the array being compared is
above a certain size.
PiperOrigin-RevId: 230834776
Previously, we'd always report expected nan vs. actual inf as a miscompare,
even if relaxed_nan was set. This is just a bug; the intent of relaxed_nan is
to allow any actual value if the expected is nan.
PiperOrigin-RevId: 230763808
Shape::Is(Array|Tuple|Token|Opaque).
No functional change. ShapeUtil methods are marked as deprecated. These methods
will be removed in a later CL.
PiperOrigin-RevId: 226425321
if:
- expected is infinity
- actual != expected
This prevents Near from generating a NaN for relative error.
Also compare the real and imaginary parts of complex numbers independently.
PiperOrigin-RevId: 210637112
Unlike Printf, StrFormat does not require type-length qualifiers, e.g
%z, %ll. Nor does it require that you call c_str() to print strings.
So these are fixed up here as well.
PiperOrigin-RevId: 210435915
Make the error messages more consistent between "Near" comparisons and "Equal" comparisons, and give Shape index for mismatches in tuples. Also, polish flag descriptions and test output in run_hlo_module.
==== BEFORE:
Mismatches in shape (s32[], s32[], s32[]) (3 elements):
Expected equality of these values:
470211269
0
at index {}:
expected: 470211269
actual: 0
==== AFTER:
Mismatches in shape (s32[], s32[], s32[]) (3 elements):
Array at shape index {1}, first mismatch at array index {}:
expected value: 470211269
actual value: 0
Expected literal:
(s32[], s32[], s32[]) (
-1865008400,
470211269,
470211269
)
Actual literal:
(s32[], s32[], s32[]) (
-1865008400,
0,
470211269
)
PiperOrigin-RevId: 210017733
Unfortunately this has to be one big patch, because e.g. absl::StrCat
doesn't accept a TF StringPiece, but as soon as we switch to
absl::string_view, we have to switch away from all of the TF functions.
PiperOrigin-RevId: 209957896
Previously, for equal comparisons the reported mismatched index would always be the last index in the shape rather than the index of the actual miscompare.
PiperOrigin-RevId: 209086635
Currently Literal classes sits in literal_util.{h,cc} instead of literal.{h,cc}.
It also contains helper functions that are better fit to be their own separate
class/namespace. This change starts this process by moving most static factory
methods to LiteralUtil namespace.
PiperOrigin-RevId: 203217065
TOKENs will be used for ordering side-effecting operations. They are not materialized but can be contained in tuples and flow into and out of computations. This CL adds a trivial representation for the cpu and gpu backends to support TOKENs and modifies copy insertion to avoid making copies of tokens.
This also adds a Literal TOKEN which is required for the interpreter backend.
PiperOrigin-RevId: 200623120
A TOKEN primitive type was added with cl/199215963 and XLA also has an OPAQUE primitive type. However, in many places in XLA we assume either a tuple or array. This CL fixes many of those instances, but some may remain. Identified instances were discovered by searching for IsTuple or IsArray so the set of fixes is not exhaustive.
Also opportunistically addressed a couple potential points of confusion in the ShapeUtil interface:
(1) Rename ShapeUtil::HasZeroElements to ShapeUtil::IsZeroElementArray. The point of confusion here is that tuples can also have zero elements and HasZeroElements would check fail on tuple shapes. Method no longer check fails if the given shape is not an array.
(2) ShapeUtil::IsNil now returns true only for empty tuples. Previously it also returned true for zero-element array types which was confusing because ShapeUtil::MakeNil creates an empty tuple.
PiperOrigin-RevId: 200452672
In literal_comparison, don't try to compute a relative error when the
expected value is 0, because doing so would mean that the only
acceptable value *is* zero, which probably isn't what you mean.
PiperOrigin-RevId: 198137414
Moves methods from LiteralTestUtil::* to Literal::* where they have nothing
to do with test infrastructure.
Pares down the "void" variants of the LiteralTestUtil methods and consolidates
to the version that return success/failure such that the values can be
EXPECT_TRUE / ASSERT_TRUE asserted in the caller test cases.
This way the literal comparison functionality can be used from cc_libraries
that are not test only / cc_binary.
PiperOrigin-RevId: 196209410