Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RF] Fixup to parameter index calculation in ParamHistFunc #10989

Merged
merged 1 commit into from
Jul 19, 2022

Conversation

guitargeek
Copy link
Contributor

@guitargeek guitargeek commented Jul 19, 2022

Last year, with commit 3657e7c, the parameter index calculation was
changed to be on the fly instead of using a look-up map, which is much
faster.

However, the implemented formula was not correct for two or three
dimensions, which is fixed by this commit.

To make sure that the index computation is correct this time, the new
code was tested in this code snippet with various inputs:

void runTest(int nx = 42, int ny = 42, int nz = 42) {
  const int nxy = nx * ny;
  const int nyz = ny * nz;

  for (int i = 0; i < nx; ++i) {
    for (int j = 0; j < ny; ++j) {
      for (int k = 0; k < nz; ++k) {
        const int index = k + j * nz + i * ny * nz;
        const int gammaIndex = i + j * nx + k * nx * ny;

        const int i2 = index / nyz;
        const int tmp = index % nyz;
        const int j2 = tmp / nz;
        const int k2 = tmp % nz;

        const int gammaIndex2 = i2 + j2 * nx + k2 * nxy;

        if (gammaIndex2 != gammaIndex) {
          std::cout << "The unraveled indices were not correct!"
                    << std::endl;
          return;
        }
      }
    }
  }
}

Needs to be backported to the 6.26 branch to get into the 6.26.06 patch
release.

This commit the following problem reported on the forum:
https://root-forum.cern.ch/t/cpycppyy-segfault-on-mac-m1/50822

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14
How to customize builds

Copy link
Member

@lmoneta lmoneta left a comment

Choose a reason for hiding this comment

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

Ligtm

yust a comment on using % operator

thanks for the fix

// because in the parameter set the dimensions are ordered in reverse order
// compared to the RooDataHist (for historical reasons).
const int i = index / n.yz;
const int tmp = index - i * n.yz;
Copy link
Member

Choose a reason for hiding this comment

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

It is not equivalent to
temp=index%n.yz?

Copy link
Member

Choose a reason for hiding this comment

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

Same for k

Copy link
Member

Choose a reason for hiding this comment

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

K=(index%n.yz)%n.z

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, you are right! The expression for tmp and k could be simplified, which I changed now.

Last year, with commit 3657e7c, the parameter index calculation was
changed to be on the fly instead of using a look-up map, which is much
faster.

However, the implemented formula was not correct for two or three
dimensions, which is fixed by this commit.

To make sure that the index computation is correct this time, the new
code was tested in this code snippet with various inputs:

```C++
void runTest(int nx = 42, int ny = 42, int nz = 42) {
  const int nxy = nx * ny;
  const int nyz = ny * nz;

  for (int i = 0; i < nx; ++i) {
    for (int j = 0; j < ny; ++j) {
      for (int k = 0; k < nz; ++k) {
        const int index = k + j * nz + i * ny * nz;
        const int gammaIndex = i + j * nx + k * nx * ny;

        const int i2 = index / nyz;
        const int tmp = index % nyz;
        const int j2 = tmp / nz;
        const int k2 = tmp % nz;

        const int gammaIndex2 = i2 + j2 * nx + k2 * nxy;

        if (gammaIndex2 != gammaIndex) {
          std::cout << "The unraveled indices were not correct!"
                    << std::endl;
          return;
        }
      }
    }
  }
}
```

Needs to be backported to the 6.26 branch to get into the 6.26.06 patch
release.

This commit the following problem reported on the forum:
https://root-forum.cern.ch/t/cpycppyy-segfault-on-mac-m1/50822
@guitargeek guitargeek force-pushed the ParamHistFunc_fixup branch from 13b3e3f to 4b05e75 Compare July 19, 2022 16:48
@phsft-bot
Copy link
Collaborator

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-performance-centos8-multicore/cxx17.
Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Collaborator

Build failed on mac1015/cxx17.
Running on macitois21.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

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

Successfully merging this pull request may close these issues.

3 participants