Skip to content

Added _contract_iter3 utility to simplify iteration space over 3 arrays#1044

Merged
oleksandr-pavlyk merged 1 commit intomasterfrom
add-contract-iter3
Jan 26, 2023
Merged

Added _contract_iter3 utility to simplify iteration space over 3 arrays#1044
oleksandr-pavlyk merged 1 commit intomasterfrom
add-contract-iter3

Conversation

@oleksandr-pavlyk
Copy link
Copy Markdown
Contributor

Added dpctl.tensor._tensor_impl._contract_iter3 utility to simplify iteration space over indices of 3 arrays with the same shape, but possibly different strides.

In [1]: import dpctl.tensor as dpt, dpctl.tensor._tensor_impl as ti, dpctl

In [4]: import itertools

In [5]: ti._contract_iter2((2, 5, 3), (15, -3, 1), (0,0,1))
Out[5]: ([10, 3], [3, 1], -12, [0, 1], 0)

In [6]: or_s = set( (15*i0 - 3*i1 + i2, i2, 15*i0 - 3*i1 + i2) for i0,i1,i2 in itertools.product(range(2), range(5), range(3)) )

In [7]: alt_s = set( (3*i0 + i1 - 12, i1, 3*i0 + i1 - 12) for i0,i1 in itertools.product(range(10), range(3)) )

In [8]: or_s == alt_s
Out[8]: True

This utility is going to be useful in implementation of binary functions, _binary_func( in1, in2, out), example of which is out = in1 + in2.

  • Have you provided a meaningful PR description?

@github-actions
Copy link
Copy Markdown

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Jan 23, 2023

Coverage Status

Coverage: 82.19%. Remained the same when pulling e5c7552 on add-contract-iter3 into 3c512ca on master.

@github-actions
Copy link
Copy Markdown

Array API standard conformance tests for dpctl=0.14.1dev1=py310h76be34b_31 ran successfully.
Passed: 33
Failed: 801
Skipped: 280

```

In [1]: import dpctl.tensor as dpt, dpctl.tensor._tensor_impl as ti, dpctl

In [4]: import itertools

In [5]: ti._contract_iter2((2, 5, 3), (15, -3, 1), (0,0,1))
Out[5]: ([10, 3], [3, 1], -12, [0, 1], 0)

In [6]: or_s = set( (15*i0 - 3*i1 + i2, i2, 15*i0 - 3*i1 + i2) for i0,i1,i2 in itertools.product(range(2), range(5), range(3)) )

In [7]: alt_s = set( (3*i0 + i1 - 12, i1, 3*i0 + i1 - 12) for i0,i1 in itertools.product(range(10), range(3)) )

In [8]: or_s == alt_s
Out[8]: True
```
@github-actions
Copy link
Copy Markdown

Array API standard conformance tests for dpctl=0.14.1dev1=py310h76be34b_31 ran successfully.
Passed: 33
Failed: 801
Skipped: 280

@oleksandr-pavlyk oleksandr-pavlyk merged commit 949711e into master Jan 26, 2023
@oleksandr-pavlyk oleksandr-pavlyk deleted the add-contract-iter3 branch January 26, 2023 14:59
@github-actions
Copy link
Copy Markdown

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

@github-actions
Copy link
Copy Markdown

Array API standard conformance tests for dpctl=0.14.1dev1=py310h76be34b_45 ran successfully.
Passed: 33
Failed: 801
Skipped: 280

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