]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
ggml : fix instructions for using data pointer
authorGeorgi Gerganov <redacted>
Fri, 25 Aug 2023 13:56:09 +0000 (16:56 +0300)
committerGeorgi Gerganov <redacted>
Fri, 25 Aug 2023 13:56:09 +0000 (16:56 +0300)
include/ggml/ggml.h

index 3c48fd27fab39d2986f76f3fc4a3b1543a6cb915..2074fd04b0f5c36338c613f250d468ddbb4b3ef8 100644 (file)
 // The data of the tensor is accessed via the "data" pointer. For example:
 //
 //   {
-//       struct ggml_tensor * a = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, 2, 3);
+//       const int nx = 2;
+//       const int ny = 3;
 //
-//       // a[2, 1] = 1.0f;
-//       *(float *) ((char *) a->data + 2*a->nb[1] + 1*a->nb[0]) = 1.0f;
+//       struct ggml_tensor * a = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, nx, ny);
 //
-//       // a[0, 2] = 2.0f;
-//       *(float *) ((char *) a->data + 0*a->nb[1] + 2*a->nb[0]) = 2.0f;
+//       for (int y = 0; y < ny; y++) {
+//           for (int x = 0; x < nx; x++) {
+//               *(float *) ((char *) a->data + y*a->nb[1] + x*a->nb[0]) = x + y;
+//           }
+//       }
 //
 //       ...
 //   }