Skip to content

Commit

Permalink
Merge pull request #312 from bashtage/maint-black-version
Browse files Browse the repository at this point in the history
MAINT: Switch version manager and upgrade black
  • Loading branch information
bashtage authored May 18, 2022
2 parents 8cd5702 + bce30b7 commit 3015e67
Show file tree
Hide file tree
Showing 31 changed files with 268 additions and 2,677 deletions.
6 changes: 4 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
freebsd_instance:
image_family: freebsd-12-2
image_family: freebsd-12-3

task:
install_script: . ./ci/cirrus-install.sh
script: pytest-3.8 randomgen
script: mkdir test_dir && cd test_dir && echo $PWD && python3.9 -c "import randomgen; randomgen.test()"


14 changes: 9 additions & 5 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
---
kind: pipeline
type: docker
name: test-on-arm64

platform:
os: linux
arch: arm64


steps:
- name: test
image: ubuntu:latest
image: ubuntu:focal
commands:
- uname -a
- ln -s /usr/bin/gpgv /usr/bin/gnupg2
# - apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 871920D1991BC93C
- apt-get update
- export DEBIAN_FRONTEND=noninteractive
- apt-get install libatlas-base-dev build-essential cython3 python3-numpy python3 python3-dev python3-pip libxml2-dev libxslt-dev python3-lxml -y
- apt-get install libatlas-base-dev build-essential cython3 python3-numpy python3 python3-dev python3-pip libxml2-dev libxslt-dev python3-lxml git -y
- gcc tools/long_double_sizes.c -o long_double_sizes && ./long_double_sizes
- pip3 install -r requirements.txt --upgrade
- pip3 install -r requirements-dev.txt
- pip3 install -e . --no-build-isolation
- python3 -m pip install -r requirements.txt --upgrade
- python3 -m pip install -r requirements-dev.txt
- python3 -m pip install -e . --no-build-isolation
- pytest -r a randomgen
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
recursive-exclude randomgen *.c
include versioneer.py
include randomgen/_version.py
include requirements.txt
include README.md
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,19 @@ test suite where still relevant.
Either install from PyPi using

```bash
pip install randomgen
python -m pip install randomgen
```

or, if you want the latest version,

```bash
pip install git+https://github.com/bashtage/randomgen.git
python -m pip install git+https://github.com/bashtage/randomgen.git
```

or from a cloned repo,

```bash
python setup.py install
python -m pip install .
```

If you use conda, you can install using conda forge
Expand All @@ -180,7 +180,8 @@ conda install -c conda-forge randomgen
or are building on non-x86, you can install using:

```bash
python setup.py install --no-sse2
export RANDOMGEN_NO_SSE2=1
python -m pip install .
```

### Windows
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ build_script:
- conda update conda --quiet
- conda install numpy cython nose pandas pytest scipy --quiet
- conda install -c numba numba --quiet
- python setup.py develop
- python -m pip install -e .
- set "GIT_DIR=%cd%"

test_script:
Expand Down
13 changes: 7 additions & 6 deletions ci/azure/azure_template_posix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ jobs:
NUMPY: 1.16.6
python39_latest:
python.version: '3.9'
python310_latest:
python.version: '3.10'
python36_latest:
python.version: '3.6'
python38_mid_conda:
python.version: '3.8'
use.conda: true
NUMPY: 1.18.5
CYTHON: 0.29.22
CYTHON: 0.29.24
USE_SCIPY: "true"
USE_NUMBA: "true"
python_38_coverage:
Expand All @@ -48,8 +50,7 @@ jobs:
python.version: '3.7'
use.conda: true
coverage: false
NUMPY: 1.17.4
TEST_INSTALL: true
test.install: true
${{ if eq(parameters.name, 'macOS') }}:
python39_latest_macos:
python.version: '3.9'
Expand Down Expand Up @@ -91,9 +92,9 @@ jobs:

- script: |
echo "Installing to site packages"
python setup.py bdist_wheel
WHL=$(ls -t dist)
pip install ./dist/${WHL}
python -m pip wheel . -w wheelhouse/
WHL=$(ls -t wheelhouse/randomgen-*.whl | head -n1)
pip install ${WHL}
displayName: 'Install randomgen (site-packages)'
condition: eq(variables['test.install'], 'true')
Expand Down
2 changes: 1 addition & 1 deletion ci/azure/install-posix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ else
fi

# Not all available in conda
python -m pip install setuptools wheel pip black==20.8b1 isort flake8 --upgrade
python -m pip install setuptools "setuptools_scm[toml]<7" "oldest-supported-numpy" wheel pip black==22.3.0 isort flake8 --upgrade

EXTRA="pytest pytest-xdist coverage pytest-cov"

Expand Down
10 changes: 8 additions & 2 deletions ci/cirrus-install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/usr/bin/env bash

pkg install -y python38 py38-pip py38-numpy py38-cython py38-pytest
python3.8 setup.py develop

pkg install -y python39 py39-numpy py39-cython wget git
python3.9 -m ensurepip --upgrade
python3.9 -m pip install wheel setuptools_scm[toml] pytest
python3.9 -m pip list
git fetch --tags
python3.9 -m pip install . --no-build-isolation

69 changes: 47 additions & 22 deletions doc/source/custom-bit-generators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"class PythonPCG64:\n",
" # A 128 bit multiplier\n",
" PCG_DEFAULT_MULTIPLIER = (2549297995355413924 << 64) + 4865540595714422341\n",
" MODULUS = 2 ** 128\n",
" MODULUS = 2**128\n",
"\n",
" def __init__(self, state, inc):\n",
" \"\"\"Directly set the state and increment, no seed support\"\"\"\n",
Expand All @@ -104,9 +104,10 @@
" a closure than to wrap the state in an array, pass it's address as a\n",
" ctypes void pointer, and then to get the pointer in the function.\n",
" \"\"\"\n",
"\n",
" def _next_64(void_p):\n",
" return self.random_raw()\n",
" \n",
"\n",
" self._next_64 = _next_64\n",
" return _next_64\n",
"\n",
Expand All @@ -117,6 +118,7 @@
" ``next_64`` except that it return a 32-bit unsigned int. Here we save\n",
" half of the raw 64 bit output for subsequent calls.\n",
" \"\"\"\n",
"\n",
" def _next_32(void_p):\n",
" if self._has_uint32:\n",
" self._has_uint32 = False\n",
Expand All @@ -128,19 +130,21 @@
"\n",
" self._next_32 = _next_32\n",
" return _next_32\n",
" \n",
"\n",
" @property\n",
" def state_getter(self):\n",
" def f():\n",
" return {\"state\": self.state, \"inc\": self.inc}\n",
"\n",
" return f\n",
"\n",
" @property\n",
" def state_setter(self):\n",
" def f(value):\n",
" self.state = value[\"state\"]\n",
" self.inc = value[\"inc\"]\n",
" return f\n"
"\n",
" return f"
]
},
{
Expand Down Expand Up @@ -239,6 +243,7 @@
],
"source": [
"from numpy.random import Generator\n",
"\n",
"gen = Generator(python_pcg)\n",
"print(f\"Before: {prng.state}\")\n",
"print(f\"Std. Normal : {gen.standard_normal()}\")\n",
Expand Down Expand Up @@ -282,7 +287,13 @@
}
],
"source": [
"python_pcg = UserBitGenerator(prng.next_64, 64, next_32=prng.next_32, state_getter=prng.state_getter, state_setter=prng.state_setter)\n",
"python_pcg = UserBitGenerator(\n",
" prng.next_64,\n",
" 64,\n",
" next_32=prng.next_32,\n",
" state_getter=prng.state_getter,\n",
" state_setter=prng.state_setter,\n",
")\n",
"python_pcg.state"
]
},
Expand Down Expand Up @@ -356,17 +367,20 @@
"\n",
"rotate64_sig = types.uint64(types.uint64, types.int_)\n",
"\n",
"\n",
"@jit(signature_or_function=rotate64_sig, inline=\"always\")\n",
"def rotate64(x, k):\n",
" return (x << k) | (x >> (64 - k));\n",
" return (x << k) | (x >> (64 - k))\n",
"\n",
"\n",
"jsf_next_sig = types.uint64(types.uint64[:])\n",
"\n",
"\n",
"@jit(signature_or_function=jsf_next_sig, inline=\"always\")\n",
"def jsf_next(state):\n",
" \"\"\"\n",
" Update the state in place\n",
" \n",
"\n",
" This is a literal translation of the C code where the value p, q,\n",
" and r are fixed.\n",
" \"\"\"\n",
Expand All @@ -375,17 +389,17 @@
" q = 13\n",
" r = 37\n",
" # Update\n",
" e = state[0] - rotate64(state[1], p);\n",
" state[0] = state[1] ^ rotate64(state[2], q);\n",
" state[1] = state[2] + (rotate64(state[3], r) if r else state[3]);\n",
" state[2] = state[3] + e;\n",
" state[3] = e + state[0];\n",
" return state[3];\n",
" e = state[0] - rotate64(state[1], p)\n",
" state[0] = state[1] ^ rotate64(state[2], q)\n",
" state[1] = state[2] + (rotate64(state[3], r) if r else state[3])\n",
" state[2] = state[3] + e\n",
" state[3] = e + state[0]\n",
" return state[3]\n",
"\n",
"\n",
"class NumbaJSF:\n",
" def __init__(self, seed):\n",
" if not isinstance(seed, (int, np.integer)) or not (0 <= state < 2 ** 64):\n",
" if not isinstance(seed, (int, np.integer)) or not (0 <= state < 2**64):\n",
" raise ValueError(\"seed must be a valid uint64\")\n",
" # state[0:4] is the JSF state\n",
" # state[4] contains both the has_uint flag in bit 0\n",
Expand All @@ -398,13 +412,13 @@
" self.seed(seed)\n",
"\n",
" def seed(self, value):\n",
" self._state[0] = 0xf1ea5eed;\n",
" self._state[1] = value;\n",
" self._state[2] = value;\n",
" self._state[3] = value;\n",
" self._state[0] = 0xF1EA5EED\n",
" self._state[1] = value\n",
" self._state[2] = value\n",
" self._state[3] = value\n",
" for i in range(20):\n",
" jsf_next(self._state)\n",
" \n",
"\n",
" @property\n",
" def state_address(self):\n",
" \"\"\"Get the location in memory of the state NumPy array.\"\"\"\n",
Expand Down Expand Up @@ -485,6 +499,7 @@
" @property\n",
" def state_getter(self):\n",
" \"\"\"A function that returns the state. This is Python and is not decorated\"\"\"\n",
"\n",
" def f() -> dict:\n",
" return {\n",
" \"bit_gen\": type(self).__name__,\n",
Expand All @@ -498,6 +513,7 @@
" @property\n",
" def state_setter(self):\n",
" \"\"\"A function that sets the state. This is Python and is not decorated\"\"\"\n",
"\n",
" def f(value: dict):\n",
" name = value.get(\"bit_gen\", None)\n",
" if name != type(self).__name__:\n",
Expand Down Expand Up @@ -547,7 +563,9 @@
],
"source": [
"# From random.org\n",
"state = np.array([0x77, 0x5e, 0xb7, 0x11, 0x14, 0x3f, 0xd1, 0x0e], dtype=np.uint8).view(np.uint64)[0]\n",
"state = np.array([0x77, 0x5E, 0xB7, 0x11, 0x14, 0x3F, 0xD1, 0x0E], dtype=np.uint8).view(\n",
" np.uint64\n",
")[0]\n",
"njsf = NumbaJSF(state)\n",
"njsf.state_getter()"
]
Expand Down Expand Up @@ -585,8 +603,15 @@
}
],
"source": [
"jsf_ubg = UserBitGenerator.from_cfunc(njsf.next_raw, njsf.next_64, njsf.next_32, njsf.next_double, njsf.state_address, \n",
" state_getter=njsf.state_getter, state_setter=njsf.state_setter)\n",
"jsf_ubg = UserBitGenerator.from_cfunc(\n",
" njsf.next_raw,\n",
" njsf.next_64,\n",
" njsf.next_32,\n",
" njsf.next_double,\n",
" njsf.state_address,\n",
" state_getter=njsf.state_getter,\n",
" state_setter=njsf.state_setter,\n",
")\n",
"print(jsf_ubg.state)\n",
"print(jsf_ubg.random_raw(2))\n",
"print(jsf_ubg.state)"
Expand Down
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ requires = [
"setuptools",
"wheel",
"Cython>=0.29.24,<3.0",
"numpy==1.16.6; python_version<='3.7'",
"numpy==1.17.5; python_version=='3.8'",
"numpy==1.19.5; python_version=='3.9'",
"numpy; python_version>='3.10'",
"numpy>=1.14"
"oldest-supported-numpy",
"numpy; python_version>='3.11'",
"setuptools_scm[toml]>=6.4.2,<7.0.0",
]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "randomgen/_version.py"
7 changes: 3 additions & 4 deletions randomgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from randomgen.xoshiro256 import Xoshiro256
from randomgen.xoshiro512 import Xoshiro512

from ._version import get_versions
from ._version import version as __version__, version_tuple as __version_info__

PKG_TESTS = os.path.join(os.path.dirname(__file__), "tests")

Expand Down Expand Up @@ -67,11 +67,10 @@
"Xoshiro256",
"Xoshiro512",
"random_entropy",
"__version__",
"__version_info__",
]

__version__ = get_versions()["version"]
del get_versions


def test(extra_args: Union[str, List[str]] = None) -> None:
try:
Expand Down
Loading

0 comments on commit 3015e67

Please sign in to comment.