|
22 | 22 | - Avoid fancy-looking modern STL constructs, use basic `for` loops, avoid templates, keep it simple
|
23 | 23 | - There are no strict rules for the code style, but try to follow the patterns in the code (indentation, spaces, etc.). Vertical alignment makes things more readable and easier to batch edit
|
24 | 24 | - Clean-up any trailing whitespaces, use 4 spaces for indentation, brackets on the same line, `void * ptr`, `int & a`
|
| 25 | +- Use sized integer types in the public API |
| 26 | +- Follow the existing code style, in case of doubt use `clang-format` to format the added code |
| 27 | +- Declare structs with `struct x {}` instead of `typedef struct x {} x` |
| 28 | + - In C++ code omit the `struct` keyword whenever it is not necessary |
| 29 | + > [!NOTE] |
| 30 | + > This guideline is yet to be applied to the `llama.cpp` codebase. New code should follow this guideline. |
25 | 31 | - Tensors store data in row-major order. We refer to dimension 0 as columns, 1 as rows, 2 as matrices
|
26 | 32 | - Matrix multiplication is unconventional: [`C = ggml_mul_mat(ctx, A, B)`](https://github.com/ggerganov/llama.cpp/blob/880e352277fc017df4d5794f0c21c44e1eae2b84/ggml.h#L1058-L1064) means $C^T = A B^T \Leftrightarrow C = B A^T.$
|
27 | 33 |
|
|
30 | 36 | # Naming guidelines
|
31 | 37 |
|
32 | 38 | - Use `snake_case` for function, variable and type names
|
33 |
| -- Use sized integer types in the public API |
34 | 39 | - Naming usually optimizes for common prefix (see https://github.com/ggerganov/ggml/pull/302#discussion_r1243240963)
|
35 | 40 |
|
36 | 41 | ```cpp
|
|
72 | 77 | - The `_context` suffix of the `<class>` is optional
|
73 | 78 | - Use `init`/`free` for constructor/destructor `<action>`
|
74 | 79 |
|
75 |
| -- Declare structs with `struct x {}` instead of `typedef struct x {} x` |
76 |
| - - In C++ code omit the `struct` keyword whenever it is not necessary |
77 |
| - > [!NOTE] |
78 |
| - > This guideline is yet to be applied to the `llama.cpp` codebase. New code should follow this guideline. |
79 |
| - |
80 | 80 | - Use the `_t` suffix when a type is supposed to be opaque to the user - it's not relevant to them if it is a struct or anything else
|
81 | 81 |
|
82 | 82 | ```cpp
|
|
88 | 88 | > [!NOTE]
|
89 | 89 | > This guideline is yet to be applied to the `llama.cpp` codebase. New code should follow this guideline.
|
90 | 90 |
|
91 |
| -- Follow the existing code style, in case of doubt use `clang-format` to format the added code |
92 |
| -
|
93 | 91 | - (TODO: abbreviations usage)
|
94 | 92 |
|
95 | 93 | # Resources
|
|
0 commit comments