Struct CategoricalChoice
- Namespace
- OptunaSharp.Distributions
- Assembly
- OptunaSharp.dll
A categorical parameter value — Python's
CategoricalChoiceType = Union[None, bool, int, float, str] as a value type.
Equality implements Python == semantics, which is a plan §2 ground rule:
True == 1, 1.0 == 1, nan != nan, and cross-type number/string
comparisons are false. This is the one place C# object equality would silently
diverge from Optuna, so it is pinned by dedicated tests.
public readonly struct CategoricalChoice : IEquatable<CategoricalChoice>
- Implements
- Inherited Members
Properties
IsNaN
True when the value is a real number whose float value is NaN (Python isinstance(v, Real) and math.isnan(float(v))).
public bool IsNaN { get; }
Property Value
IsNone
Gets whether the choice represents Python None.
public bool IsNone { get; }
Property Value
Kind
Gets the Python scalar category of the stored value.
public CategoricalChoiceKind Kind { get; }
Property Value
None
Python None.
public static CategoricalChoice None { get; }
Property Value
Value
public object? Value { get; }
Property Value
Methods
Equals(CategoricalChoice)
Python ==.
public bool Equals(CategoricalChoice other)
Parameters
otherCategoricalChoiceValue to compare with this instance; null compares unequal.
Returns
- bool
True for equal normalized values; NaN remains unequal to itself.
Equals(object?)
Compares categorical values using Python scalar equality.
public override bool Equals(object? obj)
Parameters
objobjectObject to compare with this instance.
Returns
- bool
True for equal normalized values; NaN remains unequal to itself.
Exceptions
- TypeError
An object operand has an unsupported categorical type or an unsigned value outside Int64.
From(object?)
public static CategoricalChoice From(object? value)
Parameters
valueobjectScalar to normalize as a categorical choice; null represents Python None.
Returns
- CategoricalChoice
A choice containing the normalized scalar, or the existing choice unchanged.
Exceptions
- TypeError
The value is unsupported, or an unsigned integer exceeds Int64.MaxValue.
GetHashCode()
Hashes equal Python numeric values alike across Boolean, integer, and float kinds.
public override int GetHashCode()
Returns
- int
Hash code consistent with supported categorical equality.
Repr()
Python repr(value) rendering (strings quoted).
public string Repr()
Returns
- string
Python repr-style text, quoting and escaping strings.
ToString()
Python str(value) rendering (None / True / 1.0 / raw string).
public override string ToString()
Returns
- string
Python str-style text, leaving strings unquoted.
Operators
operator ==(CategoricalChoice, CategoricalChoice)
Applies the == comparison using the type's value equality.
public static bool operator ==(CategoricalChoice left, CategoricalChoice right)
Parameters
leftCategoricalChoiceLeft operand of the comparison.
rightCategoricalChoiceRight operand of the comparison.
Returns
- bool
True when the comparison holds.
implicit operator CategoricalChoice(bool)
Wraps the scalar in the corresponding categorical representation.
public static implicit operator CategoricalChoice(bool value)
Parameters
valueboolScalar to normalize as a categorical choice; null represents Python None.
Returns
- CategoricalChoice
A normalized choice; a null string becomes None.
implicit operator CategoricalChoice(double)
Wraps the scalar in the corresponding categorical representation.
public static implicit operator CategoricalChoice(double value)
Parameters
valuedoubleScalar to normalize as a categorical choice; null represents Python None.
Returns
- CategoricalChoice
A normalized choice; a null string becomes None.
implicit operator CategoricalChoice(int)
Wraps the scalar in the corresponding categorical representation.
public static implicit operator CategoricalChoice(int value)
Parameters
valueintScalar to normalize as a categorical choice; null represents Python None.
Returns
- CategoricalChoice
A normalized choice; a null string becomes None.
implicit operator CategoricalChoice(long)
Wraps the scalar in the corresponding categorical representation.
public static implicit operator CategoricalChoice(long value)
Parameters
valuelongScalar to normalize as a categorical choice; null represents Python None.
Returns
- CategoricalChoice
A normalized choice; a null string becomes None.
implicit operator CategoricalChoice(string?)
Wraps the scalar in the corresponding categorical representation.
public static implicit operator CategoricalChoice(string? value)
Parameters
valuestringScalar to normalize as a categorical choice; null represents Python None.
Returns
- CategoricalChoice
A normalized choice; a null string becomes None.
operator !=(CategoricalChoice, CategoricalChoice)
Applies the != comparison using the type's value equality.
public static bool operator !=(CategoricalChoice left, CategoricalChoice right)
Parameters
leftCategoricalChoiceLeft operand of the comparison.
rightCategoricalChoiceRight operand of the comparison.
Returns
- bool
True when the comparison holds.