1. Å« ¹è¿¿¡¼ ºÎºÐ ¹è¿À» ã¾Æ³»´Â ÇÔ¼ö¸¦ ¸¸µé¾ú´Âµ¥¿ä, sub_region ÇÔ¼ö º¸½Ã¸é ÀÔ·Â ÀÎÀÚÁß Çϳª°¡ Æ÷ÀÎÅÍÀε¥ À̰͵µ ÇÔ¼ö ³¡³¯ ¶§ ÇØÁ¦ ÇØÁÙ¼ö°¡ ÀÖ³ª¿ä?
2. ±×¸®°í ÇÔ¼ö¿¡¼ Æ÷ÀÎÅ͸¦ ¹Ýȯ ½ÃÅ°°í ½ÍÀºµ¥ ¸¸¾à ÀÌ Æ÷ÀÎÅÍ°¡ µ¿Àû ÇÒ´çµÈ °´Ã¼¸é ¾î¶»°Ô/¾îµð¼ ¹Ýȯ ½ÃÄÑ¾ß Çϳª¿ä? Á¦°¡ ÀÛ¼ºÇÑ Äڵ忡¼ sug_region ÇÔ¼ö ³¡ÀÚ¶ô¿¡ º¸¸é Æ÷ÀÎÅÍ °´Ã¼¸¦ ¹Ýȯ½ÃÅ°°í ³ª¼ ÀÌ°É ÇØü½ÃÅ°´Âµ¥ ÀÌ·± ¹æ¹ýµµ ±¦Âú³ª¿ä? ¸¸¾à ¾È±¦Âú´Ù¸é ¾îµð¼/¾î¶»°Ô ÇØÁ¦È÷ÄÑ¾ß Çϳª¿ä?
#include <stdio.h>
#include <stdlib.h>
float *sub_region(float *in_fld, int in_fld_nx, int in_fld_ny, int in_sub_nx, int in_sub_ny, int in_sub_num);
int main()
{
int i,j,k;
int x_siz = 12,
y_siz = 12,
sub_region_x_siz = 3,
sub_region_y_siz = 6,
sub_region_siz = x_siz/sub_region_x_siz * y_siz/sub_region_y_siz;
float *arr = malloc(sizeof(float) * x_siz * y_siz),
*sub = malloc(sizeof(float) * sub_region_x_siz * sub_region_y_siz);
printf("orig arrayn");
for (j=0;j<y_siz;j++)
{
for (i=0;i<x_siz;i++)
{
arr[j * x_siz + i] = j * x_siz + i;
//printf("%3d %3.1fn",j * x_size + i, arr[j * x_size + i]);
printf("%3d ",j * x_siz + i);
}
printf("n");
}
for (k=0;k<sub_region_siz;k++)
{
sub = sub_region((float*)arr, x_siz, y_siz, sub_region_x_siz, sub_region_y_siz, k);
printf("nnsub area : %d nn",k);
for (j=0;j<sub_region_y_siz;j++)
{
for (i=0;i<sub_region_x_siz;i++)
{
printf("%3.0f ",sub[j * sub_region_x_siz + i]);
}
printf("n");
}
}
free(arr);
free(sub);
return 0;
}
float *sub_region(
float *in_fld ,
int in_fld_nx ,
int in_fld_ny ,
int in_sub_nx ,
int in_sub_ny ,
int in_sub_num
)
{
// funtion that sub-sets a specified size of an input array
// inputs :
// 1. *in_fld : 2d field array [float* ]
// 2. in_fld_nx : size of x dimension of the 2d field array [integer]
// 3. in_fld_ny : size of y dimension of the 2d field array [integer]
// 4. in_sub_nx : size of x dimension of the sub-set array [integer]
// 5. in_sub_ny : size of y dimension of the sub-set array [integer]
// 6. in_sub_num : number of sub-set array [integer]
//
// outputs :
// 1. out_arr : sub-set array [float* ]
int i,j;
int x_idx_siz = in_fld_nx/in_sub_nx ,
y_idx_siz = in_fld_ny/in_sub_ny ,
y_stride = in_fld_ny * in_sub_ny,
*lt_idxs = malloc(sizeof(int) * x_idx_siz * y_idx_siz);
float *out_arr = malloc(sizeof(float) * in_sub_nx * in_sub_ny);
printf("ny stride : %dn",y_stride);
printf("idxs: ");
// calculating left top indexes for the sub-set arrays (x-direction)
for (j=0;j<y_idx_siz;j++)
for (i=0;i<x_idx_siz;i++)
{
lt_idxs[j * x_idx_siz + i] = j * y_stride + i * in_sub_nx;
printf("%d ",j * y_stride + i * in_sub_nx);
}
// sub-setting array
for (j=0;j<in_sub_ny;j++)
for (i=0;i<in_sub_nx;i++)
{
out_arr[j * in_sub_nx + i] = in_fld[lt_idxs[in_sub_num] + j * in_fld_nx + i];
}
return out_arr;
free(out_arr);
free(lt_idxs);
free(in_fld);
}
°¨»çÇÕ´Ï´Ù.
2022.01.06 06:55:07 |
[C] ÇÔ¼ö¿¡¼ Æ÷ÀÎÅÍ °´Ã¼ ÇØÁ¦ Áú¹® |
Àâ´ã | 3,015¸íÀÌ Àоú¾î¿ä.
|
6°³ÀÇ ´ñ±Û |
³¡ÀÚ¶ô¸¸ Àоú½À´Ï´Ù¸¸
ÇÔ¼ö¸¦ ¸®ÅÏÇÏ¸é ¸®ÅÏ ÀÌÈÄ ÄÚµå´Â ½ÇÇàµÇÁö ¾Ê°í ÇÔ¼ö°¡ Á¾·áµË´Ï´Ù ±×·¸´Ù°í ¸®ÅÏ Àü¿¡ freeÇϽðųª ¹Ýȯ Æ÷ÀÎÅÍ »ç¿ë Àü freeÇϽøé ÀÇ¹Ì ¾ø´Â ÇÔ¼ö°¡ µË´Ï´Ù. ºÒÇÊ¿äÇÑ Æ÷ÀÎÅÍ´Â ¸®ÅÏ Àü¿¡ ÇØÁ¦ÇÏ½Ã°í »ç¿ëÇÒ Æ÷ÀÎÅÍ´Â »ç¿ë ÈÄ ÇØÁ¦Çϼ¼¿ä |
|
2022/01/06 10:22
|
ÀÌÀü Áú¹®µéÀ̶û º¸¸é ¾ÕÀ¸·Îµµ °è¼Ó C¸¦ ¾²½Ç°Å °°Àºµ¥
C ±âÃÊ Ã¥À» Çϳª »ç¼ º¸½Ã´ø°¡, ÀÎÇÁ·± °°Àºµ¥¼¶óµÎ Àΰ Çϳª º¸½Ã´Â°É ÃßõÇÕ´Ï´Ù. ¹°¾îº¸½Ã´ø ³»¿ëµéÀº ÀüºÎ ±âÃÊÀûÀÎ ³»¿ëµéÀÌ¶ó¼ ¾Æ¸¶ ±âº» Ã¥µé¸¸ º¸¼Åµµ ´Ù ¸¶½ºÅÍ ÇÏ½Ç °Å¿¡¿ä ¹°³í ¾ËÁö·Õ¿¡ ¹°¾îº¸¸é ´Ù ¾Ë·ÁÁÖ±ä ÇÏÁö¸¸ ºñÈ¿À²ÀûÀ̴ϱñ¿µ ´ä 1. ³× °¡´ÉÇÕ´Ï´Ù. ±×³É ¾Æ¹«µ¥¼³ª free È£ÃâÇÏ¸é µË´Ï´Ù. ´ä 2. return Å°¿öµå µÚÀÇ ³»¿ëµéÀº ½ÇÇàµÇÁö ¾Ê½À´Ï´Ù. °í·Î free µÇÁö ¾Ê½À´Ï´Ù. free´Â Ç×»ó ÇØ´ç Æ÷ÀÎÅ͸¦ ¸¶Áö¸·À¸·Î »ç¿ëÇÑ À§Ä¡¿¡¼ È£ÃâÇÏ¼Å¾ß ÇÕ´Ï´Ù. |
|
2022/01/06 11:50
|
°¨»çÇÕ´Ï´Ù. return ÀÌÈķδ ¾Æ¹«°Íµµ ½ÇÇà ¾ÈµÈ´Ù´Â°É ¾Ë°í ÀÖ¾ú´Âµ¥ ¿¹Àü¿¡ ¾îµð ÀÌ»óÇѵ¥¼ ÁÖ¿öµéÀº°Ô ÀÖ¾î¼ °è¼Ó ½á¿Ô³×¿ä;;;; ¾Æ¹«·± »ý°¢ ¾ÈÇÏ°í ÃÖ±Ù¿¡ ÇÁ·Î±×·¥ ½ÇÇàÇÏ´Ù°¡ ¸Þ¸ð¸®°¡ »õ´Â°Å °°¾Æ¼ ´Ù½Ã ºÃ³×¿ä. | |
2022/01/06 12:02
|
´Ù¸¥ Áú¹®ÀÌ Çϳª ´õ Àִµ¥¿ä. À§ÀÇ Äڵ忡¼ °°ÀÌ sub_region ÇÔ¼ö¸¦ ¿©·¯¹ø ºÒ·¯¾ßÇÏ´Â °æ¿ì¿¡´Â Á¦°¡ »ç¿ëÇÑ ÇÔ¼öÀÇ ¹æ½ÄÀÌ À߸øµÈ »ç¿ëµÈ°Ç°¡¿ä? ÇÔ¼ö ³»¿¡¼ free°¡ µÇÁö´Â ¾Ê°í, ¸ÞÀÎ ÇÔ¼ö ³¡¿¡¼¸¸ free µÇ´Ï±î fpr loop ¾È¿¡¼´Â ¹Ýº¹ÀûÀÎ ÇÔ¼ö È£Ãâ ¶§¹®¿¡ ¸Þ¸ð¸®°¡ »õ´Â°Ô ¸Â´Â°¡¿ä? | |
2022/01/06 12:08
|
³× ½ÇÁ¦·Ð Çϳªµµ ÇØÁ¦ ¾ÈµÇ°í ÀÖ´Â °Ì´Ï´Ù | |
2022/01/06 19:56
|
5// ÇÏ... ±×·³ Áö±Ý ±îÁö »ðÁú ÇѰűº¿ä... ´äº¯ °¨»çÇÕ´Ï´Ù. | |
2022/01/07 04:21
|
°Ô½ÃÆÇ ¸ñ·ÏÀ¸·Î µ¹¾Æ°¡±â