Skip to content

Commit ec498d8

Browse files
[release/3.0] fix #6949 (#6953)
* fix #6949 * add MoveForwardToAttribute to assembly.cs and fix search space sub namespace --------- Co-authored-by: XiaoYun Zhang <[email protected]>
1 parent a5b5c7a commit ec498d8

File tree

13 files changed

+226
-185
lines changed

13 files changed

+226
-185
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
namespace Microsoft.ML.SearchSpace;
8+
9+
/// <summary>
10+
/// Boolean choice attribute
11+
/// </summary>
12+
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
13+
public sealed class BooleanChoiceAttribute : Attribute
14+
{
15+
/// <summary>
16+
/// Create a <see cref="BooleanChoiceAttribute"/>.
17+
/// </summary>
18+
public BooleanChoiceAttribute()
19+
{
20+
DefaultValue = true;
21+
}
22+
23+
/// <summary>
24+
/// Create a <see cref="BooleanChoiceAttribute"/> with default value.
25+
/// </summary>
26+
/// <param name="defaultValue">default value for this option.</param>
27+
public BooleanChoiceAttribute(bool defaultValue)
28+
{
29+
DefaultValue = defaultValue;
30+
}
31+
32+
public bool DefaultValue { get; }
33+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Diagnostics.Contracts;
7+
using System.Linq;
8+
9+
namespace Microsoft.ML.SearchSpace;
10+
11+
/// <summary>
12+
/// Choice attribute
13+
/// </summary>
14+
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
15+
public sealed class ChoiceAttribute : Attribute
16+
{
17+
/// <summary>
18+
/// Create a <see cref="ChoiceAttribute"/> with <paramref name="candidates"/>.
19+
/// </summary>
20+
public ChoiceAttribute(params object[] candidates)
21+
{
22+
var candidatesType = candidates.Select(o => o.GetType()).Distinct();
23+
Contract.Assert(candidatesType.Count() == 1, "multiple candidates type detected");
24+
this.Candidates = candidates;
25+
this.DefaultValue = null;
26+
}
27+
28+
/// <summary>
29+
/// Create a <see cref="ChoiceAttribute"/> with <paramref name="candidates"/> and <paramref name="defaultValue"/>.
30+
/// </summary>
31+
public ChoiceAttribute(object[] candidates, object defaultValue)
32+
{
33+
var candidatesType = candidates.Select(o => o.GetType()).Distinct();
34+
Contract.Assert(candidatesType.Count() == 1, "multiple candidates type detected");
35+
Contract.Assert(candidatesType.First() == defaultValue.GetType(), "candidates type doesn't match with defaultValue type");
36+
37+
this.Candidates = candidates;
38+
this.DefaultValue = defaultValue;
39+
}
40+
41+
/// <summary>
42+
/// Get the candidates of this option.
43+
/// </summary>
44+
public object[] Candidates { get; }
45+
46+
/// <summary>
47+
/// Get the default value of this option.
48+
/// </summary>
49+
public object DefaultValue { get; }
50+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
namespace Microsoft.ML.SearchSpace;
8+
9+
/// <summary>
10+
/// attribution class for nest option.
11+
/// </summary>
12+
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
13+
public sealed class NestOptionAttribute : Attribute
14+
{
15+
/// <summary>
16+
/// Create an <see cref="NestOptionAttribute"/>.
17+
/// </summary>
18+
public NestOptionAttribute()
19+
{
20+
}
21+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
namespace Microsoft.ML.SearchSpace;
8+
9+
/// <summary>
10+
/// Range attribute
11+
/// </summary>
12+
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
13+
public sealed class RangeAttribute : Attribute
14+
{
15+
/// <summary>
16+
/// Create a <see cref="RangeAttribute"/>
17+
/// </summary>
18+
public RangeAttribute(double min, double max, bool logBase = false)
19+
{
20+
this.Min = min;
21+
this.Max = max;
22+
this.Init = null;
23+
this.LogBase = logBase;
24+
}
25+
26+
/// <summary>
27+
/// Create a <see cref="RangeAttribute"/>
28+
/// </summary>
29+
public RangeAttribute(double min, double max, double init, bool logBase = false)
30+
{
31+
this.Min = min;
32+
this.Max = max;
33+
this.Init = init;
34+
this.LogBase = logBase;
35+
}
36+
37+
/// <summary>
38+
/// Create a <see cref="RangeAttribute"/>
39+
/// </summary>
40+
public RangeAttribute(int min, int max, bool logBase = false)
41+
{
42+
this.Min = min;
43+
this.Max = max;
44+
this.Init = null;
45+
this.LogBase = logBase;
46+
}
47+
48+
/// <summary>
49+
/// Create a <see cref="RangeAttribute"/>
50+
/// </summary>
51+
public RangeAttribute(int min, int max, int init, bool logBase = false)
52+
{
53+
this.Min = min;
54+
this.Max = max;
55+
this.Init = init;
56+
this.LogBase = logBase;
57+
}
58+
59+
/// <summary>
60+
/// Create a <see cref="RangeAttribute"/>
61+
/// </summary>
62+
public RangeAttribute(float min, float max, bool logBase = false)
63+
{
64+
this.Min = min;
65+
this.Max = max;
66+
this.Init = null;
67+
this.LogBase = logBase;
68+
}
69+
70+
/// <summary>
71+
/// Create a <see cref="RangeAttribute"/>
72+
/// </summary>
73+
public RangeAttribute(float min, float max, float init, bool logBase = false)
74+
{
75+
this.Min = min;
76+
this.Max = max;
77+
this.Init = init;
78+
this.LogBase = logBase;
79+
}
80+
81+
public object Min { get; }
82+
83+
public object Max { get; }
84+
85+
public object Init { get; }
86+
87+
public bool LogBase { get; }
88+
}

src/Microsoft.ML.SearchSpace/Assembly.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
[assembly: InternalsVisibleTo("Microsoft.ML.SearchSpace.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")]
99
[assembly: InternalsVisibleTo("Microsoft.ML.AutoML, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")]
1010

11+
[assembly: TypeForwardedTo(typeof(Microsoft.ML.SearchSpace.BooleanChoiceAttribute))]
12+
[assembly: TypeForwardedTo(typeof(Microsoft.ML.SearchSpace.ChoiceAttribute))]
13+
[assembly: TypeForwardedTo(typeof(Microsoft.ML.SearchSpace.NestOptionAttribute))]
14+
[assembly: TypeForwardedTo(typeof(Microsoft.ML.SearchSpace.RangeAttribute))]

src/Microsoft.ML.SearchSpace/Attribute/BooleanChoiceAttribute.cs

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

src/Microsoft.ML.SearchSpace/Attribute/ChoiceAttribute.cs

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

src/Microsoft.ML.SearchSpace/Attribute/NestOptionAttribute.cs

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

src/Microsoft.ML.SearchSpace/Attribute/RangeAttribute.cs

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

src/Microsoft.ML.SearchSpace/Microsoft.ML.SearchSpace.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12+
<ProjectReference Include="..\Microsoft.ML.Core\Microsoft.ML.Core.csproj" />
1213
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
1314
</ItemGroup>
1415
</Project>

0 commit comments

Comments
 (0)