Skip to main content

Arrex

support-version PyPI version shields.io Documentation Status

Arrex is a module that allows to create typed arrays much like numpy.ndarray and array.array, but resizeable and using any kind of element, not only numbers. Its dtype system is extremely flexible and makes it ideal to work and share structured data with compiled code.

The elements can be many different things, there is just 2 requirements:

  • they must be of a fixed binary size
  • they must be byte copiable, therefore without any reference or pointer to something else

interests

  • much smaller memory footprint (an arrex array is at most 30x smaller than pure python data storage)
  • content can be directly shared with compiled code which improves computation performances
  • slice & view without a copy
  • compatible with standard python libraries

basic usage:

>>> from arrex import *
>>> a = typedlist([
			myclass(...), 
			myclass(...),
			], dtype=myclass)
>>> a[0]
myclass(...)

in that example, myclass can be a primitive numpy type, like np.float64

>>> import arrex.numpy		# this is enabling numpy dtypes for arrex
>>> typedlist(dtype=np.float64)

it can be a more complex type, from module pyglm for instance

>>> import arrex.glm		# this is enabling glm dtypes for arrex
>>> typedlist(dtype=glm.vec4)

typedlist is a dynamically sized, borrowing array, which mean the internal buffer of data is reallocated on append, but can be used to view and extract from any buffer without a copy.

Use it as a list:

>>> a = typedlist(dtype=vec3)

# build from an iterable
>>> a = typedlist([], dtype=vec3)

# append some data
>>> a.append(vec3(1,2,3))

# extend with an iterable
>>> a.extend(vec3(i)  for i in range(5))

>>> len(a)	# the current number of elements
6

>>> a.owner	# the current data buffer
b'.........'

>>> a[0]
vec3(1,2,3)

Use it as a slice:

>>> myslice = a[:5]		# no data is copied
typedlist(....)

Use it as a view on top of a random buffer

>>> a = np.ones((6,3), dtype='f4')
>>> myslice = typedlist(a, dtype=vec3)

buffer protocol

It does support the buffer protocol, so it can be converted into a great variety of well known arrays, even without any copy

>>> np.array(typedlist([....]))

Which dtype is allowed

answer is: whatever you want, but here is some examples:

# an extension type, previously declared
typedlist(dtype=glm.vec3)

# a Struct
typedlist(dtype='ffxI')

# a ctype
typedlist(dtype=ctypes.c_int*5)

# a pure python class
class test_class:
    __packlayout__ = 'ff'
    _struct = struct.Struct(__packlayout__)

    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __bytes__(self):
        return self._struct.pack(self.x, self.y)
    @classmethod
    def frombytes(cls, b):
        return cls(*cls._struct.unpack(b))

typedlist(dtype=test_class)

# and so much more !

performances

Time performances comparison between list, numpy.ndarray, and arrex.typedlist (see benchmark )

execution time (s) for 10k elements (dvec3)

set item
  list:         7.9847e-04 s
  numpy:        1.2727e-02 s
  arrex:        1.0481e-03 s  (10x faster than numpy)

get item
  creation:     1.0655e-03 s
  list:         5.1503e-04 s
  numpy:        1.8619e-03 s
  arrex:        8.0111e-04 s   (2x faster than numpy)

Roadmap

There is additionnal features planned, but no precise schedul yet:

  • typedarray

    a n-dim array view much like numpy arrays but using dtypes as in typedlist. Its purpose is mostly to access its items with n-dim indices and slices.

  • a ufunc system

    to collect and put defaults to any kind of array scale operations, like __add__, __mul__, __matmul__, ... The goal would be to have a standard way to apply any function to every element of one or more array, that defaults to the python implementation, but can be overloaded with a compiled implementation

  • maybe

    even extend to the complete API of numcy

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arrex-0.5.5.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arrex-0.5.5-cp313-cp313-manylinux_2_41_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.41+ x86-64

File details

Details for the file arrex-0.5.5.tar.gz.

File metadata

  • Download URL: arrex-0.5.5.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.5 Linux/6.12.95+deb13-amd64

File hashes

Hashes for arrex-0.5.5.tar.gz
Algorithm Hash digest
SHA256 b4cba632faf1a147b8475106cb0c47f8b4352fd2b998b984c1e4ea45902e03cd
MD5 153ef9c4efbc72fb8ee469594d5094b3
BLAKE2b-256 a51a0f3634cd5d7a4d343d9dbb115f631622238d59f8804d521fc021a050979d

See more details on using hashes here.

File details

Details for the file arrex-0.5.5-cp313-cp313-manylinux_2_41_x86_64.whl.

File metadata

  • Download URL: arrex-0.5.5-cp313-cp313-manylinux_2_41_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.13, manylinux: glibc 2.41+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.5 Linux/6.12.95+deb13-amd64

File hashes

Hashes for arrex-0.5.5-cp313-cp313-manylinux_2_41_x86_64.whl
Algorithm Hash digest
SHA256 708813e684e0c432eb0a5ce07cc114bc27d36cbb7393ca60d83965ece78da593
MD5 698656bd88c494bf4ca856f3f1d994fc
BLAKE2b-256 e15634a0f5d0596a7099b6865e813ed953c7d7f47f9cf3b84ed5e209b8c28fc2

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.5 This release

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

1 file

0.5.1

1 file

0.5.0

2 files

0.4.1

1 file

0.4.0

1 file

0.3.2

1 file

0.3.1

1 file

0.3

1 file

0.2

1 file

0.1

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page