Skip to content

Commit 5ed54be

Browse files
committed
Remove ColumnType.RawKind.
Fix dotnet#1533
1 parent 0dd50fc commit 5ed54be

File tree

1 file changed

+29
-66
lines changed

1 file changed

+29
-66
lines changed

src/Microsoft.ML.Core/Data/ColumnType.cs

Lines changed: 29 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,6 @@ private protected ColumnType(Type rawType)
2525
{
2626
Contracts.CheckValue(rawType, nameof(rawType));
2727
RawType = rawType;
28-
RawType.TryGetDataKind(out var rawKind);
29-
RawKind = rawKind;
30-
}
31-
32-
/// <summary>
33-
/// Internal sub types can pass both the <paramref name="rawType"/> and <paramref name="rawKind"/> values.
34-
/// This asserts that they are consistent.
35-
/// </summary>
36-
private protected ColumnType(Type rawType, DataKind rawKind)
37-
{
38-
Contracts.AssertValue(rawType);
39-
#if DEBUG
40-
DataKind tmp;
41-
rawType.TryGetDataKind(out tmp);
42-
Contracts.Assert(tmp == rawKind);
43-
#endif
44-
RawType = rawType;
45-
RawKind = rawKind;
4628
}
4729

4830
/// <summary>
@@ -54,20 +36,11 @@ private protected ColumnType(Type rawType, DataKind rawKind)
5436
/// </summary>
5537
public Type RawType { get; }
5638

57-
/// <summary>
58-
/// The <see cref="DataKind"/> corresponding to <see cref="RawType"/>, if there is one (<c>default</c> otherwise).
59-
/// It is equivalent to the result produced by <see cref="DataKindExtensions.TryGetDataKind(Type, out DataKind)"/>.
60-
/// For external code it would be preferable to operate over <see cref="RawType"/>.
61-
/// </summary>
62-
[BestFriend]
63-
internal DataKind RawKind { get; }
64-
6539
// IEquatable<T> interface recommends also to override base class implementations of
6640
// Object.Equals(Object) and GetHashCode. In classes below where Equals(ColumnType other)
6741
// is effectively a referencial comparison, there is no need to override base class implementations
6842
// of Object.Equals(Object) (and GetHashCode) since its also a referencial comparison.
6943
public abstract bool Equals(ColumnType other);
70-
7144
}
7245

7346
/// <summary>
@@ -79,11 +52,6 @@ protected StructuredType(Type rawType)
7952
: base(rawType)
8053
{
8154
}
82-
83-
private protected StructuredType(Type rawType, DataKind rawKind)
84-
: base(rawType, rawKind)
85-
{
86-
}
8755
}
8856

8957
/// <summary>
@@ -99,12 +67,6 @@ protected PrimitiveType(Type rawType)
9967
"A " + nameof(PrimitiveType) + " cannot have a disposable " + nameof(RawType));
10068
}
10169

102-
private protected PrimitiveType(Type rawType, DataKind rawKind)
103-
: base(rawType, rawKind)
104-
{
105-
Contracts.Assert(!typeof(IDisposable).IsAssignableFrom(RawType));
106-
}
107-
10870
[BestFriend]
10971
internal static PrimitiveType FromKind(DataKind kind)
11072
{
@@ -155,7 +117,7 @@ public static TextType Instance
155117
}
156118

157119
private TextType()
158-
: base(typeof(ReadOnlyMemory<char>), DataKind.TX)
120+
: base(typeof(ReadOnlyMemory<char>))
159121
{
160122
}
161123

@@ -177,8 +139,8 @@ public sealed class NumberType : PrimitiveType
177139
{
178140
private readonly string _name;
179141

180-
private NumberType(DataKind kind, string name)
181-
: base(kind.ToType(), kind)
142+
private NumberType(Type rawType, string name)
143+
: base(rawType)
182144
{
183145
Contracts.AssertNonEmpty(name);
184146
_name = name;
@@ -190,7 +152,7 @@ public static NumberType I1
190152
get
191153
{
192154
if (_instI1 == null)
193-
Interlocked.CompareExchange(ref _instI1, new NumberType(DataKind.I1, "I1"), null);
155+
Interlocked.CompareExchange(ref _instI1, new NumberType(typeof(sbyte), "I1"), null);
194156
return _instI1;
195157
}
196158
}
@@ -201,7 +163,7 @@ public static NumberType U1
201163
get
202164
{
203165
if (_instU1 == null)
204-
Interlocked.CompareExchange(ref _instU1, new NumberType(DataKind.U1, "U1"), null);
166+
Interlocked.CompareExchange(ref _instU1, new NumberType(typeof(byte), "U1"), null);
205167
return _instU1;
206168
}
207169
}
@@ -212,7 +174,7 @@ public static NumberType I2
212174
get
213175
{
214176
if (_instI2 == null)
215-
Interlocked.CompareExchange(ref _instI2, new NumberType(DataKind.I2, "I2"), null);
177+
Interlocked.CompareExchange(ref _instI2, new NumberType(typeof(short), "I2"), null);
216178
return _instI2;
217179
}
218180
}
@@ -223,7 +185,7 @@ public static NumberType U2
223185
get
224186
{
225187
if (_instU2 == null)
226-
Interlocked.CompareExchange(ref _instU2, new NumberType(DataKind.U2, "U2"), null);
188+
Interlocked.CompareExchange(ref _instU2, new NumberType(typeof(ushort), "U2"), null);
227189
return _instU2;
228190
}
229191
}
@@ -234,7 +196,7 @@ public static NumberType I4
234196
get
235197
{
236198
if (_instI4 == null)
237-
Interlocked.CompareExchange(ref _instI4, new NumberType(DataKind.I4, "I4"), null);
199+
Interlocked.CompareExchange(ref _instI4, new NumberType(typeof(int), "I4"), null);
238200
return _instI4;
239201
}
240202
}
@@ -245,7 +207,7 @@ public static NumberType U4
245207
get
246208
{
247209
if (_instU4 == null)
248-
Interlocked.CompareExchange(ref _instU4, new NumberType(DataKind.U4, "U4"), null);
210+
Interlocked.CompareExchange(ref _instU4, new NumberType(typeof(uint), "U4"), null);
249211
return _instU4;
250212
}
251213
}
@@ -256,7 +218,7 @@ public static NumberType I8
256218
get
257219
{
258220
if (_instI8 == null)
259-
Interlocked.CompareExchange(ref _instI8, new NumberType(DataKind.I8, "I8"), null);
221+
Interlocked.CompareExchange(ref _instI8, new NumberType(typeof(long), "I8"), null);
260222
return _instI8;
261223
}
262224
}
@@ -267,7 +229,7 @@ public static NumberType U8
267229
get
268230
{
269231
if (_instU8 == null)
270-
Interlocked.CompareExchange(ref _instU8, new NumberType(DataKind.U8, "U8"), null);
232+
Interlocked.CompareExchange(ref _instU8, new NumberType(typeof(ulong), "U8"), null);
271233
return _instU8;
272234
}
273235
}
@@ -278,7 +240,7 @@ public static NumberType UG
278240
get
279241
{
280242
if (_instUG == null)
281-
Interlocked.CompareExchange(ref _instUG, new NumberType(DataKind.UG, "UG"), null);
243+
Interlocked.CompareExchange(ref _instUG, new NumberType(typeof(RowId), "UG"), null);
282244
return _instUG;
283245
}
284246
}
@@ -289,7 +251,7 @@ public static NumberType R4
289251
get
290252
{
291253
if (_instR4 == null)
292-
Interlocked.CompareExchange(ref _instR4, new NumberType(DataKind.R4, "R4"), null);
254+
Interlocked.CompareExchange(ref _instR4, new NumberType(typeof(float), "R4"), null);
293255
return _instR4;
294256
}
295257
}
@@ -300,7 +262,7 @@ public static NumberType R8
300262
get
301263
{
302264
if (_instR8 == null)
303-
Interlocked.CompareExchange(ref _instR8, new NumberType(DataKind.R8, "R8"), null);
265+
Interlocked.CompareExchange(ref _instR8, new NumberType(typeof(double), "R8"), null);
304266
return _instR8;
305267
}
306268
}
@@ -379,7 +341,7 @@ public static BoolType Instance
379341
}
380342

381343
private BoolType()
382-
: base(typeof(bool), DataKind.BL)
344+
: base(typeof(bool))
383345
{
384346
}
385347

@@ -411,7 +373,7 @@ public static DateTimeType Instance
411373
}
412374

413375
private DateTimeType()
414-
: base(typeof(DateTime), DataKind.DT)
376+
: base(typeof(DateTime))
415377
{
416378
}
417379

@@ -440,7 +402,7 @@ public static DateTimeOffsetType Instance
440402
}
441403

442404
private DateTimeOffsetType()
443-
: base(typeof(DateTimeOffset), DataKind.DZ)
405+
: base(typeof(DateTimeOffset))
444406
{
445407
}
446408

@@ -472,7 +434,7 @@ public static TimeSpanType Instance
472434
}
473435

474436
private TimeSpanType()
475-
: base(typeof(TimeSpan), DataKind.TS)
437+
: base(typeof(TimeSpan))
476438
{
477439
}
478440

@@ -506,7 +468,7 @@ public override bool Equals(ColumnType other)
506468
public sealed class KeyType : PrimitiveType
507469
{
508470
private KeyType(Type type, DataKind kind, ulong min, int count, bool contiguous)
509-
: base(type, kind)
471+
: base(type)
510472
{
511473
Contracts.AssertValue(type);
512474
Contracts.Assert(kind.ToType() == type);
@@ -623,17 +585,18 @@ public override bool Equals(object other)
623585

624586
public override int GetHashCode()
625587
{
626-
return Hashing.CombinedHash(RawKind.GetHashCode(), Contiguous, Min, Count);
588+
return Hashing.CombinedHash(RawType.GetHashCode(), Contiguous, Min, Count);
627589
}
628590

629591
public override string ToString()
630592
{
593+
DataKind rawKind = this.GetRawKind();
631594
if (Count > 0)
632-
return string.Format("Key<{0}, {1}-{2}>", RawKind.GetString(), Min, Min + (ulong)Count - 1);
595+
return string.Format("Key<{0}, {1}-{2}>", rawKind.GetString(), Min, Min + (ulong)Count - 1);
633596
if (Contiguous)
634-
return string.Format("Key<{0}, {1}-*>", RawKind.GetString(), Min);
597+
return string.Format("Key<{0}, {1}-*>", rawKind.GetString(), Min);
635598
// This is the non-contiguous case - simply show the Min.
636-
return string.Format("Key<{0}, Min:{1}>", RawKind.GetString(), Min);
599+
return string.Format("Key<{0}, Min:{1}>", rawKind.GetString(), Min);
637600
}
638601
}
639602

@@ -642,7 +605,7 @@ public override string ToString()
642605
/// </summary>
643606
public sealed class VectorType : StructuredType
644607
{
645-
/// <summary>b
608+
/// <summary>
646609
/// The dimensions. This will always have at least one item. All values will be non-negative.
647610
/// As with <see cref="Size"/>, a zero value indicates that the vector type is considered to have
648611
/// unknown length along that dimension.
@@ -655,7 +618,7 @@ public sealed class VectorType : StructuredType
655618
/// <param name="itemType">The type of the items contained in the vector.</param>
656619
/// <param name="size">The size of the single dimension.</param>
657620
public VectorType(PrimitiveType itemType, int size = 0)
658-
: base(GetRawType(itemType), 0)
621+
: base(GetRawType(itemType))
659622
{
660623
Contracts.CheckParam(size >= 0, nameof(size));
661624

@@ -672,7 +635,7 @@ public VectorType(PrimitiveType itemType, int size = 0)
672635
/// non-negative values. Also, because <see cref="Size"/> is the product of <see cref="Dimensions"/>, the result of
673636
/// multiplying all these values together must not overflow <see cref="int"/>.</param>
674637
public VectorType(PrimitiveType itemType, params int[] dimensions)
675-
: base(GetRawType(itemType), default)
638+
: base(GetRawType(itemType))
676639
{
677640
Contracts.CheckParam(Utils.Size(dimensions) > 0, nameof(dimensions));
678641
Contracts.CheckParam(dimensions.All(d => d >= 0), nameof(dimensions));
@@ -687,7 +650,7 @@ public VectorType(PrimitiveType itemType, params int[] dimensions)
687650
/// </summary>
688651
[BestFriend]
689652
internal VectorType(PrimitiveType itemType, VectorType template)
690-
: base(GetRawType(itemType), default)
653+
: base(GetRawType(itemType))
691654
{
692655
Contracts.CheckValue(template, nameof(template));
693656

@@ -702,7 +665,7 @@ internal VectorType(PrimitiveType itemType, VectorType template)
702665
/// </summary>
703666
[BestFriend]
704667
internal VectorType(PrimitiveType itemType, VectorType template, params int[] dims)
705-
: base(GetRawType(itemType), default)
668+
: base(GetRawType(itemType))
706669
{
707670
Contracts.CheckValue(template, nameof(template));
708671
Contracts.CheckParam(Utils.Size(dims) > 0, nameof(dims));

0 commit comments

Comments
 (0)