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

Implement np.asarray() #3598

Merged
merged 3 commits into from Jan 3, 2019
Merged

Conversation

stuartarchibald
Copy link
Contributor

This implements np.asarray() and adds tests.

This implements np.asarray() and adds tests.
@stuartarchibald
Copy link
Contributor Author

Seems like a test that was relying on np.asarray being unsupported is now failing, because this adds support!

else:
def impl(a, dtype=None):
return np.array(a, dtype)
elif isinstance(a, (types.Float, types.Integer, types.Boolean)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace types.Float and types.Integer with types.Number so that complex dtype also work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@codecov-io
Copy link

codecov-io commented Dec 14, 2018

Codecov Report

Merging #3598 into master will decrease coverage by 0.18%.
The diff coverage is 90.14%.

@@            Coverage Diff            @@
##           master   #3598      +/-   ##
=========================================
- Coverage   80.68%   80.5%   -0.19%     
=========================================
  Files         393     395       +2     
  Lines       80485   81179     +694     
  Branches     9164    9240      +76     
=========================================
+ Hits        64942   65351     +409     
- Misses      14127   14399     +272     
- Partials     1416    1429      +13

return np.array(a, dtype)
elif isinstance(a, (types.Float, types.Integer, types.Boolean)):
dt_conv = a if _is_nonelike(dtype) else dtype
ty = as_dtype(dt_conv)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty is frozen as a compile-time constant. the first dt_conv will always be used afterwards

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, thanks, that explains some of the weirdness

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that my explanation is wrong. The cache is per signature. A different a should not reach into the same cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem here is due to this #3612

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b6e8f5a has some more tests for different scalar types, merging #3612 into this branch permits them to pass.

@stuartarchibald
Copy link
Contributor Author

On merge this #3628 can be closed.

@stuartarchibald stuartarchibald added this to the Numba 0.43 RC milestone Dec 27, 2018
@seibert
Copy link
Contributor

seibert commented Jan 2, 2019

This is currently failing two unit tests:

2018-12-31T21:45:49.9986907Z ======================================================================
2018-12-31T21:45:49.9987155Z FAIL: test_asarray (numba.tests.test_np_functions.TestNPFunctions)
2018-12-31T21:45:49.9988076Z ----------------------------------------------------------------------
2018-12-31T21:45:49.9988372Z Traceback (most recent call last):
2018-12-31T21:45:49.9988591Z   File "/home/vsts/work/1/s/numba/tests/test_np_functions.py", line 1604, in test_asarray
2018-12-31T21:45:49.9988808Z     _check(params)
2018-12-31T21:45:49.9989007Z   File "/home/vsts/work/1/s/numba/tests/test_np_functions.py", line 596, in _check_output
2018-12-31T21:45:49.9989216Z     self.assertPreciseEqual(expected, got, abs_tol=abs_tol)
2018-12-31T21:45:49.9989413Z   File "/home/vsts/work/1/s/numba/tests/support.py", line 263, in assertPreciseEqual
2018-12-31T21:45:49.9989609Z     self.fail("when comparing %s and %s: %s" % (first, second, failure_msg))
2018-12-31T21:45:49.9990587Z AssertionError: when comparing 1.2 and (1.2+0j): dtype('float64') != dtype('complex128')
2018-12-31T21:45:49.9990942Z 
2018-12-31T21:45:49.9991180Z ======================================================================
2018-12-31T21:45:49.9991601Z FAIL: test_asarray (numba.tests.test_np_functions.TestNPFunctions)
2018-12-31T21:45:49.9992124Z ----------------------------------------------------------------------
2018-12-31T21:45:49.9992424Z Traceback (most recent call last):
2018-12-31T21:45:49.9992675Z   File "/home/vsts/work/1/s/numba/tests/support.py", line 643, in tearDown
2018-12-31T21:45:49.9992890Z     self.memory_leak_teardown()
2018-12-31T21:45:49.9993125Z   File "/home/vsts/work/1/s/numba/tests/support.py", line 617, in memory_leak_teardown
2018-12-31T21:45:49.9993342Z     self.assert_no_memory_leak()
2018-12-31T21:45:49.9993713Z   File "/home/vsts/work/1/s/numba/tests/support.py", line 626, in assert_no_memory_leak
2018-12-31T21:45:49.9993929Z     self.assertEqual(total_alloc, total_free)
2018-12-31T21:45:49.9994116Z AssertionError: 3 != 2

@stuartarchibald
Copy link
Contributor Author

@seibert Think it needs #3612, will merge that and then see if it is happier.

@seibert
Copy link
Contributor

seibert commented Jan 2, 2019

This seems to be passing Azure now, except for a random failure in the Windows Py27 environment caused by a failure to install VS2008.

@stuartarchibald
Copy link
Contributor Author

Build seems to be ok now as noted :)

@stuartarchibald stuartarchibald added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 3 - Ready for Review labels Jan 3, 2019
@seibert
Copy link
Contributor

seibert commented Jan 3, 2019

Looks good.

@seibert seibert added 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Jan 3, 2019
@stuartarchibald stuartarchibald merged commit 293fb61 into numba:master Jan 3, 2019
Active automation moved this from Need Review to Done Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to merge Review and testing done, is ready to merge
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants