<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/715" rel="nofollow">http://projects.scipy.org/scipy/ticket/715</a> on 2008-08-07 by trac user mgogoulos@..., assigned to unknown.</em></p>
<p dir="auto">scipy.object0 and scipy.object result in segmentation fault, see the following:</p>
<p dir="auto">$ gdb python</p>
<p dir="auto">...</p>
<p dir="auto">(gdb) run -c "import scipy; obj = scipy.object0()"</p>
<p dir="auto">Starting program: /usr/bin/python -c "import scipy; obj = scipy.object0()"</p>
<p dir="auto">Program received signal SIGSEGV, Segmentation fault.</p>
<p dir="auto">[Switching to Thread 0xb7d408c0 (LWP 17657)]</p>
<p dir="auto">object_arrtype_new (type=0xb7c2e1c0, args=0xb7d0002c, kwds=0x0) at numpy/core/src/scalartypes.inc.src:1977</p>
<p dir="auto">1977        Py_INCREF(<em>((PyObject *</em>)dest));</p>
<p dir="auto">kernel: [ 1713.721411] python[17644]: segfault at 00000003 eip b7c28de7 esp bfe1d6d0 error 6</p>
<p dir="auto">Tested with scipy 0.6.0, on Ubuntu hardy (python 2.5.2)</p>
<p dir="auto">Best regards,<br>
Markos Gogoulos</p>
<h3 dir="auto">Is your feature request related to a problem? Please describe.</h3>
<h2 dir="auto">Motivation</h2>
<p dir="auto">Sometimes you have pairs of values x, y and you want to know whether y is independent of x or not. People sometimes compute a test statistic of x, y pairs directly, examples are Pearson/Spearman coefficient, Kendall tau or similar.</p>
<p dir="auto">Other tests use contingency tables (histograms), like the popular <a href="https://royalsocietypublishing.org/doi/10.1098/rspa.2021.0549" rel="nofollow">USP test</a>. This can be more computationally efficient when the sample is very large (think of applications with Big Data, like in my field, high-energy physics). For these tests, one needs to generate random 2D tables that have the same row and column totals as the original data. The probability distribution for such a table has been worked out in the 80'ies, and Patefield found an elegant non-trivial algorithm to randomly sample from this distribution.</p>
<h3 dir="auto">Describe the solution you'd like.</h3>
<p dir="auto">I searched the net for implementations in C/C++ of Patefield's algorithm, but only found implementations under GPL license and none of them is available to Python. I want to have the code under a less restrictive license and so I translated the published FORTRAN code to C from scratch and <a href="https://github.com/resample-project/resample/blob/develop/src/rcont.c">based my implementation on that</a>. My code is licensed under BSD 3-clause and I would like to contribute it to SciPy.</p>
<p dir="auto">My implementation already evolved from the original and has cool features that the original implementation lacks. The changes are documented in the code. Sorry for all the <code class="notranslate">goto</code>s, it is how the original code was written. In time, I am interested in removing the <code class="notranslate">goto</code>s step by step, but for now it is more important to have a baseline code that works.</p>
<p dir="auto">In addition to Patefield's algorithm, I also want to add a simple shuffling algorithm. The shuffling algorithm requires additional memory, but is faster than Patefield in certain scenarios. Patefield is more time efficient when the table contains few cells and depends only logarithmically on the number of total entries, while the time for the shuffling algorithm does not depend on the number of cells and only depends on the number of entries.</p>
<p dir="auto">I would like to start a PR; some pointers where this algorithm fits in best, would be helpful.</p>
<h3 dir="auto">Describe alternatives you've considered.</h3>
<p dir="auto">As mentioned above, before I started writing mine, there were only GPL licensed implementations and none available to Python.</p>
<h3 dir="auto">Additional context (e.g. screenshots, GIFs)</h3>
<p dir="auto"><em>No response</em></p>