Search is not available for this dataset
repo_id
stringlengths
12
110
file_path
stringlengths
24
164
content
stringlengths
3
89.3M
__index_level_0__
int64
0
0
public_repos/numpy-user-dtypes/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/__init__.py
import numpy as np from ._mpfdtype_main import MPFDType, MPFloat # Lets add some uglier hacks: # NumPy uses repr as a fallback (as of writing this code), we want to # customize the printing of MPFloats though... def mystr(obj): if isinstance(obj, MPFloat): return f"'{obj}'" return repr(obj) np.set...
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/umath.cpp
#include "scalar.h" #define PY_ARRAY_UNIQUE_SYMBOL MPFDType_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY extern "C" { #include <Python.h> #include "numpy/arrayobject.h" #include "numpy/ndarraytypes.h" #include "numpy/ufuncobject.h" #include "numpy/experimen...
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/ops.hpp
#include "mpfr.h" typedef int unary_op_def(mpfr_t, mpfr_t); typedef int binop_def(mpfr_t, mpfr_t, mpfr_t); typedef npy_bool cmp_def(mpfr_t, mpfr_t); /* * Unary operations */ static inline int negative(mpfr_t op, mpfr_t out) { return mpfr_neg(out, op, MPFR_RNDN); } static inline int positive(mpfr_t op, mpfr_t ...
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/casts.h
#ifndef _NPY_CASTS_H #define _NPY_CASTS_H #ifdef __cplusplus extern "C" { #endif extern PyArrayMethod_Spec MPFToMPFCastSpec; PyArrayMethod_Spec ** init_casts(void); void free_casts(void); #ifdef __cplusplus } #endif #endif /* _NPY_CASTS_H */
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/numbers.cpp
/* * This file defines scalar numeric operations. */ #define PY_ARRAY_UNIQUE_SYMBOL MPFDType_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY extern "C" { #include <Python.h> #include "numpy/arrayobject.h" #include "numpy/ndarraytypes.h" #include "numpy/ufuncobjec...
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/scalar.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL MPFDType_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/ndarraytypes.h" #include "numpy/experimental_dtype_api.h" #include "scalar.h" #include "numbers.h" mpfr_prec_t get_prec_from_...
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/casts.cpp
#define PY_ARRAY_UNIQUE_SYMBOL MPFDType_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY extern "C" { #include <Python.h> #include "numpy/arrayobject.h" #include "numpy/ndarraytypes.h" #include "numpy/experimental_dtype_api.h" } #include <vector> #include "mpfr.h" ...
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/dtype.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL MPFDType_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/ndarraytypes.h" #include "numpy/experimental_dtype_api.h" #include "mpfr.h" #include "scalar.h" #include "casts.h" #include "d...
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/dtype.h
#ifndef _MPRFDTYPE_DTYPE_H #define _MPRFDTYPE_DTYPE_H #include "mpfr.h" #ifdef __cplusplus extern "C" { #endif #include "scalar.h" typedef struct { PyArray_Descr base; mpfr_prec_t precision; } MPFDTypeObject; /* * It would be more compat to just store the kind, exponent and signfificand, * however. Fo...
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/terrible_hacks.h
#include <Python.h> int init_terrible_hacks(void);
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/mpfdtype_main.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL MPFDType_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "dtype.h" #include "umath.h" #include "terrible_hacks.h" static struct PyModuleDef moduledef = { PyModuleDe...
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/numbers.h
#ifndef _MPF_NUMBERS_H #define _MPF_NUMBERS_H #ifdef __cplusplus extern "C" { #endif PyObject * mpf_richcompare(MPFloatObject *self, PyObject *other, int cmp_op); extern PyNumberMethods mpf_as_number; #ifdef __cplusplus } #endif #endif /* _MPF_NUMBERS_H */
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/scalar.h
#ifndef _MPRFDTYPE_SCALAR_H #define _MPRFDTYPE_SCALAR_H #include "mpfr.h" #ifdef __cplusplus extern "C" { #endif #include <Python.h> typedef struct { mpfr_t x; mp_limb_t significand[]; } mpf_field; typedef struct { PyObject_VAR_HEAD; mpf_field mpf; } MPFloatObject; extern PyTypeObject MPFloat_T...
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/umath.h
#ifndef _MPRFDTYPE_UMATH_H #define _MPRFDTYPE_UMATH_H #ifdef __cplusplus extern "C" { #endif int init_mpf_umath(void); #ifdef __cplusplus } #endif #endif /*_MPRFDTYPE_UMATH_H */
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/src/terrible_hacks.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL MPFDType_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/ndarraytypes.h" #include "numpy/experimental_dtype_api.h" #include "mpfr.h" #include "dtype.h" #include "scalar.h" /* * Some ...
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/tests/conftest.py
import os os.environ["NUMPY_EXPERIMENTAL_DTYPE_API"] = "1"
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/tests/test_scalar.py
import pytest import sys import numpy as np import operator from mpfdtype import MPFDType, MPFloat def test_create_scalar_simple(): # currently inferring 53bit precision from float: assert MPFloat(12.).prec == 53 # currently infers 64bit or 32bit depending on system: assert MPFloat(1).prec == sys.ma...
0
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype
public_repos/numpy-user-dtypes/mpfdtype/mpfdtype/tests/test_array.py
import numpy as np from numpy.testing import assert_array_equal from mpfdtype import MPFDType def test_advanced_indexing(): # As of writing the test, this relies on copyswap arr = np.arange(100).astype(MPFDType(100)) orig = np.arange(100).astype(MPFDType(100)) # second one, not a copy b = arr[[1, 2...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/asv_benchmarks/asv.conf.json
{ // The version of the config file format. Do not change, unless // you know what you are doing. "version": 1, // The name of the project being benchmarked "project": "numpy-user-dtypes", // The project's homepage "project_url": "https://github.com/numpy/numpy-user-dtypes", // The U...
0
public_repos/numpy-user-dtypes/asv_benchmarks
public_repos/numpy-user-dtypes/asv_benchmarks/benchmarks/strings.py
# Write the benchmarking functions here. # See "Writing benchmarks" in the asv docs for more information. import uuid import numpy as np from asciidtype import ASCIIDType from stringdtype import StringDType def generate_data(n=100000): """Generate data for the benchmarks. The vast majority of the time spen...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/unytdtype/meson.build
project( 'unytdtype', 'c', ) py_mod = import('python') py = py_mod.find_installation() incdir_numpy = run_command(py, [ '-c', 'import numpy; print(numpy.get_include())' ], check: true ).stdout().strip() includes = include_directories( [ incdir_numpy, 'unytdtype/src' ] ) srcs = [ 'uny...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/unytdtype/.clang-format
# A clang-format style that approximates Python's PEP 7 # Useful for IDE integration # # Based on Paul Ganssle's version at # https://gist.github.com/pganssle/0e3a5f828b4d07d79447f6ced8e7e4db # and modified for NumPy BasedOnStyle: Google AlignAfterOpenBracket: Align AllowShortEnumsOnASingleLine: false AllowShortIfState...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/unytdtype/pyproject.toml
[build-system] requires = [ "meson>=0.63.0", "meson-python", "patchelf", "wheel", "numpy", ] build-backend = "mesonpy" [project] name = "unytdtype" description = "A unit dtype backed by unyt" version = "0.0.1" readme = 'README.md' author = "Nathan Goldbaum" requires-python = ">=3.9.0" dependencies ...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/unytdtype/README.md
# A dtype that stores unit metadata This is a simple proof-of-concept dtype using the (as of late 2022) experimental [new dtype implementation](https://numpy.org/neps/nep-0041-improved-dtype-support.html) in NumPy. It leverages the [unyt](https://unyt.readthedocs.org) library's `Unit` type to store unit metadata, but ...
0
public_repos/numpy-user-dtypes/unytdtype
public_repos/numpy-user-dtypes/unytdtype/unytdtype/scalar.py
"""A scalar type needed by the dtype machinery.""" from unyt import Unit class UnytScalar: def __init__(self, value, unit): from . import UnytDType self.value = value if isinstance(unit, (str, Unit)): self.dtype = UnytDType(unit) elif isinstance(unit, UnytDType): ...
0
public_repos/numpy-user-dtypes/unytdtype
public_repos/numpy-user-dtypes/unytdtype/unytdtype/__init__.py
"""A dtype that carries around unit metadata. This is an example usage of the experimental new dtype API in Numpy and is not yet intended for any real purpose. """ from .scalar import UnytScalar # isort: skip from ._unytdtype_main import UnytDType __all__ = ["UnytDType", "UnytScalar"]
0
public_repos/numpy-user-dtypes/unytdtype/unytdtype
public_repos/numpy-user-dtypes/unytdtype/unytdtype/src/casts.h
#ifndef _NPY_CASTS_H #define _NPY_CASTS_H #include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL unytdtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "numpy/ndarraytypes.h" /* Gets the conversion be...
0
public_repos/numpy-user-dtypes/unytdtype/unytdtype
public_repos/numpy-user-dtypes/unytdtype/unytdtype/src/dtype.c
#include "dtype.h" #include "casts.h" PyTypeObject *UnytScalar_Type = NULL; /* * `get_value` and `get_unit` are small helpers to deal with the scalar. */ // NJG hack: get_value assumes scalar is a float64 - possible to generalize? static double get_value(PyObject *scalar) { PyTypeObject *scalar_type = Py_TYPE...
0
public_repos/numpy-user-dtypes/unytdtype/unytdtype
public_repos/numpy-user-dtypes/unytdtype/unytdtype/src/unytdtype_main.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL unytdtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "dtype.h" #include "umath.h" static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, .m_nam...
0
public_repos/numpy-user-dtypes/unytdtype/unytdtype
public_repos/numpy-user-dtypes/unytdtype/unytdtype/src/dtype.h
#ifndef _NPY_DTYPE_H #define _NPY_DTYPE_H // clang-format off #include <Python.h> #include "structmember.h" // clang-format on #define PY_ARRAY_UNIQUE_SYMBOL unytdtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_...
0
public_repos/numpy-user-dtypes/unytdtype/unytdtype
public_repos/numpy-user-dtypes/unytdtype/unytdtype/src/casts.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL unytdtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "numpy/ndarraytypes.h" #include "casts.h" #include "dtype.h" /* * Helper function also us...
0
public_repos/numpy-user-dtypes/unytdtype/unytdtype
public_repos/numpy-user-dtypes/unytdtype/unytdtype/src/umath.h
#ifndef _NPY_UFUNC_H #define _NPY_UFUNC_H int init_multiply_ufunc(void); #endif /*_NPY_UFUNC_H */
0
public_repos/numpy-user-dtypes/unytdtype/unytdtype
public_repos/numpy-user-dtypes/unytdtype/unytdtype/src/umath.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL unytdtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "numpy/ndarraytypes.h" #include "numpy/ufuncobject.h" #include "dtype.h" #include "umath.h"...
0
public_repos/numpy-user-dtypes/unytdtype
public_repos/numpy-user-dtypes/unytdtype/tests/test_unytdtype.py
import numpy as np import unyt from unytdtype import UnytDType, UnytScalar def test_dtype_creation(): dtype = UnytDType("m") assert str(dtype) == "UnytDType('m')" dtype2 = UnytDType(unyt.Unit("m")) assert str(dtype2) == "UnytDType('m')" assert dtype == dtype2 def test_scalar_creation(): dt...
0
public_repos/numpy-user-dtypes/unytdtype
public_repos/numpy-user-dtypes/unytdtype/tests/conftest.py
import os os.environ["NUMPY_EXPERIMENTAL_DTYPE_API"] = "1"
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/metadatadtype/.flake8
[flake8] per-file-ignores = __init__.py:F401
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/metadatadtype/meson.build
project( 'metadatadtype', 'c', ) py_mod = import('python') py = py_mod.find_installation() incdir_numpy = run_command(py, [ '-c', 'import numpy; print(numpy.get_include())' ], check: true ).stdout().strip() includes = include_directories( [ incdir_numpy, 'metadatadtype/src' ] ) srcs = ...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/metadatadtype/.clang-format
# A clang-format style that approximates Python's PEP 7 # Useful for IDE integration # # Based on Paul Ganssle's version at # https://gist.github.com/pganssle/0e3a5f828b4d07d79447f6ced8e7e4db # and modified for NumPy BasedOnStyle: Google AlignAfterOpenBracket: Align AllowShortEnumsOnASingleLine: false AllowShortIfState...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/metadatadtype/pyproject.toml
[build-system] requires = [ "meson>=0.63.0", "meson-python", "patchelf", "wheel", "numpy", ] build-backend = "mesonpy" [project] name = "metadatadtype" description = "A dtype that holds a piece of metadata" version = "0.0.1" readme = 'README.md' author = "Nathan Goldbaum" requires-python = ">=3.9.0...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/metadatadtype/README.md
# A dtype that stores metadata This is a simple proof-of-concept dtype using the (as of late 2022) experimental [new dtype implementation](https://numpy.org/neps/nep-0041-improved-dtype-support.html) in NumPy. For now all it does it storea piece of static metadata in the dtype itself. ## Building Ensure Meson and Nu...
0
public_repos/numpy-user-dtypes/metadatadtype
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype/scalar.py
"""A scalar type needed by the dtype machinery.""" class MetadataScalar: def __init__(self, value, dtype): self.value = value self.dtype = dtype def __repr__(self): return f"{self.value} {self.dtype._metadata}"
0
public_repos/numpy-user-dtypes/metadatadtype
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype/__init__.py
"""A dtype that carries around metadata. This is an example usage of the experimental new dtype API in Numpy and is not intended for any real purpose. """ from .scalar import MetadataScalar # isort: skip from ._metadatadtype_main import MetadataDType __all__ = ["MetadataDType", "MetadataScalar"]
0
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype/src/casts.h
#ifndef _NPY_CASTS_H #define _NPY_CASTS_H #include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "numpy/ndarraytypes.h" PyArrayMethod_Spec **...
0
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype/src/dtype.c
#include "dtype.h" #include "casts.h" PyTypeObject *MetadataScalar_Type = NULL; /* * `get_value` and `get_unit` are small helpers to deal with the scalar. */ static double get_value(PyObject *scalar) { PyTypeObject *scalar_type = Py_TYPE(scalar); if (scalar_type != MetadataScalar_Type) { double re...
0
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype/src/dtype.h
#ifndef _NPY_DTYPE_H #define _NPY_DTYPE_H // clang-format off #include <Python.h> #include "structmember.h" // clang-format on #define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/experimental_dt...
0
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype/src/casts.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "numpy/ndarraytypes.h" #include "casts.h" #include "dtype.h" /* * And now the actual ...
0
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype/src/metadatadtype_main.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "dtype.h" #include "umath.h" static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, .m...
0
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype/src/umath.h
#ifndef _NPY_UFUNC_H #define _NPY_UFUNC_H int init_ufuncs(void); #endif /*_NPY_UFUNC_H */
0
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype
public_repos/numpy-user-dtypes/metadatadtype/metadatadtype/src/umath.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL metadatadtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "numpy/ndarraytypes.h" #include "numpy/ufuncobject.h" #include "dtype.h" #include "umat...
0
public_repos/numpy-user-dtypes/metadatadtype
public_repos/numpy-user-dtypes/metadatadtype/tests/conftest.py
import os os.environ["NUMPY_EXPERIMENTAL_DTYPE_API"] = "1"
0
public_repos/numpy-user-dtypes/metadatadtype
public_repos/numpy-user-dtypes/metadatadtype/tests/test_metadatadtype.py
import numpy as np from metadatadtype import MetadataDType, MetadataScalar def test_dtype_creation(): dtype = MetadataDType("some metadata") assert str(dtype) == "MetadataDType('some metadata')" def test_creation_from_zeros(): dtype = MetadataDType("test") arr = np.zeros(3, dtype=dtype) assert ...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/stringdtype/meson.build
project( 'stringdtype', 'c', ) py_mod = import('python') py = py_mod.find_installation() incdir_numpy = run_command(py, [ '-c', 'import numpy; print(numpy.get_include())' ], check: true ).stdout().strip() cc = meson.get_compiler('c') npymath_path = incdir_numpy / '..' / 'lib' npymath_lib = cc.find...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/stringdtype/.clang-format
# A clang-format style that approximates Python's PEP 7 # Useful for IDE integration # # Based on Paul Ganssle's version at # https://gist.github.com/pganssle/0e3a5f828b4d07d79447f6ced8e7e4db # and modified for NumPy BasedOnStyle: Google AlignAfterOpenBracket: Align AllowShortEnumsOnASingleLine: false AllowShortIfState...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/stringdtype/pyproject.toml
[build-system] requires = [ "meson>=0.63.0", "meson-python", "patchelf", "wheel", "numpy", ] build-backend = "mesonpy" [tool.black] line-length = 79 [tool.isort] profile = "black" line_length = 79 [project] name = "stringdtype" description = "A dtype for storing UTF-8 strings" version = "0.0.1" r...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/stringdtype/README.md
# A dtype that stores pointers to strings This is a simple proof-of-concept dtype using the (as of early 2023) experimental [new dtype implementation](https://numpy.org/neps/nep-0041-improved-dtype-support.html) in NumPy. ## Building Ensure Meson and NumPy are installed in the python environment you would like to us...
0
public_repos/numpy-user-dtypes/stringdtype
public_repos/numpy-user-dtypes/stringdtype/tests/conftest.py
import os os.environ["NUMPY_EXPERIMENTAL_DTYPE_API"] = "1"
0
public_repos/numpy-user-dtypes/stringdtype
public_repos/numpy-user-dtypes/stringdtype/tests/test_stringdtype.py
import concurrent.futures import os import pickle import string import tempfile import numpy as np try: from pandas import NA as pd_NA except ImportError: pd_NA = None import pytest from stringdtype import StringDType, StringScalar, _memory_usage @pytest.fixture def string_list(): return ["abc", "def",...
0
public_repos/numpy-user-dtypes/stringdtype
public_repos/numpy-user-dtypes/stringdtype/tests/test_char.py
import numpy as np import pytest from numpy.testing import assert_array_equal from stringdtype import StringDType TEST_DATA = [ "hello" * 10, "Ae¢☃€ 😊" * 100, "entry\nwith\nnewlines", "entry\twith\ttabs", ] @pytest.fixture def string_array(): return np.array(TEST_DATA, dtype=StringDType()) @p...
0
public_repos/numpy-user-dtypes/stringdtype
public_repos/numpy-user-dtypes/stringdtype/stringdtype/scalar.py
"""Scalar types needed by the dtype machinery.""" class StringScalar(str): pass
0
public_repos/numpy-user-dtypes/stringdtype
public_repos/numpy-user-dtypes/stringdtype/stringdtype/__init__.py
"""A dtype for working with variable-length string data """ from .scalar import StringScalar # isort: skip from ._main import StringDType, _memory_usage __all__ = [ "NA", "StringDType", "StringScalar", "_memory_usage", ]
0
public_repos/numpy-user-dtypes/stringdtype/stringdtype
public_repos/numpy-user-dtypes/stringdtype/stringdtype/src/casts.h
#ifndef _NPY_CASTS_H #define _NPY_CASTS_H // needed for Py_UCS4 #include <Python.h> // need these defines and includes for PyArrayMethod_Spec #define PY_ARRAY_UNIQUE_SYMBOL stringdtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION #define NPY_TARGET_VERSION NPY_2_0_API_VERSION #define NO_IMPORT_ARRAY #i...
0
public_repos/numpy-user-dtypes/stringdtype/stringdtype
public_repos/numpy-user-dtypes/stringdtype/stringdtype/src/main.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL stringdtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION #define NPY_TARGET_VERSION NPY_2_0_API_VERSION #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "dtype.h" #include "static_string.h" #include "umath.h" static Py...
0
public_repos/numpy-user-dtypes/stringdtype/stringdtype
public_repos/numpy-user-dtypes/stringdtype/stringdtype/src/static_string.c
#include "static_string.h" #include <stdint.h> #include <string.h> #if NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN // the high byte in vstring.size is reserved for flags // SSSS SSSF typedef struct _npy_static_string_t { size_t offset; size_t size; } _npy_static_string_t; typedef struct _short_string_buffer { ...
0
public_repos/numpy-user-dtypes/stringdtype/stringdtype
public_repos/numpy-user-dtypes/stringdtype/stringdtype/src/dtype.c
#include "dtype.h" #include "casts.h" #include "static_string.h" PyTypeObject *StringScalar_Type = NULL; /* * Internal helper to create new instances */ PyObject * new_stringdtype_instance(PyObject *na_object, int coerce) { npy_string_allocator *allocator = NULL; PyThread_type_lock *allocator_lock = NULL; ...
0
public_repos/numpy-user-dtypes/stringdtype/stringdtype
public_repos/numpy-user-dtypes/stringdtype/stringdtype/src/dtype.h
#ifndef _NPY_DTYPE_H #define _NPY_DTYPE_H // clang-format off #include <Python.h> #include "structmember.h" // clang-format on #include "static_string.h" #define PY_ARRAY_UNIQUE_SYMBOL stringdtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION #define NPY_TARGET_VERSION NPY_2_0_API_VERSION #define NO_IM...
0
public_repos/numpy-user-dtypes/stringdtype/stringdtype
public_repos/numpy-user-dtypes/stringdtype/stringdtype/src/casts.c
#include "casts.h" #include "dtype.h" #include "static_string.h" #define ANY_TO_STRING_RESOLVE_DESCRIPTORS(safety) \ static NPY_CASTING any_to_string_##safety##_resolve_descriptors( \ PyObject *NPY_UNUSED(self), \ PyArray_DT...
0
public_repos/numpy-user-dtypes/stringdtype/stringdtype
public_repos/numpy-user-dtypes/stringdtype/stringdtype/src/umath.h
#ifndef _NPY_UFUNC_H #define _NPY_UFUNC_H int init_ufuncs(void); #endif /*_NPY_UFUNC_H */
0
public_repos/numpy-user-dtypes/stringdtype/stringdtype
public_repos/numpy-user-dtypes/stringdtype/stringdtype/src/static_string.h
#ifndef _NPY_STATIC_STRING_H #define _NPY_STATIC_STRING_H #include "stdint.h" #include "stdlib.h" typedef struct npy_packed_static_string { char packed_buffer[sizeof(char *) + sizeof(size_t)]; } npy_packed_static_string; typedef struct npy_static_string { size_t size; const char *buf; } npy_static_string...
0
public_repos/numpy-user-dtypes/stringdtype/stringdtype
public_repos/numpy-user-dtypes/stringdtype/stringdtype/src/umath.c
#include <Python.h> #include "umath.h" #include "dtype.h" #include "static_string.h" static NPY_CASTING multiply_resolve_descriptors( struct PyArrayMethodObject_tag *NPY_UNUSED(method), PyArray_DTypeMeta *dtypes[], PyArray_Descr *given_descrs[], PyArray_Descr *loop_descrs[], npy_intp *NPY_UNU...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/quaddtype/.flake8
[flake8] max-line-length = 100 ignore = D107,D104,W503 per-file-ignores = __init__.py:F401,tests/*:D100 docstring-convention = numpy docstring_style = numpy
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/quaddtype/meson.build
project( 'quaddtype', 'c', ) py_mod = import('python') py = py_mod.find_installation() incdir_numpy = run_command(py, [ '-c', 'import numpy; print(numpy.get_include())' ], check: true ).stdout().strip() includes = include_directories( [ incdir_numpy, 'quaddtype/src' ] ) srcs = [ 'qua...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/quaddtype/pyproject.toml
[build-system] requires = [ "meson>=0.63.0", "meson-python", "patchelf", "wheel", "numpy" ] build-backend = "mesonpy" [project] name = "quaddtype" description = "Quad (128-bit) float dtype for numpy" version = "0.0.1" readme = 'README.md' author = "Peyton Murray" requires-python = ">=3.9.0" depende...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/quaddtype/README.md
# quaddtype Quad (128-bit) float dtype for numpy ## Installation To install, make sure you have `numpy` nightly installed. Then build without isolation so that the `quaddtype` can link against the experimental dtype API headers, which aren't in the latest releases of `numpy`: ```bash pip install -i https://pypi.ana...
0
public_repos/numpy-user-dtypes/quaddtype
public_repos/numpy-user-dtypes/quaddtype/tests/conftest.py
import os os.environ["NUMPY_EXPERIMENTAL_DTYPE_API"] = "1"
0
public_repos/numpy-user-dtypes/quaddtype
public_repos/numpy-user-dtypes/quaddtype/tests/test_quaddtype.py
import numpy as np from quaddtype import QuadDType, QuadScalar def test_dtype_creation(): assert str(QuadDType()) == "This is a quad (128-bit float) dtype." def test_scalar_creation(): assert str(QuadScalar(3.1)) == "3.1" def test_create_with_explicit_dtype(): assert ( repr(np.array([3.0, 3.1...
0
public_repos/numpy-user-dtypes/quaddtype
public_repos/numpy-user-dtypes/quaddtype/quaddtype/quadscalar.py
"""Quad scalar floating point type for numpy.""" class QuadScalar: """Quad scalar floating point type.""" def __init__(self, value): self.value = value def __repr__(self): return f"{self.value}"
0
public_repos/numpy-user-dtypes/quaddtype
public_repos/numpy-user-dtypes/quaddtype/quaddtype/__init__.py
# Scalar quantity must be defined _before_ the dtype, so don't isort it. # During initialization of _quaddtype_main, QuadScalar is imported from this # (partially initialized) # module, and therefore has to be defined first. from .quadscalar import QuadScalar # isort: skip from ._quaddtype_main import QuadDType __all...
0
public_repos/numpy-user-dtypes/quaddtype/quaddtype
public_repos/numpy-user-dtypes/quaddtype/quaddtype/src/casts.h
#ifndef _NPY_CASTS_H #define _NPY_CASTS_H #include "numpy/experimental_dtype_api.h" extern PyArrayMethod_Spec QuadToQuadCastSpec; extern PyArrayMethod_Spec QuadToFloat128CastSpec; #endif /* _NPY_CASTS_H */
0
public_repos/numpy-user-dtypes/quaddtype/quaddtype
public_repos/numpy-user-dtypes/quaddtype/quaddtype/src/dtype.c
#include "dtype.h" #include "abstract.h" #include "casts.h" PyTypeObject *QuadScalar_Type = NULL; QuadDTypeObject * new_quaddtype_instance(void) { QuadDTypeObject *new = (QuadDTypeObject *)PyArrayDescr_Type.tp_new((PyTypeObject *)&QuadDType, NULL, NULL); if (new == NULL) { return NULL; ...
0
public_repos/numpy-user-dtypes/quaddtype/quaddtype
public_repos/numpy-user-dtypes/quaddtype/quaddtype/src/dtype.h
#ifndef _NPY_DTYPE_H #define _NPY_DTYPE_H #include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL quaddtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/ndarraytypes.h" #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" typedef struct { PyAr...
0
public_repos/numpy-user-dtypes/quaddtype/quaddtype
public_repos/numpy-user-dtypes/quaddtype/quaddtype/src/casts.c
#include "casts.h" #include "dtype.h" // And now the actual cast code! Starting with the "resolver" which tells // us about cast safety. // Note also the `view_offset`! It is a way for you to tell NumPy, that this // cast does not require anything at all, but the cast can simply be done as // a view. // For `arr.ast...
0
public_repos/numpy-user-dtypes/quaddtype/quaddtype
public_repos/numpy-user-dtypes/quaddtype/quaddtype/src/quaddtype_main.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL quaddtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "dtype.h" #include "umath.h" static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, .m_nam...
0
public_repos/numpy-user-dtypes/quaddtype/quaddtype
public_repos/numpy-user-dtypes/quaddtype/quaddtype/src/umath.h
#ifndef _NPY_UFUNC_H #define _NPY_UFUNC_H int init_multiply_ufunc(void); #endif /*_NPY_UFUNC_H */
0
public_repos/numpy-user-dtypes/quaddtype/quaddtype
public_repos/numpy-user-dtypes/quaddtype/quaddtype/src/umath.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL quaddtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/ndarraytypes.h" #include "numpy/ufuncobject.h" #include "numpy/experimental_dtype_api.h" #include "dtype.h" #include "umath.h...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/asciidtype/.flake8
[flake8] per-file-ignores = __init__.py:F401 max-line-length = 160
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/asciidtype/meson.build
project( 'asciidtype', 'c', ) py_mod = import('python') py = py_mod.find_installation() incdir_numpy = run_command(py, [ '-c', 'import numpy; print(numpy.get_include())' ], check: true ).stdout().strip() includes = include_directories( [ incdir_numpy, 'asciidtype/src' ] ) srcs = [ 'a...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/asciidtype/.clang-format
# A clang-format style that approximates Python's PEP 7 # Useful for IDE integration # # Based on Paul Ganssle's version at # https://gist.github.com/pganssle/0e3a5f828b4d07d79447f6ced8e7e4db # and modified for NumPy BasedOnStyle: Google AlignAfterOpenBracket: Align AllowShortEnumsOnASingleLine: false AllowShortIfState...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/asciidtype/pyproject.toml
[build-system] requires = [ "meson>=0.63.0", "meson-python", "patchelf", "wheel", "numpy", ] build-backend = "mesonpy" [tool.black] line-length = 79 [project] name = "asciidtype" description = "A dtype for ASCII data" version = "0.0.1" readme = 'README.md' author = "Nathan Goldbaum" requires-pytho...
0
public_repos/numpy-user-dtypes
public_repos/numpy-user-dtypes/asciidtype/README.md
# A dtype that stores ASCII data This is a simple proof-of-concept dtype using the (as of late 2022) experimental [new dtype implementation](https://numpy.org/neps/nep-0041-improved-dtype-support.html) in NumPy. ## Building Ensure Meson and NumPy are installed in the python environment you would like to use: ``` $ ...
0
public_repos/numpy-user-dtypes/asciidtype
public_repos/numpy-user-dtypes/asciidtype/tests/conftest.py
import os os.environ["NUMPY_EXPERIMENTAL_DTYPE_API"] = "1"
0
public_repos/numpy-user-dtypes/asciidtype
public_repos/numpy-user-dtypes/asciidtype/tests/test_asciidtype.py
import os import pickle import re import tempfile import numpy as np import pytest from asciidtype import ASCIIDType, ASCIIScalar def test_dtype_creation(): dtype = ASCIIDType(4) assert str(dtype) == "ASCIIDType(4)" def test_scalar_creation(): dtype = ASCIIDType(7) ASCIIScalar("string", dtype) d...
0
public_repos/numpy-user-dtypes/asciidtype
public_repos/numpy-user-dtypes/asciidtype/asciidtype/scalar.py
"""A scalar type needed by the dtype machinery.""" class ASCIIScalar(str): def __new__(cls, value, dtype): instance = super().__new__(cls, value) instance.dtype = dtype return instance def partition(self, sep): ret = super().partition(sep) return (str(ret[0]), str(ret[...
0
public_repos/numpy-user-dtypes/asciidtype
public_repos/numpy-user-dtypes/asciidtype/asciidtype/__init__.py
"""A dtype for working with ASCII data This is an example usage of the experimental new dtype API in Numpy and is not intended for any real purpose. """ from .scalar import ASCIIScalar # isort: skip from ._asciidtype_main import ASCIIDType __all__ = [ "ASCIIDType", "ASCIIScalar", ]
0
public_repos/numpy-user-dtypes/asciidtype/asciidtype
public_repos/numpy-user-dtypes/asciidtype/asciidtype/src/casts.h
#ifndef _NPY_CASTS_H #define _NPY_CASTS_H #include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "numpy/ndarraytypes.h" PyArrayMethod_Spec ** ge...
0
public_repos/numpy-user-dtypes/asciidtype/asciidtype
public_repos/numpy-user-dtypes/asciidtype/asciidtype/src/dtype.c
#include "dtype.h" #include "casts.h" PyTypeObject *ASCIIScalar_Type = NULL; static PyObject * get_value(PyObject *scalar) { PyObject *ret_bytes = NULL; PyTypeObject *scalar_type = Py_TYPE(scalar); if (scalar_type == &PyUnicode_Type) { // attempt to decode as ASCII ret_bytes = PyUnicode_A...
0
public_repos/numpy-user-dtypes/asciidtype/asciidtype
public_repos/numpy-user-dtypes/asciidtype/asciidtype/src/dtype.h
#ifndef _NPY_DTYPE_H #define _NPY_DTYPE_H // clang-format off #include <Python.h> #include "structmember.h" // clang-format on #define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/experimental_dtype...
0
public_repos/numpy-user-dtypes/asciidtype/asciidtype
public_repos/numpy-user-dtypes/asciidtype/asciidtype/src/casts.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "numpy/ndarraytypes.h" #include "casts.h" #include "dtype.h" static NPY_CASTING ascii_to_...
0
public_repos/numpy-user-dtypes/asciidtype/asciidtype
public_repos/numpy-user-dtypes/asciidtype/asciidtype/src/umath.h
#ifndef _NPY_UFUNC_H #define _NPY_UFUNC_H int init_ufuncs(void); #endif /*_NPY_UFUNC_H */
0
public_repos/numpy-user-dtypes/asciidtype/asciidtype
public_repos/numpy-user-dtypes/asciidtype/asciidtype/src/umath.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "numpy/ndarraytypes.h" #include "numpy/ufuncobject.h" #include "dtype.h" #include "string....
0
public_repos/numpy-user-dtypes/asciidtype/asciidtype
public_repos/numpy-user-dtypes/asciidtype/asciidtype/src/asciidtype_main.c
#include <Python.h> #define PY_ARRAY_UNIQUE_SYMBOL asciidtype_ARRAY_API #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include "numpy/arrayobject.h" #include "numpy/experimental_dtype_api.h" #include "dtype.h" #include "umath.h" static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, .m_na...
0