Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Api/ApiUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static OpCode GetAssignmentOpCode(Type t)
// REVIEW: This should be a Dictionary<Type, OpCode> based solution.
// DvTypes, strings, arrays, all nullable types, VBuffers and UInt128.
if (t == typeof(DvInt8) || t == typeof(DvInt4) || t == typeof(DvInt2) || t == typeof(DvInt1) ||
t == typeof(DvBool) || t == typeof(DvText) || t == typeof(string) || t.IsArray ||
t == typeof(DvText) || t == typeof(string) || t.IsArray ||
(t.IsGenericType && t.GetGenericTypeDefinition() == typeof(VBuffer<>)) ||
(t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>)) ||
t == typeof(DvDateTime) || t == typeof(DvDateTimeZone) || t == typeof(DvTimeSpan) || t == typeof(UInt128))
Expand Down
17 changes: 3 additions & 14 deletions src/Microsoft.ML.Api/DataViewConstructionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,7 @@ private Delegate CreateGetter(int index)
else if (outputType.GetElementType() == typeof(bool))
{
Ch.Assert(colType.ItemType.IsBool);
return CreateConvertingArrayGetterDelegate<bool, DvBool>(index, x => x);
}
else if (outputType.GetElementType() == typeof(bool?))
{
Ch.Assert(colType.ItemType.IsBool);
return CreateConvertingArrayGetterDelegate<bool?, DvBool>(index, x => x ?? DvBool.NA);
return CreateConvertingArrayGetterDelegate<bool, bool>(index, x => x);

@Ivanidzo4ka Ivanidzo4ka Aug 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool [](start = 77, length = 4)

you don't have to do it.
just fall back to default T[] -> VBuffer code. #Resolved

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course.


In reply to: 211109130 [](ancestors = 211109130)

}

// T[] -> VBuffer<T>
Expand Down Expand Up @@ -210,15 +205,9 @@ private Delegate CreateGetter(int index)
}
else if (outputType == typeof(bool))
{
// Bool -> DvBool
Ch.Assert(colType.IsBool);
return CreateConvertingGetterDelegate<bool, DvBool>(index, x => x);
}
else if (outputType == typeof(bool?))
{
// Bool? -> DvBool
// Bool -> Bool.
Ch.Assert(colType.IsBool);
return CreateConvertingGetterDelegate<bool?, DvBool>(index, x => x ?? DvBool.NA);
return CreateConvertingGetterDelegate<bool, bool>(index, x => x);

@Ivanidzo4ka Ivanidzo4ka Aug 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return CreateConvertingGetterDelegate<bool, bool>(index, x => x); [](start = 27, length = 66)

not needed, fall back to T-> T default #Resolved

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep.


In reply to: 211109149 [](ancestors = 211109149)

}
else if (outputType == typeof(int))
{
Expand Down
15 changes: 2 additions & 13 deletions src/Microsoft.ML.Api/TypedCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,7 @@ private Action<TRow> GenerateSetter(IRow input, int index, InternalSchemaDefinit
else if (fieldType.GetElementType() == typeof(bool))
{
Ch.Assert(colType.ItemType.IsBool);
return CreateConvertingVBufferSetter<DvBool, bool>(input, index, poke, peek, x => (bool)x);
}
else if (fieldType.GetElementType() == typeof(bool?))
{
Ch.Assert(colType.ItemType.IsBool);
return CreateConvertingVBufferSetter<DvBool, bool?>(input, index, poke, peek, x => (bool?)x);
return CreateConvertingVBufferSetter<bool, bool>(input, index, poke, peek, x => x);

@Ivanidzo4ka Ivanidzo4ka Aug 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fall back to // VBuffer -> T[] #Resolved

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is correct.


In reply to: 211109159 [](ancestors = 211109159)

}
else if (fieldType.GetElementType() == typeof(int))
{
Expand Down Expand Up @@ -361,13 +356,7 @@ private Action<TRow> GenerateSetter(IRow input, int index, InternalSchemaDefinit
{
Ch.Assert(colType.IsBool);
Ch.Assert(peek == null);
return CreateConvertingActionSetter<DvBool, bool>(input, index, poke, x => (bool)x);
}
else if (fieldType == typeof(bool?))
{
Ch.Assert(colType.IsBool);
Ch.Assert(peek == null);
return CreateConvertingActionSetter<DvBool, bool?>(input, index, poke, x => (bool?)x);
return CreateConvertingActionSetter<bool, bool>(input, index, poke, x => x);

@Ivanidzo4ka Ivanidzo4ka Aug 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateConvertingActionSetter [](start = 31, length = 28)

fall back to // T -> T #Resolved

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

falling back ...


In reply to: 211109169 [](ancestors = 211109169)

}
else if (fieldType == typeof(int))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Data/ColumnType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public static BoolType Instance
}

private BoolType()
: base(typeof(DvBool), DataKind.BL)
: base(typeof(bool), DataKind.BL)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.ML.Core/Data/DataKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static Type ToType(this DataKind kind)
case DataKind.TX:
return typeof(DvText);
case DataKind.BL:
return typeof(DvBool);
return typeof(bool);
case DataKind.TS:
return typeof(DvTimeSpan);
case DataKind.DT:
Expand Down Expand Up @@ -207,7 +207,7 @@ public static bool TryGetDataKind(this Type type, out DataKind kind)
kind = DataKind.R8;
else if (type == typeof(DvText))
kind = DataKind.TX;
else if (type == typeof(DvBool) || type == typeof(bool) || type == typeof(bool?))
else if (type == typeof(bool))
kind = DataKind.BL;
else if (type == typeof(DvTimeSpan))
kind = DataKind.TS;
Expand Down
66 changes: 2 additions & 64 deletions src/Microsoft.ML.Core/Data/DvInt1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.ML.Runtime.Data
{
using BL = DvBool;
using BL = Boolean;
using I2 = DvInt2;
using I4 = DvInt4;
using I8 = DvInt8;
Expand Down Expand Up @@ -93,9 +93,7 @@ public static explicit operator RawIX(IX value)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator IX(BL a)
{
if (a.IsNA)
return RawNA;
return (RawIX)a.RawValue;
return Convert.ToSByte(a);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -200,65 +198,5 @@ public override string ToString()
return "NA";
return _value.ToString();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator ==(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av == bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator !=(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av != bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator <(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av < bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator <=(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av <= bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator >=(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av >= bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator >(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av > bv ? BL.True : BL.False;
return BL.NA;
}
}
}
66 changes: 2 additions & 64 deletions src/Microsoft.ML.Core/Data/DvInt2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.ML.Runtime.Data
{
using BL = DvBool;
using BL = Boolean;
using I1 = DvInt1;
using I4 = DvInt4;
using I8 = DvInt8;
Expand Down Expand Up @@ -93,9 +93,7 @@ public static explicit operator RawIX(IX value)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator IX(BL a)
{
if (a.IsNA)
return RawNA;
return (RawIX)a.RawValue;
return Convert.ToInt16(a);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -199,65 +197,5 @@ public override string ToString()
return "NA";
return _value.ToString();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator ==(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av == bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator !=(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av != bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator <(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av < bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator <=(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av <= bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator >=(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av >= bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator >(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av > bv ? BL.True : BL.False;
return BL.NA;
}
}
}
66 changes: 2 additions & 64 deletions src/Microsoft.ML.Core/Data/DvInt4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.ML.Runtime.Data
{
using BL = DvBool;
using BL = Boolean;
using I1 = DvInt1;
using I2 = DvInt2;
using I8 = DvInt8;
Expand Down Expand Up @@ -93,9 +93,7 @@ public static explicit operator RawIX(IX value)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator IX(BL a)
{
if (a.IsNA)
return RawNA;
return (RawIX)a.RawValue;
return Convert.ToInt32(a);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -199,66 +197,6 @@ public override string ToString()
return _value.ToString();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator ==(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av == bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator !=(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av != bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator <(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av < bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator <=(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av <= bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator >=(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av >= bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BL operator >(IX a, IX b)
{
var av = a._value;
var bv = b._value;
if (av != RawNA && bv != RawNA)
return av > bv ? BL.True : BL.False;
return BL.NA;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IX operator -(IX a)
{
Expand Down
Loading