Skip to main content

Extend broadcasting rules of numpy to abstract tabularshape of data from cellular shape

Project description

Introduction

Some engineering problems strain array representation due to tabulation and degeneracy. tablarray disambiguates data structure of tables-of-cells and extends powerful methods into these domains.

Linked below are introductions to the concepts:

  • the Big Idea of TablArray is to disambiguate tables of cells, which traditionally would have been stacks of arrays, or arrays of arrays. In this doc, we see that new math operators are provided with upgraded broadcasting rules, and in examples we see that we can now write formulas with a blind eye toward tabular convention as well as parameter degeneracy.

  • the Big Idea of TablaSet (work in progress) is to extend TablArray into a territory that overlaps roughly with a database, and yet we retain the speed of slicing. In fact, when we marry database and slicing concepts, a new concept emerges, called projection. As a side benefit, TablaSet also has some elegant utilities (or will soon).

  • the Big Idea of TablaSolve (work in progress) is to build object-oriented datasets by adding computational flow on top of a TablaSet. In practice, this separates a modeling task into defining operators that solve individual dependencies, defining a seed data-set, and then handing control to the TablaSolve to resolve all of the system’s dependent parameters.

(tablarray was originally developed to manage large numbers of optical modes in laser simulation.)

Brief Illustration

import numpy as np
import tablarray as ta
x = ta.TablArray(np.linspace(-2, 2, 4), 0)
y = ta.TablArray(np.linspace(-1.5, 1.5, 4).reshape(4,1), 0)
E = ta.zeros((4, 4, 2), cdim=1)
E.cell[0] = 1.5 / (x**2 + y**2)
E.cell[1] = -.01 + x * 0
print(E)
[[|[ 0.24  -0.01 ]|
  |[ 0.557 -0.01 ]|
  |[ 0.557 -0.01 ]|
  |[ 0.24  -0.01 ]|]

 [|[ 0.353 -0.01 ]|
  |[ 2.16  -0.01 ]|
  |[ 2.16  -0.01 ]|
  |[ 0.353 -0.01 ]|]

 [|[ 0.353 -0.01 ]|
  |[ 2.16  -0.01 ]|
  |[ 2.16  -0.01 ]|
  |[ 0.353 -0.01 ]|]

 [|[ 0.24  -0.01 ]|
  |[ 0.557 -0.01 ]|
  |[ 0.557 -0.01 ]|
  |[ 0.24  -0.01 ]|]]t(4, 4)|c(2,)

Those ‘|’ separate tabular vs cellular structure. Similarly ‘t(4, 4)|c(2,)’ is a reminder that E is set of arrays ‘c(2,)’ arranged in a 4x4 table ‘t(4, 4)’.

En = ta.abs(ta.linalg.norm(E)**2)
Efield = ta.TablaSet(x=x, y=y, E=E, En=En)
Efield['r'] = ta.sqrt(Efield['x']**2 + Efield['y']**2)
ta.set_printoptions(threshold=10, precision=3)
print(Efield.table)
        | x      | y      | E        | En    | r     |
--------+--------+--------+----------+-------+-------+
 [0, 0] | -2.000 | -1.500 | [ 0.24   | 0.058 | 2.500 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [0, 1] | -0.667 |        | [ 0.557  | 0.310 | 1.641 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [0, 2] | 0.667  |        | [ 0.557  | 0.310 | 1.641 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [0, 3] | 2.000  |        | [ 0.24   | 0.058 | 2.500 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [1, 0] |        | -0.500 | [ 0.353  | 0.125 | 2.062 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [1, 1] |        |        | [ 2.16   | 4.666 | 0.833 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [1, 2] |        |        | [ 2.16   | 4.666 | 0.833 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [1, 3] |        |        | [ 0.353  | 0.125 | 2.062 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [2, 0] |        | 0.500  | [ 0.353  | 0.125 | 2.062 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [2, 1] |        |        | [ 2.16   | 4.666 | 0.833 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [2, 2] |        |        | [ 2.16   | 4.666 | 0.833 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [2, 3] |        |        | [ 0.353  | 0.125 | 2.062 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [3, 0] |        | 1.500  | [ 0.24   | 0.058 | 2.500 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [3, 1] |        |        | [ 0.557  | 0.310 | 1.641 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [3, 2] |        |        | [ 0.557  | 0.310 | 1.641 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [3, 3] |        |        | [ 0.24   | 0.058 | 2.500 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
print(Efield.bcast)
        | x      | y      | E        | En    | r     |
--------+--------+--------+----------+-------+-------+
 [0, 0] | -2.000 | -1.500 | [ 0.24   | 0.058 | 2.500 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [0, 1] | -0.667 | -1.500 | [ 0.557  | 0.310 | 1.641 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [0, 2] | 0.667  | -1.500 | [ 0.557  | 0.310 | 1.641 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [0, 3] | 2.000  | -1.500 | [ 0.24   | 0.058 | 2.500 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [1, 0] | -2.000 | -0.500 | [ 0.353  | 0.125 | 2.062 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [1, 1] | -0.667 | -0.500 | [ 2.16   | 4.666 | 0.833 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [1, 2] | 0.667  | -0.500 | [ 2.16   | 4.666 | 0.833 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [1, 3] | 2.000  | -0.500 | [ 0.353  | 0.125 | 2.062 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [2, 0] | -2.000 | 0.500  | [ 0.353  | 0.125 | 2.062 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [2, 1] | -0.667 | 0.500  | [ 2.16   | 4.666 | 0.833 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [2, 2] | 0.667  | 0.500  | [ 2.16   | 4.666 | 0.833 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [2, 3] | 2.000  | 0.500  | [ 0.353  | 0.125 | 2.062 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [3, 0] | -2.000 | 1.500  | [ 0.24   | 0.058 | 2.500 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
 [3, 1] | -0.667 | 1.500  | [ 0.557  | 0.310 | 1.641 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [3, 2] | 0.667  | 1.500  | [ 0.557  | 0.310 | 1.641 |
        |        |        |  -0.01 ] |       |       |
--------+--------+--------+----------+-------+-------+
 [3, 3] | 2.000  | 1.500  | [ 0.24   | 0.058 | 2.500 |
        |        |        |  -0.01]  |       |       |
--------+--------+--------+----------+-------+-------+
print(Efield.cell)
     | x          | y          | E           | En          | r           |
-----+------------+------------+-------------+-------------+-------------+
 [0] | [|-2.|     | [[|-1.5|]  | [[|0.24|    | [[|0.058|   | [[|2.5|     |
     |  |-0.667|  |  [|-0.5|]  |   |0.557|   |   |0.31|    |   |1.641|   |
     |  | 0.667|  |  [| 0.5|]  |   |0.557|   |   |0.31|    |   |1.641|   |
     |  | 2.   |] |  [| 1.5|]] |   |0.24 |]  |   |0.058|]  |   |2.5  |]  |
     |            |            |  [|0.353|   |  [|0.125|   |  [|2.062|   |
     |            |            |   |2.16|    |   |4.666|   |   |0.833|   |
     |            |            |   |2.16|    |   |4.666|   |   |0.833|   |
     |            |            |   |0.353|]  |   |0.125|]  |   |2.062|]  |
     |            |            |  [|0.353|   |  [|0.125|   |  [|2.062|   |
     |            |            |   |2.16|    |   |4.666|   |   |0.833|   |
     |            |            |   |2.16|    |   |4.666|   |   |0.833|   |
     |            |            |   |0.353|]  |   |0.125|]  |   |2.062|]  |
     |            |            |  [|0.24|    |  [|0.058|   |  [|2.5|     |
     |            |            |   |0.557|   |   |0.31|    |   |1.641|   |
     |            |            |   |0.557|   |   |0.31|    |   |1.641|   |
     |            |            |   |0.24 |]] |   |0.058|]] |   |2.5  |]] |
-----+------------+------------+-------------+-------------+-------------+
 [1] |            |            | [[|-0.01|   |             |             |
     |            |            |   |-0.01|   |             |             |
     |            |            |   |-0.01|   |             |             |
     |            |            |   |-0.01|]  |             |             |
     |            |            |  [|-0.01|   |             |             |
     |            |            |   |-0.01|   |             |             |
     |            |            |   |-0.01|   |             |             |
     |            |            |   |-0.01|]  |             |             |
     |            |            |  [|-0.01|   |             |             |
     |            |            |   |-0.01|   |             |             |
     |            |            |   |-0.01|   |             |             |
     |            |            |   |-0.01|]  |             |             |
     |            |            |  [|-0.01|   |             |             |
     |            |            |   |-0.01|   |             |             |
     |            |            |   |-0.01|   |             |             |
     |            |            |   |-0.01|]] |             |             |
-----+------------+------------+-------------+-------------+-------------+

Lessons from above:

  1. TablArray and TablaSet have bcast, table, and cell views.

  2. Broadcasting rules of numpy are extended to recognize tabular and cellular shapes.

  3. This frees physics libraries to write formulas while blind to tabular super-structure of the application. In other words, the goal is to abstract formulas from tabular shape.

  4. TablaSet adds to TablArray by enforcing broadcast-ability across datasets. Once a TablaSet is built, you know it is ready for formulas.

Installation

pip install tablarray

Status

Alpha - tablarray might be stable enough for prototype applications, though it may continue to be unstable for a while longer.

I.e.:

  • Critical features are implemented and not expected to change significantly.

  • A few features need further adaptation for certain cases.

  • A little testing is done, most not so much.

  • Some features are still missing.

  • I remain concerned about undesirable, or worse - undefined, behavior at edge cases.

Project details


Download files

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

Source Distribution

tablarray-0.5.0.tar.gz (46.0 kB view details)

Uploaded Source

Built Distribution

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

tablarray-0.5.0-py3-none-any.whl (53.0 kB view details)

Uploaded Python 3

File details

Details for the file tablarray-0.5.0.tar.gz.

File metadata

  • Download URL: tablarray-0.5.0.tar.gz
  • Upload date:
  • Size: 46.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for tablarray-0.5.0.tar.gz
Algorithm Hash digest
SHA256 33eeed0b39aed7b587ea85383c33d18f34e339f63665da7009cfdf13d277db83
MD5 4eb32686e53814d817c78fcc65ef1ec6
BLAKE2b-256 59b7da97a32429a9b5b5dc874c4497956397aedc1f1ebedd30c039bb2ae200ac

See more details on using hashes here.

File details

Details for the file tablarray-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: tablarray-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 53.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for tablarray-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d625221a87df39b83bf876fff54e3e560a697a50041d26793288bd8d939273a9
MD5 0fb95d6c0eed18c60426700ecbeeea6b
BLAKE2b-256 9d7299e5225b822bc4f558afd0702f12256605e6da277dd15b9096139e568eb8

See more details on using hashes here.

Supported by

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