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

Ditch python2 #216

Merged
merged 58 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
16be285
Round 1.
jaycedowell Feb 14, 2023
b82abaa
Round 2.
jaycedowell Feb 14, 2023
c65f658
Round 3.
jaycedowell Feb 14, 2023
6e4bfeb
Round 4.
jaycedowell Feb 14, 2023
811441a
Round 5.
jaycedowell Feb 14, 2023
05512e0
Round 6.
jaycedowell Feb 14, 2023
5fde61f
Round 7.
jaycedowell Feb 14, 2023
d2e4ece
Drop PyPy stuff.
jaycedowell Feb 14, 2023
323f36f
Cleanup.
jaycedowell Feb 14, 2023
d8792d6
Missed one.
jaycedowell Feb 14, 2023
3fcd11e
No longer needed.
jaycedowell Feb 14, 2023
14f8cff
More cleanup.
jaycedowell Feb 14, 2023
255ace3
We still need sys.
jaycedowell Feb 14, 2023
b517c62
Ugh.
jaycedowell Feb 14, 2023
20b399e
We still need sys.
jaycedowell Feb 14, 2023
a9b74f0
Selective decode.
jaycedowell Feb 14, 2023
be95d00
Missed a few more.
jaycedowell Feb 14, 2023
1f06f6c
Try out type hinting.
jaycedowell Feb 14, 2023
0bed5c2
Var -> Type
jaycedowell Feb 14, 2023
58ffa93
Naming cleanup.
jaycedowell Feb 14, 2023
9a6ccbc
Another naming scheme for the type hinting.
jaycedowell Feb 14, 2023
bbd50d9
Removed test_fft.cu.
jaycedowell Feb 14, 2023
eadb105
Yet another approach to type hinting.
jaycedowell Feb 15, 2023
74b4b4b
Fixes for libbifrost.py plus an idea for Space.py.
jaycedowell Feb 15, 2023
741113c
Add in short names for BF_SPACE_* enums.
jaycedowell Feb 15, 2023
35865f9
Fix space handling in a way that works for other part of Bifrost.
jaycedowell Feb 15, 2023
d411cd0
Do something similar for the BF_REDUCE_* enums.
jaycedowell Feb 15, 2023
6d5ca02
First round of type hinting.
jaycedowell Feb 15, 2023
3b15030
No longer needed?
jaycedowell Feb 15, 2023
6dafd29
Too much 'Any'.
jaycedowell Feb 15, 2023
2a147c5
Copy and paste.
jaycedowell Feb 15, 2023
fd427f4
Type hinting round 2.
jaycedowell Feb 15, 2023
a8822a9
Update for type hints module.
jaycedowell Feb 15, 2023
4c9ff5d
No long in Py3.
jaycedowell Feb 15, 2023
009bbd7
Another import fix.
jaycedowell Feb 16, 2023
3aa91cc
Typo.
jaycedowell Feb 16, 2023
c41af72
Drop Any from args and kwargs.
jaycedowell Feb 16, 2023
0dd12ce
Actual fixes.
jaycedowell Feb 16, 2023
0d1f8d2
Merge branch 'master' into no_python2
league Jul 20, 2023
ef644d3
Removed commented out code in ring.py
jaycedowell Apr 22, 2022
8cdc0c7
Remove dtype in favor of DataType
league Jul 21, 2023
6faac95
Oops, somehow this didn't make it into last commit
league Jul 21, 2023
8cff5c2
Switch to `Run(exit=False)` for #214.
jaycedowell Jul 21, 2023
26637e2
`.data` is 2D so try `.data[0,0]` for #214.
jaycedowell Jul 21, 2023
f25ee95
Another str -> bytes-related Py2 catch.
jaycedowell Jul 21, 2023
30a1aa6
Date fix.
jaycedowell Aug 25, 2023
b5f503a
Require Python 3.6+.
jaycedowell Aug 25, 2023
7902717
Merge branch 'master' into no_python2
jaycedowell Aug 25, 2023
a8dbc15
More f strings.
jaycedowell Aug 25, 2023
848a8d0
Preserve spacing.
jaycedowell Aug 25, 2023
808422d
A few more f strings.
jaycedowell Aug 25, 2023
e01355f
Add a Python version check to configure as well.
jaycedowell Aug 25, 2023
82cd448
a or b can by None.
jaycedowell Aug 25, 2023
523c8a4
Reorder imports.
jaycedowell Aug 25, 2023
5c4bdb1
Drop encoding line.
jaycedowell Aug 25, 2023
1231369
Ugh.
jaycedowell Aug 25, 2023
ff06f45
Only check for ctypesgen if we have an allowed Python version.
jaycedowell Aug 28, 2023
f5b0b02
Drop shell=True.
jaycedowell Aug 28, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ doc
version.py
/python/bifrost/version/__init__.py
*_generated.py
*_typehints.py
.log*.txt
test/data/
*.bin
Expand Down
14 changes: 13 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -22310,7 +22310,19 @@ fi
fi
if test x${PYTHON} != xno
then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $PYTHON as ctypesgen" >&5
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $PYTHON is version 3.6 or later" >&5
printf %s "checking if $PYTHON is version 3.6 or later... " >&6; }
if ! ${PYTHON} -c "import sys; assert(sys.version_info >= (3,6,0))" 2>/dev/null
then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: python module will not be built" >&5
printf "%s\n" "$as_me: WARNING: python module will not be built" >&2;}
else $as_nop
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $PYTHON as ctypesgen" >&5
printf %s "checking whether $PYTHON as ctypesgen... " >&6; }
if ! ${PYTHON} -c "import ctypesgen" 2>/dev/null
then :
Expand Down
7 changes: 6 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ AS_IF([test x$enable_python != xno],
AS_IF([test x${PYTHON3} != xno],
[AC_SUBST([PYTHON], [$PYTHON3])])])
AS_IF([test x${PYTHON} != xno],
[AC_MSG_CHECKING([whether $PYTHON as ctypesgen])
[AC_MSG_CHECKING([if $PYTHON is version 3.6 or later])
AS_IF([! ${PYTHON} -c "import sys; assert(sys.version_info >= (3,6,0))" 2>/dev/null],
[AC_MSG_RESULT([no])
AC_MSG_WARN([python module will not be built])],
[AC_MSG_RESULT([yes])])
AC_MSG_CHECKING([whether $PYTHON as ctypesgen])
jaycedowell marked this conversation as resolved.
Show resolved Hide resolved
AS_IF([! ${PYTHON} -c "import ctypesgen" 2>/dev/null],
[AC_MSG_RESULT([no])
AC_MSG_WARN([python module will not be built])],
Expand Down
6 changes: 6 additions & 0 deletions python/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ define run_ctypesgen
@SED@ -i.orig -e '/errcheck = ReturnString/s/^/#/' $@
endef

define run_typehinting
# Build the libbifrost typing hinting
@PYTHON@ -c 'from typehinting import build_typehinting; build_typehinting("$@")'
endef

ifeq "$(wildcard $(PSRDADA_HEADERS))" ""
PSRDADA_PYTHON_BINDINGS_FILE =
endif
Expand All @@ -46,6 +51,7 @@ $(PSRDADA_PYTHON_BINDINGS_FILE): $(PSRDADA_HEADERS)

$(BIFROST_PYTHON_BINDINGS_FILE): $(INC_DIR)/bifrost/*.h
$(call run_ctypesgen,$(BIFROST_NAME),$(INC_DIR))
$(call run_typehinting,$(BIFROST_NAME),$(INC_DIR))

build: bifrost/*.py Makefile $(BIFROST_PYTHON_VERSION_FILE) $(BIFROST_PYTHON_BINDINGS_FILE) $(PSRDADA_PYTHON_BINDINGS_FILE)
@PYTHON@ setup.py build @PYBUILDFLAGS@
Expand Down
66 changes: 30 additions & 36 deletions python/bifrost/DataType.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Copyright (c) 2016-2020, The Bifrost Authors. All rights reserved.
# Copyright (c) 2016-2023, The Bifrost Authors. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -38,18 +38,12 @@
cf32: 32+32-bit complex floating point
"""

# Python2 compatibility
from __future__ import division, absolute_import
import sys
string_types = (str,)
if sys.version_info < (3,):
range = xrange
string_types = (basestring,)

from bifrost.libbifrost import _bf
from bifrost.libbifrost import _bf, _th
from bifrost.libbifrost_generated import BF_FLOAT128_ENABLED
import numpy as np

from typing import Optional, Union

from bifrost import telemetry
telemetry.track_module()

Expand Down Expand Up @@ -114,7 +108,7 @@
NUMPY_TYPEMAP['f'][128] = np.float128
NUMPY_TYPEMAP['cf'][128] = np.complex256

def is_vector_structure(dtype):
def is_vector_structure(dtype: np.dtype) -> bool:
if dtype.names is None:
return False
ndim = len(dtype.names)
Expand All @@ -125,17 +119,17 @@ def is_vector_structure(dtype):

class DataType(object):
# Note: Default of None results in default Numpy type (np.float)
def __init__(self, t=None):
if isinstance(t, string_types):
def __init__(self, t: Optional[Union[str,_th.BFdtype_enum,_bf.BFdtype,"DataType",np.dtype]]=None):
if isinstance(t, str):
for i, char in enumerate(t):
if char.isdigit():
break
self._kind = t[:i]
self._nbit = int(t[i:])
self._veclen = 1 # TODO: Consider supporting this as part of string
elif isinstance(t, _bf.BFdtype): # Note: This is actually just a c_int
t = int(t)
self._nbit = t & BF_DTYPE_NBIT_BITS
elif isinstance(t, (_th.BFdtype_enum, _bf.BFdtype)): # Note: This is actually just a c_int
t = _th.BFdtype_enum(t).value
self._nbit = t & _bf.BF_DTYPE_NBIT_BITS
is_complex = bool(t & _bf.BF_DTYPE_COMPLEX_BIT)
self._kind = KINDMAP[t & _bf.BF_DTYPE_TYPE_BITS]
if is_complex:
Expand All @@ -157,10 +151,10 @@ def __init__(self, t=None):
self._veclen = t.shape[0]
t = t.base
else:
raise TypeError("Unsupported Numpy dtype: " + str(t))
raise TypeError(f"Unsupported Numpy dtype: {t}")
self._nbit = t.itemsize * 8
if t.kind not in set(['i', 'u', 'f', 'c', 'V', 'b']):
raise TypeError('Unsupported data type: %s' % str(t))
raise TypeError(f"Unsupported data type: {t}")
if is_vector_structure(t): # Field structure representing vector
self._veclen = len(t.names)
t = t[0]
Expand All @@ -175,7 +169,7 @@ def __init__(self, t=None):
elif t in [cf16]:
self._kind = 'cf'
else:
raise TypeError('Unsupported data type: %s' % str(t))
raise TypeError(f"Unsupported data type: {t}")
elif t.kind == 'b':
# Note: Represents booleans as uint8 inside Bifrost
self._kind = 'u'
Expand All @@ -185,10 +179,10 @@ def __eq__(self, other):
self._veclen == other._veclen)
def __ne__(self, other):
return not (self == other)
def as_BFdtype(self):
def as_BFdtype(self) -> _bf.BFdtype:
base = TYPEMAP[self._kind][self._nbit]
return base | ((self._veclen - 1) << _bf.BF_DTYPE_VECTOR_BIT0)
def as_numpy_dtype(self):
def as_numpy_dtype(self) -> np.dtype:
base = np.dtype(NUMPY_TYPEMAP[self._kind][self._nbit])
if self._veclen == 1:
return base
Expand All @@ -201,25 +195,25 @@ def as_numpy_dtype(self):
return np.dtype(','.join((str(base),)*self._veclen))
def __str__(self):
if self._veclen == 1:
return '%s%i' % (self._kind, self._nbit)
return f"{self._kind}{self._nbit}"
else:
return '%s%i[%i]' % (self._kind, self._nbit, self._veclen)
return f"{self._kind}{self._nbit}[{self._veclen}]"
@property
def is_complex(self):
def is_complex(self) -> bool:
return self._kind[0] == 'c'
@property
def is_real(self):
def is_real(self) -> bool:
return not self.is_complex
@property
def is_signed(self):
def is_signed(self) -> bool:
return 'i' in self._kind or 'f' in self._kind
@property
def is_floating_point(self):
def is_floating_point(self) -> bool:
return 'f' in self._kind
@property
def is_integer(self):
def is_integer(self) -> bool:
return 'i' in self._kind or 'u' in self._kind
def as_floating_point(self):
def as_floating_point(self) -> "DataType":
"""Returns the smallest floating-point type that can represent all
values that self can.
"""
Expand All @@ -228,32 +222,32 @@ def as_floating_point(self):
kind = 'cf' if self.is_complex else 'f'
nbit = 32 if self._nbit <= 24 else 64
return DataType((kind, nbit, self._veclen))
def as_integer(self, nbit=None):
def as_integer(self, nbit: int=None) -> "DataType":
if nbit is None:
nbit = self._nbit
kind = self._kind
if self.is_floating_point:
kind = kind.replace('f', 'i')
return DataType((kind, nbit, self._veclen))
def as_real(self):
def as_real(self) -> "DataType":
if self.is_complex:
return DataType((self._kind[1:], self._nbit, self._veclen))
else:
return self
def as_complex(self):
def as_complex(self) -> "DataType":
if self.is_complex:
return self
else:
return DataType(('c' + self._kind, self._nbit, self._veclen))
def as_nbit(self, nbit):
def as_nbit(self, nbit: int) -> "DataType":
return DataType((self._kind, nbit, self._veclen))
def as_vector(self, veclen):
def as_vector(self, veclen: int) -> "DataType":
return DataType((self._kind, self._nbit, veclen))
@property
def itemsize_bits(self):
def itemsize_bits(self) -> int:
return self._nbit * (1 + self.is_complex) * self._veclen
@property
def itemsize(self):
def itemsize(self) -> int:
item_nbit = self.itemsize_bits
if item_nbit < 8:
raise ValueError('itemsize is undefined when nbit < 8')
Expand Down
122 changes: 0 additions & 122 deletions python/bifrost/GPUArray.py

This file was deleted.

Loading