Instructions to use Zipeng365/WISP with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use Zipeng365/WISP with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("Zipeng365/WISP", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Download src/wisp_fast/cis_intervals.c from Zipeng365/WISP: direct link, hf CLI and curl.
- Browser
- Download file 18.5 kB
-
https://huggingface.co/Zipeng365/WISP/resolve/main/src/wisp_fast/cis_intervals.c
- Command line
-
hf download hf://Zipeng365/WISP/src/wisp_fast/cis_intervals.c
-
curl -L -o cis_intervals.c https://huggingface.co/Zipeng365/WISP/resolve/main/src/wisp_fast/cis_intervals.c
18.5 kB
| /* All arrays originate inside our Python wrapper. Enforce contiguous native | |
| buffers, dtype, rank, extents and index ranges before native indexing. */ | |
| static int view(PyObject *obj, Py_buffer *v, int rank, char type, int write) { | |
| if (PyObject_GetBuffer(obj, v, PyBUF_C_CONTIGUOUS|PyBUF_FORMAT|(write?PyBUF_WRITABLE:0)) < 0) return 0; | |
| int integer = type=='q'; | |
| if (v->ndim!=rank || v->itemsize!=8 || !v->format || | |
| (integer ? strcmp(v->format,"q") && strcmp(v->format,"l") : strcmp(v->format,"d")) || | |
| (uintptr_t)v->buf % 8) { | |
| PyErr_SetString(PyExc_ValueError,"invalid contiguous buffer type or rank");return 0; | |
| } | |
| return 1; | |
| } | |
| static int separate_output(const Py_buffer *views,int output){ | |
| uintptr_t dst=(uintptr_t)views[output].buf; | |
| for(int i=0;i<output;i++){ | |
| uintptr_t src=(uintptr_t)views[i].buf; | |
| if(views[i].len && views[output].len && | |
| (dst>=src ? dst-src<(uintptr_t)views[i].len : src-dst<(uintptr_t)views[output].len)){ | |
| PyErr_SetString(PyExc_ValueError,"output overlaps an input"); | |
| return 0; | |
| } | |
| } | |
| return 1; | |
| } | |
| /* ord is the sorted list of time positions. Select interval membership in | |
| rank order; one packed value per rank, no per-interval indirect gathers. */ | |
| __attribute__((target("avx512f,popcnt"))) | |
| static Py_ssize_t filter_wide(const int64_t *ord,const double *rankval,double *out, | |
| Py_ssize_t n,Py_ssize_t a,Py_ssize_t b) { | |
| Py_ssize_t j=0,count=0; | |
| __m512i lo=_mm512_set1_epi64(a),hi=_mm512_set1_epi64(b); | |
| for(;j+8<=n;j+=8){ | |
| __m512i ix=_mm512_loadu_si512(ord+j); | |
| __mmask8 mask=_mm512_cmpge_epi64_mask(ix,lo)&_mm512_cmplt_epi64_mask(ix,hi); | |
| _mm512_mask_compressstoreu_pd(out+count,mask,_mm512_loadu_pd(rankval+j)); | |
| count+=__builtin_popcount((unsigned)mask); | |
| } | |
| for(;j<n;j++)if(ord[j]>=a && ord[j]<b)out[count++]=rankval[j]; | |
| return count; | |
| } | |
| /* A prefix at timestamp u stores the ranks seen before that timestamp. A | |
| bounded range query needs at most four words for common wearable windows. */ | |
| __attribute__((target("bmi2,popcnt"))) | |
| static int masked_quantiles(const uint64_t *prefix,int words,Py_ssize_t a,Py_ssize_t b, | |
| const double *rankval,const double *q,int nq,int turbo, | |
| double *out,double *range) { | |
| uint64_t bits[4];int cumulative[5]={0}; | |
| for(int w=0;w<words;w++){ | |
| bits[w]=prefix[b*words+w]^prefix[a*words+w]; | |
| cumulative[w+1]=cumulative[w]+__builtin_popcountll(bits[w]); | |
| } | |
| int len=(int)(b-a); | |
| if(cumulative[words]!=len)return 0; | |
| int first=0,last=words-1; | |
| while(!bits[first])first++; | |
| while(!bits[last])last--; | |
| double low=rankval[first*64+__builtin_ctzll(bits[first])]; | |
| double high=rankval[last*64+63-__builtin_clzll(bits[last])]; | |
| *range=high==low?0.:high-low; | |
| int w=first; | |
| for(int k=0;k<nq;k++){ | |
| double loc=(len-1)*q[k];int lo=(int)loc;double f=loc-lo; | |
| while(lo>=cumulative[w+1])w++; | |
| uint64_t flag=_pdep_u64((uint64_t)1<<(lo-cumulative[w]),bits[w]); | |
| double x=rankval[64*w+__builtin_ctzll(flag)],y=x; | |
| if(lo+1<len){ | |
| uint64_t next=bits[w] & ~(flag | (flag-1)); | |
| int ww=w; | |
| while(!next)next=bits[++ww]; | |
| y=rankval[64*ww+__builtin_ctzll(next)]; | |
| } | |
| out[k]=turbo?((len&1)?x:(x+y)*.5):(f>=.5?y-(y-x)*(1.-f):x+(y-x)*f); | |
| } | |
| return 1; | |
| } | |
| /* Across-window SIMD leaves every within-interval sum strictly serial. | |
| A small [time][8 windows] tile avoids a gather per scalar visit. */ | |
| __attribute__((target("avx512f"))) | |
| static void numeric_eight(const double *x,const int64_t *bounds,double *out,double *tile, | |
| Py_ssize_t t,Py_ssize_t c,Py_ssize_t m,int width,int turbo){ | |
| for(Py_ssize_t ch=0;ch<c;ch++){ | |
| for(Py_ssize_t j=0;j<t;j++)for(int k=0;k<8;k++)tile[j*8+k]=x[(k*t+j)*c+ch]; | |
| for(Py_ssize_t h=0;h<m;h++){ | |
| int a=(int)bounds[2*h],b=(int)bounds[2*h+1],len=b-a; | |
| __m512d sum=_mm512_setzero_pd(),p=sum,ss=sum,sl=sum,length=_mm512_set1_pd(len); | |
| double mid=(len-1)*.5,den=(double)len*((double)len*len-1.)/12.; | |
| for(int j=a;j<b;j++){ | |
| __m512d v=_mm512_loadu_pd(tile+8*j); | |
| sum=_mm512_add_pd(sum,v); | |
| if(!turbo)p=_mm512_add_pd(p,_mm512_mul_pd(v,v)); | |
| } | |
| __m512d mu=_mm512_div_pd(sum,length); | |
| for(int j=a;j<b;j++){ | |
| __m512d v=_mm512_sub_pd(_mm512_loadu_pd(tile+8*j),mu); | |
| ss=_mm512_add_pd(ss,_mm512_mul_pd(v,v)); | |
| if(!turbo)sl=_mm512_add_pd(sl,_mm512_mul_pd(_mm512_set1_pd((j-a)-mid),v)); | |
| } | |
| double dst[4][8];_mm512_storeu_pd(dst[0],mu); | |
| _mm512_storeu_pd(dst[1],_mm512_sqrt_pd(_mm512_div_pd(ss,length))); | |
| if(!turbo){ | |
| _mm512_storeu_pd(dst[2],_mm512_div_pd(p,length)); | |
| _mm512_storeu_pd(dst[3],den?_mm512_div_pd(sl,_mm512_set1_pd(den)):_mm512_setzero_pd()); | |
| } | |
| for(int k=0;k<8;k++){ | |
| double *o=out+(k*m+h)*width*c+ch; | |
| o[0]=dst[0][k];o[c]=dst[1][k]; | |
| if(!turbo){o[3*c]=dst[2][k];o[4*c]=dst[3][k];} | |
| } | |
| } | |
| } | |
| } | |
| __attribute__((target("avx512f"))) | |
| static void state_fused(const double *u,const double *th,double *hist,int t,int k){ | |
| int64_t states[8];int prev=0,j=0; | |
| for(;j+8<=t;j+=8){ | |
| __m512d x=_mm512_loadu_pd(u+j);__m512i s=_mm512_setzero_si512(),one=_mm512_set1_epi64(1); | |
| for(int l=0;l<k-1;l++) | |
| s=_mm512_mask_add_epi64(s,_mm512_cmp_pd_mask(x,_mm512_set1_pd(th[l]),_CMP_GT_OQ),s,one); | |
| _mm512_storeu_si512((void*)states,s); | |
| for(int i=0;i<8;i++){int a=(int)states[i];hist[a]++;if(j||i)hist[k+prev*k+a]++;prev=a;} | |
| } | |
| for(;j<t;j++){ | |
| int a=0;for(int l=0;l<k-1;l++)a+=u[j]>th[l]; | |
| hist[a]++;if(j)hist[k+prev*k+a]++;prev=a; | |
| } | |
| } | |
| /* Bucket by value then insertion-sort locally. Equal finite values may be | |
| permuted, but ordered value statistics do not depend on tied time positions. | |
| Defer signed zero / extreme exponents to the NumPy ordering implementation. */ | |
| static PyObject *rank_short(PyObject *self,PyObject *args) { | |
| PyObject *xo,*oo;Py_buffer v[2]={{0}};int ok=1; | |
| if(!PyArg_ParseTuple(args,"OO",&xo,&oo))return NULL; | |
| if(!view(xo,v,3,'d',0)||!view(oo,v+1,3,'q',1)||!separate_output(v,1))goto done; | |
| Py_ssize_t n=v[0].shape[0],t=v[0].shape[1],c=v[0].shape[2]; | |
| if(t<1||t>256||c<1||v[1].shape[0]!=n||v[1].shape[1]!=c||v[1].shape[2]!=t){ | |
| PyErr_SetString(PyExc_ValueError,"invalid short-rank geometry");goto done; | |
| } | |
| const double *x=v[0].buf;int64_t *out=v[1].buf; | |
| Py_BEGIN_ALLOW_THREADS | |
| for(Py_ssize_t i=0;ok && i<n;++i)for(Py_ssize_t ch=0;ok && ch<c;++ch){ | |
| int64_t *idx=out+(i*c+ch)*t;double vals[256],lo=INFINITY,hi=-INFINITY; | |
| uint8_t key[256];uint16_t edges[257]={0}; | |
| for(int j=0;j<t;++j){ | |
| double z=x[(i*t+j)*c+ch]; | |
| if(!isfinite(z) || (z==0. && signbit(z)))ok=0; | |
| if(z<lo)lo=z;if(z>hi)hi=z;vals[j]=z; | |
| } | |
| if(!ok)break; | |
| if(hi==lo){for(int j=0;j<t;++j)idx[j]=j;continue;} | |
| double span=hi-lo,s=(t-1)/span; | |
| if(!isfinite(s)||!isfinite(span)){ok=0;break;} | |
| for(int j=0;j<t;++j){ | |
| int k=(int)((vals[j]-lo)*s);if(k>=t)k=(int)t-1; | |
| key[j]=(uint8_t)k;edges[k+1]++; | |
| } | |
| for(int j=1;j<=t;++j)edges[j]+=edges[j-1]; | |
| for(int j=0;j<t;++j)idx[edges[key[j]]++]=j; | |
| int begin=0; | |
| for(int j=0;j<t;++j){ | |
| int end=edges[j]; | |
| for(int a=begin+1;a<end;++a){ | |
| int h=a;int64_t id=idx[a]; | |
| while(h>begin && vals[idx[h-1]]>vals[id]){idx[h]=idx[h-1];--h;}idx[h]=id; | |
| } | |
| begin=end; | |
| } | |
| } | |
| Py_END_ALLOW_THREADS | |
| done: | |
| for(int j=0;j<2;++j)if(v[j].obj)PyBuffer_Release(v+j); | |
| if(PyErr_Occurred())return NULL; | |
| return PyBool_FromLong(ok); | |
| } | |
| static PyObject *intervals(PyObject *self,PyObject *args) { | |
| PyObject *obj[5]; int turbo; | |
| Py_buffer v[5]={{0}}; | |
| if(!PyArg_ParseTuple(args,"OOOOOi",&obj[0],&obj[1],&obj[2],&obj[3],&obj[4],&turbo)) return NULL; | |
| if(!view(obj[0],v+0,3,'d',0)||!view(obj[1],v+1,2,'q',0)|| | |
| !view(obj[2],v+2,3,'q',0)||!view(obj[3],v+3,1,'d',0)||!view(obj[4],v+4,3,'d',1)) goto finish; | |
| if(!separate_output(v,4))goto finish; | |
| Py_ssize_t n=v[0].shape[0],t=v[0].shape[1],c=v[0].shape[2],m=v[1].shape[0],nq=v[3].shape[0]; | |
| const int width=(turbo?3:5)+(int)nq; | |
| if((turbo && (nq!=1 || ((const double*)v[3].buf)[0]!=0.5)) || t<1 || t>1048576 || c<2 || c>256 || nq<1 || nq>16 || v[1].shape[1]!=2 || | |
| v[2].shape[0]!=n || v[2].shape[1]!=c || v[2].shape[2]!=t || | |
| v[4].shape[0]!=n || v[4].shape[1]!=m || v[4].shape[2]!=width*c) { | |
| PyErr_SetString(PyExc_ValueError,"incompatible interval arguments");goto finish; | |
| } | |
| const double *x=v[0].buf,*q=v[3].buf; double *out=v[4].buf; | |
| const int64_t *bounds=v[1].buf,*order=v[2].buf; | |
| for(Py_ssize_t j=0;j<nq;j++) if(!isfinite(q[j]) || q[j]<0 || q[j]>1 || (j && q[j]<q[j-1])) { | |
| PyErr_SetString(PyExc_ValueError,"invalid ascending quantiles");goto finish; | |
| } | |
| for(Py_ssize_t j=0;j<m;j++) if(bounds[2*j]<0 || bounds[2*j+1]>t || bounds[2*j]>=bounds[2*j+1]){ | |
| PyErr_SetString(PyExc_ValueError,"empty or invalid interval");goto finish; | |
| } | |
| for(Py_ssize_t j=0;j<v[2].len/8;j++) if(order[j]<0||order[j]>=t){ | |
| PyErr_SetString(PyExc_ValueError,"invalid ordering");goto finish; | |
| } | |
| double *sorted=PyMem_Malloc(3*(size_t)t*sizeof(double)); | |
| if(!sorted){PyErr_NoMemory();goto finish;} | |
| uint64_t *prefix=NULL; | |
| int words=(int)((t+63)/64); | |
| if(t<=256 && m>=8 && CAN_FILTER && __builtin_cpu_supports("bmi2")){ | |
| prefix=PyMem_Malloc((t+1)*words*sizeof(uint64_t)); | |
| if(!prefix){PyMem_Free(sorted);PyErr_NoMemory();goto finish;} | |
| } | |
| double *tile=NULL;Py_ssize_t packed=0; | |
| if(n>=8 && t<=1024 && m>=4 && CAN_FILTER){ | |
| tile=PyMem_Malloc(8*t*sizeof(double)); | |
| if(tile)packed=n/8*8; | |
| } | |
| Py_BEGIN_ALLOW_THREADS | |
| for(Py_ssize_t i=0;i<packed;i+=8)numeric_eight(x+i*t*c,bounds,out+i*m*width*c,tile,t,c,m,width,turbo); | |
| double *rankval=sorted+t,*signal=rankval+t; | |
| int wide=CAN_FILTER; | |
| for(Py_ssize_t i=0;i<n;i++)for(Py_ssize_t ch=0;ch<c;ch++){ | |
| const int64_t *ord=order+(i*c+ch)*t; | |
| const double *src=x+i*t*c+ch; | |
| for(Py_ssize_t j=0;j<t;j++)signal[j]=src[j*c]; | |
| int monotonic=1; | |
| for(Py_ssize_t j=0;j<t;j++){ | |
| rankval[j]=signal[ord[j]]; | |
| monotonic &= isfinite(rankval[j]) && (!j || rankval[j]>=rankval[j-1]); | |
| } | |
| if(monotonic && prefix){ | |
| memset(prefix,0,(t+1)*words*sizeof(uint64_t)); | |
| for(Py_ssize_t rank=0;rank<t;rank++) | |
| prefix[(ord[rank]+1)*words+rank/64] |= (uint64_t)1<<(rank%64); | |
| for(Py_ssize_t j=0;j<t;j++) | |
| for(int w=0;w<words;w++)prefix[(j+1)*words+w] |= prefix[j*words+w]; | |
| } | |
| for(Py_ssize_t h=0;h<m;h++){ | |
| const Py_ssize_t a=bounds[2*h],b=bounds[2*h+1],len=b-a; | |
| const double mid=(len-1)*0.5, den=(double)len*(len* (double)len-1.0)/12.0; | |
| double *dst=out+(i*m+h)*width*c; | |
| const double *part=signal+a; | |
| if(i>=packed){ | |
| double sum=0,power=0; | |
| for(Py_ssize_t j=0;j<len;j++){ | |
| double u=part[j];sum+=u;if(!turbo)power+=u*u; | |
| } | |
| double mu=sum/len,ss=0,sl=0; | |
| for(Py_ssize_t j=0;j<len;j++){ | |
| double y=part[j]-mu; ss+=y*y;if(!turbo)sl+=(j-mid)*y; | |
| } | |
| dst[ch]=mu;dst[c+ch]=sqrt(ss/len); | |
| if(!turbo){dst[3*c+ch]=power/len; dst[4*c+ch]=den?sl/den:0;} | |
| } | |
| Py_ssize_t count=0; | |
| if(monotonic && prefix && masked_quantiles(prefix,words,a,b,rankval,q,(int)nq,turbo, | |
| dst+(width-nq)*c+ch*nq,dst+2*c+ch))continue; | |
| if(wide && t>=16)count=filter_wide(ord,rankval,sorted,t,a,b);else | |
| for(Py_ssize_t j=0;j<t;j++){ | |
| int64_t ix=ord[j];if(ix>=a && ix<b)sorted[count++]=rankval[j]; | |
| } | |
| /* Wrapper supplies an argsort permutation. Guard duplicate indices | |
| even if an external extension caller supplies its own buffer. */ | |
| if(monotonic && count==len){ | |
| dst[2*c+ch]=sorted[len-1]==sorted[0]?0.:sorted[len-1]-sorted[0]; | |
| }else{ | |
| double min=part[0],max=min; | |
| for(Py_ssize_t j=1;j<len;j++){min=fmin(min,part[j]);max=fmax(max,part[j]);} | |
| dst[2*c+ch]=max-min; | |
| } | |
| if(count!=len){ for(Py_ssize_t k=0;k<nq;k++)dst[(width-nq)*c+ch*nq+k]=NAN;continue; } | |
| for(Py_ssize_t k=0;k<nq;k++){ | |
| double loc=(len-1)*q[k];Py_ssize_t lo=(Py_ssize_t)loc,hi=lo+1<len?lo+1:lo; | |
| double f=loc-lo,low=sorted[lo],high=sorted[hi],delta=high-low; | |
| dst[(width-nq)*c+ch*nq+k]=turbo ? ((len&1)?low:(low+high)*0.5) : | |
| (f>=0.5?high-delta*(1.0-f):low+delta*f); | |
| } | |
| } | |
| } | |
| Py_END_ALLOW_THREADS | |
| PyMem_Free(tile);PyMem_Free(prefix);PyMem_Free(sorted); | |
| finish: | |
| for(int i=0;i<5;i++)if(v[i].obj)PyBuffer_Release(&v[i]); | |
| if(PyErr_Occurred())return NULL; | |
| Py_RETURN_NONE; | |
| } | |
| static PyObject *state_counts(PyObject *self,PyObject *args){ | |
| PyObject *xx,*qq,*oo;Py_buffer v[3]={{0}}; | |
| if(!PyArg_ParseTuple(args,"OOO",&xx,&qq,&oo))return NULL; | |
| if(!view(xx,&v[0],3,'d',0)||!view(qq,&v[1],3,'d',0)||!view(oo,&v[2],3,'d',1))goto done; | |
| if(!separate_output(v,2))goto done; | |
| Py_ssize_t n=v[0].shape[0],c=v[0].shape[1],t=v[0].shape[2],k=v[1].shape[2]+1; | |
| if(t<1||k<2||k>32||v[1].shape[0]!=n||v[1].shape[1]!=c||v[2].shape[0]!=n|| | |
| v[2].shape[1]!=c||v[2].shape[2]!=k*(1+k)){ | |
| PyErr_SetString(PyExc_ValueError,"incompatible count buffers");goto done; | |
| } | |
| const double *x=v[0].buf,*q=v[1].buf;double *out=v[2].buf; | |
| Py_BEGIN_ALLOW_THREADS | |
| memset(out,0,v[2].len); | |
| for(Py_ssize_t z=0;z<n*c;z++){ | |
| const double *u=x+z*t,*th=q+z*(k-1); | |
| double *hist=out+z*k*(k+1); | |
| if(t>=16 && t<=8192 && CAN_FILTER){state_fused(u,th,hist,(int)t,(int)k);continue;} | |
| int prev=0; | |
| for(Py_ssize_t j=0;j<t;j++){ | |
| int state=0; | |
| for(int l=0;l<k-1;l++)state+=u[j]>th[l]; | |
| hist[state]++; | |
| if(j)hist[k+prev*k+state]++; | |
| prev=state; | |
| } | |
| } | |
| Py_END_ALLOW_THREADS | |
| done: | |
| for(int i=0;i<3;i++)if(v[i].obj)PyBuffer_Release(&v[i]); | |
| if(PyErr_Occurred())return NULL; | |
| Py_RETURN_NONE; | |
| } | |
| /* Pool normalized histogram, transition probabilities and Shannon terms in | |
| one pass. A small table prepared by NumPy retains the original log and | |
| division for all attainable (numerator, denominator) pairs. */ | |
| static double symbolic_sum(const double *a,int m){ | |
| if(m<8){ double s=-0.;for(int i=0;i<m;i++)s+=a[i];return s; } | |
| if(m>128){int cut=m/16*8;return symbolic_sum(a,cut)+symbolic_sum(a+cut,m-cut);} | |
| double sums[8];memcpy(sums,a,sizeof sums); | |
| int j=8; | |
| for(;j+8<=m;j+=8)for(int i=0;i<8;i++)sums[i]+=a[j+i]; | |
| double res=((sums[0]+sums[1])+(sums[2]+sums[3]))+((sums[4]+sums[5])+(sums[6]+sums[7])); | |
| for(;j<m;j++)res+=a[j];return res; | |
| } | |
| static PyObject *state_pool(PyObject *self,PyObject *args){ | |
| PyObject *ob[4];Py_buffer v[4]={{0}}; | |
| if(!PyArg_ParseTuple(args,"OOOO",&ob[0],&ob[1],&ob[2],&ob[3]))return NULL; | |
| for(int i=0;i<4;i++)if(!view(ob[i],v+i,3,'d',i==3))goto done; | |
| if(!separate_output(v,3))goto done; | |
| Py_ssize_t n=v[0].shape[0],c=v[0].shape[1],t=v[0].shape[2],k=v[1].shape[2]+1; | |
| if(t<1 || t>512 || k<2 || k>16 || v[1].shape[0]!=n || v[1].shape[1]!=c || | |
| v[2].shape[0]!=t+1 || v[2].shape[1]!=t+1 || v[2].shape[2]!=2 || | |
| v[3].shape[0]!=n || v[3].shape[1]!=c || v[3].shape[2]!=k+k*k+1){ | |
| PyErr_SetString(PyExc_ValueError,"invalid bounded symbolic pooling dimensions");goto done; | |
| } | |
| const double *x=v[0].buf,*b=v[1].buf,*tab=v[2].buf;double *out=v[3].buf; | |
| Py_BEGIN_ALLOW_THREADS | |
| for(Py_ssize_t row=0;row<n*c;row++){ | |
| const double *src=x+row*t,*th=b+row*(k-1); | |
| double counts[16+256]={0.},terms[256],*dest=out+row*(k+k*k+1); | |
| if(t>=16 && CAN_FILTER)state_fused(src,th,counts,t,k); | |
| else | |
| { | |
| int prev=0; | |
| for(int j=0;j<t;j++){ | |
| int a=0;for(int l=0;l<k-1;l++)a+=src[j]>th[l]; | |
| counts[a]++;if(j)counts[k+prev*k+a]++;prev=a; | |
| } | |
| } | |
| for(int j=0;j<k;j++){ | |
| int den=0;dest[j]=counts[j]/t; | |
| for(int l=0;l<k;l++)den+=(int)counts[k+j*k+l]; | |
| const double *lookup=tab+2*(den?den:1)*(t+1); | |
| for(int l=0;l<k;l++){ | |
| int ix=j*k+l,count=(int)counts[k+ix]; | |
| dest[k+ix]=lookup[2*count];terms[ix]=lookup[2*count+1]; | |
| } | |
| } | |
| dest[k+k*k]=-(symbolic_sum(terms,k*k)+0.); | |
| } | |
| Py_END_ALLOW_THREADS | |
| done: | |
| for(int i=0;i<4;i++)if(v[i].obj)PyBuffer_Release(v+i); | |
| if(PyErr_Occurred())return NULL;Py_RETURN_NONE; | |
| } | |
| static PyMethodDef methods[]={ | |
| {"levels",interval_levels,METH_VARARGS,"Exact low-cardinality interval quantiles."}, | |
| {"rank_short",rank_short,METH_VARARGS,"Build short-window rank permutations for finite statistics."},{"state_pool",state_pool,METH_VARARGS,"Normalized state, transition and entropy features."},{"intervals",intervals,METH_VARARGS,"Pool interval statistics."},{"state_counts",state_counts,METH_VARARGS,"Count occupancy and successive states."},{NULL,NULL,0,NULL}}; | |
| static struct PyModuleDef mod={PyModuleDef_HEAD_INIT,"_cis_intervals",NULL,-1,methods}; | |
| PyMODINIT_FUNC PyInit__cis_intervals(void){return PyModule_Create(&mod);} | |