Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

BUG: ticket #2028: ... #356

Closed
wants to merge 5 commits into from

4 participants

@ericfode

When min_scalar was not checking to see if numbers could fit into unsigned long longs. This was fixed by adding an extra case to function to check if the passed number could fit into a unsigned long long if it could not fit into anything else. Additionaly, regression tests were added.

Cleaned up version of previous pull request

@travisbot

This pull request fails (merged 85104586 into 6a1ab03).

Eric Fode BUG: ticket #2028: When min_scalar was not checking to see if numbers…
… could fit into unsigned long longs. This was fixed by adding an extra case to function to check if the passed number could fit into a unsigned long long if it could not fit into anything else. Additionaly, regression tests were added.
6966bdc
@travisbot

This pull request passes (merged 6966bdc into 6a1ab03).

@charris
Owner

That didn't seem to work. What did you try?

@ericfode
numpy/core/src/multiarray/common.c
((9 lines not shown))
return PyArray_DescrFromType(NPY_OBJECT);
- }
- return PyArray_DescrFromType(NPY_LONGLONG);
+ } else {
+ return PyArray_DescrFromType(NPY_LONGLONG);
+ }
}
return NULL;
}
@teoliphant Owner

The indentation on this does not look quite right. Could you check alignment?

Otherwise, this seems like a useful patch.

@charris Owner
charris added a note

They're tabs instead of spaces. Eric, you need to fix your editor.

Also, else like so:

}
else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@travisbot

This pull request fails (merged 3d31029 into 6a1ab03).

@travisbot

This pull request passes (merged 681bceb into 6a1ab03).

numpy/core/src/multiarray/common.c
@@ -36,9 +36,17 @@
/* if integer can fit into a longlong then return that*/
if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {
PyErr_Clear();
+ if((PyLong_AsUnsignedLongLong(op) == -1) && PyErr_Occurred()){
@charris Owner
charris added a note

There are still hard tabs here, they have to be spaces. If you are using vim, :set list will show the tabs. I assume there is something similar in other editors.

Sorry to be so picky, but once you get a few commits right things will go much easier.

No don't worry about being picky it drives me crazy when people don't follow codding standards :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@travisbot

This pull request passes (merged 120c6bd into 6a1ab03).

numpy/core/src/multiarray/common.c
@@ -36,9 +36,17 @@
/* if integer can fit into a longlong then return that*/
if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {
PyErr_Clear();
+ if((PyLong_AsUnsignedLongLong(op) == -1) && PyErr_Occurred()){
@charris Owner
charris added a note

Getting close ;) These lines need an extra indent. Also, checking an unsigned integer for a negative value should raise a compile warning at minimum. I think the value checks need to be done away with in any case as the documentation doesn't indicate any special return value as a possible error code, but perhaps that is a defect of the documentation.

@charris Owner
charris added a note

OK, I checked the http://docs.python.org/c-api/long.html documentation and -1 indeed indicates a possible error, however the docs also show a cast for the unsigned types, i.e., (unsigned long long) -1.

I feel like i am missing what it is that makes these lines need more indents, can you explain?

@charris Owner
charris added a note

The second if is part the body of the first if.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@travisbot

This pull request passes (merged 78f6672 into 6a1ab03).

@charris
Owner

My bad. I think this should go

else if (PyLong_Check(op)) {
    /* if integer can fit into a longlong then return that*/
    if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {
        PyErr_Clear();
    }
    else {
        return PyArray_DescrFromType(NPY_LONGLONG);
    }

    if ((PyLong_AsUnsignedLongLong(op) == (unsigned long long) -1) &&
            PyErr_Occurred()) {
        PyErr_Clear();
    }
    else {
         return PyArray_DescrFromType(NPY_ULONGLONG);
    }

    return PyArray_DescrFromType(NPY_OBJECT);
}
@teoliphant teoliphant closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 14, 2012
  1. @ericfode

    BUG: ticket #2028: When min_scalar was not checking to see if numbers…

    Eric Fode authored ericfode committed
    … could fit into unsigned long longs. This was fixed by adding an extra case to function to check if the passed number could fit into a unsigned long long if it could not fit into anything else. Additionaly, regression tests were added.
Commits on Jul 15, 2012
  1. @ericfode

    Style Fix

    ericfode authored
  2. @ericfode

    Tab Fix

    ericfode authored
  3. @ericfode
  4. @ericfode
This page is out of date. Refresh to see the latest.
View
11 numpy/core/src/multiarray/common.c
@@ -36,9 +36,18 @@ _array_find_python_scalar_type(PyObject *op)
/* if integer can fit into a longlong then return that*/
if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {
PyErr_Clear();
+ if ((PyLong_AsUnsignedLongLong(op) == (unsigned long long) -1)
+ && PyErr_Occurred()){
+ PyErr_Clear();
+ }
+ else {
+ return PyArray_DescrFromType(NPY_ULONGLONG);
+ }
return PyArray_DescrFromType(NPY_OBJECT);
}
- return PyArray_DescrFromType(NPY_LONGLONG);
+ else {
+ return PyArray_DescrFromType(NPY_LONGLONG);
+ }
}
return NULL;
}
View
23 numpy/core/tests/test_multiarray.py
@@ -2377,6 +2377,29 @@ def test_complex_warning(self):
finally:
warn_ctx.__exit__()
+class TestMinScalarType(object):
+ def test_usigned_shortshort(self):
+ dt = np.min_scalar_type(2**8-1)
+ wanted = np.dtype('uint8')
+ assert_equal(wanted, dt)
+ def test_usigned_short(self):
+ dt = np.min_scalar_type(2**16-1)
+ wanted = np.dtype('uint16')
+ assert_equal(wanted, dt)
+ def test_usigned_int(self):
+ dt = np.min_scalar_type(2**32-1)
+ wanted = np.dtype('uint32')
+ assert_equal(wanted, dt)
+ def test_usigned_longlong(self):
+ dt = np.min_scalar_type(2**63-1)
+ wanted = np.dtype('uint64')
+ assert_equal(wanted, dt)
+ def test_object(self):
+ dt = np.min_scalar_type(2**64)
+ wanted = np.dtype('O')
+ assert_equal(wanted, dt)
+
+
if sys.version_info >= (2, 6):
if sys.version_info[:2] == (2, 6):
Something went wrong with that request. Please try again.