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

Fix conversion from cupy in categorical rescale_discrete_levels #1179

Merged
merged 2 commits into from
Feb 16, 2023
Merged

Fix conversion from cupy in categorical rescale_discrete_levels #1179

merged 2 commits into from
Feb 16, 2023

Conversation

ianthomas23
Copy link
Member

See issue #1178.

When using cudf, a categorical aggregate, how='eq_hist' and rescale_discrete_levels=True then categorical shading raises an error when trying to convert a tuple that contains a cupy array and scalar to a cupy array.

The simplest possible fix would have been in _rescale_discrete_levels() here:

if multiple > 1:
lower_span = max(span[1] - multiple*(span[1] - span[0]), 0)
span = (lower_span, 1)

by casting lower_span to a float. This is fine if lower_span ia a scalar or numpy array, but if it is a cupy array then this would transfer it from GPU to CPU memory, only to be pushed back to the GPU subsequently. The solution here is to convert the span from tuple to numpy/cupy array using hstack in _interpolate_alpha.

This fixes the error produced by the OP's example code, but there is still a problem in holoviews not displaying the categorical legend if using the GPU. I will create a separate holoviews issue for this.

@codecov
Copy link

codecov bot commented Feb 10, 2023

Codecov Report

Merging #1179 (efb55d0) into main (d8167b4) will increase coverage by 0.00%.
The diff coverage is 75.00%.

@@           Coverage Diff           @@
##             main    #1179   +/-   ##
=======================================
  Coverage   85.38%   85.38%           
=======================================
  Files          35       35           
  Lines        8011     8012    +1     
=======================================
+ Hits         6840     6841    +1     
  Misses       1171     1171           
Impacted Files Coverage Δ
datashader/transfer_functions/__init__.py 86.91% <75.00%> (+0.02%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ianthomas23 ianthomas23 added this to the v0.14.5 milestone Feb 10, 2023
@ianthomas23 ianthomas23 merged commit d9de71f into holoviz:main Feb 16, 2023
@ianthomas23 ianthomas23 deleted the 1178_cudf_rescale_span branch February 16, 2023 09:47
Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

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.

2 participants