Skip to content

get_intg_record writes every element of a row to the same column #11

Description

@shimwell

Summary

In get_intg_record (src/endf/records.py), the inner loop reads successive matrix elements across a row but assigns all of them to the same column jj, instead of advancing to jj + j.

https://github.com/shimwell/endf-python/blob/main/src/endf/records.py#L259-L271

for j in range(nrow):
    if jj+j >= ii:
        break
    element = int_endf(line[11+(ndigit+1)*j:11+(ndigit+1)*(j+1)])
    if element > 0:
        corr[ii, jj] = (element+0.5)/factor    # <-- jj, not jj + j
    elif element < 0:
        corr[ii, jj] = (element-0.5)/factor    # <-- same

The field offset 11+(ndigit+1)*j advances with j, and the loop guard is if jj+j >= ii: break — both of which say the column being filled is jj + j. Only the assignment does not follow.

Effect

For an INTG line covering more than one column, every element is written on top of the previous one at column jj. The result is that:

  • only the last in-range element of each line survives, and it lands in the wrong column;
  • every other column the line was meant to fill stays at its initialised value (0, or 1 on the diagonal).

The correlation matrix returned for LCOMP=2 compact covariances is therefore wrong wherever a line carries more than one element. Since the guard jj+j >= ii stops at the diagonal, single-element lines (jj == ii-1) happen to come out right, which is probably why this has gone unnoticed.

Suggested fix

        if element > 0:
            corr[ii, jj+j] = (element+0.5)/factor
        elif element < 0:
            corr[ii, jj+j] = (element-0.5)/factor

Notes

  • get_intg_record currently has no caller in the package — MF32 (LCOMP=2) is not parsed yet — so this is latent rather than user-visible today.
  • The symmetrisation at the end is fine: np.diag(corr.diagonal()) is evaluated against the pre-addition matrix, so the diagonal correctly stays at 1.
  • Found while porting the reader to Rust. The port reproduces the current behaviour deliberately, with a comment pointing here, so the two agree until this is settled.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions