Table of Contents

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

bool

IsNone

Gets whether the choice represents Python None.

public bool IsNone { get; }

Property Value

bool

Kind

Gets the Python scalar category of the stored value.

public CategoricalChoiceKind Kind { get; }

Property Value

CategoricalChoiceKind

None

Python None.

public static CategoricalChoice None { get; }

Property Value

CategoricalChoice

Value

The underlying value: null, bool, long, double or string.

public object? Value { get; }

Property Value

object

Methods

Equals(CategoricalChoice)

Python ==.

public bool Equals(CategoricalChoice other)

Parameters

other CategoricalChoice

Value 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

obj object

Object 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?)

Wraps an arbitrary value, normalizing numerics (all integrals → long, float → double).

public static CategoricalChoice From(object? value)

Parameters

value object

Scalar 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

left CategoricalChoice

Left operand of the comparison.

right CategoricalChoice

Right 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

value bool

Scalar 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

value double

Scalar 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

value int

Scalar 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

value long

Scalar 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

value string

Scalar 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

left CategoricalChoice

Left operand of the comparison.

right CategoricalChoice

Right operand of the comparison.

Returns

bool

True when the comparison holds.