Skip to content

Int ​

SUMMARY

An integer scalar value.

python
from telekinesis import datatypes
value = datatypes.Int(42)
API Reference
Complete API documentation for Int, including parameters, attributes, and methods.
View Reference →

Parameters ​

ParameterTypeDefaultDescription
dataint | floatRequiredThe value to store. A float must be integral (e.g. 3.0).

Raises ​

ExceptionCondition
TypeErrordata is a bool or any other non-numeric type
ValueErrordata is a float with a fractional part

Attributes ​

AttributeTypeDescription
dataintThe wrapped value. Since int is immutable, no copying is ever required — reading data returns the normalized value directly. Assigning a new value re-validates it the same way as construction.

Methods ​

MethodTypeDescription
Int.coerce(value, name="value")IntConverts an int or whole-number float into an Int. If value is already an Int, it is returned unchanged. The optional name is only used to make validation error messages more descriptive. A float with a fractional part (e.g. 3.5) isn't accepted, and bool values are rejected even though they're technically ints.

Operators ​

OperationReturns
bool(a)bool
int(a)int
float(a)float
range(a)Works, via __index__
a + bInt or Float
a - bInt or Float
a * bInt or Float
a / bFloat
a // bInt or Float
a % bInt or Float
-aInt
+aInt
abs(a)Int
a == bbool
a != bbool
a < bbool
a <= bbool
a > bbool
a >= bbool

Int supports standard numeric arithmetic, comparisons, and conversions. Arithmetic operators accept Int, Float, int, or float operands. Results remain Int when the operation stays integral, and otherwise produce Float. Int also supports integer-style indexing, so it can be used with operations such as range().

Visualization ​

python
import rerun as rr

# Your code block
# ....

rr.init("int_example", spawn=True)
datatypes.visualize(value, entity_path="/value", label="Int")

Example ​

python
"""Demonstrates the Telekinesis Int datatype."""

import time

import rerun as rr
from loguru import logger

from telekinesis import datatypes

def int_example():
    """Demonstrate creation, inspection, operations, visualization, and serialization."""

    # ======================= Create ============================================
    value = datatypes.Int(42)
    logger.info(f"Created Int: {value}")

    coerced = datatypes.Int.coerce(7.0)
    logger.info(f"Int coerced from float: {coerced}")

    # ======================= Inspect ===========================================
    logger.info(f"data={value.data}")

    # ======================= Operations ========================================
    value.data = 100
    logger.info(f"Updated Int: {value}")

    other = datatypes.Int(58)

    logger.info(f"{value} + {other} = {value + other}")
    logger.info(f"{value} - {other} = {value - other}")
    logger.info(f"{value} * {other} = {value * other}")
    logger.info(f"{value} / {other} = {value / other}")
    logger.info(f"{value} // {other} = {value // other}")
    logger.info(f"{value} % {other} = {value % other}")
    logger.info(f"Reflected add: 10 + {value} = {10 + value}")
    logger.info(f"Reflected sub: 200 - {value} = {200 - value}")
    logger.info(f"Reflected mul: 2 * {value} = {2 * value}")
    logger.info(f"Reflected truediv: 1000 / {value} = {1000 / value}")
    logger.info(f"Reflected floordiv: 1000 // {value} = {1000 // value}")
    logger.info(f"Reflected mod: 1000 % {value} = {1000 % value}")

    logger.info(f"negated={-value}")
    logger.info(f"positive={+value}")
    logger.info(f"absolute={abs(value)}")

    logger.info(f"EQ: {value} == {other} = {value == other}")
    logger.info(f"LT: {value} < {other} = {value < other}")
    logger.info(f"LE: {value} <= {other} = {value <= other}")
    logger.info(f"GT: {value} > {other} = {value > other}")
    logger.info(f"GE: {value} >= {other} = {value >= other}")

    logger.info(f"int(value)={int(value)}")
    logger.info(f"float(value)={float(value)}")
    logger.info(f"bool(value)={bool(value)}")

    items = [1, 2, 3, 4, 5]
    index = value % len(items)
    logger.info(f"Used as index via __index__: items[{index}] = {items[index]}")

    # ======================= Visualize =========================================
    rr.init("int_example", spawn=True)
    datatypes.visualize(value, entity_path="/int")

    # ======================= Serialize / Deserialize ===========================
    start = time.perf_counter()
    serialized = datatypes.serialize(value)
    serialization_ms = (time.perf_counter() - start) * 1000

    start = time.perf_counter()
    deserialized = datatypes.deserialize(serialized)["param_0"]
    deserialization_ms = (time.perf_counter() - start) * 1000

    logger.info(f"Deserialized Int: {deserialized}")
    logger.info(f"Round-trip successful: {deserialized == value}")
    logger.info(f"Serialization time: {serialization_ms:.3f} ms")
    logger.info(f"Deserialization time: {deserialization_ms:.3f} ms")

if __name__ == "__main__":
    int_example()