Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/3.0] fix #6949 #6953

Merged
merged 2 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions src/Microsoft.ML.Core/SearchSpace/BoolearnChoiceAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace Microsoft.ML.SearchSpace;

/// <summary>
/// Boolean choice attribute
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
public sealed class BooleanChoiceAttribute : Attribute
{
/// <summary>
/// Create a <see cref="BooleanChoiceAttribute"/>.
/// </summary>
public BooleanChoiceAttribute()
{
DefaultValue = true;
}

/// <summary>
/// Create a <see cref="BooleanChoiceAttribute"/> with default value.
/// </summary>
/// <param name="defaultValue">default value for this option.</param>
public BooleanChoiceAttribute(bool defaultValue)
{
DefaultValue = defaultValue;
}

public bool DefaultValue { get; }
}
50 changes: 50 additions & 0 deletions src/Microsoft.ML.Core/SearchSpace/ChoiceAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics.Contracts;
using System.Linq;

namespace Microsoft.ML.SearchSpace;

/// <summary>
/// Choice attribute
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
public sealed class ChoiceAttribute : Attribute
{
/// <summary>
/// Create a <see cref="ChoiceAttribute"/> with <paramref name="candidates"/>.
/// </summary>
public ChoiceAttribute(params object[] candidates)
{
var candidatesType = candidates.Select(o => o.GetType()).Distinct();
Contract.Assert(candidatesType.Count() == 1, "multiple candidates type detected");
this.Candidates = candidates;
this.DefaultValue = null;
}

/// <summary>
/// Create a <see cref="ChoiceAttribute"/> with <paramref name="candidates"/> and <paramref name="defaultValue"/>.
/// </summary>
public ChoiceAttribute(object[] candidates, object defaultValue)
{
var candidatesType = candidates.Select(o => o.GetType()).Distinct();
Contract.Assert(candidatesType.Count() == 1, "multiple candidates type detected");
Contract.Assert(candidatesType.First() == defaultValue.GetType(), "candidates type doesn't match with defaultValue type");

this.Candidates = candidates;
this.DefaultValue = defaultValue;
}

/// <summary>
/// Get the candidates of this option.
/// </summary>
public object[] Candidates { get; }

/// <summary>
/// Get the default value of this option.
/// </summary>
public object DefaultValue { get; }
}
21 changes: 21 additions & 0 deletions src/Microsoft.ML.Core/SearchSpace/NestOptionAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace Microsoft.ML.SearchSpace;

/// <summary>
/// attribution class for nest option.
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
public sealed class NestOptionAttribute : Attribute
{
/// <summary>
/// Create an <see cref="NestOptionAttribute"/>.
/// </summary>
public NestOptionAttribute()
{
}
}
88 changes: 88 additions & 0 deletions src/Microsoft.ML.Core/SearchSpace/RangeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace Microsoft.ML.SearchSpace;

/// <summary>
/// Range attribute
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
public sealed class RangeAttribute : Attribute
{
/// <summary>
/// Create a <see cref="RangeAttribute"/>
/// </summary>
public RangeAttribute(double min, double max, bool logBase = false)
{
this.Min = min;
this.Max = max;
this.Init = null;
this.LogBase = logBase;
}

/// <summary>
/// Create a <see cref="RangeAttribute"/>
/// </summary>
public RangeAttribute(double min, double max, double init, bool logBase = false)
{
this.Min = min;
this.Max = max;
this.Init = init;
this.LogBase = logBase;
}

/// <summary>
/// Create a <see cref="RangeAttribute"/>
/// </summary>
public RangeAttribute(int min, int max, bool logBase = false)
{
this.Min = min;
this.Max = max;
this.Init = null;
this.LogBase = logBase;
}

/// <summary>
/// Create a <see cref="RangeAttribute"/>
/// </summary>
public RangeAttribute(int min, int max, int init, bool logBase = false)
{
this.Min = min;
this.Max = max;
this.Init = init;
this.LogBase = logBase;
}

/// <summary>
/// Create a <see cref="RangeAttribute"/>
/// </summary>
public RangeAttribute(float min, float max, bool logBase = false)
{
this.Min = min;
this.Max = max;
this.Init = null;
this.LogBase = logBase;
}

/// <summary>
/// Create a <see cref="RangeAttribute"/>
/// </summary>
public RangeAttribute(float min, float max, float init, bool logBase = false)
{
this.Min = min;
this.Max = max;
this.Init = init;
this.LogBase = logBase;
}

public object Min { get; }

public object Max { get; }

public object Init { get; }

public bool LogBase { get; }
}
4 changes: 4 additions & 0 deletions src/Microsoft.ML.SearchSpace/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
[assembly: InternalsVisibleTo("Microsoft.ML.SearchSpace.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")]
[assembly: InternalsVisibleTo("Microsoft.ML.AutoML, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")]

[assembly: TypeForwardedTo(typeof(Microsoft.ML.SearchSpace.BooleanChoiceAttribute))]
[assembly: TypeForwardedTo(typeof(Microsoft.ML.SearchSpace.ChoiceAttribute))]
[assembly: TypeForwardedTo(typeof(Microsoft.ML.SearchSpace.NestOptionAttribute))]
[assembly: TypeForwardedTo(typeof(Microsoft.ML.SearchSpace.RangeAttribute))]
37 changes: 0 additions & 37 deletions src/Microsoft.ML.SearchSpace/Attribute/BooleanChoiceAttribute.cs

This file was deleted.

46 changes: 0 additions & 46 deletions src/Microsoft.ML.SearchSpace/Attribute/ChoiceAttribute.cs

This file was deleted.

22 changes: 0 additions & 22 deletions src/Microsoft.ML.SearchSpace/Attribute/NestOptionAttribute.cs

This file was deleted.

66 changes: 0 additions & 66 deletions src/Microsoft.ML.SearchSpace/Attribute/RangeAttribute.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.ML.Core\Microsoft.ML.Core.csproj" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
</ItemGroup>
</Project>
Loading