Repository navigation
Conversation
An odd n leaves a denominator of 2 in n/2, so pow(x, n/2) is non-real for x < 0 exactly where sqrt(x) is, and the two sides agree for every real x. An even n would make the right side finite there, so it still requires a nonnegative radicand. Restores the odd-exponent assertion the blanket gate had replaced. Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
Only the factory checked that the index sequence covers the operand's rank, so a direct construction could build a node claiming to be a rank-2 transpose while wrapping a rank-4 tensor — is_trans_of accepted it. The check moves into a shared helper the ctor and the factory both use, so rebuild, substitution and direct construction are covered. Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #475.
Closes #476.
Base is
fix-336-pow-pow-domain(PR #462), not main — #475 relaxes the gate that PR adds, so this merges after it.#475 —
pow(sqrt(x), n)folds for an oddn. An oddnleaves a denominator of 2 inn/2, sopow(x, n/2)is non-real forx < 0exactly wheresqrt(x)is; the two sides agree for every realx. An evennwould make the right side finite there, so it still requires a nonnegative radicand.pow(sqrt(x), 3), unassumedxpow(sqrt(x),3)pow(x,3/2)pow(sqrt(x), 2), unassumedxpow(sqrt(x),2)pow(sqrt(x), -3)pow(x,-3/2)Numerically verified at x = −4, −0.5, 0, 0.5, 4 for both parities, and for
n = -3/n = -2: folded results matchstd::pow(std::sqrt(x), n)everywhere, including NaN for negative x andinfat x = 0.Spelling variants (
3,3.0,6/2) all fold and evaluate identically. Note the resulting exponent's representation still differs (3/2vs1.5) on this base, so the test compares by value; #459/#473 are what make numerically equal spellings one value.Test change, called out explicitly.
Scalar_PowSqrtSimplificationassertedpow(sqrt(x), _3)→"pow(sqrt(x),3)". That assertion was introduced by #462's blanket gate; onmainit reads"pow(x,3/2)". This restores the original for the odd case and keeps #462's new even-case assertion, with a comment stating the parity condition.#476 — permutation validated in the node constructor. Only
permute_indices()checked that the index sequence covers the operand's rank, so a direct construction could build a node claiming to be a rank-2 transpose while wrapping a rank-4 tensor, whichis_trans_ofaccepted. The check moved into a sharedvalidate_permutationhelper that the constructor and the factory both call, so rebuild, substitution and direct construction are covered — the same precedent #438 set for the inner/outer product wrappers. The factory's duplicated loop is gone and its messages are unchanged.Internal direct constructions audited, all pass validated sequences:
tensor_rebuild_visitor.h:112(reuses the node's own indices), the composition fold and the factory tail intensor_functions.h, andtrans()(rank-2 gated,{2,1}).Since the malformed node can no longer be constructed, "
is_trans_ofcannot be fooled" is now enforced at construction rather than asserted separately.Tests:
ScalarEval.PowOfSqrtFoldsForOddExponentsandTensorShapeValidation.PermuteWrapperCtorValidatesIndices(mismatched rank, out-of-range, duplicate, plus valid rank-2 and rank-4 permutations still constructing).Negative control (both production files restored from the base with
git show, rebuilt clean): all three ofPowOfSqrtFoldsForOddExponents,PermuteWrapperCtorValidatesIndicesand the updatedScalar_PowSqrtSimplificationfail; all pass with the fixes.Full suite 2414/2414 (gcc-14 Debug) and 2600/2600 parser-enabled; clang-format clean.