Comments (3)
shallowSlice
and shallowReshape
are added. Tests pending.
shallowAxis
(yields reference) and maxis
(yields mutable reference, similar to items
) are planned but will probably be blocked by nim-lang/Nim#5887 (shallowCopy in iterators yields full copies).
Discussion:
-
Add
unsafeShallowSlice
which can take "let" parameter (and notvar
) and writing fast libraries that uses Arraymancer. cc @edubart. Relevant discussion aboutshallow
vsunsafeShallow
in nim-lang/Nim#644 and https://github.com/nim-lang/Nim/issues/3377 -
RFC in Nim bug tracker about slicing Views - https://github.com/nim-lang/Nim/issues/5753. Should we have a separate view type and have proc generics over
Tensor
andTensorView
My opinion:
-
It is important to provide sane defaults but allow higher performance when needed/possible.
unsafeShallow
while long is good because easily grep-able and safe code is by default/easier to write ( '=' for copy,shallowSlice
for var shallow,unsafeShallowSlice
for let shallow).
Shallow copy by default is also a source of (bad) surprise for Numpy users.
Another explanation from the Matrix Template Library on the issue of shallowCopy for numerical software.
When nim-lang/Nim#6348 is solved, Arraymancer will implement "move" optimization so that tensors with refcount of 1 will get shallow-copied on assignment using this.
Also it is possible to rely on Nim GC to efficiently get refcount with proc getRefcount. -
Implementing Tensor and TensorView, CudaTensor and CudaTensorView, etc seems too cumbersome to use and maintain. Having
shallow
,unsafeShallow
andgetRefcount
should already be explicit and flexible enough.
from arraymancer.
- Implementing
unsafeShallowCopy
will be useful, there are many cases that user may want to work with just an slice of a tensor. For example multiplying a slice of tensor with a matrix, in this case having an extra copy by value of the slice would have a bad performance and the user might be inside a method where this tensor is alet
variable, so in this caseunsafeShallowCopy
is needed.
I suggest that unsafeShallowCopy
could be called just view
or if you want to avoid user mistakes unsafeView
. View meaning it much more clear in the Tensor/Matrix context. Or other name option would be unsafeSlice
.
- If things workout for shallow slicing in both usability and performance-wise I don't see the needs for a separate
TensorView
object at the moment. Unless for user safety reasons, like removing elements assignment procs from the tensor view to prevent misuse of a read only slice view.
from arraymancer.
I added unsafeView
(for copy and slicing) and unsafeReshape
(for contiguous tensors only).
I don't think the issue with shallowCopy in iterators will be closed anytime soon so for now axis shallowCopy will not work. (And I don't think there are critical algo relying on that)
To be reopened when nim-lang/Nim#5887 is closed.
from arraymancer.
Related Issues (20)
- --gc:orc -d:openmp cause a segfault when calling sum(axis = 2) HOT 2
- Importing std/enumerate breaks arraymancer HOT 1
- einsum fails in proc HOT 1
- einsum in proc fails when result is a Tensor HOT 4
- example 3 breaks with Nim >= 1.6 HOT 3
- Issues w/ softmax procedure HOT 11
- Importing model refusing to output any information that is new? HOT 1
- Ability to clone neural nets instead of all the weights/biases tensors manually HOT 3
- set[int] used that depends on odd compiler behavior.
- Device workload split feature HOT 2
- Fix CI by fixing doc generation
- Error: type mismatch: got 'float' for 'sum(conv2d(x, dkernel, dbias, padding, stride, Im2ColGEMM))' but expected 'Tensor[system.float]'
- Multiplication of tensors with rank > 2 HOT 6
- Can't read hdf5: io_hdf5.nim(17, 6) Error: 'parseNameAndGroup' can have side effects
- ShallowCopy problem using Nim v2 RCx HOT 2
- Futuristic premium
- Using the .item function on a Complex Tensor crashes
- Using arange within a [] expression fails HOT 1
- delete it
- 2023-12-31 - Longstanding missing features HOT 25
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arraymancer.