From e195aee3b8a5d5e309d1c77060a49985188d3ae0 Mon Sep 17 00:00:00 2001 From: fanasina Date: Thu, 1 Feb 2024 18:42:44 +0100 Subject: [PATCH] add sub dimension --- dimension_t/src/dimension_t/dimension_t.c | 18 +++++++++++++++++- dimension_t/src/dimension_t/dimension_t.h | 3 +++ dimension_t/test/is_good.c | 17 +++++++++++++++++ .../src/permutation_t/permutation_t.c | 7 +++++++ .../src/permutation_t/permutation_t.h | 1 + 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/dimension_t/src/dimension_t/dimension_t.c b/dimension_t/src/dimension_t/dimension_t.c index adf6e7c..ed0f9c3 100644 --- a/dimension_t/src/dimension_t/dimension_t.c +++ b/dimension_t/src/dimension_t/dimension_t.c @@ -10,7 +10,7 @@ long int incr(long int i) { return i + 1; } long int decr(long int i) { return i - 1; } dimension* init_dim(size_t *t, size_t sz){ - dimension *d = INIT_PERMUTATION_TYPE_SIZE_T(t,sz); + dimension *d = INIT_COPY_PERMUTATION_TYPE_SIZE_T(t,sz); updateRankDim(d); return d; } @@ -19,6 +19,22 @@ create_dim(size_t sz){ return CREATE_PERMUTATION_TYPE_SIZE_T(sz); } +dimension* sub_dim_head(dimension *root, size_t minusSubdim){ + if(minusSubdim < (root->size)){ + dimension *d = INIT_PERMUTATION_TYPE_SIZE_T(root->perm, (root->size)-minusSubdim); + updateRankDim(d); + return d; + } + return NULL; +} +dimension* sub_dim_tail(dimension *root, size_t minusSubdim){ + if(minusSubdim < (root->size)){ + dimension *d = INIT_PERMUTATION_TYPE_SIZE_T((root->perm)+minusSubdim, (root->size)-minusSubdim); + updateRankDim(d); + return d; + } + return NULL; +} void add_dimension(dimension **d, dimension *d0, dimension *d1) { (*d) = create_dim(d0->size + d1->size); //printf("d size : %ld\n",(*d)->size); diff --git a/dimension_t/src/dimension_t/dimension_t.h b/dimension_t/src/dimension_t/dimension_t.h index cf80c00..d79b275 100644 --- a/dimension_t/src/dimension_t/dimension_t.h +++ b/dimension_t/src/dimension_t/dimension_t.h @@ -10,6 +10,9 @@ typedef struct PERMUTATION_TYPE_SIZE_T dimension ; dimension * create_dim(size_t size); dimension* init_dim(size_t *t, size_t sz); +dimension* sub_dim_head(dimension *t, size_t minusSubdim); +dimension* sub_dim_tail(dimension *t, size_t minusSubdim); + void add_dimension(dimension **d, dimension *d0, dimension *d1); void min_dimension(dimension **d, dimension *d0, dimension *d1); diff --git a/dimension_t/test/is_good.c b/dimension_t/test/is_good.c index fa81f44..19adc8c 100644 --- a/dimension_t/test/is_good.c +++ b/dimension_t/test/is_good.c @@ -34,6 +34,23 @@ TEST(rank){ EXPECT_EQ(D->rank, 180); } +TEST(SubDim){ + dimension *D=create_dim(4); + D->perm[0]=2; + D->perm[1]=3; + D->perm[2]=5; + D->perm[3]=6; + + dimension *d_head2 = sub_dim_head(D,2); + + + EXPECT_EQ(d_head2->rank, 2*3); + + dimension *d_tail2 = sub_dim_tail(D,2); + EXPECT_EQ(d_tail2->rank, 5*6); + +} + TEST(Coord_linear){ dimension *D=create_dim(4); diff --git a/ypermutation_t/src/permutation_t/permutation_t.c b/ypermutation_t/src/permutation_t/permutation_t.c index 0bfa231..ae3d951 100644 --- a/ypermutation_t/src/permutation_t/permutation_t.c +++ b/ypermutation_t/src/permutation_t/permutation_t.c @@ -42,6 +42,13 @@ int sign(long int a){ return p;\ }\ PERMUTATION_##type * INIT_PERMUTATION_##type(type *perm, size_t size){\ + if (size == 0) return NULL;\ + PERMUTATION_##type *p = CREATE_PERMUTATION_##type(size);\ + p->perm = perm ; /*malloc(size*sizeof(type));\ + for(size_t i=0;iperm[i] = perm[i];*/\ + return p;\ + }\ + PERMUTATION_##type * INIT_COPY_PERMUTATION_##type(type *perm, size_t size){\ if (size == 0) return NULL;\ PERMUTATION_##type *p = CREATE_PERMUTATION_##type(size);\ p->perm = malloc(size*sizeof(type));\ diff --git a/ypermutation_t/src/permutation_t/permutation_t.h b/ypermutation_t/src/permutation_t/permutation_t.h index 0ea6f12..12e224b 100644 --- a/ypermutation_t/src/permutation_t/permutation_t.h +++ b/ypermutation_t/src/permutation_t/permutation_t.h @@ -20,6 +20,7 @@ typedef struct PERMUTATION_##type PERMUTATION_##type;\ PERMUTATION_##type * CREATE_PERMUTATION_##type(size_t size);\ PERMUTATION_##type * INIT_PERMUTATION_##type(type *perm, size_t size);\ + PERMUTATION_##type * INIT_COPY_PERMUTATION_##type(type *perm, size_t size);\ PERMUTATION_TYPE_SIZE_T * TRANSLATE_TO_SET_THEORIC_SIZE_T_##type(const PERMUTATION_##type *p );\ bool IS_PERMUTATION_##type(const PERMUTATION_##type *p );\ size_t TabToPlaceAlgo_##type(const PERMUTATION_##type *p);\