From 5a1120ef42cd0314f815ffa660f28af706660367 Mon Sep 17 00:00:00 2001
From: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
Date: Thu, 12 Mar 2026 14:02:28 -0700
Subject: [PATCH 1/5] Import tensors and add methods to sbox
---
Directory.Packages.props | 1 +
.../NumericsHelpers/AddBenchmark.cs | 28 +++++--
Robust.Benchmarks/Robust.Benchmarks.csproj | 2 +
Robust.Shared/ContentPack/Sandbox.yml | 82 +++++++++++++++++++
Robust.Shared/Robust.Shared.csproj | 1 +
5 files changed, 108 insertions(+), 6 deletions(-)
diff --git a/Directory.Packages.props b/Directory.Packages.props
index 20962c6c74d..514e430eaab 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -74,6 +74,7 @@
+
diff --git a/Robust.Benchmarks/NumericsHelpers/AddBenchmark.cs b/Robust.Benchmarks/NumericsHelpers/AddBenchmark.cs
index 100ad649423..5584a1cf2e9 100644
--- a/Robust.Benchmarks/NumericsHelpers/AddBenchmark.cs
+++ b/Robust.Benchmarks/NumericsHelpers/AddBenchmark.cs
@@ -1,32 +1,48 @@
-using BenchmarkDotNet.Attributes;
+using System.Numerics.Tensors;
+using BenchmarkDotNet.Attributes;
+using BenchmarkDotNet.Configs;
using Robust.Shared.Analyzers;
namespace Robust.Benchmarks.NumericsHelpers;
[Virtual]
+[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByMethod)]
+[MemoryDiagnoser]
+[DisassemblyDiagnoser]
public class AddBenchmark
{
- [Params(32, 128)]
+ [Params(32, 128, 256, 512, 1024, 2048, 4096, 8192, 16384)]
public int N { get; set; }
- [Params(1,2)]
- public int T { get; set; }
-
private float[] _inputA = default!;
private float[] _inputB = default!;
private float[] _output = default!;
+ private Tensor _tensorA = default!;
+ private Tensor _tensorB = default!;
+ private Tensor _tensorOutput = default!;
+
[GlobalSetup]
public void Setup()
{
_inputA = new float[N];
_inputB = new float[N];
_output = new float[N];
+
+ _tensorA = Tensor.Create(_inputA);
+ _tensorB = Tensor.Create(_inputB);
+ _tensorOutput = Tensor.Create(_output);
}
[Benchmark]
- public void Bench()
+ public void BenchNumericsHelpers()
{
Shared.Maths.NumericsHelpers.Add(_inputA, _inputB, _output);
}
+
+ [Benchmark]
+ public void BenchTensor()
+ {
+ TensorPrimitives.Add(_inputA, _inputB, _output);
+ }
}
diff --git a/Robust.Benchmarks/Robust.Benchmarks.csproj b/Robust.Benchmarks/Robust.Benchmarks.csproj
index 7e114649cce..f47c475bc93 100644
--- a/Robust.Benchmarks/Robust.Benchmarks.csproj
+++ b/Robust.Benchmarks/Robust.Benchmarks.csproj
@@ -22,6 +22,8 @@
+
+
diff --git a/Robust.Shared/ContentPack/Sandbox.yml b/Robust.Shared/ContentPack/Sandbox.yml
index c969a9d03c4..d3247b03db3 100644
--- a/Robust.Shared/ContentPack/Sandbox.yml
+++ b/Robust.Shared/ContentPack/Sandbox.yml
@@ -641,6 +641,88 @@ Types:
Vector2: { All: True }
Vector3: { All: True }
Vector4: { All: True }
+ System.Numerics.Tensors:
+ TensorPrimitives: { All: True }
+ NIndex: { All: True }
+ NRange: { All: True }
+ TensorSpan`1:
+ Methods:
+ - "void .ctor(!0[])"
+ - "void .ctor(!0[], System.ReadOnlySpan`1)"
+ - "void .ctor(!0[], System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
+ - "void .ctor(!0[], int, System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
+ - "void .ctor(System.Span`1)"
+ - "void set_Item(System.ReadOnlySpan`1, System.Numerics.Tensors.TensorSpan`1)"
+ - "System.Numerics.Tensors.TensorSpan`1 Slice(System.ReadOnlySpan`1)"
+ - "System.Numerics.Tensors.TensorSpan`1 Slice(System.ReadOnlySpan`1)"
+ - "System.Numerics.Tensors.TensorSpan`1 Slice(System.ReadOnlySpan`1)"
+ - "nativeint get_FlattenedLength()"
+ - "bool get_HasAnyDenseDimensions()"
+ - "bool get_IsDense()"
+ - "bool get_IsEmpty()"
+ - "bool get_IsPinned()"
+ - "System.ReadOnlySpan`1 get_Lengths()"
+ - "int get_Rank()"
+ - "System.ReadOnlySpan`1 get_Strides()"
+ - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 AsReadOnlyTensorSpan()"
+ - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 AsReadOnlyTensorSpan(System.ReadOnlySpan`1)"
+ - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 AsReadOnlyTensorSpan(System.ReadOnlySpan`1)"
+ - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 AsReadOnlyTensorSpan(System.ReadOnlySpan`1)"
+ - "System.Span`1 GetSpan(System.ReadOnlySpan`1, int)"
+ - "System.Span`1 GetSpan(System.ReadOnlySpan`1, int)"
+ - "bool TryGetSpan(System.ReadOnlySpan`1, int, ref System.Span`1)"
+ - "bool TryGetSpan(System.ReadOnlySpan`1, int, ref System.Span`1)"
+ - "void Clear()"
+ - "void Fill(!0)"
+ - "void CopyTo(System.Numerics.Tensors.TensorSpan`1)"
+ - "bool TryCopyTo(System.Numerics.Tensors.TensorSpan`1)"
+ - "void FlattenTo(System.Span`1)"
+ - "bool TryFlattenTo(System.Span`1)"
+ - "System.Numerics.Tensors.TensorDimensionSpan`1 GetDimensionSpan(int)"
+ - "string ToString()"
+ - "string ToString(System.ReadOnlySpan`1)"
+ - "bool op_Equality(System.Numerics.Tensors.TensorSpan`1, System.Numerics.Tensors.TensorSpan`1)"
+ - "bool op_Inequality(System.Numerics.Tensors.TensorSpan`1, System.Numerics.Tensors.TensorSpan`1)"
+ - "System.Numerics.Tensors.TensorSpan`1 op_Implicit(!0[])"
+ - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 op_Implicit(System.Numerics.Tensors.TensorSpan`1)"
+ NestedTypes:
+ Enumerator: { All: True }
+ ReadOnlyTensorSpan`1:
+ Methods:
+ - "void .ctor(!0[])"
+ - "void .ctor(!0[], System.ReadOnlySpan`1)"
+ - "void .ctor(!0[], System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
+ - "void .ctor(!0[], int, System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
+ - "void .ctor(System.ReadOnlySpan`1)"
+ - "void .ctor(System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
+ - "void .ctor(System.ReadOnlySpan`1, System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
+ - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 Slice(System.ReadOnlySpan`1)"
+ - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 Slice(System.ReadOnlySpan`1)"
+ - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 Slice(System.ReadOnlySpan`1)"
+ - "nativeint get_FlattenedLength()"
+ - "bool get_HasAnyDenseDimensions()"
+ - "bool get_IsDense()"
+ - "bool get_IsEmpty()"
+ - "bool get_IsPinned()"
+ - "System.ReadOnlySpan`1 get_Lengths()"
+ - "int get_Rank()"
+ - "System.ReadOnlySpan`1 get_Strides()"
+ - "System.ReadOnlySpan`1 GetSpan(System.ReadOnlySpan`1, int)"
+ - "System.ReadOnlySpan`1 GetSpan(System.ReadOnlySpan`1, int)"
+ - "bool TryGetSpan(System.ReadOnlySpan`1, int, ref System.ReadOnlySpan`1)"
+ - "bool TryGetSpan(System.ReadOnlySpan`1, int, ref System.ReadOnlySpan`1)"
+ - "void FlattenTo(System.Span`1)"
+ - "bool TryFlattenTo(System.Span`1)"
+ - "System.Numerics.Tensors.TensorDimensionSpan`1 GetDimensionSpan(int)"
+ - "string ToString()"
+ - "string ToString(System.ReadOnlySpan`1)"
+ - "bool op_Equality(System.Numerics.Tensors.ReadOnlyTensorSpan`1, System.Numerics.Tensors.ReadOnlyTensorSpan`1)"
+ - "bool op_Inequality(System.Numerics.Tensors.ReadOnlyTensorSpan`1, System.Numerics.Tensors.ReadOnlyTensorSpan`1)"
+ - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 op_Implicit(!0[])"
+ - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 op_Implicit(System.ReadOnlySpan`1)"
+ - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 op_Implicit(System.Numerics.Tensors.TensorSpan`1)"
+ NestedTypes:
+ Enumerator: { All: True }
System.Reflection:
Assembly:
Methods:
diff --git a/Robust.Shared/Robust.Shared.csproj b/Robust.Shared/Robust.Shared.csproj
index 424cc81c669..cdd7bf9746e 100644
--- a/Robust.Shared/Robust.Shared.csproj
+++ b/Robust.Shared/Robust.Shared.csproj
@@ -13,6 +13,7 @@
+
From 8bdb3d30f39e4612d891ee81861207f01cd04ac5 Mon Sep 17 00:00:00 2001
From: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
Date: Thu, 12 Mar 2026 16:38:07 -0700
Subject: [PATCH 2/5] might be a good idea to expose pseudo-ctors also nuke
spans as tey're too much to review rn
---
Robust.Shared/ContentPack/Sandbox.yml | 86 +++------------------------
1 file changed, 8 insertions(+), 78 deletions(-)
diff --git a/Robust.Shared/ContentPack/Sandbox.yml b/Robust.Shared/ContentPack/Sandbox.yml
index d3247b03db3..331a93e01b8 100644
--- a/Robust.Shared/ContentPack/Sandbox.yml
+++ b/Robust.Shared/ContentPack/Sandbox.yml
@@ -642,87 +642,17 @@ Types:
Vector3: { All: True }
Vector4: { All: True }
System.Numerics.Tensors:
+ Tensor:
+ Methods:
+ - "System.Numerics.Tensors.Tensor`1 Create<>(!!0[])"
+ - "System.Numerics.Tensors.Tensor`1 Create<>(!!0[], System.ReadOnlySpan`1)"
+ - "System.Numerics.Tensors.Tensor`1 Create<>(!!0[], System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
+ - "System.Numerics.Tensors.Tensor`1 Create<>(!!0[], int, System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
+ Tensor`1:
+ Methods: []
TensorPrimitives: { All: True }
NIndex: { All: True }
NRange: { All: True }
- TensorSpan`1:
- Methods:
- - "void .ctor(!0[])"
- - "void .ctor(!0[], System.ReadOnlySpan`1)"
- - "void .ctor(!0[], System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
- - "void .ctor(!0[], int, System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
- - "void .ctor(System.Span`1)"
- - "void set_Item(System.ReadOnlySpan`1, System.Numerics.Tensors.TensorSpan`1)"
- - "System.Numerics.Tensors.TensorSpan`1 Slice(System.ReadOnlySpan`1)"
- - "System.Numerics.Tensors.TensorSpan`1 Slice(System.ReadOnlySpan`1)"
- - "System.Numerics.Tensors.TensorSpan`1 Slice(System.ReadOnlySpan`1)"
- - "nativeint get_FlattenedLength()"
- - "bool get_HasAnyDenseDimensions()"
- - "bool get_IsDense()"
- - "bool get_IsEmpty()"
- - "bool get_IsPinned()"
- - "System.ReadOnlySpan`1 get_Lengths()"
- - "int get_Rank()"
- - "System.ReadOnlySpan`1 get_Strides()"
- - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 AsReadOnlyTensorSpan()"
- - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 AsReadOnlyTensorSpan(System.ReadOnlySpan`1)"
- - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 AsReadOnlyTensorSpan(System.ReadOnlySpan`1)"
- - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 AsReadOnlyTensorSpan(System.ReadOnlySpan`1)"
- - "System.Span`1 GetSpan(System.ReadOnlySpan`1, int)"
- - "System.Span`1 GetSpan(System.ReadOnlySpan`1, int)"
- - "bool TryGetSpan(System.ReadOnlySpan`1, int, ref System.Span`1)"
- - "bool TryGetSpan(System.ReadOnlySpan`1, int, ref System.Span`1)"
- - "void Clear()"
- - "void Fill(!0)"
- - "void CopyTo(System.Numerics.Tensors.TensorSpan`1)"
- - "bool TryCopyTo(System.Numerics.Tensors.TensorSpan`1)"
- - "void FlattenTo(System.Span`1)"
- - "bool TryFlattenTo(System.Span`1)"
- - "System.Numerics.Tensors.TensorDimensionSpan`1 GetDimensionSpan(int)"
- - "string ToString()"
- - "string ToString(System.ReadOnlySpan`1)"
- - "bool op_Equality(System.Numerics.Tensors.TensorSpan`1, System.Numerics.Tensors.TensorSpan`1)"
- - "bool op_Inequality(System.Numerics.Tensors.TensorSpan`1, System.Numerics.Tensors.TensorSpan`1)"
- - "System.Numerics.Tensors.TensorSpan`1 op_Implicit(!0[])"
- - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 op_Implicit(System.Numerics.Tensors.TensorSpan`1)"
- NestedTypes:
- Enumerator: { All: True }
- ReadOnlyTensorSpan`1:
- Methods:
- - "void .ctor(!0[])"
- - "void .ctor(!0[], System.ReadOnlySpan`1)"
- - "void .ctor(!0[], System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
- - "void .ctor(!0[], int, System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
- - "void .ctor(System.ReadOnlySpan`1)"
- - "void .ctor(System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
- - "void .ctor(System.ReadOnlySpan`1, System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
- - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 Slice(System.ReadOnlySpan`1)"
- - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 Slice(System.ReadOnlySpan`1)"
- - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 Slice(System.ReadOnlySpan`1)"
- - "nativeint get_FlattenedLength()"
- - "bool get_HasAnyDenseDimensions()"
- - "bool get_IsDense()"
- - "bool get_IsEmpty()"
- - "bool get_IsPinned()"
- - "System.ReadOnlySpan`1 get_Lengths()"
- - "int get_Rank()"
- - "System.ReadOnlySpan`1 get_Strides()"
- - "System.ReadOnlySpan`1 GetSpan(System.ReadOnlySpan`1, int)"
- - "System.ReadOnlySpan`1 GetSpan(System.ReadOnlySpan`1, int)"
- - "bool TryGetSpan(System.ReadOnlySpan`1, int, ref System.ReadOnlySpan`1)"
- - "bool TryGetSpan(System.ReadOnlySpan`1, int, ref System.ReadOnlySpan`1)"
- - "void FlattenTo(System.Span`1)"
- - "bool TryFlattenTo(System.Span`1)"
- - "System.Numerics.Tensors.TensorDimensionSpan`1 GetDimensionSpan(int)"
- - "string ToString()"
- - "string ToString(System.ReadOnlySpan`1)"
- - "bool op_Equality(System.Numerics.Tensors.ReadOnlyTensorSpan`1, System.Numerics.Tensors.ReadOnlyTensorSpan`1)"
- - "bool op_Inequality(System.Numerics.Tensors.ReadOnlyTensorSpan`1, System.Numerics.Tensors.ReadOnlyTensorSpan`1)"
- - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 op_Implicit(!0[])"
- - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 op_Implicit(System.ReadOnlySpan`1)"
- - "System.Numerics.Tensors.ReadOnlyTensorSpan`1 op_Implicit(System.Numerics.Tensors.TensorSpan`1)"
- NestedTypes:
- Enumerator: { All: True }
System.Reflection:
Assembly:
Methods:
From 24cd43af73cc4670cb21ac07056934f5404b85c1 Mon Sep 17 00:00:00 2001
From: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
Date: Fri, 13 Mar 2026 13:52:03 -0700
Subject: [PATCH 3/5] nuke buffers
---
Robust.Shared/ContentPack/Sandbox.yml | 2 --
1 file changed, 2 deletions(-)
diff --git a/Robust.Shared/ContentPack/Sandbox.yml b/Robust.Shared/ContentPack/Sandbox.yml
index 331a93e01b8..ebf92d18f46 100644
--- a/Robust.Shared/ContentPack/Sandbox.yml
+++ b/Robust.Shared/ContentPack/Sandbox.yml
@@ -651,8 +651,6 @@ Types:
Tensor`1:
Methods: []
TensorPrimitives: { All: True }
- NIndex: { All: True }
- NRange: { All: True }
System.Reflection:
Assembly:
Methods:
From 17be22eb1fe1760fe5f04e9795907ce5669c77de Mon Sep 17 00:00:00 2001
From: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
Date: Fri, 13 Mar 2026 14:07:02 -0700
Subject: [PATCH 4/5] nuke unconsumable types
---
Robust.Shared/ContentPack/Sandbox.yml | 8 --------
1 file changed, 8 deletions(-)
diff --git a/Robust.Shared/ContentPack/Sandbox.yml b/Robust.Shared/ContentPack/Sandbox.yml
index ebf92d18f46..db9eaffd4ec 100644
--- a/Robust.Shared/ContentPack/Sandbox.yml
+++ b/Robust.Shared/ContentPack/Sandbox.yml
@@ -642,14 +642,6 @@ Types:
Vector3: { All: True }
Vector4: { All: True }
System.Numerics.Tensors:
- Tensor:
- Methods:
- - "System.Numerics.Tensors.Tensor`1 Create<>(!!0[])"
- - "System.Numerics.Tensors.Tensor`1 Create<>(!!0[], System.ReadOnlySpan`1)"
- - "System.Numerics.Tensors.Tensor`1 Create<>(!!0[], System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
- - "System.Numerics.Tensors.Tensor`1 Create<>(!!0[], int, System.ReadOnlySpan`1, System.ReadOnlySpan`1)"
- Tensor`1:
- Methods: []
TensorPrimitives: { All: True }
System.Reflection:
Assembly:
From 451a6cdc00a5591da1044f32dd84d7038f091b31 Mon Sep 17 00:00:00 2001
From: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
Date: Sat, 14 Mar 2026 00:21:14 -0700
Subject: [PATCH 5/5] hilarious
---
Robust.Benchmarks/NumericsHelpers/AddBenchmark.cs | 8 --------
1 file changed, 8 deletions(-)
diff --git a/Robust.Benchmarks/NumericsHelpers/AddBenchmark.cs b/Robust.Benchmarks/NumericsHelpers/AddBenchmark.cs
index 5584a1cf2e9..6be5f3de6aa 100644
--- a/Robust.Benchmarks/NumericsHelpers/AddBenchmark.cs
+++ b/Robust.Benchmarks/NumericsHelpers/AddBenchmark.cs
@@ -18,20 +18,12 @@ public class AddBenchmark
private float[] _inputB = default!;
private float[] _output = default!;
- private Tensor _tensorA = default!;
- private Tensor _tensorB = default!;
- private Tensor _tensorOutput = default!;
-
[GlobalSetup]
public void Setup()
{
_inputA = new float[N];
_inputB = new float[N];
_output = new float[N];
-
- _tensorA = Tensor.Create(_inputA);
- _tensorB = Tensor.Create(_inputB);
- _tensorOutput = Tensor.Create(_output);
}
[Benchmark]