esper icon indicating copy to clipboard operation
esper copied to clipboard

Array components

Open ShaDuBois opened this issue 7 months ago • 2 comments

Describe the addition or change you'd like to see. Often we need to work on array of data (positions, quaternions, etc). It would be great to have a standard way to build those array data classes and then use array processing libraries with batched operations (Numpy, PyTorch, Taichi, …). Using those libraries would leverage high performance implementations, particularly for the later two that support GPU operations.

An example of how the API might look. The API would introduce another data class decorator for “array” oriented components (for example like https://docs.taichi-lang.org/fr-FR/docs/data_oriented_class)

In a second step, this could be used to propose a collection of high performance components.

ShaDuBois avatar May 21 '25 06:05 ShaDuBois

Thanks for opening the ticket, and pardon the delay in responding.

I'm not 100% clear on what you're asking for. What would the decorator do? Starting from the obvious point, which is just to make a Component take an array as an attribute:

class SomeComponent:
    def __init__(self, array):
        self.array = array

What would the difference be from there? The ability to consume the Component directly in some way?

benmoran56 avatar May 31 '25 07:05 benmoran56

No worries for the delay :)

The decorator would be used to transform the usual esper statement for a component class like:

from dataclasses import dataclass as component

@component
class Position:
    x: float = 0.0
    y: float = 0.0

to something like

from esper import arraydataclass as component

@component
class Position:
    x: float = 0.0
    y: float = 0.0

In which Position, rather than instantiating 2 pythonic floats, would use an underlying array library to represent compactly x and y. In some way, this decorator would "pack" components. This is useful for optimized speed and storage.

A direct extension of this "packing" decorator, would be to tightly arrange N components into a larger array of size (N, 2) for the example of Position.

sebastienwood avatar May 31 '25 12:05 sebastienwood