# Why do I get a Partition::pdep error?

I've been running an iterative job (j=1,2.,3,.....300,000,000). The vast majority of steps proceed smoothly. Every several million or so steps, I get a "General::inf: Input matrix contains an infinite entry error" message when I try to orthogonalize a $4 \times 4$ matrix. Using the Check command, I then increase precision, and mostly then recovery occurs, with no immediately subsequent error message. On very rare occasions, however, recovery apparently doesn't occur after I increase the precision, and I get the indicated "Partition::pdep" error when I try to partition the hopefully $4 \times 4$ matrix denoted Y1.Transpose[Y1] into $2 \times 2$ blocks. I've tried looking at what's happening step-by-step, but I can't seem to put my finger on the problem.

I realize that this debugging task might be "beyond the call of duty" of the community. (I did write to support@wolfram.com with apparently no response.) But I'm rather irked I can't isolate/correct the specific problem, as it might have some impact (probably very small) on my precise results.

Here's the code for one (259,961,928) of the (very rare) problematical values of the index j (let me note that the problem appears to be arising more frequently for larger values of j):

sp2 = x /. Solve[x^(37) == x + 1, x][[1]]; G = Array[1, 36]; Do[
G[[i]] = N[j/sp2^i], {i, 1, 36}]; rB = 0; Do[
P = InverseCDF[NormalDistribution[0, 1], FractionalPart[G]];
Y1 = Check[(Orthogonalize[ArrayReshape[Take[P, {1, 16}], {4, 4}]] +
IdentityMatrix[4]).ArrayReshape[Take[P, {17, 36}], {4, 5}], err;
G1 = Array[1, 36]; Do[G1[[i]] = N[j/sp2^i, 40], {i, 1, 36}];
P = InverseCDF[NormalDistribution[0, 1], FractionalPart[G1]];
Y1 = (Orthogonalize[ArrayReshape[Take[P, {1, 16}], {4, 4}]] +
IdentityMatrix[4]).ArrayReshape[Take[P, {17, 36}], {4, 5}];
G1 =.]; z = Partition[Y1.Transpose[Y1], {2, 2}];
If[PositiveDefiniteMatrixQ[
ArrayFlatten@{{z[[1, 1]], z[[2, 1]]}, {z[[1, 2]], z[[2, 2]]}}] ==
True, rB = rB + 1], {j, 259961928, 259961928}]


When I run this I get

Orthogonalize::inf: Input matrix contains an infinite entry.

Partition::pdep: Depth 2 requested in object with dimensions {2}.


The problem is that the fractional part can be 0, and:

InverseCDF[NormalDistribution[0,1], 0.]


-∞

Block[{j=259961928},
InverseCDF[NormalDistribution[0,1], FractionalPart[G]]
]


{-0.686634, -0.408716, 0.0332409, 0.123996, -0.898186, 0.000442094, -0.428241, 0.532492, -0.731212, 0.259953, -∞, 0.206171, 1.63377, 0.333986, 0.197397, 0.429496, -0.818742, -0.0781347, -0.799857, -0.765432, 1.08724, 0.319201, 0.538826, 0.158753, 0.0322993, -0.501248, 0.640965, -0.713103, -0.0288126, -1.67174, 1.85786, -0.158104, -0.22699, -0.63659, -0.152324, -1.17485}

Perhaps you could Clip your inputs:

Block[{j=259961928},
InverseCDF[NormalDistribution[0,1], Clip[FractionalPart[G], {\$MachineEpsilon, 1}]]
]


{-0.686634, -0.408716, 0.0332409, 0.123996, -0.898186, 0.000442094, -0.428241, 0.532492, -0.731212, 0.259953, -8.12589, 0.206171, 1.63377, 0.333986, 0.197397, 0.429496, -0.818742, -0.0781347, -0.799857, -0.765432, 1.08724, 0.319201, 0.538826, 0.158753, 0.0322993, -0.501248, 0.640965, -0.713103, -0.0288126, -1.67174, 1.85786, -0.158104, -0.22699, -0.63659, -0.152324, -1.17485}

• Looks very good!! I was not at all familiar with the Clip command, and not really Block either. So, it looks like I should use the indicated Clip command in both invocations of InverseCDF--the first occurrence, and then the second after I obtain the "Orthogonalize::inf: Input matrix contains an infinite entry" message and use increased precision? Any possible negative [truncation,..] impacts? So, on further thought, it looks like using Clip in the first InverseCDF call would avoid both types of error--so maybe the need for Check would not even arise. – Paul B. Slater Aug 17 '18 at 19:25

The problem can also (in addition to the answer of Carl Wall) be successfully addressed by taking the response to the first error "Orthogonalize::inf: Input matrix contains an infinite entry" outside the original Check command. That is after this error occurs, I increase the precision, and then exit Check, and then re-perform it. This is accomplished by the added Goto[wuh] and Label[wuh] in the attached modified notebook. (It seems I must have misapplied Check--in a way not yet clear to me--first time I used the command.) So now there seems to be no need (as Carl Wall suggested) for the introduction of the Clip command. So, perhaps now less (minimal) chance for an errant subsequent PositiveDefiniteMatrixQ command, since no "clipping" seems needed. So, no second error "Partition::pdep: Depth 2 requested in object with dimensions {2}" now appears in the output, indicating that the PositiveDefiniteMatrixQ was performed without error. (So, what was wrong about my original use of Check?)

sp2 = x /. Solve[x^(37) == x + 1, x][[1]]; G = Array[1, 36]; Do[ G[[i]] = N[j/sp2^i], {i, 1, 36}]; rB = 0; Do[ P = InverseCDF[NormalDistribution[0, 1], FractionalPart[G]]; Label[wuh]; Y1 = Check[(Orthogonalize[ArrayReshape[Take[P, {1, 16}], {4, 4}]] + IdentityMatrix[4]).ArrayReshape[Take[P, {17, 36}], {4, 5}], err; G1 = Array[1, 36]; Do[G1[[i]] = N[j/sp2^i, 40], {i, 1, 36}]; P = InverseCDF[NormalDistribution[0, 1], FractionalPart[G1]]; Goto[wuh] ]; z = Partition[Y1.Transpose[Y1], {2, 2}]; If[PositiveDefiniteMatrixQ[ ArrayFlatten@{{z[[1, 1]], z[[2, 1]]}, {z[[1, 2]], z[[2, 2]]}}] == True, rB = rB + 1], {j, 259961928, 259961928}]

Orthogonalize::inf: Input matrix contains an infinite entry.