ztensor 0.1.0__py3-none-win32.whl → 0.1.1__py3-none-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ztensor might be problematic. Click here for more details.

ztensor/__init__.py CHANGED
@@ -1,5 +1,6 @@
1
1
  import numpy as np
2
2
  from .ztensor import ffi, lib
3
+ from ml_dtypes import bfloat16
3
4
 
4
5
 
5
6
  # --- Pythonic Wrapper ---
@@ -52,7 +53,10 @@ DTYPE_NP_TO_ZT = {
52
53
  np.dtype('uint64'): 'uint64', np.dtype('uint32'): 'uint32',
53
54
  np.dtype('uint16'): 'uint16', np.dtype('uint8'): 'uint8',
54
55
  np.dtype('bool'): 'bool',
56
+ # ADDED: Mapping for bfloat16 to handle writing
57
+ np.dtype(bfloat16): 'bfloat16',
55
58
  }
59
+ # MODIFIED: Re-construct the reverse mapping
56
60
  DTYPE_ZT_TO_NP = {v: k for k, v in DTYPE_NP_TO_ZT.items()}
57
61
 
58
62
 
@@ -90,6 +94,7 @@ class TensorMetadata:
90
94
  @property
91
95
  def dtype(self):
92
96
  """Returns the numpy dtype for this tensor."""
97
+ # This will now correctly return a bfloat16 dtype object when dtype_str is 'bfloat16'
93
98
  return DTYPE_ZT_TO_NP.get(self.dtype_str)
94
99
 
95
100
  # RE-ENABLED: This property now works because the underlying FFI functions are available.
@@ -137,6 +142,12 @@ class Reader:
137
142
  def read_tensor(self, name: str) -> np.ndarray:
138
143
  """Reads a tensor by name and returns it as a NumPy array (zero-copy)."""
139
144
  metadata = self.get_metadata(name)
145
+
146
+ # This check is now more robust.
147
+ dtype = metadata.dtype
148
+ if dtype is None:
149
+ raise ZTensorError(f"Unsupported ztensor dtype: '{metadata.dtype_str}'")
150
+
140
151
  view_ptr = lib.ztensor_reader_read_tensor_view(self._ptr, metadata._ptr)
141
152
  _check_ptr(view_ptr, f"read_tensor: {name}")
142
153
 
@@ -144,9 +155,11 @@ class Reader:
144
155
  view_ptr = ffi.gc(view_ptr, lib.ztensor_free_tensor_view)
145
156
 
146
157
  # CORRECTED: Create array using the subclass, which handles reshaping and memory.
158
+ # With the correct bfloat16 dtype, np.frombuffer will now correctly interpret
159
+ # the buffer, creating an array with the right number of elements (2048).
147
160
  array = _ZTensorView(
148
161
  buffer=ffi.buffer(view_ptr.data, view_ptr.len),
149
- dtype=metadata.dtype,
162
+ dtype=dtype,
150
163
  shape=metadata.shape,
151
164
  view_ptr=view_ptr
152
165
  )
@@ -189,6 +202,7 @@ class Writer:
189
202
  shape_array = np.array(tensor.shape, dtype=np.uint64)
190
203
  shape_ptr = ffi.cast("uint64_t*", shape_array.ctypes.data)
191
204
 
205
+ # The updated DTYPE_NP_TO_ZT will now correctly handle bfloat16 tensors.
192
206
  dtype_str = DTYPE_NP_TO_ZT.get(tensor.dtype)
193
207
  if not dtype_str:
194
208
  raise ZTensorError(f"Unsupported NumPy dtype: {tensor.dtype}")
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ztensor
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -9,6 +9,7 @@ Classifier: Intended Audience :: Developers
9
9
  Classifier: Topic :: Scientific/Engineering
10
10
  Requires-Dist: numpy
11
11
  Requires-Dist: cffi
12
+ Requires-Dist: ml-dtypes
12
13
  License-File: LICENSE
13
14
  Summary: Python bindings for the zTensor library.
14
15
  Author: In Gim <in.gim@yale.edu>
@@ -0,0 +1,8 @@
1
+ ztensor-0.1.1.dist-info/METADATA,sha256=hpFnvbYe6JDNWzbgozx-V_DwwZF2e6dxL5QDeEa9uKs,4530
2
+ ztensor-0.1.1.dist-info/WHEEL,sha256=v0atuDHRmBdo6voLOtYJ8NlQfECX5fZNHOXLlNqbhus,89
3
+ ztensor-0.1.1.dist-info/licenses/LICENSE,sha256=qxF7VFxBvMlfiDRJ5oXQuQYaloq0Tcbk95Pn0DFlnss,1084
4
+ ztensor/__init__.py,sha256=3xHeBl9o9RyUriUlgPr3UwBZC3h15sgIGElnlJ2kIRY,9316
5
+ ztensor/ztensor/__init__.py,sha256=DDVvoEhcXithkluOJ4Dd7H6wIqKcxT6mm6vvPgrQMz4,138
6
+ ztensor/ztensor/ffi.py,sha256=5HqR7Szwsn6HmKARaYQqF0nJKEUWZsWpYD4ZiOaoWnk,2756
7
+ ztensor/ztensor/ztensor.dll,sha256=BJiNGoqQXsRAQkLMDAHR2S5r2WvspjsvJvJk706VPzc,871936
8
+ ztensor-0.1.1.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- ztensor-0.1.0.dist-info/METADATA,sha256=4s1ZEgsJePgp3S96g56LTjgNeGZeopSGoFk6jvZkXLE,4505
2
- ztensor-0.1.0.dist-info/WHEEL,sha256=v0atuDHRmBdo6voLOtYJ8NlQfECX5fZNHOXLlNqbhus,89
3
- ztensor-0.1.0.dist-info/licenses/LICENSE,sha256=qxF7VFxBvMlfiDRJ5oXQuQYaloq0Tcbk95Pn0DFlnss,1084
4
- ztensor/__init__.py,sha256=Blfw3ZTJQPAsFQgqAw2y2KY_Zwh5Do-hjkOMS_Fx5Xs,8619
5
- ztensor/ztensor/__init__.py,sha256=DDVvoEhcXithkluOJ4Dd7H6wIqKcxT6mm6vvPgrQMz4,138
6
- ztensor/ztensor/ffi.py,sha256=5HqR7Szwsn6HmKARaYQqF0nJKEUWZsWpYD4ZiOaoWnk,2756
7
- ztensor/ztensor/ztensor.dll,sha256=a8TSYxK-0prNrBkjMsr02Dz8GB69qLdwAfq6DNRGP78,871936
8
- ztensor-0.1.0.dist-info/RECORD,,