Using vvvv Gamma 2019.2.081
I try to use or create a ReadOnly Span and I hit this error:
ReadOnlySpan Error.log (99.8 KB)
To reproduce, create a ReadOnlySpan from ReadonlyMemory
Show stopper at the moment. This error doesn’t occur with VL 2019.1.975
Interesting. Root cause is https://github.com/dotnet/csharplang/issues/1148 combined with how value tracing works in VL. I will need to find a way to disable tracing on such ref structs all together :/ Will report back once this is done.
Thanks, this one’s killing me
It’s a little tricky to do this so can I ask what you need Span for? Or any chance you can outsource that functionality for now to C#?
Thanks for looking. Its part of System.Numerics.Tensors and is needed to create a new tensor. It expects
Memory<T>Data, IReadOnlySpan<int>Dimensions , so this merked the WIP Onnx with Gamma 2019.2
When you mentioned that this is tricky to fix I figured I’ll might to break my golden rule.
My wrapper is this so far:
public class OnnxTensorsVL<T>
public static Tensor<T> CreateNewTensor(string Name, Memory<T> InputData, int Dimensions)
var DimSpan = new ReadOnlySpan<int>(Dimensions);
return new DenseTensor<T>(InputData, DimSpan);
ReadOnlySpan contains an implicit cast operator from array msdn
passing an array to denstensor didn’t give me any syntaxerror in vs. can you just cast or even just input the array?
Hi @woei, and thanks for having a look,
I’ll check it out. Should make the code a little tidier. VL itself will throw an error on any pin interacting with ReadOnlySpan, so it has to be wrapped away for now.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Upcoming 2020.3 preview builds will have much better support for ref structs (like Span or ReadOnlySpan). Ref structs have very special usage rules (https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-7.2/span-safety). Some of those rules have been added to our compiler so one should now get red links, red pads, red nodes when violating them (instead of a code emit error).
- It’s not allowed to use
Span<T> as a type argument, like
Spread<Span<float>> is not valid.
- Linking into a delegate is not possible. A
ref struct can’t be captured.
ref struct is not an
object either. So trying to link to an input of type
object will yield to an error.
ref struct can’t be stored in a pad.
Also the tracing code was modified so it calls ToArray on spans and ToString on all other ref structs so we can actually see the data instead of an emit error. This is essentially what this thread is about.