Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-openvino/openvino/op/diag.cpp # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-openvino / openvino / op / diag.cpp` 37 lines · 1201 bytes Raw Blame History 1 #include "../node_context.h" 2 #include "../op_table.h" 3 #include "../utils.h" 4 5 #include 6 #include 7 #include 8 9 namespace ov { 10 namespace frontend { 11 namespace ggml { 12 namespace op { 13 14 // GGML DIAG takes a 1D vector (ne0, 1, ne2, ne3) and produces a diagonal matrix 15 // of shape (ne0, ne0, ne2, ne3). 16 // In OV layout (ggml [ne0, ne1, ne2, ne3] → OV [ne3, ne2, ne1, ne0]): 17 // input: [ne3, ne2, 1, ne0] 18 // output: [ne3, ne2, ne0, ne0] 19 // The diagonal: output[..., i, j] = input[..., 0, j] if i == j, else 0. 20 OutputVector translate_diag(const NodeContext & context) { 21 num_inputs_check(context, 1, 1); 22 23 auto x = process_view_input_new(context, 0); // OV shape: [ne3, ne2, 1, ne0] 24 25 auto n = get_dimensions(x.get_node_shared_ptr(), {3}); 26 auto zero_diag = ov::op::v0::Constant::create(ov::element::i64, {}, {0}); 27 28 auto eye = std::make_shared(n, n, zero_diag, x.get_element_type()); 29 auto res = std::make_shared(x, eye); 30 31 return rename_outputs_with_suffix({res}, context.get_name()); 32 } 33 34 } // namespace op 35 } // namespace ggml 36 } // namespace frontend 37 } // namespace ov