@@ -1464,14 +1464,14 @@ bool ggml_is_transposed(const struct ggml_tensor * tensor) {
14641464 return tensor -> nb [0 ] > tensor -> nb [1 ];
14651465}
14661466
1467- static bool ggml_is_contiguous_n (const struct ggml_tensor * tensor , int n ) {
1467+ static bool ggml_is_contiguous_m_n (const struct ggml_tensor * tensor , int m , int n ) {
14681468 size_t next_nb = ggml_type_size (tensor -> type );
14691469 if (tensor -> ne [0 ] != ggml_blck_size (tensor -> type ) && tensor -> nb [0 ] != next_nb ) {
14701470 return false;
14711471 }
14721472 next_nb *= tensor -> ne [0 ]/ggml_blck_size (tensor -> type );
1473- for (int i = 1 ; i < GGML_MAX_DIMS ; i ++ ) {
1474- if (i > n ) {
1473+ for (int i = 1 ; i < n ; i ++ ) {
1474+ if (i > m ) {
14751475 if (tensor -> ne [i ] != 1 && tensor -> nb [i ] != next_nb ) {
14761476 return false;
14771477 }
@@ -1489,15 +1489,27 @@ bool ggml_is_contiguous(const struct ggml_tensor * tensor) {
14891489}
14901490
14911491bool ggml_is_contiguous_0 (const struct ggml_tensor * tensor ) {
1492- return ggml_is_contiguous_n (tensor , 0 );
1492+ return ggml_is_contiguous_m_n (tensor , 0 , GGML_MAX_DIMS );
14931493}
14941494
14951495bool ggml_is_contiguous_1 (const struct ggml_tensor * tensor ) {
1496- return ggml_is_contiguous_n (tensor , 1 );
1496+ return ggml_is_contiguous_m_n (tensor , 1 , GGML_MAX_DIMS );
14971497}
14981498
14991499bool ggml_is_contiguous_2 (const struct ggml_tensor * tensor ) {
1500- return ggml_is_contiguous_n (tensor , 2 );
1500+ return ggml_is_contiguous_m_n (tensor , 2 , GGML_MAX_DIMS );
1501+ }
1502+
1503+ bool ggml_is_contiguous_to_1 (const struct ggml_tensor * tensor ) {
1504+ return ggml_is_contiguous_m_n (tensor , 0 , 1 );
1505+ }
1506+
1507+ bool ggml_is_contiguous_to_2 (const struct ggml_tensor * tensor ) {
1508+ return ggml_is_contiguous_m_n (tensor , 0 , 2 );
1509+ }
1510+
1511+ bool ggml_is_contiguous_to_3 (const struct ggml_tensor * tensor ) {
1512+ return ggml_is_contiguous_m_n (tensor , 0 , 3 );
15011513}
15021514
15031515bool ggml_is_contiguously_allocated (const struct ggml_tensor * tensor ) {
0 commit comments