From 09bb15a66aff90dc7db1d386f9e738e1bbfc4e7f Mon Sep 17 00:00:00 2001 From: Francis Couture-Harpin Date: Mon, 18 Mar 2024 20:21:02 -0400 Subject: [PATCH] ggml : make ggml_is_empty public and work with views --- ggml.c | 12 ++++++++---- ggml.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ggml.c b/ggml.c index ed2cbe30f..94ae9b9ef 100644 --- a/ggml.c +++ b/ggml.c @@ -2542,10 +2542,14 @@ static inline bool ggml_is_padded_1d(const struct ggml_tensor * tensor) { tensor->nb[3] == tensor->nb[2]*tensor->ne[2]; } -static inline bool ggml_is_empty(const struct ggml_tensor * tensor) { - // the stride of the last dimension is zero if any of the previous dimensions has no elements - // but to be sure, the number of elements in the last dimension must also be checked - return tensor->nb[GGML_MAX_DIMS - 1] == 0 || tensor->ne[GGML_MAX_DIMS - 1] == 0; +GGML_CALL bool ggml_is_empty(const struct ggml_tensor * tensor) { + for (int i = 0; i < GGML_MAX_DIMS; ++i) { + if (tensor->ne[i] == 0) { + // empty if any dimension has no elements + return true; + } + } + return false; } bool ggml_are_same_shape(const struct ggml_tensor * t0, const struct ggml_tensor * t1) { diff --git a/ggml.h b/ggml.h index c937d4a53..7bb870f79 100644 --- a/ggml.h +++ b/ggml.h @@ -744,6 +744,7 @@ extern "C" { GGML_API GGML_CALL bool ggml_is_transposed(const struct ggml_tensor * tensor); GGML_API GGML_CALL bool ggml_is_contiguous(const struct ggml_tensor * tensor); GGML_API GGML_CALL bool ggml_is_permuted (const struct ggml_tensor * tensor); + GGML_API GGML_CALL bool ggml_is_empty (const struct ggml_tensor * tensor); GGML_API bool ggml_is_scalar (const struct ggml_tensor * tensor); GGML_API bool ggml_is_vector (const struct ggml_tensor * tensor); GGML_API bool ggml_is_matrix (const struct ggml_tensor * tensor);