Skip to content

Operation

Operation

Methods for numeric operations, string manipulation, and other functions.

fl.Op is a shortcut to this class.

Attributes

isinf class-attribute instance-attribute

isinf = isinf

isnan class-attribute instance-attribute

isnan = isnan

Functions

arity_of staticmethod

arity_of(method: Callable) -> int

Gets the arity of the method.

Parameters:

Name Type Description Default
method Callable

method to get the arity from

required

Returns:

Type Description
int

arity of the method.

as_identifier staticmethod

as_identifier(name: str) -> str

Convert the name into a valid FuzzyLite and Python identifier by removing non-alphanumeric characters and prepending _ to names starting with a number.

Parameters:

Name Type Description Default
name str

name to convert

required

Returns:

Type Description
str

name as a valid identifier.

bound staticmethod

bound(x: Scalar, minimum: float, maximum: float) -> Scalar

Return \(x\) clipped between [minimum, maximum].

Parameters:

Name Type Description Default
x Scalar

value to be clipped

required
minimum float

minimum value of the range

required
maximum float

maximum value of the range

required

Returns:

Type Description
Scalar
\[\begin{cases} \min & \mbox{if $x < \min$} \cr \max & \mbox{if $x > \max$} \cr x & \mbox{otherwise} \end{cases}\]

class_name staticmethod

class_name(x: Any, /, qualname: bool = False) -> str

Return the class name of the object.

Parameters:

Name Type Description Default
x Any

object to get the class name

required
qualname bool

use fully qualified classes

False

Returns:

Type Description
str

class name of the given object.

describe staticmethod

describe(instance: object, variables: bool = True, class_hierarchy: bool = False) -> str

Describe the instance based on its variables and class hierarchy.

Parameters:

Name Type Description Default
instance object

instance to describe

required
variables bool

include variables in the description

True
class_hierarchy bool

include class hierarchy in the description.

False

Returns:

Type Description
str

description of the instance

eq staticmethod

eq(a: Scalar, b: Scalar) -> Scalar

Return \(a = b\) (with NaN's as equal).

Parameters:

Name Type Description Default
a Scalar

scalar

required
b Scalar

scalar

required

Returns:

Type Description
Scalar

\(a=b\)

ge staticmethod

ge(a: Scalar, b: Scalar) -> Scalar

Return \(a \ge b\) (with NaN's as equal).

Parameters:

Name Type Description Default
a Scalar

scalar

required
b Scalar

scalar

required

Returns:

Type Description
Scalar

\(a \ge b\)

glob_examples staticmethod

glob_examples(
    return_type: (
        Literal["module"]
        | Literal["engine"]
        | Literal["dataset"]
        | Literal["fld"]
        | Literal["language"]
        | Literal["fll"]
        | Literal["files"]
    ) = "engine",
    module: ModuleType | None = None,
    recursive: bool = True,
) -> Iterable[ModuleType | Engine | ScalarArray | str | Path]

Glob the examples (alphabetically and in ascending order) returning the specified type.

Parameters:

Name Type Description Default
return_type Literal['module'] | Literal['engine'] | Literal['dataset'] | Literal['fld'] | Literal['language'] | Literal['fll'] | Literal['files']

type of objects to return

'engine'
module ModuleType | None

package (eg, fuzzylite.examples) or module (eg, fuzzylite.examples.terms.arc) to glob

None
recursive bool

recursively glob into subdirectories

True

Yields:

Type Description
Iterable[ModuleType | Engine | ScalarArray | str | Path]

Iterable of the specified type.

gt staticmethod

gt(a: Scalar, b: Scalar) -> Scalar

Return \(a > b\).

Parameters:

Name Type Description Default
a Scalar

scalar

required
b Scalar

scalar

required

Returns:

Type Description
Scalar

\(a>b\)

increment staticmethod

increment(x: list[int], minimum: list[int], maximum: list[int], position: int | None = None) -> bool

Increment the list by the unit.

Parameters:

Name Type Description Default
x list[int]

list to increment

required
minimum list[int]

list of minimum values for each element in the list

required
maximum list[int]

list of maximum values for each element in the list

required
position int | None

position in the list to increment

None

Returns:

Type Description
bool

whether the list was incremented.

is_close staticmethod

is_close(a: Scalar, b: Scalar) -> bool | Array[bool_]

Return \(a \approx b\) (with NaN's as equal) using the absolute and relative tolerances of the library.

Parameters:

Name Type Description Default
a Scalar

scalar

required
b Scalar

scalar

required

Returns:

Type Description
bool | Array[bool_]

\(a \approx b\)

related

le staticmethod

le(a: Scalar, b: Scalar) -> Scalar

Return \(a \le b\) (with NaN's as equal).

Parameters:

Name Type Description Default
a Scalar

scalar

required
b Scalar

scalar

required

Returns:

Type Description
Scalar

\(a \le b\)

lt staticmethod

lt(a: Scalar, b: Scalar) -> Scalar

Return \(a < b\).

Parameters:

Name Type Description Default
a Scalar

scalar

required
b Scalar

scalar

required

Returns:

Type Description
Scalar

\(a < b\)

midpoints staticmethod

midpoints(start: float, end: float, resolution: int = 1000) -> ScalarArray

Return the list of values in the range at the given resolution using the midpoint rule.

Parameters:

Name Type Description Default
start float

start of range

required
end float

end of range

required
resolution int

number of divisions to discretize the range

1000

Returns:

Type Description
ScalarArray

list of values in the range at the given resolution using the midpoint rule

neq staticmethod

neq(a: Scalar, b: Scalar) -> Scalar

Return \(a \not= b\) (with NaN's as equal).

Parameters:

Name Type Description Default
a Scalar

scalar

required
b Scalar

scalar

required

Returns:

Type Description
Scalar

\(a\not=b\)

pascal_case staticmethod

pascal_case(text: str) -> str

Converts the string to PascalCase.

Parameters:

Name Type Description Default
text str

any string

required

Returns:

Type Description
str

text in PascalCase

scale staticmethod

scale(x: Scalar, x_min: float, x_max: float, y_min: float, y_max: float) -> Scalar

Linearly interpolates \(x\) from the source range [from_minimum, from_maximum] to its new value in the target range [to_minimum, to_maximum].

Parameters:

Name Type Description Default
x Scalar

value to interpolate

required
x_min float

minimum value of the source range

required
x_max float

maximum value of the source range

required
y_min float

minimum value of the target range

required
y_max float

maximum value of the target range

required

Returns:

Type Description
Scalar

\(x\) linearly interpolated to the target range as: \(y = \dfrac{y_\max - y_\min}{x_\max-x_\min} (x-x_\min) + y_\min\)

snake_case staticmethod

snake_case(text: str) -> str

Converts the string to snake_case.

Parameters:

Name Type Description Default
text str

any string

required

Returns:

Type Description
str

text in snake_case

str staticmethod

str(x: Any, /, delimiter: str = ' ') -> str

Returns a string representation of the value.

Parameters:

Name Type Description Default
x Any

value

required
delimiter str

delimiter to use when x is a Sequence or ScalarArray

' '

Returns:

Type Description
str

string representation of the value.

strip_comments staticmethod

strip_comments(fll: str, /, delimiter: str = '#') -> str

Remove the comments from the text.

Parameters:

Name Type Description Default
fll str

text to strip comments from

required
delimiter str

delimiter that indicates the start of a comment.

'#'

Returns:

Type Description
str

text with comments stripped out.

to_fll staticmethod

to_fll(x: Any) -> str

Return the string representation of the object in the FuzzyLite Language.

Parameters:

Name Type Description Default
x Any

object

required

Returns:

Type Description
str

string representation of the object in the FuzzyLite Language.