-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
int is not a Number? #3186
Comments
(Talking about numbers.Number, naturally) |
Thank you for reporting this! It looks like this is mostly a typeshed issue. Structursl subtyping (see PR #3132) will help, but it looks like still some changes will be necessary in typeshed, since we can't declare @JelleZijlstra what do you think? |
Not sure we need to keep this open, if it can be fixed in typeshed once protocols land. (Maybe there should be an omnibus issue for things we can change once it lands?) Also see PEP 484, which has this to say:
|
I am not too familiar with the numeric tower, but maybe we should just go with PEP 484's recommendation and avoid the numbers ABCs.
What are concrete use cases where one would use the numbers ABCs instead of int/float/complex? Maybe numpy numeric types? |
It's come up a few times before, the only places I found that were using it were just trying to be hyper-correct. E.g. numpy supports it but barely mentions it in its docs. [Warning: Luddite mode on] |
I'm not sure if the other ABCs beyond However, I don't believe that the numeric tower is going to be very useful for type checking. The current types seem to be good enough for the vast majority of use cases, and just providing another set of types for essentially the same purpose seems like unnecessary complexity. In my opinion, a much more promising (and somewhat related) project would be figuring out how to type check code using numpy. |
I agree this looks very interesting. This would require some simple dependent types, since fixed size arrays/matrices are everywhere in mypy. The rules for those are non-trivial, e.g. |
It would be really cool at least to document it a bit more clearly than the PEP 484 quote, which I read as
when it appears that the real situation is
I (quite reasonably?) thought that
type declaration. Are there other places where this is not the case? |
(or even just a warning in mypy if one of the |
Just noting that I seem to have a use-case affected by this; I'm adding annotations for use w/ def foo(lat, lng):
# type: (?, ?) -> None I started with (I agree with tjltjl's reasoning that if the specification is |
|
@ilevkivskyi, has that PR landed? Because I have just encountered the same problem with Mypy 0.590: def bug(n: Real = 1) -> Real:
return n + 1
# error: Incompatible default for argument "n" (default has type "int", argument has type "Real") Motivating example is HypothesisWorks/hypothesis#200; we have several test strategies for some type of number within a range, and the bounding values can be specified as int/float/fraction - so it would be really nice to show |
Yes, but those types are still not labeled as protocols. I personally don't see any harm in labelling them as protocols. Note that the |
One consideration around the numeric tower is that when a function returns numpy.float, it would be nice to mark it as returning numbers.Real, since (1) I don't want to force people to fix type annotations because they happened to return a float in the future |
Raised priority to high since this is constantly coming. |
What solution do you propose? |
One possible option is to add a bit of lie to typeshed, see python/typeshed#3108. |
Another option is to reject the use of |
This would be a bit sad, especially taking into account this is a 12-th most liked issue on the tracker. TBH I forgot the details of the discussion, but if the typeshed attempt will work out are there any reasons not to do this? |
I'm wondering if the types will be useful for their intended purpose. If not, the effort may be wasted. |
As far as I can tell trunc works with SymPy: >>> import sympy
>>> e = sympy.sqrt(2)
>>> e
sqrt(2)
>>> import math
>>> math.trunc(e)
1 Please open a SymPy issue if I've misunderstood (the thread here is long enough that it doesn't need any further discussion on this point). |
If I may add the discussion. 1. Solution ProtocolsAs already stated, using Number as a protocol doesn't really make sense right now, because it doesn't tell you what a Number should be doing (it doesn't have any members). One solution would be to change that and add some common functions like
class MutableFloat:
value: float
def __init__(self, value):
self.set(value)
def set(self, value):
self.value = float(value)
forbidden = {
"__new__", "__init__", "__getattribute__", "__getattr__", "__setattr__", "__delattr__",
"__dir__", "__class__", "__init_subclass__", "__subclasshook__"
}
for name in float().__dir__():
if name in forbidden or not name.startswith("__"): continue
func = getattr(float, name)
if not callable(func): continue
change = "if type(x) is float: self.value=x" if name.startswith("__i") and name != "__int__" else ""
s = f"""
def {name}(self, *args, **kwargs):
args = [arg.value if type(arg) is MutableFloat else arg for arg in args]
x = float.{name}(self.value, *args, **kwargs)
{change}
return x
""".strip()
exec(s) It isn't beautiful, but it works (I haven't tested it completely) and there are actual use cases. It's basically a float proxy, so it is a Number, but the type checker wouldn't know because I didn't want to write down all the possible methods and used the power of python to make my life easier. This is probably a bad example, but what I am trying to bring close to you is that there needs to be a way to distinguish a number, not only with a protocol. I think the real problem is that in the documentation it says that all numbers inherit from Number, which is wrong. So I suggest we should fix that.
The above implication not holding true is IMO not acceptable for a proper language. And I feel like there is not enough will to solve this issue if this is already 5 years old. I know this sounds harsh, but I just want to express how absurd this is.
I would love this question to be answered. 2. Solution: User defines what numbers mean to themSeveral comments noted that what a number really is depends on the person and the use case. Should a Vector (complex numbers are basically just 2-Vectors) be a number? Can floats be considered real? In conclusion, we could just say everyone defines for themselves what a number is. This could also just be temporary solution Here, I want to show a simple solution for most projects:
Number = int, float, Decimal # and whatever else you like
NumberType = int | float | Decimal # I know it feels weird to write the same thing twice just with different delimiters, but this might just be the life of a python developer for some time.
# 3. Now you can import Number and NumberType in another file and use them together
def test_Numbers(x: None|NumberType)->NumberType:
if isinstance(x, Number):
reveal_type(x)
y: NumberType = x
else:
y = 0
return y To make this process easier, Python could support two canonical function that convert a Union into a tuple, and the reverse and are understood by type checkers. Another similar possibility would be allowing Union types as parameter for Note: The revealed type of 3. Solution: Special case in type checkingThe comment above actually shows us how to do it. Just like 4. Solution: Nominal SubtypingThe easiest and maybe just the best way to do it is good old nominal subtyping. Just like before, it is decided on a case to case basis what a number is. However, not by the end user, but by the library makers (The Python language just gives guidelines on what a Making theory and practice coherent again would mean to make SummaryHotfix
Additional Notes to PrototypingWhat shouldn't happen is that we get types like # I define this here.
style_mapping = Mapping[str, Style] # Style could be anything
# somewhere totally different
d1: style_mapping = {
"example": Style()
}
# somewhere different again, maybe in a function
d2: style_mapping = {
"example": Style()
}
d3 = ChainMap(d1, d2)
# error because ChainMap wants to have a MutableMapping I will never edit anything in this I would really love some feedback on these ideas. I can also take some hits 😁. |
@theRealProHacker It's also been pointed out in a few places that the number 3 solution here: #2922 (comment) would solve the Numbers problem. This would require no special cases. You would just register the appropriate numerical types and they would work.
I feel like the reason people want to use protocols is because protocols get around the registration problem. The protocol is automatically bound as a parent class. But the issue is that protocols are really inferior to explicit registration. You'd have to be so careful when designing your class to match the protocol, and the protocol could never change or else everyone counting on the automatic registration would suddenly find that their numerical class isn't a number anymore. It's a bad solution.
This is what I do now, but it's not a good solution compared with just fixing the registration.
Would be fine as a hotfix. I still think the registration fix would be the best long term solution.
I don't think that's necessary (or even desirable). Registration is just as good as inheritance. |
I agree that ABCMeta.register() support #2922 is a better solution than the one I used, and I had assumed that at some point in the future it would be the fix that actually resolved this issue. I just couldn't figure out how to make that change myself. If I've correctly understood the solutions proposed in that issue, approach three would provide a practically workable solution without introducing performance problems or creating complex multi-pass algorithms. Such an approach would be required to support my other extensions to Numbers (see cfcohen@eee71ca). As for the comment on sympy, it wasn't meant to be a bug report -- it was just an example of the most recent problem that mypy had helped me find. While math.trunc() works for number-like values, it doesn't work for symbols, producing |
I experimented a bit and tried to build a plugin as a hotfix. I would suggest that either this or 09d8367 should be used as a hotfix. Additionally, I would still suggest that if someone uses anything from
I think that would be a huge and simple improvement right now. 😁 from mypy.plugin import Plugin as _Plugin, ClassDefContext, TypeInfo
import numbers
from numbers import __all__
from decimal import Decimal
import os
tdata: dict[str, tuple[type, int]] = {
f"numbers.{cls}":(getattr(numbers, cls), -1-i) for i,cls in enumerate(__all__)
}
bdata: dict[str, type] = { # these are all the builtin numbers I am aware of
"builtins.int": int,
"builtins.float": float,
"builtins.complex": complex,
"_decimal.Decimal": Decimal
}
bstore: dict[str, TypeInfo] = {}
tstore: dict[str, TypeInfo] = {}
_key = "number-plugin-done"
def is_done(info: TypeInfo):
rv = _key in info.metadata
info.metadata[_key] = {}
return rv
abspath = os.path.abspath(__file__)
prep = "import sys\n"
class Plugin(_Plugin):
refreshed = False
def get_customize_class_mro_hook(self, name: str):
# refreshing to trick mypys caching. That however leads to inefficiency.
# So this should be integrated into mypy in such a way that it runs every
# time without forcing everything else to restart
if not self.refreshed:
self.refreshed = True
with open(abspath) as file:
s = file.read()
with open(abspath, "w") as file:
file.write(s.removeprefix(prep) if s.startswith(prep) \
else prep + s)
# handling Numbers
if name.startswith("numbers."):
tcls, index = tdata[name]
def tinner(ctx: ClassDefContext):
tinfo = ctx.cls.info
if is_done(tinfo): return
tstore[name] = tinfo
for bname, binfo in bstore.items():
if not issubclass(bdata[bname], tcls): break
binfo.mro.insert(index, tinfo)
return tinner
# handling numbers
if not name in bdata: return
def binner(ctx: ClassDefContext):
binfo = ctx.cls.info
if is_done(binfo): return
bstore[name] = binfo
bcls = bdata[name]
for tname, tinfo in tstore.items():
tcls, index = tdata[tname]
if not issubclass(bcls, tcls): continue
binfo.mro.insert(index, tinfo)
return binner
def plugin(version: str):
# TODO:
# if version >= fix_version: return _Plugin
return Plugin Additionally, a small test file that should run without errors. from numbers import Number, Complex
from decimal import Decimal
class OwnNumber(int): pass
x: Number = 0
y: list[Number] = [
1, 1.0, 1+0j, Decimal(1.0), OwnNumber(1.0)
]
def main(x: Number|str)->str:
if isinstance(x,Number):
return str(x).replace(".",",")
else:
return x.strip()
def add_numbers(x: Number, y: Number):
# theoretically numbers have no attributes you can rely on but practically
# we know that they will probably be interoperable with other numbers
# this ignore is required because of the theoretic aspect.
# We need to settle on one thing that all numbers should have in common.
# I would suggest that they must have a possibility to convert to a `complex`, `float` *or* `int`
# and thats it. Everything else is optional because it can be deduced.
return x + y # type: ignore
def add_numbers_(x: Complex, y: Complex)->Complex:
# this works although the revealed type of x+y is Any
# here I would suggest that type.__add__(anything) should always return type
# for example adding a Complex to a Real should result in a Complex
return x+y |
As the original reporter of the bug, I wholeheartedly agree on the suggestion "if anyone uses anything from numbers, ...". This would have fixed the original problem right away. |
* Real and mypy don't play nice python/mypy#3186 * This allows partial typing support of HOSVD
* HOSVD: Preliminary outline of core functionality * HOSVD: Fix numeric bug * Was slicing incorrectly * Update test to check convergence * HOSVD: Finish output and test coverage * TENSOR: Prune numbers real * Real and mypy don't play nice python/mypy#3186 * This allows partial typing support of HOSVD
As of #15137, mypy will now issue a much more helpful diagnostic when this comes up. There is no plan to make naive use of numbers.Number type check:
If you have a use case, I recommend using your own Protocol to describe exactly what behaviour you expect. If for some reason a Protocol cannot do what you want it to do, please open an issue at https://github.com/python/typing If you're interested in designing some future of interoperability of numeric types or discussing the future of the Since there are no clear action items for mypy that don't have better more specific issues tracking them, I'm going to take the bold step of closing this issue. This is a long issue with a lot of history. If you feel the need to post something, please read this thread through first. |
* Update nvecs to use tenmat. * Full implementation of collapse. Required implementation of tensor.from_tensor_type for tenmat objects. Updated tensor tests. (#32) * Update __init__.py Bump version. * Create CHANGELOG.md Changelog update * Update CHANGELOG.md Consistent formatting * Update CHANGELOG.md Correction * Create ci-tests.yml * Update README.md Adding coverage statistics from coveralls.io * Create requirements.txt * 33 use standard license (#34) * Use standard, correctly formatted LICENSE * Delete LICENSE * Create LICENSE * Update and rename ci-tests.yml to regression-tests.yml * Update README.md * Fix bug in tensor.mttkrp that only showed up when ndims > 3. (#36) * Update __init__.py Bump version * Bump version * Adding files to support pypi dist creation and uploading * Fix PyPi installs. Bump version. * Fixing np.reshape usage. Adding more tests for tensor.ttv. (#38) * Fixing issues with np.reshape; requires order='F' to align with Matlab functionality. (#39) Closes #30 . * Bump version. * Adding tensor.ttm. Adding use case in tenmat to support ttm testing. (#40) Closes #27 * Bump version * Format CHANGELOG * Update CHANGELOG.md * pypi puslishing action on release * Allowing rdims or cdims to be empty array. (#43) Closes #42 * Adding tensor.ttt implementation. (#44) Closes 28 * Bump version * Implement ktensor.score and associated tests. * Changes to supporting pyttb data classes and associated tests to enable ktensor.score. * Bump version. * Compatibility with numpy 1.24.x (#49) Close #48 * Replace "numpy.float" with equivalent "float" numpy.float was deprecated in 1.20 and removed in 1.24 * sptensor.ttv: support 'vector' being a plain list (rather than just numpy.ndarray). Backwards compatible - an ndarray argument still works. This is because in newer numpy, it's not allowed to do np.array(list) where the elements of list are ndarrays of different shapes. * Make ktensor.innerprod call ttv with 'vector' as plain list (instead of numpy.ndarray, because newer versions don't allow ragged arrays) * tensor.ttv: avoid ragged numpy arrays * Fix two unit test failures due to numpy related changes * More numpy updates - numpy.int is removed - use int instead - don't try to construct ragged/inhomogeneous numpy arrays in tests. Use plain lists of vectors instead * Fix typo in assert message * Let ttb.tt_dimscheck catch empty input error In the three ttv methods, ttb.tt_dimscheck checks that 'vector' argument is not an empty list/ndarray. Revert previous changes that checked for this before calling tt_dimscheck. * Bump version * TENSOR: Fix slices ref shen return value isn't scalar or vector. #41 (#50) Closes #41 * Ttensor implementation (#51) * TENSOR: Fix slices ref shen return value isn't scalar or vector. #41 * TTENSOR: Add tensor creation (partial support of core tensor types) and display * SPTENSOR: Add numpy scalar type for multiplication filter. * TTENSOR: Double, full, isequal, mtimes, ndims, size, uminus, uplus, and partial innerprod. * TTENSOR: TTV (finishes innerprod), mttkrp, and norm * TTENSOR: TTM, permute and minor cleanup. * TTENSOR: Reconstruct * TTENSOR: Nvecs * SPTENSOR: * Fix argument mismatch for ttm (modes s.b. dims) * Fix ttm for rectangular matrices * Make error message consitent with tensor TENSOR: * Fix error message * TTENSOR: Improve test coverage and corresponding bug fixes discovered. * Test coverage (#52) * SPTENSOR: * Fix argument mismatch for ttm (modes s.b. dims) * Fix ttm for rectangular matrices * Make error message consitent with tensor TENSOR: * Fix error message * SPTENSOR: Improve test coverage, replace prints, and some doc string fixes. * PYTTUB_UTILS: Improve test coverage * TENMAT: Remove impossible condition. Shape is a property, the property handles the (0,) shape condition. So ndims should never see it. * TENSOR: Improve test coverage. One line left, but logic of setitem is unclear without MATLAB validation of behavior. * CP_APR: Add tests fpr sptensor, and corresponding bug fixes to improve test coverage. --------- Co-authored-by: Danny Dunlavy <[email protected]> * Bump version * TUCKER_ALS: Add tucker_als to validate ttucker implementation. (#53) * Bump version of actions (#55) actions/setup-python@v4 to avoid deprecation warnings * Tensor docs plus Linting and Typing and Black oh my (#54) * TENSOR: Apply black and enforce it * TENSOR: Add isort and pylint. Fix to pass then enforce * TENSOR: Variety of linked fixes: * Add mypy type checking * Update infrastructure for validating package * Fix doc tests and add more examples * DOCTEST: Add doctest automatically to regression * Fix existing failures * DOCTEST: Fix non-uniform array * DOCTEST: Fix precision errors in example * AUTOMATION: Add test directory otherwise only doctests run * TENSOR: Fix bad rebase from numpy fix * Auto formatting (#60) * COVERAGE: Fix some coverage regressions from pylint PR * ISORT: Run isort on source and tests * BLACK: Run black on source and tests * BLACK: Run black on source and tests * FORMATTING: Add tests and verification for autoformatting * FORMATTING: Add black/isort to root to simplify * Add preliminary contributor guide instructions Closes #59 * TUCKER_ALS: TTM with negative values is broken in ttensor (#62) (#66) * Replace usage in tucker_als * Update test for tucker_als to ensure result matches expectation * Add early error handling in ttensor ttm for negative dims * Hosvd (#67) * HOSVD: Preliminary outline of core functionality * HOSVD: Fix numeric bug * Was slicing incorrectly * Update test to check convergence * HOSVD: Finish output and test coverage * TENSOR: Prune numbers real * Real and mypy don't play nice python/mypy#3186 * This allows partial typing support of HOSVD * Add test that matches TTB for MATLAB output of HOSVD (#79) This closes #78 * Bump version (#81) Closes #80 * Lint pyttb_utils and lint/type sptensor (#77) * PYTTB_UTILS: Fix and enforce pylint * PYTTB_UTILS: Pull out utility only used internally in sptensor * SPTENSOR: Fix and enforce pylint * SPTENSOR: Initial pass a typing support * SPTENSOR: Complete initial typing coverage * SPTENSOR: Fix test coverage from typing changes. * PYLINT: Update test to lint files in parallel to improve dev experience. * HOSVD: Negative signs can be permuted for equivalent decomposition (#82) * Pre commit (#83) * Setup and pyproject are redundant. Remove and resolve install issue * Try adding pre-commit hooks * Update Makefile for simplicity and add notes to contributor guide. * Make pre-commit optional opt-in * Make regression tests use simplified dependencies so we track fewer places. * Using dynamic version in pyproject.toml to reduce places where version is set. (#86) * Adding shell=True to subprocess.run() calls (#87) * Adding Nick to authors (#89) * Release prep (#90) * Fix author for PyPI. Bump to dev version. * Exclude dims (#91) * Explicit Exclude_dims: * Updated tt_dimscheck * Update all uses of tt_dimscheck and propagate interface * Add test coverage for exclude dims changes * Tucker_als: Fix workaround that motivated exclude_dims * Bump version * Spelling * Tensor generator helpers (#93) * TENONES: Add initial tenones support * TENZEROS: Add initial tenzeros support * TENDIAG: Add initial tendiag support * SPTENDIAG: Add initial sptendiag support * Link in autodocumentation for recently added code: (#98) * TTENSOR, HOSVD, TUCKER_ALS, Tensor generators * Remove warning for nvecs: (#99) * Make debug level log for now * Remove test enforcement * Rand generators (#100) * Non-functional change: * Fix numpy deprecation warning, logic should be equivalent * Tenrand initial implementation * Sptenrand initial implementation * Complete pass on ktensor docs. (#101) * Bump version * Bump version * Trying to fix coveralls * Trying coveralls github action * Fixing arrange and normalize. (#103) * Fixing arrange and normalize. * Merge main (#104) * Trying to fix coveralls * Trying coveralls github action * Rename contributor guide for github magic (#106) * Rename contributor guide for github magic * Update reference to contributor guide from README * Fixed the mean and stdev typo for cp_als (#117) * Changed cp_als() param 'tensor' to 'input_tensor' to avoid ambiguity (#118) * Changed cp_als() param 'tensor' to 'input_tensor' to avoid ambiguity * Formatted changes with isort and black. * Updated all `tensor`-named paramteres to `input_tensor`, including in docs (#120) * Tensor growth (#109) * Tensor.__setitem__: Break into methods * Non-functional change to make logic flow clearer * Tensor.__setitem__: Fix some types to resolve edge cases * Sptensor.__setitem__: Break into methods * Non-functional change to make flow clearer * Sptensor.__setitem__: Catch additional edge cases in sptensor indexing * Tensor.__setitem__: Catch subtensor additional dim growth * Tensor indexing (#116) * Tensor.__setitem__/__getitem__: Fix linear index * Before required numpy array now works on value/slice/Iterable * Tensor.__getitem__: Fix subscripts usage * Consistent with setitem now * Update usages (primarily in sptensor) * Sptensor.__setitem__/__getitem__: Fix subscripts usage * Consistent with tensor and MATLAB now * Update test usage * sptensor: Add coverage for improved indexing capability * tensor: Add coverage for improved indexing capability --------- Co-authored-by: brian-kelley <[email protected]> Co-authored-by: ntjohnson1 <[email protected]> Co-authored-by: Dunlavy <[email protected]> Co-authored-by: DeepBlockDeepak <[email protected]>
* Merge latest updates (#124) * Update nvecs to use tenmat. * Full implementation of collapse. Required implementation of tensor.from_tensor_type for tenmat objects. Updated tensor tests. (#32) * Update __init__.py Bump version. * Create CHANGELOG.md Changelog update * Update CHANGELOG.md Consistent formatting * Update CHANGELOG.md Correction * Create ci-tests.yml * Update README.md Adding coverage statistics from coveralls.io * Create requirements.txt * 33 use standard license (#34) * Use standard, correctly formatted LICENSE * Delete LICENSE * Create LICENSE * Update and rename ci-tests.yml to regression-tests.yml * Update README.md * Fix bug in tensor.mttkrp that only showed up when ndims > 3. (#36) * Update __init__.py Bump version * Bump version * Adding files to support pypi dist creation and uploading * Fix PyPi installs. Bump version. * Fixing np.reshape usage. Adding more tests for tensor.ttv. (#38) * Fixing issues with np.reshape; requires order='F' to align with Matlab functionality. (#39) Closes #30 . * Bump version. * Adding tensor.ttm. Adding use case in tenmat to support ttm testing. (#40) Closes #27 * Bump version * Format CHANGELOG * Update CHANGELOG.md * pypi puslishing action on release * Allowing rdims or cdims to be empty array. (#43) Closes #42 * Adding tensor.ttt implementation. (#44) Closes 28 * Bump version * Implement ktensor.score and associated tests. * Changes to supporting pyttb data classes and associated tests to enable ktensor.score. * Bump version. * Compatibility with numpy 1.24.x (#49) Close #48 * Replace "numpy.float" with equivalent "float" numpy.float was deprecated in 1.20 and removed in 1.24 * sptensor.ttv: support 'vector' being a plain list (rather than just numpy.ndarray). Backwards compatible - an ndarray argument still works. This is because in newer numpy, it's not allowed to do np.array(list) where the elements of list are ndarrays of different shapes. * Make ktensor.innerprod call ttv with 'vector' as plain list (instead of numpy.ndarray, because newer versions don't allow ragged arrays) * tensor.ttv: avoid ragged numpy arrays * Fix two unit test failures due to numpy related changes * More numpy updates - numpy.int is removed - use int instead - don't try to construct ragged/inhomogeneous numpy arrays in tests. Use plain lists of vectors instead * Fix typo in assert message * Let ttb.tt_dimscheck catch empty input error In the three ttv methods, ttb.tt_dimscheck checks that 'vector' argument is not an empty list/ndarray. Revert previous changes that checked for this before calling tt_dimscheck. * Bump version * TENSOR: Fix slices ref shen return value isn't scalar or vector. #41 (#50) Closes #41 * Ttensor implementation (#51) * TENSOR: Fix slices ref shen return value isn't scalar or vector. #41 * TTENSOR: Add tensor creation (partial support of core tensor types) and display * SPTENSOR: Add numpy scalar type for multiplication filter. * TTENSOR: Double, full, isequal, mtimes, ndims, size, uminus, uplus, and partial innerprod. * TTENSOR: TTV (finishes innerprod), mttkrp, and norm * TTENSOR: TTM, permute and minor cleanup. * TTENSOR: Reconstruct * TTENSOR: Nvecs * SPTENSOR: * Fix argument mismatch for ttm (modes s.b. dims) * Fix ttm for rectangular matrices * Make error message consitent with tensor TENSOR: * Fix error message * TTENSOR: Improve test coverage and corresponding bug fixes discovered. * Test coverage (#52) * SPTENSOR: * Fix argument mismatch for ttm (modes s.b. dims) * Fix ttm for rectangular matrices * Make error message consitent with tensor TENSOR: * Fix error message * SPTENSOR: Improve test coverage, replace prints, and some doc string fixes. * PYTTUB_UTILS: Improve test coverage * TENMAT: Remove impossible condition. Shape is a property, the property handles the (0,) shape condition. So ndims should never see it. * TENSOR: Improve test coverage. One line left, but logic of setitem is unclear without MATLAB validation of behavior. * CP_APR: Add tests fpr sptensor, and corresponding bug fixes to improve test coverage. --------- Co-authored-by: Danny Dunlavy <[email protected]> * Bump version * TUCKER_ALS: Add tucker_als to validate ttucker implementation. (#53) * Bump version of actions (#55) actions/setup-python@v4 to avoid deprecation warnings * Tensor docs plus Linting and Typing and Black oh my (#54) * TENSOR: Apply black and enforce it * TENSOR: Add isort and pylint. Fix to pass then enforce * TENSOR: Variety of linked fixes: * Add mypy type checking * Update infrastructure for validating package * Fix doc tests and add more examples * DOCTEST: Add doctest automatically to regression * Fix existing failures * DOCTEST: Fix non-uniform array * DOCTEST: Fix precision errors in example * AUTOMATION: Add test directory otherwise only doctests run * TENSOR: Fix bad rebase from numpy fix * Auto formatting (#60) * COVERAGE: Fix some coverage regressions from pylint PR * ISORT: Run isort on source and tests * BLACK: Run black on source and tests * BLACK: Run black on source and tests * FORMATTING: Add tests and verification for autoformatting * FORMATTING: Add black/isort to root to simplify * Add preliminary contributor guide instructions Closes #59 * TUCKER_ALS: TTM with negative values is broken in ttensor (#62) (#66) * Replace usage in tucker_als * Update test for tucker_als to ensure result matches expectation * Add early error handling in ttensor ttm for negative dims * Hosvd (#67) * HOSVD: Preliminary outline of core functionality * HOSVD: Fix numeric bug * Was slicing incorrectly * Update test to check convergence * HOSVD: Finish output and test coverage * TENSOR: Prune numbers real * Real and mypy don't play nice python/mypy#3186 * This allows partial typing support of HOSVD * Add test that matches TTB for MATLAB output of HOSVD (#79) This closes #78 * Bump version (#81) Closes #80 * Lint pyttb_utils and lint/type sptensor (#77) * PYTTB_UTILS: Fix and enforce pylint * PYTTB_UTILS: Pull out utility only used internally in sptensor * SPTENSOR: Fix and enforce pylint * SPTENSOR: Initial pass a typing support * SPTENSOR: Complete initial typing coverage * SPTENSOR: Fix test coverage from typing changes. * PYLINT: Update test to lint files in parallel to improve dev experience. * HOSVD: Negative signs can be permuted for equivalent decomposition (#82) * Pre commit (#83) * Setup and pyproject are redundant. Remove and resolve install issue * Try adding pre-commit hooks * Update Makefile for simplicity and add notes to contributor guide. * Make pre-commit optional opt-in * Make regression tests use simplified dependencies so we track fewer places. * Using dynamic version in pyproject.toml to reduce places where version is set. (#86) * Adding shell=True to subprocess.run() calls (#87) * Adding Nick to authors (#89) * Release prep (#90) * Fix author for PyPI. Bump to dev version. * Exclude dims (#91) * Explicit Exclude_dims: * Updated tt_dimscheck * Update all uses of tt_dimscheck and propagate interface * Add test coverage for exclude dims changes * Tucker_als: Fix workaround that motivated exclude_dims * Bump version * Spelling * Tensor generator helpers (#93) * TENONES: Add initial tenones support * TENZEROS: Add initial tenzeros support * TENDIAG: Add initial tendiag support * SPTENDIAG: Add initial sptendiag support * Link in autodocumentation for recently added code: (#98) * TTENSOR, HOSVD, TUCKER_ALS, Tensor generators * Remove warning for nvecs: (#99) * Make debug level log for now * Remove test enforcement * Rand generators (#100) * Non-functional change: * Fix numpy deprecation warning, logic should be equivalent * Tenrand initial implementation * Sptenrand initial implementation * Complete pass on ktensor docs. (#101) * Bump version * Bump version * Trying to fix coveralls * Trying coveralls github action * Fixing arrange and normalize. (#103) * Fixing arrange and normalize. * Merge main (#104) * Trying to fix coveralls * Trying coveralls github action * Rename contributor guide for github magic (#106) * Rename contributor guide for github magic * Update reference to contributor guide from README * Fixed the mean and stdev typo for cp_als (#117) * Changed cp_als() param 'tensor' to 'input_tensor' to avoid ambiguity (#118) * Changed cp_als() param 'tensor' to 'input_tensor' to avoid ambiguity * Formatted changes with isort and black. * Updated all `tensor`-named paramteres to `input_tensor`, including in docs (#120) * Tensor growth (#109) * Tensor.__setitem__: Break into methods * Non-functional change to make logic flow clearer * Tensor.__setitem__: Fix some types to resolve edge cases * Sptensor.__setitem__: Break into methods * Non-functional change to make flow clearer * Sptensor.__setitem__: Catch additional edge cases in sptensor indexing * Tensor.__setitem__: Catch subtensor additional dim growth * Tensor indexing (#116) * Tensor.__setitem__/__getitem__: Fix linear index * Before required numpy array now works on value/slice/Iterable * Tensor.__getitem__: Fix subscripts usage * Consistent with setitem now * Update usages (primarily in sptensor) * Sptensor.__setitem__/__getitem__: Fix subscripts usage * Consistent with tensor and MATLAB now * Update test usage * sptensor: Add coverage for improved indexing capability * tensor: Add coverage for improved indexing capability --------- Co-authored-by: brian-kelley <[email protected]> Co-authored-by: ntjohnson1 <[email protected]> Co-authored-by: Dunlavy <[email protected]> Co-authored-by: DeepBlockDeepak <[email protected]> * Adding tests and data for import_data, export_data, sptensor, ktensor. Small changes in code that was unreachable. * Updating formatting with black * More updates for coverage. * Black formatting updates * Update regression-tests.yml Adding verbose to black and isort calls * Black updated locally to align with CI testing * Update regression-tests.yml --------- Co-authored-by: brian-kelley <[email protected]> Co-authored-by: ntjohnson1 <[email protected]> Co-authored-by: Dunlavy <[email protected]> Co-authored-by: DeepBlockDeepak <[email protected]>
The Python standard library `numbers` module defines abstract base classes for different types of numbers, but those classes are not suitable for type checking (python/mypy#3186), so `astropy` should define these types itself.
The Python standard library `numbers` module defines abstract base classes for different types of numbers, but those classes are not suitable for type checking (python/mypy#3186), so `astropy` should define these types itself.
The Python standard library `numbers` module defines abstract base classes for different types of numbers, but those classes are not suitable for type checking (python/mypy#3186), so `astropy` should define these types itself.
n : Number = 5
produces
test_compiler.py:18: error: Incompatible types in assignment (expression has type "int", variable has type "Number")
Which it probably shouldn't because isinstance(n, Number) == True
The text was updated successfully, but these errors were encountered: