MCPcopy Create free account
hub / github.com/ml-explore/mlx / buffer_format

Function buffer_format

python/src/buffer.h:20–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18namespace nb = nanobind;
19
20std::string buffer_format(const mx::array& a) {
21 // https://docs.python.org/3.10/library/struct.html#format-characters
22 switch (a.dtype()) {
23 case mx::bool_:
24 return "?";
25 case mx::uint8:
26 return "B";
27 case mx::uint16:
28 return "H";
29 case mx::uint32:
30 return "I";
31 case mx::uint64:
32 return "Q";
33 case mx::int8:
34 return "b";
35 case mx::int16:
36 return "h";
37 case mx::int32:
38 return "i";
39 case mx::int64:
40 return "q";
41 case mx::float16:
42 return "e";
43 case mx::float32:
44 return "f";
45 case mx::bfloat16:
46 return "B";
47 case mx::float64:
48 return "d";
49 case mx::complex64:
50 return "Zf\0";
51 default: {
52 std::ostringstream os;
53 os << "bad dtype: " << a.dtype();
54 throw std::runtime_error(os.str());
55 }
56 }
57}
58
59struct buffer_info {
60 std::string format;

Callers 1

getbufferFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected