Skip to content

Commit 29a7423

Browse files
authored
Merge pull request #382 from SciSharp/ndarray-indexing
NDArray Getter Rework
2 parents 65c4c6c + 2de01b7 commit 29a7423

File tree

94 files changed

+3428
-1855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3428
-1855
lines changed

NumSharp.sln

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.28307.645
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29519.181
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.UnitTest", "test\NumSharp.UnitTest\NumSharp.UnitTest.csproj", "{3EDDE7AA-8037-4663-9DD4-FFB85FF962E5}"
77
EndProject
@@ -19,6 +19,8 @@ Global
1919
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2020
Debug|Any CPU = Debug|Any CPU
2121
Debug|x64 = Debug|x64
22+
Debug-Minimal|Any CPU = Debug-Minimal|Any CPU
23+
Debug-Minimal|x64 = Debug-Minimal|x64
2224
Publish|Any CPU = Publish|Any CPU
2325
Publish|x64 = Publish|x64
2426
Release|Any CPU = Release|Any CPU
@@ -29,6 +31,10 @@ Global
2931
{3EDDE7AA-8037-4663-9DD4-FFB85FF962E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
3032
{3EDDE7AA-8037-4663-9DD4-FFB85FF962E5}.Debug|x64.ActiveCfg = Debug|x64
3133
{3EDDE7AA-8037-4663-9DD4-FFB85FF962E5}.Debug|x64.Build.0 = Debug|x64
34+
{3EDDE7AA-8037-4663-9DD4-FFB85FF962E5}.Debug-Minimal|Any CPU.ActiveCfg = Debug|Any CPU
35+
{3EDDE7AA-8037-4663-9DD4-FFB85FF962E5}.Debug-Minimal|Any CPU.Build.0 = Debug|Any CPU
36+
{3EDDE7AA-8037-4663-9DD4-FFB85FF962E5}.Debug-Minimal|x64.ActiveCfg = Debug|x64
37+
{3EDDE7AA-8037-4663-9DD4-FFB85FF962E5}.Debug-Minimal|x64.Build.0 = Debug|x64
3238
{3EDDE7AA-8037-4663-9DD4-FFB85FF962E5}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
3339
{3EDDE7AA-8037-4663-9DD4-FFB85FF962E5}.Publish|Any CPU.Build.0 = Publish|Any CPU
3440
{3EDDE7AA-8037-4663-9DD4-FFB85FF962E5}.Publish|x64.ActiveCfg = Publish|x64
@@ -41,6 +47,10 @@ Global
4147
{2D475706-0F69-4C9B-83B9-03AB1AE38186}.Debug|Any CPU.Build.0 = Debug|Any CPU
4248
{2D475706-0F69-4C9B-83B9-03AB1AE38186}.Debug|x64.ActiveCfg = Debug|x64
4349
{2D475706-0F69-4C9B-83B9-03AB1AE38186}.Debug|x64.Build.0 = Debug|x64
50+
{2D475706-0F69-4C9B-83B9-03AB1AE38186}.Debug-Minimal|Any CPU.ActiveCfg = Debug|Any CPU
51+
{2D475706-0F69-4C9B-83B9-03AB1AE38186}.Debug-Minimal|Any CPU.Build.0 = Debug|Any CPU
52+
{2D475706-0F69-4C9B-83B9-03AB1AE38186}.Debug-Minimal|x64.ActiveCfg = Debug|x64
53+
{2D475706-0F69-4C9B-83B9-03AB1AE38186}.Debug-Minimal|x64.Build.0 = Debug|x64
4454
{2D475706-0F69-4C9B-83B9-03AB1AE38186}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
4555
{2D475706-0F69-4C9B-83B9-03AB1AE38186}.Publish|Any CPU.Build.0 = Publish|Any CPU
4656
{2D475706-0F69-4C9B-83B9-03AB1AE38186}.Publish|x64.ActiveCfg = Publish|x64
@@ -53,6 +63,10 @@ Global
5363
{190A2514-31CD-4738-AF20-3492DD47DE8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
5464
{190A2514-31CD-4738-AF20-3492DD47DE8C}.Debug|x64.ActiveCfg = Debug|x64
5565
{190A2514-31CD-4738-AF20-3492DD47DE8C}.Debug|x64.Build.0 = Debug|x64
66+
{190A2514-31CD-4738-AF20-3492DD47DE8C}.Debug-Minimal|Any CPU.ActiveCfg = Debug-Minimal|Any CPU
67+
{190A2514-31CD-4738-AF20-3492DD47DE8C}.Debug-Minimal|Any CPU.Build.0 = Debug-Minimal|Any CPU
68+
{190A2514-31CD-4738-AF20-3492DD47DE8C}.Debug-Minimal|x64.ActiveCfg = Debug-Minimal|x64
69+
{190A2514-31CD-4738-AF20-3492DD47DE8C}.Debug-Minimal|x64.Build.0 = Debug-Minimal|x64
5670
{190A2514-31CD-4738-AF20-3492DD47DE8C}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
5771
{190A2514-31CD-4738-AF20-3492DD47DE8C}.Publish|Any CPU.Build.0 = Publish|Any CPU
5872
{190A2514-31CD-4738-AF20-3492DD47DE8C}.Publish|x64.ActiveCfg = Publish|x64
@@ -65,6 +79,8 @@ Global
6579
{B9253A77-0652-4091-A7F5-14E9FE2630FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
6680
{B9253A77-0652-4091-A7F5-14E9FE2630FF}.Debug|x64.ActiveCfg = Debug|x64
6781
{B9253A77-0652-4091-A7F5-14E9FE2630FF}.Debug|x64.Build.0 = Debug|x64
82+
{B9253A77-0652-4091-A7F5-14E9FE2630FF}.Debug-Minimal|Any CPU.ActiveCfg = Debug|Any CPU
83+
{B9253A77-0652-4091-A7F5-14E9FE2630FF}.Debug-Minimal|x64.ActiveCfg = Debug|x64
6884
{B9253A77-0652-4091-A7F5-14E9FE2630FF}.Publish|Any CPU.ActiveCfg = Release|Any CPU
6985
{B9253A77-0652-4091-A7F5-14E9FE2630FF}.Publish|x64.ActiveCfg = Release|x64
7086
{B9253A77-0652-4091-A7F5-14E9FE2630FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -75,6 +91,10 @@ Global
7591
{16C45DA5-D006-4229-B457-4F5E36D5DC55}.Debug|Any CPU.Build.0 = Debug|Any CPU
7692
{16C45DA5-D006-4229-B457-4F5E36D5DC55}.Debug|x64.ActiveCfg = Debug|x64
7793
{16C45DA5-D006-4229-B457-4F5E36D5DC55}.Debug|x64.Build.0 = Debug|x64
94+
{16C45DA5-D006-4229-B457-4F5E36D5DC55}.Debug-Minimal|Any CPU.ActiveCfg = Debug|Any CPU
95+
{16C45DA5-D006-4229-B457-4F5E36D5DC55}.Debug-Minimal|Any CPU.Build.0 = Debug|Any CPU
96+
{16C45DA5-D006-4229-B457-4F5E36D5DC55}.Debug-Minimal|x64.ActiveCfg = Debug|x64
97+
{16C45DA5-D006-4229-B457-4F5E36D5DC55}.Debug-Minimal|x64.Build.0 = Debug|x64
7898
{16C45DA5-D006-4229-B457-4F5E36D5DC55}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
7999
{16C45DA5-D006-4229-B457-4F5E36D5DC55}.Publish|Any CPU.Build.0 = Publish|Any CPU
80100
{16C45DA5-D006-4229-B457-4F5E36D5DC55}.Publish|x64.ActiveCfg = Publish|x64

src/NumSharp.Bitmap/NumSharp.Bitmap.csproj

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
2929
<Platforms>AnyCPU;x64</Platforms>
3030
<PackageLicenseFile>LICENSE</PackageLicenseFile>
31-
<Configurations>Debug;Release;Publish</Configurations>
31+
<Configurations>Debug;Release;Publish;Debug-Minimal</Configurations>
3232
</PropertyGroup>
3333

3434
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Publish|AnyCPU'">
@@ -57,13 +57,27 @@
5757
<PlatformTarget>x64</PlatformTarget>
5858
</PropertyGroup>
5959

60+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Minimal|AnyCPU'">
61+
<DefineConstants>TRACE;DEBUG</DefineConstants>
62+
<NoWarn>1701;1702;IDE1006;0029</NoWarn>
63+
<DocumentationFile />
64+
<PlatformTarget>x64</PlatformTarget>
65+
</PropertyGroup>
66+
6067
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
6168
<DefineConstants>TRACE;DEBUG;BIT64</DefineConstants>
6269
<NoWarn>1701;1702;IDE1006;0029</NoWarn>
6370
<DocumentationFile />
6471
<PlatformTarget>x64</PlatformTarget>
6572
</PropertyGroup>
6673

74+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Minimal|x64'">
75+
<DefineConstants>TRACE;DEBUG;BIT64</DefineConstants>
76+
<NoWarn>1701;1702;IDE1006;0029</NoWarn>
77+
<DocumentationFile />
78+
<PlatformTarget>x64</PlatformTarget>
79+
</PropertyGroup>
80+
6781
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
6882
<DocumentationFile></DocumentationFile>
6983
</PropertyGroup>

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

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -36,63 +36,24 @@ public static NDArray fromfile(string file, Type dtype)
3636
switch (dtype.GetTypeCode())
3737
{
3838
#if _REGEN
39-
%foreach supported_dtypes,supported_dtypes_lowercase%
40-
case NPTypeCode.#1:
41-
{
42-
return new NDArray(new ArraySlice<#2>(UnmanagedMemoryBlock<#2>.FromBuffer(bytes, false)));
43-
}
39+
%foreach supported_dtypes, supported_dtypes_lowercase%
40+
case NPTypeCode.#1: return new NDArray(new ArraySlice<#2>(UnmanagedMemoryBlock<#2>.FromBuffer(bytes, false)));
4441
%
4542
default:
4643
throw new NotSupportedException();
4744
#else
48-
case NPTypeCode.Boolean:
49-
{
50-
return new NDArray(new ArraySlice<bool>(UnmanagedMemoryBlock<bool>.FromBuffer(bytes, false)));
51-
}
52-
case NPTypeCode.Byte:
53-
{
54-
return new NDArray(new ArraySlice<byte>(UnmanagedMemoryBlock<byte>.FromBuffer(bytes, false)));
55-
}
56-
case NPTypeCode.Int16:
57-
{
58-
return new NDArray(new ArraySlice<short>(UnmanagedMemoryBlock<short>.FromBuffer(bytes, false)));
59-
}
60-
case NPTypeCode.UInt16:
61-
{
62-
return new NDArray(new ArraySlice<ushort>(UnmanagedMemoryBlock<ushort>.FromBuffer(bytes, false)));
63-
}
64-
case NPTypeCode.Int32:
65-
{
66-
return new NDArray(new ArraySlice<int>(UnmanagedMemoryBlock<int>.FromBuffer(bytes, false)));
67-
}
68-
case NPTypeCode.UInt32:
69-
{
70-
return new NDArray(new ArraySlice<uint>(UnmanagedMemoryBlock<uint>.FromBuffer(bytes, false)));
71-
}
72-
case NPTypeCode.Int64:
73-
{
74-
return new NDArray(new ArraySlice<long>(UnmanagedMemoryBlock<long>.FromBuffer(bytes, false)));
75-
}
76-
case NPTypeCode.UInt64:
77-
{
78-
return new NDArray(new ArraySlice<ulong>(UnmanagedMemoryBlock<ulong>.FromBuffer(bytes, false)));
79-
}
80-
case NPTypeCode.Char:
81-
{
82-
return new NDArray(new ArraySlice<char>(UnmanagedMemoryBlock<char>.FromBuffer(bytes, false)));
83-
}
84-
case NPTypeCode.Double:
85-
{
86-
return new NDArray(new ArraySlice<double>(UnmanagedMemoryBlock<double>.FromBuffer(bytes, false)));
87-
}
88-
case NPTypeCode.Single:
89-
{
90-
return new NDArray(new ArraySlice<float>(UnmanagedMemoryBlock<float>.FromBuffer(bytes, false)));
91-
}
92-
case NPTypeCode.Decimal:
93-
{
94-
return new NDArray(new ArraySlice<decimal>(UnmanagedMemoryBlock<decimal>.FromBuffer(bytes, false)));
95-
}
45+
case NPTypeCode.Boolean: return new NDArray(new ArraySlice<bool>(UnmanagedMemoryBlock<bool>.FromBuffer(bytes, false)));
46+
case NPTypeCode.Byte: return new NDArray(new ArraySlice<byte>(UnmanagedMemoryBlock<byte>.FromBuffer(bytes, false)));
47+
case NPTypeCode.Int16: return new NDArray(new ArraySlice<short>(UnmanagedMemoryBlock<short>.FromBuffer(bytes, false)));
48+
case NPTypeCode.UInt16: return new NDArray(new ArraySlice<ushort>(UnmanagedMemoryBlock<ushort>.FromBuffer(bytes, false)));
49+
case NPTypeCode.Int32: return new NDArray(new ArraySlice<int>(UnmanagedMemoryBlock<int>.FromBuffer(bytes, false)));
50+
case NPTypeCode.UInt32: return new NDArray(new ArraySlice<uint>(UnmanagedMemoryBlock<uint>.FromBuffer(bytes, false)));
51+
case NPTypeCode.Int64: return new NDArray(new ArraySlice<long>(UnmanagedMemoryBlock<long>.FromBuffer(bytes, false)));
52+
case NPTypeCode.UInt64: return new NDArray(new ArraySlice<ulong>(UnmanagedMemoryBlock<ulong>.FromBuffer(bytes, false)));
53+
case NPTypeCode.Char: return new NDArray(new ArraySlice<char>(UnmanagedMemoryBlock<char>.FromBuffer(bytes, false)));
54+
case NPTypeCode.Double: return new NDArray(new ArraySlice<double>(UnmanagedMemoryBlock<double>.FromBuffer(bytes, false)));
55+
case NPTypeCode.Single: return new NDArray(new ArraySlice<float>(UnmanagedMemoryBlock<float>.FromBuffer(bytes, false)));
56+
case NPTypeCode.Decimal: return new NDArray(new ArraySlice<decimal>(UnmanagedMemoryBlock<decimal>.FromBuffer(bytes, false)));
9657
default:
9758
throw new NotSupportedException();
9859
#endif

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,14 @@ private static Type GetType(string dtype, out int bytes, out bool? isLittleEndia
380380
return typeof(Int32);
381381
if (typeCode == "i8")
382382
return typeof(Int64);
383+
if (typeCode == "u1")
384+
return typeof(Byte);
385+
if (typeCode == "u2")
386+
return typeof(UInt16);
387+
if (typeCode == "u4")
388+
return typeof(UInt32);
389+
if (typeCode == "u8")
390+
return typeof(UInt64);
383391
if (typeCode == "f4")
384392
return typeof(Single);
385393
if (typeCode == "f8")

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ private static string GetDtypeFromType(Array array, out Type type, out int bytes
252252
return "<f4";
253253
if (type == typeof(Double))
254254
return "<f8";
255+
if (type == typeof(UInt16))
256+
return "<u2";
257+
if (type == typeof(UInt32))
258+
return "<u4";
259+
if (type == typeof(UInt64))
260+
return "<u8";
255261
if (type == typeof(String))
256262
return "|S" + bytes;
257263

@@ -301,12 +307,15 @@ public static void Save_Npz(Array array, string path, CompressionLevel compressi
301307

302308
public static void Save_Npz(Dictionary<string, Array> arrays, Stream stream, CompressionLevel compression = DEFAULT_COMPRESSION, bool leaveOpen = false)
303309
{
304-
using (var zip = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true))
310+
using (var zip = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: leaveOpen))
305311
{
306312
foreach (KeyValuePair<string, Array> p in arrays)
307313
{
308314
var entry = zip.CreateEntry(p.Key, compression);
309-
Save(p.Value, entry.Open());
315+
using (Stream s = entry.Open())
316+
{
317+
Save(p.Value, s);
318+
}
310319
}
311320
}
312321
}
@@ -316,7 +325,11 @@ public static void Save_Npz(Array array, Stream stream, CompressionLevel compres
316325
using (var zip = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: leaveOpen))
317326
{
318327
var entry = zip.CreateEntry("arr_0");
319-
Save(array, entry.Open());
328+
using (Stream s = entry.Open())
329+
{
330+
Save(array, s);
331+
}
332+
320333
}
321334
}
322335

0 commit comments

Comments
 (0)