Skip to content

Use integers instead of floats for arrays returned from scheduler.array#94

Merged
meatballs merged 6 commits intoPyconUK:masterfrom
alexwlchan:arrays-should-be-ints
May 19, 2017
Merged

Use integers instead of floats for arrays returned from scheduler.array#94
meatballs merged 6 commits intoPyconUK:masterfrom
alexwlchan:arrays-should-be-ints

Conversation

@alexwlchan
Copy link
Contributor

Resolves #91.

@meatballs
Copy link
Member

We seem to have a problem on appveyor here. Not sure why....

@drvinceknight
Copy link
Collaborator

We seem to have a problem on appveyor here. Not sure why....

Is this perhaps a clue? http://stackoverflow.com/questions/36278590/numpy-array-dtype-is-coming-as-int32-by-default-in-a-windows-10-64-bit-machine

@alexwlchan
Copy link
Contributor Author

At a total guess, numpy is picking a slightly different int type on Windows?

@drvinceknight
Copy link
Collaborator

Would setting the type to be np.int64 work? (I am stabbing in the dark here)

@alexwlchan
Copy link
Contributor Author

alexwlchan commented May 18, 2017

Would setting the type to be np.int64 work?

Not sure. Either way, it was probably a mistake of me to be inconsistent in the first place. Let's give it a go!

@drvinceknight
Copy link
Collaborator

. Let's give it a go!

Appveyor seems happy! 👍

@meatballs
Copy link
Member

using int64 for these seems a little OTT. They will only ever be 0 or 1, so I'd have thought bool would be more appropriate.

@alexwlchan
Copy link
Contributor Author

using int64 for these seems a little OTT. They will only ever be 0 or 1, so I'd have thought bool would be more appropriate.

I will freely admit I’m not a numpy expert. If you use np.bool, it looks like you're getting True or False out. Maybe np.int8?

@meatballs
Copy link
Member

I believe that in Python 3, True and False are keywords and will be always be equal to 1 and 0. In Python 2 it was different, but we should be with bool here.

@drvinceknight
Copy link
Collaborator

We don't want the array str to actually have True False in it thought right? We want 0 and 1.

@drvinceknight
Copy link
Collaborator

We want 0 and 1.

For completeness:

>>> import numpy as np
>>> a = np.zeros((3, 3), dtype=np.bool)
>>> a[0, 1] = 1
>>> a[2, 1] = 1
>>> a
array([[False,  True, False],
       [False, False, False],
       [False,  True, False]], dtype=bool)
>>> b = np.zeros((3, 3), dtype=np.int8)
>>> b[0, 1] = 1
>>> b[2, 1] = 1
>>> b
array([[0, 1, 0],
       [0, 0, 0],
       [0, 1, 0]], dtype=int8)

My preference would be np.int8.

@meatballs
Copy link
Member

Ah well. Bool would have been nice but we really do need to see actual integers! Int8 for me too.

@drvinceknight
Copy link
Collaborator

Simple doctest failure in mathematical-model.rst:

029     >>> array = scheduler.schedule_to_array(schedule, events=events, slots=slots)
030     >>> array
Expected:
    array([[1, 0],
           [0, 1]])
Got:
    array([[1, 0],
           [0, 1]], dtype=int8)

@alexwlchan
Copy link
Contributor Author

Tests seemed to have passed, just waiting for coveralls. 😕

@drvinceknight
Copy link
Collaborator

Tests seemed to have passed, just waiting for coveralls.

I've tried running coverage locally but get:

============================================================= 79 passed in 0.35 seconds ==============================================================
Coverage.py warning: No data was collected.

(This isn't happening on travis, we're definitely waiting on coveralls there).

@drvinceknight
Copy link
Collaborator

(This isn't happening on travis, we're definitely waiting on coveralls there).

DUH! And here's the coverage report from travis:

0.18s$ coverage report -m
Name                                                         Stmts   Miss  Cover   Missing
------------------------------------------------------------------------------------------
src/conference_scheduler/__init__.py                             0      0   100%
src/conference_scheduler/lp_problem/__init__.py                  2      0   100%
src/conference_scheduler/lp_problem/constraints.py              52      0   100%
src/conference_scheduler/lp_problem/objective_functions.py      16      0   100%
src/conference_scheduler/lp_problem/utils.py                    63      0   100%
src/conference_scheduler/resources.py                           64      0   100%
src/conference_scheduler/scheduler.py                           56      0   100%
src/conference_scheduler/validator.py                           25      0   100%
------------------------------------------------------------------------------------------
TOTAL                                                          278      0   100%

I think this is good to go!

@meatballs meatballs merged commit a834eb5 into PyconUK:master May 19, 2017
@alexwlchan alexwlchan deleted the arrays-should-be-ints branch May 19, 2017 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants