Skip to content

Commit 0e463ad

Browse files
committed
Remove dead LAPACK code, fix Marshal.SizeOf pragma, convert hot-path dictionaries to FrozenDictionary
Dead code removal: - Delete Backends/LAPACK/ directory (LAPACK.cs, LAPACK.NetLib.cs, np.LAPACK.cs) containing 6 DllImport P/Invoke declarations and the LAPACKProviderType enum — all dead code, called only from linear algebra stubs that return null/default (inv, qr, svd, lstsq) - Delete test/NumSharp.UnitTest/LAPACK/ (dgels.cs, dgesvd.cs) — tests for the removed dead LAPACK infrastructure Marshal.SizeOf fix: - np.save.cs: Remove unnecessary #pragma warning disable 618 around Marshal.SizeOf(Type) — only the Marshal.SizeOf(Object) overload is obsolete, not the Type overload used here FrozenDictionary conversion (System.Collections.Frozen, .NET 8+): - np.find_common_type.cs: Convert all 4 type promotion dictionaries (_typemap_arr_arr, _nptypemap_arr_arr, _typemap_arr_scalar, _nptypemap_arr_scalar) from Dictionary to FrozenDictionary. These contain 180+ entries each and are hit on every arithmetic/comparison operation for type resolution. FrozenDictionary optimizes the hash table at freeze time for faster lookups. - np.dtype.cs: Convert DType._kind_list_map from Dictionary to FrozenDictionary (14 entries, used in find_common_type). - TypelessConvert.cs: Convert _delegates from Dictionary to FrozenDictionary (156 entries, boxing type-conversion lookup table). Test results unchanged: 1601 passed, 50 failed on both net8.0/net10.0. 2 previously-skipped LAPACK tests removed with the dead code.
1 parent 623c39b commit 0e463ad

9 files changed

Lines changed: 545 additions & 731 deletions

File tree

src/NumSharp.Core/APIs/np.save.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ private static string GetDtypeFromType(Array array, out Type type, out int bytes
219219
}
220220
else
221221
{
222-
#pragma warning disable 618 // SizeOf would be Obsolete
223-
bytes = Marshal.SizeOf(type);
224-
#pragma warning restore 618 // SizeOf would be Obsolete
222+
bytes = System.Runtime.InteropServices.Marshal.SizeOf(type);
225223
}
226224

227225
if (type == typeof(bool))

src/NumSharp.Core/Backends/LAPACK/LAPACK.NetLib.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/NumSharp.Core/Backends/LAPACK/LAPACK.cs

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/NumSharp.Core/Backends/LAPACK/np.LAPACK.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/NumSharp.Core/Creation/np.dtype.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Frozen;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Numerics;
@@ -10,7 +11,7 @@ namespace NumSharp
1011
/// <remarks>https://docs.scipy.org/doc/numpy-1.16.0/reference/generated/numpy.dtype.html#numpy.dtype</remarks>
1112
public class DType
1213
{
13-
protected internal static readonly Dictionary<NPTypeCode, char> _kind_list_map = new Dictionary<NPTypeCode, char>()
14+
protected internal static readonly FrozenDictionary<NPTypeCode, char> _kind_list_map = new Dictionary<NPTypeCode, char>()
1415
{
1516
{NPTypeCode.Complex, 'c'},
1617
{NPTypeCode.Boolean, '?'},
@@ -26,7 +27,7 @@ public class DType
2627
{NPTypeCode.Single, 'f'},
2728
{NPTypeCode.Decimal, 'f'},
2829
{NPTypeCode.String, 'S'},
29-
};
30+
}.ToFrozenDictionary();
3031

3132
/// <summary>Initializes a new instance of the <see cref="T:System.Object"></see> class.</summary>
3233
public DType(Type type)

0 commit comments

Comments
 (0)