Skip to content

Function Units

isa_manim.isa_objects.func_unit presents one function unit in ISA flow. This object can be used to present one operator (like +/-) or one predefined function (like max/min).

This object provides the name of the function, as well as input arguments and output results. One function unit can have as many input arguments and output results as necessary.

Source code: test_func_unit.py

As shown in the above figure, one function unit contains the following Manim objects: - func_rect presents the function unit. - The width of func_rect should cover all source and destination operands. - name_text presents the name of the function unit, which centrally aligns with func_rect. - args_rect_list and res_rect_list present the group of source operands and the group of destination operands. - Each operand is presented by one dot rectangle. - The width of each rectangle in args_rect_list and res_rect_list presents the bit width of the corresponding operand. - args_text_list and res_text_list present the group of names of source operands and the group of names of destination operands. - One Text item in args_text_list and res_rect_list horizontally aligns with the corresponding rectangle in args_rect_list and res_rect_list. The Text item is also vertically below the corresponding rectangle.

The height of func_rect, args_rect_list, res_rect_list is 1.0. Then, a gap of 1.0 is added between these Manim objects in veritial. So, the total height of one function unit is 5.0.

The origin point is located in the center position of func_ellipse. The function unit is symmetrical about the center of the origin.

Function get_arg_pos and get_res_pos return the position of one specified source and destination operand separately. The bit width of the specified element can be different from the bit width of the operand.

The function unit maintains one pointer to function in func_callee. The assigned function can be one complete function or an inline function (lambda function). When performing function calling animations, the assigned function can operate on the value from element units of source operands and return the output value. Member functions cannot be assigned to func_callee because positional operation self cannot be passed to func_callee.

FunctionUnit

Bases: VGroup

Object for one function unit.

Attributes:

Name Type Description
func_rect RoundedRectangle

Round rectangle of function unit.

name_text Text

Text of name of function unit locating at the center of func_rect.

args_rect_list List[Rectangle]

List of rectangle of source operands.

args_text_list List[Text]

List of text of name of source operands.

res_rect_list List[Rectangle]

List of rectangle of destination operands.

res_text_list List[Text]

List of text of name of destination operands.

func_name str

Function name.

func_color Color

Color of function rectangle, operand rectangles and operand name label.

func_font_size int

Font size of function rectangle.

func_value_format str

Format string for result values. Inherented by element units.

func_callee Callable

Pointer to function that perform the functionality of this unit.

func_args_width_list List[int]

List of bit width of source operands.

func_args_name_list List[str]

List of name of source operands.

func_res_width_list List[int]

List of bit width of destination operands.

func_res_name_list List[str]

List of name of destination operands.

func_args_count int

Number of source operands

func_res_count int

Number of destination operands.

require_serialization = True class-attribute instance-attribute

Animation related with this object must be serialized.

__init__(name, color, args_width_list, res_width_list, args_name_list, res_name_list, font_size, value_format, func_callee)

Constructor a function call.

Parameters:

Name Type Description Default
name str

Function name.

required
color Color

Color of function rectangle, operand rectangles and operand name label.

required
args_width_list List[int]

List of bit width of source operands.

required
res_width_list List[int]

List of bit width of destination operands.

required
args_name_list List[str]

List of name of source operands.

required
res_name_list List[str]

List of name of destination operands.

required
font_size int

Font size of function rectangle.

required
value_format str

Format string for result values.

required
func_callee Callable

Pointer to function that perform the functionality of this unit.

required

__repr__()

Return a string for debugging.

Returns:

Type Description
str

A string for debugging.

__str__()

Return a string for debugging.

Returns:

Type Description
str

A string for debugging.

get_arg_pos(index, offset, elem_width)

Return the center position of one specified source operand.

elem_width specifies the bit width of generated element unit, which equals the bit width of operand in most case. It is possible that generated element unit only cover a part of the specified operands.

Parameters:

Name Type Description Default
index int

Index of source operand.

required
offset int

Offset of lower bits.

required
elem_width int

Width of element in bits.

required

Returns:

Type Description
ndarray

Position of the specified source operand.

get_placement_height()

Return the height of this object for placement. The height is ceil to an integer.

Returns:

Type Description
int

The height of this object.

get_placement_mark()

Return the marker of this object for placement, which is 3.

Returns:

Type Description
int

Marker of this object.

get_placement_width()

Return the width of this object for placement. The width is ceil to an integer.

Returns:

Type Description
int

The width of this object.

get_res_pos(index, offset, elem_width)

Return the center position of one specified destination operand.

elem_width specifies the bit width of generated element unit, which equals the bit width of operand in most case. It is possible that generated element unit only cover a part of the specified operands. For example, 16-bit multiple operation generate 32-bit result.

  • The whole destination operand is accessed if index is 0, offset is 0 and elem_width is 16.
  • Lower half of the product is accessed if index is 0, offset is 0 and elem_width is 16.
  • Higher half of the product is accessed if index is 0, offset is 16 and elem_width is 16.

Parameters:

Name Type Description Default
index int

Index of destination operand.

required
offset int

Offset of lower bits.

required
elem_width int

Width of element in bits.

required

Returns:

Type Description
ndarray

Position of the specified destination operand.

set_placement_corner(row, col)

Set the position of object by the left-up corner position. Move object to the specified position.

Parameters:

Name Type Description Default
row int

Vertical ordinate of left-up corner.

required
col int

Horizontal ordinate of left-up corner.

required