MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / __get_floats

Function __get_floats

external/ggml/examples/python/ggml/utils.py:135–150  ·  view source on GitHub ↗
(tensor: TensorLike)

Source from the content-addressed store, hash-verified

133def __is_contiguous(tensor: TensorLike): return tensor.flags['C_CONTIGUOUS'] if isinstance(tensor, np.ndarray) else lib.ggml_is_contiguous(tensor)
134
135def __get_floats(tensor: TensorLike) -> ffi.CData:
136 data, type = __get_data(tensor), __get_type(tensor)
137 if type == lib.GGML_TYPE_F32:
138 return ffi.cast('float*', data)
139 else:
140 nelements = __get_nelements(tensor)
141 floats = ffi.new('float[]', nelements)
142 if type == lib.GGML_TYPE_F16:
143 lib.ggml_fp16_to_fp32_row(ffi.cast('uint16_t*', data), floats, nelements)
144 elif lib.ggml_is_quantized(type):
145 qtype = lib.ggml_internal_get_type_traits(type)
146 assert qtype.to_float, f"Type {__type_name(type)} is not supported by ggml"
147 qtype.to_float(data, floats, nelements)
148 else:
149 raise NotImplementedError(f'Cannot read floats from {__describe(tensor)}')
150 return floats
151
152def __set_floats(tensor: TensorLike, f32_data: ffi.CData) -> None:
153 data, type, nbytes = __get_data(tensor), __get_type(tensor), __get_nbytes(tensor)

Callers 1

copyFunction · 0.85

Calls 6

__get_dataFunction · 0.85
__get_typeFunction · 0.85
__get_nelementsFunction · 0.85
__type_nameFunction · 0.85
__describeFunction · 0.85
castMethod · 0.80

Tested by

no test coverage detected