Skip to content

Commit 6e2ecd4

Browse files
committed
Address comment
1 parent 41f56e9 commit 6e2ecd4

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

src/Microsoft.ML.Data/Dirty/ChooseColumnsByIndexTransform.cs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ private sealed class Bindings
4040
// relations between input and output schemas.
4141
private readonly Schema _sourceSchema;
4242

43+
// Variable used for saving in backward-compatible format. It's not needed actually.
44+
private readonly bool _drop;
45+
4346
// This transform's output schema.
4447
internal Schema OutputSchema { get; }
4548

@@ -49,6 +52,7 @@ internal Bindings(Arguments args, Schema sourceSchema)
4952
Contracts.AssertValue(sourceSchema);
5053

5154
_sourceSchema = sourceSchema;
55+
_drop = args.Drop;
5256

5357
if (args.Drop)
5458
// Drop columns indexed by args.Index
@@ -64,29 +68,16 @@ internal Bindings(Arguments args, Schema sourceSchema)
6468
OutputSchema = ComputeOutputSchema();
6569
}
6670

67-
internal Bindings(ModelLoadContext ctx, Schema sourceSchema)
68-
{
69-
Contracts.AssertValue(ctx);
70-
Contracts.AssertValue(sourceSchema);
71-
72-
// *** Binary format ***
73-
// int[]: selected source column indices
74-
_sources = ctx.Reader.ReadIntArray();
75-
76-
_sourceSchema = sourceSchema;
77-
OutputSchema = ComputeOutputSchema();
78-
}
79-
8071
/// <summary>
81-
/// After _input and _sources are set, pick up selected columns from _input to create output schema.
82-
/// Note that _sources tells us what columns in _input are selected.
72+
/// After <see cref="_sourceSchema"/> and <see cref="_sources"/> are set, pick up selected columns from <see cref="_sourceSchema"/> to create <see cref="OutputSchema"/>
73+
/// Note that <see cref="_sources"/> tells us what columns in <see cref="_sourceSchema"/> are put into <see cref="OutputSchema"/>.
8374
/// </summary>
8475
private Schema ComputeOutputSchema()
8576
{
8677
var schemaBuilder = new SchemaBuilder();
8778
for (int i = 0; i < _sources.Length; ++i)
8879
{
89-
// selectedIndex is an column index of input schema. Note that the input column indexed by _sources[i] in _input is sent
80+
// selectedIndex is an column index of input schema. Note that the input column indexed by _sources[i] in _sourceSchema is sent
9081
// to the i-th column in the output schema.
9182
var selectedIndex = _sources[i];
9283

@@ -101,12 +92,29 @@ private Schema ComputeOutputSchema()
10192
return schemaBuilder.GetSchema();
10293
}
10394

95+
internal Bindings(ModelLoadContext ctx, Schema sourceSchema)
96+
{
97+
Contracts.AssertValue(ctx);
98+
Contracts.AssertValue(sourceSchema);
99+
100+
// *** Binary format ***
101+
// bool (as byte): operation mode
102+
// int[]: selected source column indices
103+
_drop = ctx.Reader.ReadBoolByte();
104+
_sources = ctx.Reader.ReadIntArray();
105+
106+
_sourceSchema = sourceSchema;
107+
OutputSchema = ComputeOutputSchema();
108+
}
109+
104110
internal void Save(ModelSaveContext ctx)
105111
{
106112
Contracts.AssertValue(ctx);
107113

108114
// *** Binary format ***
115+
// bool (as byte): operation mode
109116
// int[]: selected source column indices
117+
ctx.Writer.WriteBoolByte(_drop);
110118
ctx.Writer.WriteIntArray(_sources);
111119
}
112120

@@ -139,9 +147,9 @@ private static VersionInfo GetVersionInfo()
139147
{
140148
return new VersionInfo(
141149
modelSignature: "CHSCOLIF",
142-
verWrittenCur: 0x00010002,
143-
verReadableCur: 0x00010002,
144-
verWeCanReadBack: 0x00010002,
150+
verWrittenCur: 0x00010001, // Initial
151+
verReadableCur: 0x00010001,
152+
verWeCanReadBack: 0x00010001,
145153
loaderSignature: LoaderSignature,
146154
loaderSignatureAlt: LoaderSignatureOld,
147155
loaderAssemblyName: typeof(ChooseColumnsByIndexTransform).Assembly.FullName);

0 commit comments

Comments
 (0)