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

[Bug] Field with offset cannot print or to_numpy #7775

Closed
chunleili opened this issue Apr 10, 2023 · 1 comment
Closed

[Bug] Field with offset cannot print or to_numpy #7775

chunleili opened this issue Apr 10, 2023 · 1 comment
Assignees

Comments

@chunleili
Copy link
Contributor

Describe the bug
Field with offset cannot print or to_numpy

To Reproduce

import taichi as ti
ti.init(debug=True)
shape = (3,3)
new_shape = (shape[0]+2, shape[1]+2)
val =  ti.field(dtype=ti.f32, shape=(new_shape), offset=(-1, -1))
val.fill(1.0)
print(val)

Log/Screenshots
Please post the full log of the program (instead of just a few lines around the error message, unless the log is > 1000 lines). This will help us diagnose what's happening. For example:

Output:
[Taichi] version 1.6.0, llvm 15.0.1, commit 4c3e7cd3, win, python 3.10.9[Taichi] Starting on arch=x64
Traceback (most recent call last):
  File "d:\Dev\tiPBD\misc\code_bak\offset.py", line 7, in <module>      
    print(val)
  File "C:\Users\GRBJ200045\.conda\envs\ti-build\lib\site-packages\taichi\lang\field.py", line 240, in __str__
    return str(self.to_numpy())
  File "C:\Users\GRBJ200045\.conda\envs\ti-build\lib\site-packages\taichi\lang\util.py", line 311, in wrapped
    return func(*args, **kwargs)
  File "C:\Users\GRBJ200045\.conda\envs\ti-build\lib\site-packages\taichi\lang\field.py", line 302, in to_numpy
    tensor_to_ext_arr(self, arr)
  File "C:\Users\GRBJ200045\.conda\envs\ti-build\lib\site-packages\taichi\lang\kernel_impl.py", line 1033, in wrapped
    raise type(e)('\n' + str(e)) from None
taichi.lang.exception.TaichiAssertionError:
[kernel=tensor_to_ext_arr_c6_0] Out of bound access to ndarray at arg 0 
with indices [-1, -1]
File "C:\Users\GRBJ200045\.conda\envs\ti-build\lib\site-packages\taichi\_kernels.py", line 42, in tensor_to_ext_arr:
        arr[I] = tensor[I]

@ailzhang
Copy link
Contributor

I believe this bug has been there for a while.... @chunleili would you mind help verifying if this was true for old taichi versions?

Btw the fix for it is kinda simple but we probably need to spread this in many places... https://github.com/taichi-dev/taichi/compare/master...ailzhang:example_fix?expand=1

@lin-hitonami lin-hitonami moved this from Untriaged to Todo in Taichi Lang Apr 14, 2023
dream189free added a commit that referenced this issue May 11, 2023
Issue: #7775

### Brief Summary

<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 44074b9</samp>

This pull request adds support for offset tensors in Taichi, which are
tensors with non-zero lower bounds for their index domains. It updates
the `test_offset.py` file to add more tests, the `tensor_to_ext_arr`
function to handle offset copying, and the `SNode` class to expose the
offset attribute to Python.

### Walkthrough

<!--
copilot:walkthrough
-->
### <samp>🤖 Generated by Copilot at 44074b9</samp>

* Add offset attribute to SNode class and expose it to Python interface
([link](https://github.com/taichi-dev/taichi/pull/7945/files?diff=unified&w=0#diff-af631a0c71978fe591e17005f01f7c06bc30ae36c65df306bbb3b08ade770167R471))
* Modify tensor_to_ext_arr function to account for offset attribute when
copying data to external array
([link](https://github.com/taichi-dev/taichi/pull/7945/files?diff=unified&w=0#diff-09cd7b8194d05b7454b512d74fc5b442aed2319dcb763e182288b55753ce6feeL42-R48))
* Add test cases to check the correctness of offset tensor's data and
conversion methods
([link](https://github.com/taichi-dev/taichi/pull/7945/files?diff=unified&w=0#diff-520d9ca52eed08ca617ef520e95d0d1778fb1943b9652f7a388b63abca00ddd1R148-R162),
[link](https://github.com/taichi-dev/taichi/pull/7945/files?diff=unified&w=0#diff-520d9ca52eed08ca617ef520e95d0d1778fb1943b9652f7a388b63abca00ddd1R6))

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@github-project-automation github-project-automation bot moved this from Todo to Done in Taichi Lang May 11, 2023
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
…ev#7945)

Issue: taichi-dev#7775

### Brief Summary

<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 44074b9</samp>

This pull request adds support for offset tensors in Taichi, which are
tensors with non-zero lower bounds for their index domains. It updates
the `test_offset.py` file to add more tests, the `tensor_to_ext_arr`
function to handle offset copying, and the `SNode` class to expose the
offset attribute to Python.

### Walkthrough

<!--
copilot:walkthrough
-->
### <samp>🤖 Generated by Copilot at 44074b9</samp>

* Add offset attribute to SNode class and expose it to Python interface
([link](https://github.com/taichi-dev/taichi/pull/7945/files?diff=unified&w=0#diff-af631a0c71978fe591e17005f01f7c06bc30ae36c65df306bbb3b08ade770167R471))
* Modify tensor_to_ext_arr function to account for offset attribute when
copying data to external array
([link](https://github.com/taichi-dev/taichi/pull/7945/files?diff=unified&w=0#diff-09cd7b8194d05b7454b512d74fc5b442aed2319dcb763e182288b55753ce6feeL42-R48))
* Add test cases to check the correctness of offset tensor's data and
conversion methods
([link](https://github.com/taichi-dev/taichi/pull/7945/files?diff=unified&w=0#diff-520d9ca52eed08ca617ef520e95d0d1778fb1943b9652f7a388b63abca00ddd1R148-R162),
[link](https://github.com/taichi-dev/taichi/pull/7945/files?diff=unified&w=0#diff-520d9ca52eed08ca617ef520e95d0d1778fb1943b9652f7a388b63abca00ddd1R6))

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants