[b59441]: src / ciutils.c Maximize Restore History

Download this file

ciutils.c    138 lines (120 with data), 2.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* NOT PROCESSED DIRECTLY, see ltfat_complexindependent.c */
#ifdef LTFAT_TYPE
#include <complex.h>
#include "config.h"
#include "ltfat.h"
LTFAT_EXTERN
void LTFAT_NAME(circshift)(LTFAT_TYPE *in, LTFAT_TYPE *out, const ptrdiff_t L, const ptrdiff_t shift)
{
ptrdiff_t shiftMod = shift%L;
if(in==out)
{
if(1)
{
LTFAT_TYPE *inTmp = (LTFAT_TYPE *)ltfat_malloc(L*sizeof(LTFAT_TYPE));
memcpy(inTmp,in,L*sizeof(LTFAT_TYPE));
LTFAT_NAME(circshift)(inTmp,out,L,shift);
ltfat_free(inTmp);
}
else
{
int m,count,ii,jj;
for(m=0,count=0;count!=L;m++)
{
LTFAT_TYPE t = in[m];
for(ii=m,jj=m+shiftMod;
jj!=m;
ii=jj,jj=jj+shiftMod<L?jj+shiftMod:jj+shiftMod-L,count++)
{
in[ii]=in[jj];
}
in[ii]=t;
count++;
}
}
return;
}
if(shiftMod<0)
{
memcpy(out,in-shiftMod,(L+shiftMod)*sizeof(LTFAT_TYPE));
memcpy(out+(L+shiftMod),in,-shiftMod*sizeof(LTFAT_TYPE));
}
else if(shiftMod>0)
{
memcpy(out+shiftMod,in,(L-shiftMod)*sizeof(LTFAT_TYPE));
memcpy(out,in+L-shiftMod,shiftMod*sizeof(LTFAT_TYPE));
}
else
{
memcpy(out,in,L*sizeof(LTFAT_TYPE));
}
}
LTFAT_EXTERN
void LTFAT_NAME(reverse_array)(LTFAT_TYPE *in, LTFAT_TYPE *out,const size_t L)
{
if(in==out)
{
LTFAT_TYPE tmpVar = (LTFAT_TYPE) 0.0;
for(size_t ii=0;ii<L/2;ii++)
{
tmpVar = in[L-1-ii];
in[L-1-ii] = in[ii];
in[ii] = tmpVar;
}
}
else
{
for(size_t ii=0;ii<L;ii++)
{
out[ii] = in[L-1-ii];
}
}
}
LTFAT_EXTERN
void LTFAT_NAME(conjugate_array)(LTFAT_TYPE *in, LTFAT_TYPE *out,const size_t L)
{
#ifdef LTFAT_COMPLEXTYPE
for(size_t ii=0;ii<L;ii++)
{
out[ii] = LTFAT_COMPLEXH_NAME(conj)(in[ii]);
}
#else
if(in==out)
{
return;
}
else
{
memcpy(out,in,L*sizeof(LTFAT_TYPE));
}
#endif
}
LTFAT_EXTERN
void LTFAT_NAME(array2complex)(LTFAT_TYPE *in, LTFAT_COMPLEXH *out, const size_t L)
{
#ifdef LTFAT_COMPLEXTYPE
if(in==(LTFAT_TYPE*)out)
{
return;
}
else
{
memcpy(out,in,L*sizeof(LTFAT_COMPLEXH));
}
#else
if(in==(LTFAT_TYPE*)out)
{
// This should produce an error
}
else
{
LTFAT_REAL (*outTmp)[2] = (LTFAT_REAL(*)[2]) out;
for(size_t ii=0;ii<L;ii++)
{
outTmp[ii][0] = in[ii];
outTmp[ii][1] = (LTFAT_TYPE) 0.0;
}
}
#endif
}
#endif // LTFAT_TYPE