Skip to content

Conversation

vtavana
Copy link
Collaborator

@vtavana vtavana commented Jun 14, 2023

In this PR, the following elementwise functions are implemented: dptctl.tensor.floor, dpctl.tensor.ceil, and dpctl.tensor.trunc.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • If this PR is a work in progress, are you opening the PR as a draft?

@vtavana vtavana self-assigned this Jun 14, 2023
@vtavana vtavana force-pushed the elementwise-floor-ceil-trunc branch 2 times, most recently from ea0debd to 53643f3 Compare June 14, 2023 00:31
@github-actions
Copy link

@coveralls
Copy link
Collaborator

coveralls commented Jun 14, 2023

Coverage Status

coverage: 83.219% (+0.02%) from 83.195% when pulling a2c0aee on elementwise-floor-ceil-trunc into f52182d on master.

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.3=py310h7bf5fec_2 ran successfully.
Passed: 412
Failed: 588
Skipped: 119

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.3=py310h7bf5fec_2 ran successfully.
Passed: 410
Failed: 590
Skipped: 119

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.3=py310h7bf5fec_2 ran successfully.
Passed: 412
Failed: 588
Skipped: 119

@vtavana vtavana marked this pull request as ready for review June 14, 2023 13:29
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.4=py310h7bf5fec_6 ran successfully.
Passed: 413
Failed: 587
Skipped: 119

@vtavana vtavana force-pushed the elementwise-floor-ceil-trunc branch from 1663477 to 0e31948 Compare June 16, 2023 16:31
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.4=py310h7bf5fec_9 ran successfully.
Passed: 415
Failed: 585
Skipped: 119

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.4=py310h7bf5fec_10 ran successfully.
Passed: 414
Failed: 586
Skipped: 119

@vtavana vtavana force-pushed the elementwise-floor-ceil-trunc branch from a23ebdd to 9b3b889 Compare June 19, 2023 01:16
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.4=py310h7bf5fec_10 ran successfully.
Passed: 415
Failed: 585
Skipped: 119

@ndgrigorian ndgrigorian force-pushed the elementwise-floor-ceil-trunc branch from 9b3b889 to ea451ff Compare July 4, 2023 05:40
@github-actions
Copy link

github-actions bot commented Jul 4, 2023

Array API standard conformance tests for dpctl=0.14.5dev0=py310h7bf5fec_12 ran successfully.
Passed: 427
Failed: 573
Skipped: 119

@oleksandr-pavlyk
Copy link
Contributor

The output type for of integer type inputs should be the appropriate floating point type.

Python 3.9.12 (main, Jun  1 2022, 11:38:51)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import numpy as np

In [2]: np.floor.types
Out[2]: ['e->e', 'f->f', 'd->d', 'f->f', 'd->d', 'g->g', 'O->O']

In [3]: np.ceil.types
Out[3]: ['e->e', 'f->f', 'd->d', 'f->f', 'd->d', 'g->g', 'O->O']

In [4]: np.trunc.types
Out[4]: ['e->e', 'f->f', 'd->d', 'f->f', 'd->d', 'g->g', 'O->O']

In [5]: import dpctl.tensor as dpt

In [6]: import dpctl.tensor._tensor_impl as ti

In [7]: ti._ceil_result_type(dpt.int64)
Out[7]: dtype('int64')

In [8]: dpt.ceil(dpt.ones(10, dtype="uint32"))
Out[8]: usm_ndarray([1, 1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=uint32)

In [9]: np.ceil(np.ones(10, dtype="uint32"))
Out[9]: array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])

@vtavana
Copy link
Collaborator Author

vtavana commented Jul 17, 2023

The output type for of integer type inputs should be the appropriate floating point type.

Python 3.9.12 (main, Jun  1 2022, 11:38:51)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import numpy as np

In [2]: np.floor.types
Out[2]: ['e->e', 'f->f', 'd->d', 'f->f', 'd->d', 'g->g', 'O->O']

In [3]: np.ceil.types
Out[3]: ['e->e', 'f->f', 'd->d', 'f->f', 'd->d', 'g->g', 'O->O']

In [4]: np.trunc.types
Out[4]: ['e->e', 'f->f', 'd->d', 'f->f', 'd->d', 'g->g', 'O->O']

In [5]: import dpctl.tensor as dpt

In [6]: import dpctl.tensor._tensor_impl as ti

In [7]: ti._ceil_result_type(dpt.int64)
Out[7]: dtype('int64')

In [8]: dpt.ceil(dpt.ones(10, dtype="uint32"))
Out[8]: usm_ndarray([1, 1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=uint32)

In [9]: np.ceil(np.ones(10, dtype="uint32"))
Out[9]: array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])

Yes, the behavior is different than numpy since Array API for ceil, floor and trunc says that "the returned array must have the same data type as input."

@oleksandr-pavlyk
Copy link
Contributor

Yes, I asked for clarification: data-apis/array-api#657

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.5dev1=py310h7bf5fec_15 ran successfully.
Passed: 474
Failed: 526
Skipped: 119

@oleksandr-pavlyk
Copy link
Contributor

Why are these tests so slow?

(dev_dpctl) opavlyk@opavlyk-mobl:~/repos/dpctl$ python -m pytest --durations=6 dpctl/tests/elementwise/test_floor_ceil_trunc.py
============================================================================ test session starts ============================================================================
platform linux -- Python 3.9.12, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/opavlyk/repos/dpctl
plugins: metadata-2.0.4, json-report-1.5.0, cov-4.0.0, hypothesis-6.75.3, scikit-learn-1.3.dev0
collected 186 items

dpctl/tests/elementwise/test_floor_ceil_trunc.py ..............................sss.......................................sss.................................sss..... [ 62%]
.........................sss..............................sss......sss                                                                                                [100%]

============================================================================ slowest 6 durations ============================================================================
7.31s call     dpctl/tests/elementwise/test_floor_ceil_trunc.py::test_floor_ceil_trunc_usm_type[host-trunc-UnaryElementwiseFunc]
6.96s call     dpctl/tests/elementwise/test_floor_ceil_trunc.py::test_floor_ceil_trunc_usm_type[shared-ceil-UnaryElementwiseFunc]
6.49s call     dpctl/tests/elementwise/test_floor_ceil_trunc.py::test_floor_ceil_trunc_usm_type[host-floor-UnaryElementwiseFunc]
6.46s call     dpctl/tests/elementwise/test_floor_ceil_trunc.py::test_floor_ceil_trunc_usm_type[shared-trunc-UnaryElementwiseFunc]
6.34s call     dpctl/tests/elementwise/test_floor_ceil_trunc.py::test_floor_ceil_trunc_usm_type[host-ceil-UnaryElementwiseFunc]
5.97s call     dpctl/tests/elementwise/test_floor_ceil_trunc.py::test_floor_ceil_trunc_usm_type[shared-floor-UnaryElementwiseFunc]
================================================================ 168 passed, 18 skipped in 103.48s (0:01:43) ================================================================

I am going to push changes to these tests to make them run faster.

(dev_dpctl) opavlyk@opavlyk-mobl:~/repos/dpctl$ python -m pytest --durations=6 dpctl/tests/elementwise/test_floor_ceil_trunc.py
============================================================================ test session starts ============================================================================
platform linux -- Python 3.9.12, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/opavlyk/repos/dpctl
plugins: metadata-2.0.4, json-report-1.5.0, cov-4.0.0, hypothesis-6.75.3, scikit-learn-1.3.dev0
collected 186 items

dpctl/tests/elementwise/test_floor_ceil_trunc.py ..............................sss.......................................sss.................................sss..... [ 62%]
.........................sss..............................sss......sss                                                                                                [100%]

============================================================================ slowest 6 durations ============================================================================
0.35s call     dpctl/tests/elementwise/test_floor_ceil_trunc.py::test_floor_ceil_trunc_out_type[i1-UnaryElementwiseFunc0]
0.15s call     dpctl/tests/elementwise/test_floor_ceil_trunc.py::test_floor_ceil_trunc_order[u8-trunc-UnaryElementwiseFunc]
0.14s call     dpctl/tests/elementwise/test_floor_ceil_trunc.py::test_floor_ceil_trunc_order[u4-ceil-UnaryElementwiseFunc]
0.14s call     dpctl/tests/elementwise/test_floor_ceil_trunc.py::test_floor_ceil_trunc_order[f2-floor-UnaryElementwiseFunc]
0.14s call     dpctl/tests/elementwise/test_floor_ceil_trunc.py::test_floor_ceil_trunc_order[f4-trunc-UnaryElementwiseFunc]
0.14s call     dpctl/tests/elementwise/test_floor_ceil_trunc.py::test_floor_ceil_trunc_order[u1-floor-UnaryElementwiseFunc]
====================================================================== 168 passed, 18 skipped in 9.74s ======================================================================
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.5dev1=py310h7bf5fec_16 ran successfully.
Passed: 474
Failed: 526
Skipped: 119

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.5dev1=py310h7bf5fec_26 ran successfully.
Passed: 474
Failed: 526
Skipped: 119

@oleksandr-pavlyk oleksandr-pavlyk self-requested a review July 17, 2023 21:45
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.5=py310h7bf5fec_9 ran successfully.
Passed: 475
Failed: 525
Skipped: 119

@oleksandr-pavlyk oleksandr-pavlyk merged commit 8a019d1 into master Jul 18, 2023
@oleksandr-pavlyk oleksandr-pavlyk deleted the elementwise-floor-ceil-trunc branch July 18, 2023 21:34
@github-actions
Copy link

Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.5=py310h7bf5fec_15 ran successfully.
Passed: 475
Failed: 525
Skipped: 119

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.

4 participants