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

added windows ci #94

Merged
merged 22 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/test-windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: tests-windows

on:
push:
pull_request: null

jobs:
tests:
name: tests
strategy:
fail-fast: false
matrix:
os: [windows-latest]
pyver: ["3.11"]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.pyver }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.pyver }}

- name: Install code
run: pip install -e .

- name: lint
run: |
pip install flake8
flake8 esutil

- name: test
run: |
pip install pytest
pytest -vv esutil
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ You can also use pip
```
pip install esutil
```

Windows
-------

The unit tests pass on windows with the exception of the recfile package (and
the sfile package that uses it).
12 changes: 12 additions & 0 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
0.6.14
------

Enhancements

- Add code changes to C extensions to compile on windows.
Note recfile compiles but failst the unit tests, which
are skipped for windows CI.
- Add windows CI
- remove unused _stat_util.c extension


0.6.13
------

Expand Down
2 changes: 1 addition & 1 deletion esutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class for gauss-legendre integration, which relies on the gauleg C++ extension.

import sys

__version__ = "0.6.13"
__version__ = "0.6.14"

def version():
return __version__
Expand Down
4 changes: 4 additions & 0 deletions esutil/cosmology/cosmolib.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#define FOUR_PI_G_OVER_C_SQUARED 6.0150504541630152e-07
#define CLIGHT 2.99792458e5

#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif

struct cosmo {
int flat; // is this a flat cosmology?

Expand Down
23 changes: 13 additions & 10 deletions esutil/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,10 +979,12 @@ def cholesky_sample(cov, n, means=None, dist=None):
return V.T


def random_indices(imax, nrand, **keys):
def random_indices(imax, nrand, unique=True, rng=None, seed=None):
"""
Get a unique random selection of indices in [0,imax)

Now just calls numpy random choice

parameters
----------
imax:
Expand All @@ -992,20 +994,21 @@ def random_indices(imax, nrand, **keys):
unique:
If False, the sample will have replacement, and nrand
can be greater than imax
seed: int
A seed for the random number generator
rng: np.default_rng, optional
Optional random number generator
seed: int, optional
A seed to create a new rng
"""
unique = keys.get("unique", True)
seed = keys.get("seed", None)
if seed is None:
import time

seed = int(time.time())
if rng is None:
rng = numpy.random.default_rng(seed)

if not unique:
return numpy.random.randint(0, imax, nrand)
replace = True
else:
return stat._stat_util.random_sample(imax, nrand, seed)
replace = False

return rng.choice(imax, size=nrand, replace=replace)


def randind(nmax, nrand, dtype=None):
Expand Down
16 changes: 13 additions & 3 deletions esutil/recfile/records.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ static int is_python_string(const PyObject* obj)
#endif
}



int myfseeko(FILE *stream, off_t offset, int origin) {
#ifdef _WIN32
return _fseeki64(stream, offset, origin);
#else
return fseeko(stream, offset, origin);
#endif
}

// unicode is common to python 2 and 3
static char* get_unicode_as_string(PyObject* obj)
{
Expand Down Expand Up @@ -256,7 +266,7 @@ void Records::goto_offset(void)

void Records::do_seek(npy_intp seek_distance) {
if (seek_distance > 0) {
if(fseeko(mFptr, seek_distance, SEEK_CUR) != 0) {
if(myfseeko(mFptr, seek_distance, SEEK_CUR) != 0) {
string err="Error skipping fields";
throw std::runtime_error(err);
}
Expand Down Expand Up @@ -301,7 +311,7 @@ void Records::skip_text_rows(long long nskip)
void Records::skip_binary_rows(long long nskip)
{
if (nskip > 0) {
if (fseeko(mFptr, mRowSize*nskip, SEEK_CUR) != 0) {
if (myfseeko(mFptr, mRowSize*nskip, SEEK_CUR) != 0) {
throw std::runtime_error("Failed to fseek");
}
}
Expand Down Expand Up @@ -981,7 +991,7 @@ void Records::ReadBinaryFields()

void Records::DoSeek(npy_intp seek_distance) {
if (seek_distance > 0) {
if(fseeko(mFptr, seek_distance, SEEK_CUR) != 0) {
if(myfseeko(mFptr, seek_distance, SEEK_CUR) != 0) {
string err="Error skipping fields";
throw std::runtime_error(err);
}
Expand Down
122 changes: 0 additions & 122 deletions esutil/stat/_stat_util.c

This file was deleted.

4 changes: 0 additions & 4 deletions esutil/stat/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@

from sys import stderr

# used to live in this module
# from esutil.random import cholesky_sample
# from esutil.random import random_indices

# the external C++ code for doing
# histograms.
try:
Expand Down
15 changes: 15 additions & 0 deletions esutil/tests/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,18 @@ def test_cholesky(seed):
for i in range(3):
for j in range(3):
assert abs(dcov[i, j] - cov[i, j]) < tol, '%d, %d' % (i, j)


def test_random_indices():
seed = 5
rng = np.random.default_rng(seed)

ind = rng.choice(10, size=10, replace=False)
ind2 = eu.random.random_indices(10, 10, seed=seed)
assert np.all(ind == ind2)

rng = np.random.default_rng(seed)

ind = rng.choice(10, size=10, replace=True)
ind2 = eu.random.random_indices(10, 10, seed=seed, unique=False)
assert np.all(ind == ind2)
4 changes: 4 additions & 0 deletions esutil/tests/test_recfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def compare_rec(rec1, rec2, name):
assert w.size == 0, "testing column %s" % f


@pytest.mark.skipif(os.name == 'nt',
reason='skip recfile tests on windows')
@pytest.mark.parametrize('delim', [None, ",", ":", "\t", " "])
@pytest.mark.parametrize('doswap', [False, True])
def test_recfile_writeread(delim, doswap):
Expand Down Expand Up @@ -214,6 +216,8 @@ def test_recfile_writeread(delim, doswap):
)


@pytest.mark.skipif(os.name == 'nt',
reason='skip recfile tests on windows')
@pytest.mark.parametrize('delim', [None, ",", ":", "\t", " "])
@pytest.mark.parametrize('doswap', [False, True])
def test_recfile_subsets(delim, doswap):
Expand Down
6 changes: 6 additions & 0 deletions esutil/tests/test_sfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def compare_rec(rec1, rec2, name):
assert w.size == 0, "testing column %s" % f


@pytest.mark.skipif(os.name == 'nt',
reason='skip recfile tests on windows')
@pytest.mark.parametrize('delim', [None, ",", ":", "\t", " "])
@pytest.mark.parametrize('doswap', [False, True])
def test_sfile_writeread(delim, doswap):
Expand Down Expand Up @@ -234,6 +236,8 @@ def test_sfile_writeread(delim, doswap):
compare_header(header, h)


@pytest.mark.skipif(os.name == 'nt',
reason='skip recfile tests on windows')
@pytest.mark.parametrize('delim', [None, ",", ":", "\t", " "])
@pytest.mark.parametrize('doswap', [False, True])
def test_sfile_subsets(delim, doswap):
Expand Down Expand Up @@ -373,6 +377,8 @@ def test_sfile_subsets(delim, doswap):
)


@pytest.mark.skipif(os.name == 'nt',
reason='skip recfile tests on windows')
@pytest.mark.parametrize('delim', [None, ",", ":", "\t", " "])
@pytest.mark.parametrize('doswap', [False, True])
def test_sfile_append(delim, doswap):
Expand Down
Loading
Loading