Skip to main content

dynamic-tensor

(This package is still developing and not formally tested. Please report any potential issues. Constantly reshaping the tensor could be inefficient and not suitable for high-performance computing)

A Python package for automatically and minimally expanding tensors for __setitem()__ operations based on NumPy. You don't need to worry about tensor shape initialization, reshape(), or expand_dims() anymore as if the tensor has an infinite size. Both basic (integer, slice, np.newaxis, ellipsis) and advanced (integer & boolean array) indexing are supported (refer to Indexing on ndarrays).

You can also configure a DynamicTensor to adapt the tensor type to the new value to avoid astype() (enabled by default).

Usage

Requires Python 3.6+ and NumPy 1.16+.

pip install dynamic-tensor
# or using conda
conda install dynamic-tensor

Or install from source:

git clone https://github.com/eurekazheng/dynamic-tensor.git
cd dynamic-tensor
# build the package
python setup.py sdist bdist_wheel
pip install -e .

Usage:

import densor
d = densor.dt([[1, 2], [3, 4]])
d[2, 1:3, [2, 3]] = 5.6
print(d, d.shape)

# Expected output:
# [[[1.  0.  0.  0. ]
#   [2.  0.  0.  0. ]
#   [0.  0.  0.  0. ]]
# 
#  [[3.  0.  0.  0. ]
#   [4.  0.  0.  0. ]
#   [0.  0.  0.  0. ]]
# 
#  [[0.  0.  0.  0. ]
#   [0.  0.  5.6 5.6]
#   [0.  0.  5.6 5.6]]] (3, 3, 4)

# Helper: convert a list to tensor when possible
densor.tensorify([[1, 2], [3, 4]])    # return ndarray
densor.tensorify([[1, 2], [3, 4, 5]]) # return False

Rationale

The underlying data structure of densor.dt is numpy.ndarray _a. Upon a __setitem(idx, val)__ call, the following preprocessing is done:

  1. Determine the target shape.
  2. Based on target shape, (potentially) expand the dimension of _a.
  3. (Optional) Based on val dtype, (potentially) change the dtype of _a.
  4. Based on target shape, (potentially) change the size of _a at each dimension.

Refer to src/densor.py for more details.

Metadata

Release files for dynamic-tensor 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dynamic-tensor 0.0.2
File Size Uploaded
dynamic-tensor-0.0.2.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dynamic-tensor 0.0.2
File Interpreter ABI Platform
dynamic_tensor-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / dynamic-tensor-0.0.2.tar.gz

Download URL dynamic-tensor-0.0.2.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
eab6b95099b52a7fa8e11068687a6159474e4db854504ae99c465bf9d111765b
BLAKE2b-256 checksum
How to use checksums
de96e096794152c8a8a516f67c13b837e56aa31ed0b08c049e8000f129f072e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.11

Release files / dynamic_tensor-0.0.2-py3-none-any.whl

Download URL dynamic_tensor-0.0.2-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aecd3e3a57009a1765601b47aa59fac5ebb81982f614bd81d85ff53ed271abfc
BLAKE2b-256 checksum
How to use checksums
5dff147f056dc1642d195654a9b0d2ca58fcbb30ab5a10d1edb19f803153c358
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.11

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page