| 4473 | // ggml_reshape |
| 4474 | |
| 4475 | struct 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 | |
| 4504 | struct ggml_tensor * ggml_reshape_1d( |
| 4505 | struct ggml_context * ctx, |