MCPcopy
hub / github.com/marimo-team/marimo / _contiguous_tensor_bytes

Function _contiguous_tensor_bytes

marimo/_save/encode.py:76–93  ·  view source on GitHub ↗

Return a contiguous uint8 view of a tensor/array.

(data: Tensor)

Source from the content-addressed store, hash-verified

74
75
76def _contiguous_tensor_bytes(data: Tensor) -> memoryview:
77 """Return a contiguous uint8 view of a tensor/array."""
78 data = standardize_tensor(data)
79 # From joblib.hashing
80 if data.shape == ():
81 # 0d arrays need to be flattened because viewing them as bytes
82 # raises a ValueError exception.
83 data_c_contiguous = data.flatten()
84 elif data.flags.c_contiguous:
85 data_c_contiguous = data
86 elif data.flags.f_contiguous:
87 data_c_contiguous = data.T
88 else:
89 # Cater for non-single-segment arrays, this creates a copy, and thus
90 # alleviates this issue. Note: There might be a more efficient way of
91 # doing this, check for joblib updates.
92 data_c_contiguous = data.flatten()
93 return memoryview(data_c_contiguous.view("uint8"))
94
95
96def data_to_buffer(data: Tensor) -> bytes:

Callers 2

data_to_bufferFunction · 0.85
reducer_overrideMethod · 0.85

Calls 1

standardize_tensorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…