-
Notifications
You must be signed in to change notification settings - Fork 216
Conversation
@haytham2597
haytham2597
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed some error on my FastTensorAccessor and rollback SLN file to Original of this Repo
Hey @haytham2597, are you still intending to work on this PR?
haytham2597
commented
Mar 26, 2025
Hey @haytham2597, are you still intending to work on this PR?
This PR is already Finish. At least i know is worked and is fast.
alinpahontu2912
commented
Apr 16, 2025
Hey @haytham2597, can you add a releasenotes comment, rebase and solve the conflict to get this merged ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alinpahontu2912 Finished implement of Fast TensorAccesor with current update main i think i need wait for approving of @NiklasGustafsson for merge.
...TorchSharp into fast_tensor_accesor
alinpahontu2912
commented
Jul 2, 2025
Hey @haytham2597, Niklas is no longer working on the project. I have taken over. This seems like it was reviewed by him before, so if tests pass, I can merge it.
Hey @haytham2597, Niklas is no longer working on the project. I have taken over. This seems like it was reviewed by him before, so if tests pass, I can merge it.
Nice, i think this test passed very well. I don't have any new upgrade/change for this so you can freely merge.
But i believe that need run test for the current branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a "fast" path for TensorAccessor<T> array extraction/copying, adds tests intended to validate the new behavior, and updates release notes / test tolerances accordingly.
Changes:
- Reworked
TensorAccessor<T>.ToArray(),ToNDArray(),CopyTo(), andCopyFrom()with new pointer-based implementations and a newToArray(from_index, count)overload. - Added new unit tests covering
TensorAccessor<T>.ToArray()and copy methods on contiguous/non-contiguous tensors. - Relaxed a JIT numerical comparison tolerance and documented the TensorAccessor change in release notes.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
src/TorchSharp/Utils/TensorAccessor.cs |
Adds new "fast" implementations for array extraction and copy operations. |
test/TorchSharpTest/TestTorchTensor.cs |
Adds tests targeting the new fast TensorAccessor behaviors. |
test/TorchSharpTest/TestJIT.cs |
Adjusts an allclose assertion tolerance. |
RELEASENOTES.md |
Notes the "Fast TensorAccessor" change. |
.gitignore |
Adds ignore rules for TestClear. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CopyTo(Span<T> array, int arrayIndex = 0, long tensorIndex = 0) ignores both arrayIndex and tensorIndex (it calls ToArray().CopyTo(array)), and the contiguous fast path still allocates a full intermediate array. This should copy directly from the tensor starting at tensorIndex into array.Slice(arrayIndex, ...) without allocating.
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CopyFrom(T[] array, int arrayIndex = 0, long tensorIndex = 0) passes arrayIndex into SetValueTensor() as if it were the starting tensor index, and ignores tensorIndex. This changes semantics vs. the old implementation (array offset != tensor offset) and can write into the wrong tensor positions.
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CopyFrom(ReadOnlySpan<T> array, int arrayIndex = 0, long tensorIndex = 0) uses the loop variable index as both the tensor linear index and the source span index (array[(int)index]), which will go out of range whenever Count > array.Length and also ignores tensorIndex. It should map source index src = index - tensorIndex + arrayIndex and limit the loop to the min of source/destination remaining lengths.
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using System.Diagnostics; is added but not used anywhere in this test file; it should be removed to avoid unused-using warnings (and to keep the file consistent with the rest of the using list).
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new ToArrayIndexFastTensorAccessor test doesn't assert the expected length of v and leaves trailing entries of res at default values. As written, it can still pass even if ToArray(4) returns extra default elements beyond the two expected values; add an explicit length assertion and/or fully populate res to validate the contract.
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CopyTo(T[] array, int arrayIndex = 0, long tensorIndex = 0) no longer honors tensorIndex (it always copies from the start of the tensor). This is a behavioral change from the previous implementation and will produce wrong results for callers that request copying from a non-zero tensor offset.
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Equality checks on floating point values can yield unexpected results.
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Equality checks on floating point values can yield unexpected results.
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Equality checks on floating point values can yield unexpected results.
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Equality checks on floating point values can yield unexpected results.
No description provided.