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

Function __set_floats

external/ggml/examples/python/ggml/utils.py:152–165  ·  view source on GitHub ↗
(tensor: TensorLike, f32_data: ffi.CData)

Source from the content-addressed store, hash-verified

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)
154 if type == lib.GGML_TYPE_F32:
155 ffi.memmove(data, f32_data, nbytes)
156 else:
157 nelements = __get_nelements(tensor)
158 if type == lib.GGML_TYPE_F16:
159 lib.ggml_fp32_to_fp16_row(f32_data, ffi.cast('uint16_t*', data), nelements)
160 elif lib.ggml_is_quantized(type):
161 qtype = lib.ggml_internal_get_type_traits(type)
162 assert qtype.from_float, f"Type {__type_name(type)} is not supported by ggml"
163 qtype.from_float(f32_data, data, nelements)
164 else:
165 raise NotImplementedError(f'Cannot write floats to {__describe(tensor)}')
166
167def __expect_same_layout(name1: str, tensor1: TensorLike, name2: str, tensor2: TensorLike):
168 shape1, shape2 = __get_shape(tensor1), __get_shape(tensor2)

Callers 1

copyFunction · 0.85

Calls 7

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

Tested by

no test coverage detected