MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / ggml_reshape

Function ggml_reshape

ggml.c:4475–4502  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4473// ggml_reshape
4474
4475struct ggml_tensor * ggml_reshape(
4476 struct ggml_context * ctx,
4477 struct ggml_tensor * a,
4478 struct ggml_tensor * b) {
4479 GGML_ASSERT(ggml_is_contiguous(a));
4480 // as only the shape of b is relevant, and not its memory layout, b is allowed to be non contiguous.
4481 GGML_ASSERT(ggml_nelements(a) == ggml_nelements(b));
4482
4483 bool is_node = false;
4484
4485 if (a->grad) {
4486 is_node = true;
4487 }
4488
4489 if (b->grad) {
4490 // gradient propagation is not supported
4491 //GGML_ASSERT(false);
4492 }
4493
4494 struct ggml_tensor * result = ggml_new_tensor_impl(ctx, a->type, b->n_dims, b->ne, a, 0);
4495 ggml_format_name(result, "%s (reshaped)", a->name);
4496
4497 result->op = GGML_OP_RESHAPE;
4498 result->grad = is_node ? ggml_dup_tensor(ctx, result) : NULL;
4499 result->src[0] = a;
4500
4501 return result;
4502}
4503
4504struct ggml_tensor * ggml_reshape_1d(
4505 struct ggml_context * ctx,

Callers 2

ggml_compute_backwardFunction · 0.70
mainFunction · 0.50

Calls 5

ggml_is_contiguousFunction · 0.70
ggml_nelementsFunction · 0.70
ggml_new_tensor_implFunction · 0.70
ggml_format_nameFunction · 0.70
ggml_dup_tensorFunction · 0.70

Tested by 1

mainFunction · 0.40