-
Notifications
You must be signed in to change notification settings - Fork 1
/
vecst.mod
3269 lines (3113 loc) · 107 KB
/
vecst.mod
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
: $Id: vecst.mod,v 1.499 2011/07/22 22:16:48 billl Exp $
:* COMMENT
COMMENT
thresh turns analog vec to BVBASE,1 vec separating at thresh (scalar or vec)
triplet return location of a triplet in a vector
onoff turns state vec on or off depending on values in other vecs
bpeval used by backprop: vo=outp*(1-outp)*del
w like where but sets chosen nums // modified from .wh in 1.23
whi find indices where vec equal to given values
dest.xing(src,tvec,thresh) determines where vector crosses in a positive direction
dest.snap(src,tvec,dt) interpolate src with tvec to prior dt step, saves only highest value
xzero count 0 crossings by putting in a 1 or -1
negwrap wrap negative values around to pos (with flag just set to 0)
indset(ind,val) sets spots indexed by ind to val
ismono([arg]) checks if a vector is monotonically increaseing (-1 decreasing)
count(num) count the number of nums in vec
muladd(mul,add) mul*x+add
binfind(num) find index for num in a sorted vector
scr.fewind(ind,veclist) // uses ind as index into other vecs
ind.findx(vecAlist,vecBlist) // uses ind as index into vecA's to load in vecB's
ind.sindx(vecAlist,vecBlist) // replace ind elements in vecA's with vecB's values
ind.sindv(vecAlist,valvec) // replace ind elements in vecA's with vals
scr.nind(ind,vec1,vec2[,vec3,vec4]) // uses ind to elim elems in other vecs
yv.circ(xv,x0,y0,rad) // put coords of circle into xv and yv
ind.keyind(key,vec1,vec2[,vec3,vec4]) // pick out bzw. values from vectors
ind.slct(key,args,veclist) // pick out bzw. values from vectors
ind.slor(key,args,veclist) // do OR rather than AND function of slct
vdest.intrp(flag) // interpolate numbers replacing numbers given as flag
v.insct(v1,v2) // return v1 intersect v2
vdest.cull(vsrc,key) // remove values found in key
vdest.redundout(vsrc[,INDFLAG]) // remove repeat values, with flag return indices
ind.mredundout(veclistA[,INDFLAG,veclistB]) // remove repeats from parallel vectors
v.cvlv(v1,v2) // convolve v1 with v2
v2d copy into a double block
d2v copy out of a double block NB: same as vec.from_double()
smgs rewrite of sumgauss form ivovect.cpp
smsy sum syn potentials off a tvec
iwr write integers
ird read integers
ident give pointer addresses and sizes
lcat concatentate all vectors from a list
fread2 like vec.fread but uses flag==6 for unsigned int
vfill fill vdest with multiple instances of vsrc until reach size
inv return inverse of number multiplied by optional num
slone(src,val) select indices where ==VAL from sorted vector SRC
piva.join(pivb,veclista,veclistb) copies values from one set of vecs to other
Non-vector routines
isojt compare 2 objects to see if they're of the same type
eqojt compare 2 object pointers to see if they point to same thing
sumabs return sum of absolute values
rnd round off to nearest integer
ENDCOMMENT
NEURON {
SUFFIX nothing
: BVBASE is bit vector base number (typically 0 or -1)
GLOBAL BVBASE, RES, VECST_INSTALLED, DEBUG_VECST, VERBOSE_VECST, INTERP_VECST, LOOSE
}
PARAMETER {
BVBASE = 0.
VECST_INSTALLED=0
DEBUG_VECST=0
VERBOSE_VECST=1
INTERP_VECST=1 : interpolation
LOOSE=1e-6
: code words
ERR= -1.3480e121
GET= -1.3479e121
SET= -1.3478e121
OK= -1.3477e121
NOP= -1.3476e121
: 0 args
ALL=-1.3479e120
NEG=-1.3478e120
POS=-1.3477e120
CHK=-1.3476e120
NOZ=-1.3475e120
: 1 arg
GTH=-1.3474e120
GTE=-1.3473e120
LTH=-1.3472e120
LTE=-1.3471e120
EQU=-1.3470e120
EQV=-1.3469e120 : value equal to same row value in parallel vector
EQW=-1.3468e120 : value found in other vector
EQX=-1.3467e120 : value found in sorted vector
EQY=-1.34665e120 : value found in sorted vector -- within LOOSE
NEQ=-1.3466e120
SEQ=-1.3465e120
RXP=-1.3464e120
: 2 args
IBE=-1.3463e120
EBI=-1.3462e120
IBI=-1.3461e120
EBE=-1.3460e120
}
ASSIGNED { RES }
VERBATIM
#include "misc.h"
ENDVERBATIM
VERBATIM
// Maintain parallel int vector to avoid slowness of repeated casts
int cmpdfn (double a, double b) {return ((a)<=(b))?(((a) == (b))?0:-1):1;}
static unsigned int bufsz=0;
unsigned int scrsz=0;
unsigned int *scr=0x0;
unsigned int dcrsz=0;
double *dcr=0x0;
int *iscr=0x0;
unsigned int iscrsz=0;
int *iscrset (int nx) {
if (nx>iscrsz) {
iscrsz=nx+10000;
if (iscrsz>0) { iscr=(int *)realloc((void*)iscr,(size_t)iscrsz*sizeof(int));
} else { iscr=(int *)ecalloc(iscrsz, sizeof(int)); }
}
return iscr;
}
unsigned int *scrset (int nx) {
if (nx>scrsz) {
scrsz=nx+10000;
if (scrsz>0) { scr=(unsigned int *)realloc((void*)scr,(size_t)scrsz*sizeof(int));
} else { scr=(unsigned int *)ecalloc(scrsz, sizeof(int)); }
}
return scr;
}
double *dcrset (int nx) {
if (nx>dcrsz) {
dcrsz=nx+10000;
if (dcrsz>0) { dcr=(double*) realloc((void*)dcr,(size_t)dcrsz*sizeof(double));
} else { dcr=(double*)ecalloc(dcrsz, sizeof(double)); }
}
return dcr;
}
ENDVERBATIM
:* v1.ident() gives addresses and sizes
VERBATIM
static double ident (void* vv) {
int nx,bsz; double* x;
nx = vector_instance_px(vv, &x);
bsz=vector_buffer_size((IvocVect*)vv);
printf("Obj*%x Dbl*%x Size: %d Bufsize: %d\n",vv,x,nx,bsz);
return (double)nx;
}
ENDVERBATIM
:* v1.indset(ind,x[,y]) sets indexed values to x and other values to optional y
: v1.indset(ind,vvec[,y]) sets indexed values to vvec values
: v1.indset(ind,"INC",1) increments values
: v1.indset(ind,"INC",-1) decrements values
: v1.indset(v2, "EQU",val,x[,y]) checks if v2 is EQU to val
VERBATIM
static double indset (void* vv) {
int i, nx, ny, nz, flag, equ; char *op;
double *x, *y, *z, val, val2, inc;
nx = vector_instance_px(vv, &x);
ny = vector_arg_px(1, &y);
val2=flag=equ=inc=0;
if (hoc_is_object_arg(2)) {
flag=1;
nz = vector_arg_px(2, &z);
if (ny!=nz) z=vector_newsize(vector_arg(2),ny);
} else if (hoc_is_double_arg(2)) {
val=*getarg(2);
} else if (hoc_is_str_arg(2)) {
op = gargstr(2);
if (strcmp(op,"EQU")==0) equ=1; else if (strcmp(op,"INC")==0) inc=1; else {
printf("indset %s not recog\n",op); hxe(); }
}
if (equ) {
val2 = *getarg(3); val=*getarg(4);
for (i=0; i<ny; i++) if (y[i]==val2) x[i]=val;
} else {
if (ifarg(3)) {
val2 = *getarg(3);
if (inc && val2==0) {printf("vecst:indset ERRA inc of 0\n"); hxe();}
if (inc) inc=val2; else for (i=0; i<nx; i++) { x[i]=val2; } // fill it
}
for (i=0; i<ny; i++) {
if (y[i] > nx) {printf("vecst:inset ERRB Index exceeds vector size %g %d\n",y[i],nx); hxe();}
if (inc!=0) x[(int)y[i]]+=inc; else if (flag) x[(int)y[i]]=z[i]; else x[(int)y[i]]=val;
}
}
return (double)i;
}
ENDVERBATIM
:* v1.mkind(ind) creates a simple index for starts of a sorted integer vector v1
VERBATIM
static double mkind(void* vv) {
int i, j, nx, ny, flag;
double *x, *y, flox, last, min, max;
nx = vector_instance_px(vv, &x);
ny = vector_arg_px(1, &y);
flag=ifarg(2)?(int)*getarg(2):0;
min=x[0]; max=x[nx-1];
ny=max-min+4+(flag?0:min);
if (ny>1e6) printf("vecst:mkind() WARNING: index of size %d being built\n",ny);
y=vector_newsize(vector_arg(1),ny);
y[0]=0.; y[ny-3]=nx; y[ny-2]=min; y[ny-1]=max; // last 2 record min,max
if (min==max) {printf("vecst:mkind() ERRA: min==max %g %g\n",min,max); hxe();}
if (!flag) for (j=1;j<=min;j++) y[j]=0.; else j=1;
for (i=1,last=floor(min); i<nx; i++) {
flox=floor(x[i]);
if (flox==last) continue;
if (flox<last) {printf("vecst:mkind() ERRB: non-mono vec.x[%d]<x[%d]\n",i,i-1);hxe();}
for (;flox>=last+1;j++,last++) y[j]=(double)i;
last=flox;
}
return min;
}
ENDVERBATIM
:* yv.circ(xv,x0,y0,rad) sets cartesian x,y coords for circle with center x0,y0; radius rad
VERBATIM
static double circ (void* vv) {
int i, nx, ny, flag, lnew;
double *x, *y, x0, y0, x1, y1, rad, theta;
lnew=0;
nx = vector_instance_px((IvocVect*)vv, &x);
ny = vector_arg_px(1, &y);
if (ny!=nx) { hoc_execerror("v.circ: Vector sizes don't match.", 0); }
x0=*getarg(2); y0=*getarg(3); rad=*getarg(4);
if (ifarg(6)) { // gives center and a point on the circle instead of radius
x1=rad; y1=*getarg(5);
rad=sqrt((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1));
lnew=*getarg(6); // resize the vectors
} else if (ifarg(5)) lnew=*getarg(5); // resize the vectors
if (lnew) { nx=lnew; x=vector_newsize((IvocVect*)vv,nx); y=vector_newsize(vector_arg(1),ny=nx); }
for (i=0,theta=0; i<nx; theta+=2*M_PI/(nx-1),i++) {
x[i]=y0+rad*sin(theta); y[i]=x0+rad*cos(theta);
}
return rad;
}
ENDVERBATIM
:* v1.roton(x) rotate 1-10 values onto end of constant-length queue
VERBATIM
static double roton (void* vv) {
int i, j, nx, nz, flag;
double *x, *z, val[10];
nx = vector_instance_px(vv, &x);
flag=0;
if (hoc_is_object_arg(1)) {
flag=1; nz = vector_arg_px(1, &z);
} else {
for (i=1;i<=10 && ifarg(i);i++) val[i-1]= *getarg(i);
nz=i-1;
}
if (nz>nx) {printf("v.roton: Can't rotate %d vals on vec of size %d\n",nz,nx); hxe();}
for (i=nz,j=0; i<nx; i++,j++) x[j]=x[i];
for (i=nx-nz,j=0; j<nz; i++,j++) x[i]=flag?z[j]:val[j];
return (double)nz;
}
ENDVERBATIM
:* tmp.fewind(ind,veclist)
: picks out numbers from multiple vectors using index ind
VERBATIM
static double fewind (void* vv) {
int i, j, k, nx, ni, nv[VRRY], num, flag;
Object* ob;
double *x, *ind, *vvo[VRRY];
char *ix;
nx = vector_instance_px(vv, &x);
ni = vector_arg_px(1, &ind);
ob = *hoc_objgetarg(2);
if (ifarg(3)) flag=(int)*getarg(3); else flag=0; // flag==1 for handling non-uniq indices
num = ivoc_list_count(ob);
if (num>VRRY) hoc_execerror("ERR: fewind can only handle VRRY vectors", 0);
if (flag) ix=(char*)ecalloc(nx,sizeof(char));
if (!flag && nx<ni) {printf("fewind WARNING nx!=ni: %d!=%d, setting nonuniq flag\n",nx,ni);
flag=1; }
for (i=0;i<num;i++) {
nv[i] = list_vector_px(ob, i, &vvo[i]);
if (nx!=nv[i]) { printf("fewind ERR %d %d %d\n",i,nx,nv[i]);
hoc_execerror("Vectors must all be same size: ", 0); }
}
if (nx>scrsz) {
if (scrsz>0) { free(scr); scr=(unsigned int *)NULL; }
scrsz=nx+10000;
scr=(unsigned int *)ecalloc(scrsz, sizeof(int));
}
if (flag) {
for (i=0;i<nx;i++) ix[i]=0;
for (i=0,k=0;i<ni && k<nx;i++) {
j=(int)ind[i];
if (ix[j]==0) {
if (j>=nx || j<0) { printf("fewind ERR1A %d %d\n",j,nx); free(ix);hxe();}
scr[k]=j;
ix[j]=1; // indicate that has already been used
k++;
}
}
ni=nx; // index up to max
} else for (i=0;i<ni;i++) {
scr[i]=(int)ind[i]; // copy into integer array
if (scr[i]>=nx || scr[i]<0) { printf("fewind ERR1 %d %d\n",scr[i],nx);
hoc_execerror("Index vector out-of-bounds", 0); }
}
if (flag) for (i=0;i<ni;i++) if (ix[i]==0) {printf("fewind ERR2 %d\n",i); hxe();}
for (j=0;j<num;j++) {
for (i=0;i<ni;i++) x[i]=vvo[j][scr[i]];
for (i=0;i<ni;i++) vvo[j][i]=x[i];
vvo[j]=list_vector_resize(ob, j, ni);
}
if (flag) free(ix);
return (double)ni;
}
ENDVERBATIM
:* ind.findx(vecAlist,vecBlist)
: uses ind as index into vecA's to load in vecB's (for select); a nondestructive fewind()
VERBATIM
static double findx (void* vv) {
IvocVect* vv_tmp = (IvocVect*)vv;
int i, j, ni, nx, av[VRRY], bv[VRRY], num;
Object *ob1, *ob2;
double *ind, *avo[VRRY], *bvo[VRRY];
ni = vector_instance_px((IvocVect*)vv, &ind);
ob1 = *hoc_objgetarg(1);
ob2 = *hoc_objgetarg(2);
num = ivoc_list_count(ob1);
i = ivoc_list_count(ob2);
if (i!=num) hoc_execerror("findx ****ERRA****: lists have different counts", 0);
if (num>VRRY) hoc_execerror("findx ****ERRB****: can only handle VRRY vectors", 0);
for (i=0;i<num;i++) {
av[i]=list_vector_px(ob1, i, &avo[i]); // source vectors
if (av[0]!=av[i]) { printf("findx ****ERRC**** %d %d %d\n",i,av[0],av[i]);
hoc_execerror("Src vectors must all be same size: ", 0); }
}
nx=av[0]; // size of source vecs
for (i=0;i<num;i++) {
bv[i]=list_vector_px2(ob2, i, &bvo[i], &vv_tmp); // dest vectors
if (vector_buffer_size((IvocVect*)vv)<ni) {
printf("findx ****ERRD**** arg#%d need:%d sz:%d\n",num+i+1,ni,vector_buffer_size((IvocVect*)vv));
hoc_execerror("Destination vector with insufficient size: ", 0);
} else {
vector_resize((IvocVect*)vv, ni);
}
}
if (ni>scrsz) {
if (scrsz>0) { free(scr); scr=(unsigned int *)NULL; }
scrsz=ni+10000;
scr=(unsigned int *)ecalloc(scrsz, sizeof(int));
}
for (i=0;i<ni;i++) { scr[i]=(int)ind[i]; // copy into integer array
if (scr[i]>=nx || scr[i]<0) { printf("findx ****ERRE**** **** IND:%d SZ:%d\n",scr[i],nx);
hoc_execerror("Index vector out-of-bounds", 0); }
}
for (j=0,i=0;j<num;j++) for (i=0;i<ni;i++) bvo[j][i]=avo[j][scr[i]];
return (double)ni;
}
ENDVERBATIM
:* ind.lma(vecAlist,vecBlist,beg,end[,mul,add])
: copy each vector in Alist to Blist indices from beg to end; with sequential mul/add
: ind picks out specific vectors if not doing all of them
VERBATIM
static double lma (void* vv) {
IvocVect* vv_tmp = (IvocVect*)vv;
int i, j, k, ia, ib, ni, nj, nx, av[VRRY], bv[VRRY], num, numb, beg, end, *xx;
Object *ob1, *ob2;
double *ind, *avo[VRRY], *bvo[VRRY], mul,mmul,add,madd;
ni = vector_instance_px((IvocVect*)vv, &ind);
xx=iscrset(ni);
ob1 = *hoc_objgetarg(1); ob2 = *hoc_objgetarg(2);
beg = (int)*getarg(3); end= (int)*getarg(4);
mul=ifarg(5)?*getarg(5):1; add=ifarg(6)?*getarg(6):0;
num = ivoc_list_count(ob1);
numb = ivoc_list_count(ob2);
if ((ni==0 && numb!=num) || (ni>0 && ni!=num)) {
printf("lma ERRA: wrong# of outvecs: %d (inlist:%d,inds:%d)\n",numb,num,ni); hxe();}
for (i=0,j=0;i<ni;i++) {
if (ind[i]) xx[j++]=i; // make the index array out of a masking vector
if (j>num){printf("lma ERRA1 OOB: %d %d\n",j,num); hxe();}
}
nj=j;
if (num>VRRY){printf("lma ****ERRB****: can only handle %d vectors\n",VRRY); hxe();}
for (i=0;i<num;i++) {
av[i]=list_vector_px(ob1, i, &avo[i]); // source vectors
if (av[0]!=av[i]) { printf("lma ****ERRC**** %d %d %d\n",i,av[0],av[i]);
hoc_execerror("Src vectors must all be same size: ", 0); }
}
nx=av[0]; // size of source vecs
if (beg>=end || beg<0 || end>nx) {printf("lma ERRC1 OOB %d - %d (%d)\n",beg,end,nx); hxe();}
for (i=0;i<num;i++) {
bv[i]=list_vector_px2(ob2, i, &bvo[i], &vv_tmp); // dest vectors
if (bv[i]!=(end-beg)) bvo[i]=vector_newsize((IvocVect*)vv, end-beg);
}
if (nj>0) {
for (ia=0,ib=0,mmul=1.,madd=0.;ia<nj;ia++,ib++) {
j=xx[ia];
for (i=beg,k=0;i<end;i++,k++) bvo[ib][k]=mmul*avo[j][i]+madd;
if (mul!=1) mmul*=mul; if (add!=0) madd+=add;
}
} else for (j=0,mmul=1,madd=0;j<num;j++) {
for (i=beg,k=0;i<end;i++,k++) bvo[j][k]=mmul*avo[j][i]+madd;
if (mul!=1) mmul*=mul; if (add!=0) madd+=add;
}
return (double)j;
}
ENDVERBATIM
:* ind.sindx(vecAlist,vecBlist)
: uses ind as index into vecA's to replace with elements from vecB's
VERBATIM
static double sindx (void* vv) {
int i, j, ni, nx, av[VRRY], bv[VRRY], num;
Object *ob1, *ob2;
double *ind, *avo[VRRY], *bvo[VRRY];
ni = vector_instance_px(vv, &ind);
ob1 = *hoc_objgetarg(1);
ob2 = *hoc_objgetarg(2);
num = ivoc_list_count(ob1);
i = ivoc_list_count(ob2);
if (num!=i) hoc_execerror("sindx ****ERRA****: two vec lists have different counts", 0);
if (num>VRRY) hoc_execerror("sindx ****ERRB****: can only handle VRRY vectors", 0);
for (i=0;i<num;i++) {
av[i]=list_vector_px(ob1, i, &avo[i]); // dest vectors
if (av[0]!=av[i]) { printf("sindx ****ERRC**** %d %d %d\n",i,av[0],av[i]);
hoc_execerror("Dest. vectors must all be same size: ", 0); }
}
nx=av[0]; // size of dest vecs
for (i=0;i<num;i++) {
bv[i]=list_vector_px(ob2, i, &bvo[i]); // source vectors
if (bv[i]!=ni) {
printf("sindx ****ERRD**** arg#%d does note match ind length %d vs %d\n",num+i+1,ni,bv[i]);
hoc_execerror("Source vector with insufficient size: ", 0); }
}
if (ni>scrsz) {
if (scrsz>0) { free(scr); scr=(unsigned int *)NULL; }
scrsz=ni+10000;
scr=(unsigned int *)ecalloc(scrsz, sizeof(int));
}
for (i=0;i<ni;i++) { scr[i]=(int)ind[i]; // copy into integer array
if (scr[i]>=nx || scr[i]<0) {
printf("sindx ****ERRE**** IND:%d SZ:%d\n",scr[i],nx);
hoc_execerror("Index vector out-of-bounds", 0); }
}
for (j=0,i=0;j<num;j++) for (i=0;i<ni;i++) avo[j][scr[i]]=bvo[j][i];
return (double)ni;
}
ENDVERBATIM
:* ind.sindv(vecAlist,valvec)
: uses ind as index into vecA's to replace with values in valvec
VERBATIM
static double sindv(void* vv) {
int i, j, ni, nx, av[VRRY], bv, num;
Object* ob;
double *ind, *avo[VRRY], *bvo;
ni = vector_instance_px(vv, &ind);
ob = *hoc_objgetarg(1);
bv=vector_arg_px(2, &bvo); // source vector
num = ivoc_list_count(ob);
if (num>VRRY) hoc_execerror("sindv ****ERRA****: can only handle VRRY vectors", 0);
for (i=0;i<num;i++) {
av[i]=list_vector_px(ob, i, &avo[i]); // dest vectors
if (av[0]!=av[i]) { printf("sindv ****ERRC**** %d %d %d\n",i,av[0],av[i]);
hoc_execerror("Dest. vectors must all be same size: ", 0); }
}
nx=av[0]; // size of source vecs
if (bv!=num) {
printf("sindv ****ERRD**** Vector arg does note match list count %d vs %d\n",num,bv);
hoc_execerror("Source vector is wrong size: ", 0); }
if (ni>scrsz) {
if (scrsz>0) { free(scr); scr=(unsigned int *)NULL; }
scrsz=ni+10000;
scr=(unsigned int *)ecalloc(scrsz, sizeof(int));
}
for (i=0;i<ni;i++) { scr[i]=(int)ind[i]; // copy into integer array
if (scr[i]>=nx || scr[i]<0) {
printf("sindv ****ERRE**** IND:%d SZ:%d\n",scr[i],nx);
hoc_execerror("Index vector out-of-bounds", 0); }
}
for (j=0,i=0;j<num;j++) for (i=0;i<ni;i++) avo[j][scr[i]]=bvo[j];
return (double)ni;
}
ENDVERBATIM
:* ind.slct(key,args,veclist)
: picks out indices of numbers in key from multiple vectors
VERBATIM
static double slct (void* vv) {
int i, j, k, m, n, p, ni, nk, na, nv[VRRY], num, fl, lc, field[VRRY], lt, rt, flag;
Object* lob;
double *ind, *key, *arg, *vvo[VRRY], val;
ni = vector_instance_px(vv, &ind); // vv is ind
nk = vector_arg_px(1, &key);
na = vector_arg_px(2, &arg);
lob = *hoc_objgetarg(3);
if (ifarg(4)) flag=(int)*getarg(4); else flag=0;// flag==1 to return first found
num = ivoc_list_count(lob);
if (num>VRRY) hoc_execerror("ERR: vecst::slct can only handle VRRY vectors", 0);
for (i=0,j=0;i<num;i++,j++) { // pick up vectors
nv[i] = list_vector_px(lob, i, &vvo[i]);
if (key[j]>=EQV && key[j]<=EQY) { // EQV-EQY take extra vec arg of any size
i++;
nv[i] = list_vector_px(lob, i, &vvo[i]);// pick up extra vector of any size
} else if (ni!=nv[i]) {
printf("vecst::slct ERR %d %d %d %d %d\n",i,j,k,ni,nv[i]);
hoc_execerror("index and searched vectors must all be same size: ", 0);
}
}
for (j=0;j<nk;j++) { // look for fields in a mkcode() coded double
field[j]=-1;
if (key[j]<=EBE && key[j]>=ALL) { field[j]=0;
} else for (m=1;m<=5;m++) {
if (key[j]<=EBE*(m+1) && key[j]>=ALL*(m+1)) { // m is is field key 1-5
key[j]/=(m+1);
field[j]=m;
}
}
if (field[j]==-1) {printf("vecst::slct ERRF %d %g\n",j,key[j]); hxe(); }
}
if (2*nk!=na) { printf("vecst::slct ERR3 %d %d\n",nk,na);
hoc_execerror("Arg vector must be double key length",0); }
for (i=0,n=0;i<nk;i++) if (key[i]>=EQV && key[i]<=EQY) n++; // special cases take 2 vec args
if (nk+n!=num) {
printf("vecst::slct ERR2 %d(keys)+%d(EQV/W)!=%d(vecs)\n",nk,n,num);
hoc_execerror("Key length must be number of vecs + num of EQV/W",0); }
for (j=0,k=0,m=0;j<ni;j++) { // j steps through elements of vectors
for (i=0,m=0,n=0,fl=1;i<num;i++,n++,m+=2) { // i steps thru key, m thru args
if (field[n]==0) val=vvo[i][j]; else UNCODE(vvo[i][j],field[n],val);
if (key[n]==ALL) continue; // OK - do nothing
if (key[n]==NOZ) { if (val==0.) {fl=0; break;} else continue;
} else if (key[n]==POS) { if (val<=0.) {fl=0; break;} else continue;
} else if (key[n]==NEG) { if (val>=0.) {fl=0; break;} else continue;
} else if (key[n]==GTH) { if (val<=arg[m]) {fl=0; break;} else continue;
} else if (key[n]==GTE) { if (val< arg[m]) {fl=0; break;} else continue;
} else if (key[n]==LTH) { if (val>=arg[m]) {fl=0; break;} else continue;
} else if (key[n]==LTE) { if (val> arg[m]) {fl=0; break;} else continue;
} else if (key[n]==EQU) { if (val!=arg[m]) {fl=0; break;} else continue;
} else if (key[n]==EQV) { if (val!=vvo[i+1][j]) {
fl=0; break;} else { i++; continue; }
} else if (key[n]==EQW) { // check value against values in following vec
fl=0; // assume it's not going to match
for (p=0;p<nv[i+1];p++) if (val==vvo[i+1][p]) {fl=1; break;}
if (fl==0) break; else { i++; continue; }
} else if (key[n]==EQX) { // check value against values in sorted vec
fl=0; // assume it's not going to match
lt=0; rt=nv[i+1]-1;
while (lt <= rt) {
p = (lt+rt)/2;
if (val>vvo[i+1][p]) lt=p+1; else if (val<vvo[i+1][p]) rt=p-1; else {fl=1; break;}
}
if (fl==0) break; else { i++; continue; }
} else if (key[n]==EQY) { // check value against values in sorted vec
fl=0; // assume it's not going to match
lt=0; rt=nv[i+1]-1;
while (lt <= rt) {
p = (lt+rt)/2;
if (val>vvo[i+1][p]+LOOSE) lt=p+1; else if (val<vvo[i+1][p]-LOOSE) rt=p-1; else {
fl=1; break; }
}
if (fl==0) break; else { i++; continue; }
} else if (key[n]==NEQ) { if (val==arg[m]) {fl=0; break;} else continue;
} else if (key[n]==IBE) { if ((val< arg[m])||(val>=arg[m+1])) {
fl=0; break; } else continue; // IBE="[)" include-bracket-exclude
} else if (key[n]==EBI) { if ((val<=arg[m])||(val> arg[m+1])) {
fl=0; break; } else continue; // "(]" : exclude-bracket-include
} else if (key[n]==IBI) { if ((val< arg[m])||(val> arg[m+1])) {
fl=0; break; } else continue; // "[]" : include-bracket-include
} else if (key[n]==EBE) { if ((val<=arg[m])||(val>=arg[m+1])) {
fl=0; break; } else continue; // "()" : exclude-bracket-exclude
} else {printf("vecst::slct ERR4 %g\n",key[n]); hoc_execerror("Unknown key",0);}
}
if (fl) {
ind[k++]=j; // all equal
if (flag==1) break;
}
}
vector_resize((IvocVect*)vv, k);
return (double)k;
}
ENDVERBATIM
:* ind.slor(key,args,vec1,vec2[,vec3,vec4,...])
: picks out indices of numbers in key from multiple vectors
VERBATIM
static double slor (void* vv) {
int i, j, k, m, n, p, ni, nk, na, nv[VRRY], num, fl, field[VRRY], lt, rt;
Object* lob;
double *ind, *key, *arg, *vvo[VRRY], val;
ni = vector_instance_px(vv, &ind); // vv is ind
nk = vector_arg_px(1, &key);
na = vector_arg_px(2, &arg);
lob = *hoc_objgetarg(3);
num = ivoc_list_count(lob);
if (num>VRRY) hoc_execerror("ERR: vecst::slor can only handle VRRY vectors", 0);
for (i=0,j=0;i<num;i++,j++) { // pick up vectors
nv[i] = list_vector_px(lob, i, &vvo[i]);
if (key[j]>=EQV && key[j]<=EQY) { // EQV-EQY take extra vec arg of any size
i++;
nv[i] = list_vector_px(lob, i, &vvo[i]);// pick up extra vector of any size
} else if (ni!=nv[i]) {
printf("vecst::slor ERR %d %d %d %d %d\n",i,j,k,ni,nv[i]);
hoc_execerror("index and searched vectors must all be same size: ", 0);
}
}
for (j=0;j<num;j++) { // look for fields
field[j]=-1;
if (key[j]<=EBE && key[j]>=ALL) { field[j]=0;
} else for (m=1;m<=5;m++) {
if (key[j]<=EBE*(m+1) && key[j]>=ALL*(m+1)) { // m is is field key 1-5
key[j]/=(m+1);
field[j]=m;
}
}
if (field[j]==-1) {printf("vecst::slor ERRF %g\n",key[j]); hxe(); }
}
if (2*nk!=na) { printf("vecst::slor ERR3 %d %d\n",nk,na);
hoc_execerror("Arg vector must be double key length",0); }
for (i=0,n=0;i<nk;i++) if (key[i]>=EQV && key[i]<=EQY) n++; // special case takes 2 vec args
if (nk+n!=num) {
printf("vecst::slor ERR2 %d(keys)+%d(EQV)!=%d(vecs)\n",nk,n,num);
hoc_execerror("Key length must be number of vecs + num of EQV",0); }
for (j=0,k=0,m=0;j<ni;j++) { // j steps through elements of vectors
for (i=0,m=0,n=0,fl=0;i<num;i++,n++,m+=2) { // i steps thru key, m thru args
if (field[n]==0) val=vvo[i][j]; else UNCODE(vvo[i][j],field[n],val);
if (key[n]==ALL) {fl=1; break;} // OK - do nothing
if (key[n]==NOZ) { if (val==0.) continue; else {fl=1; break;}
} else if (key[n]==POS) { if (val<=0.) continue; else {fl=1; break;}
} else if (key[n]==NEG) { if (val>=0.) continue; else {fl=1; break;}
} else if (key[n]==GTH) { if (val<=arg[m]) continue; else {fl=1; break;}
} else if (key[n]==GTE) { if (val< arg[m]) continue; else {fl=1; break;}
} else if (key[n]==LTH) { if (val>=arg[m]) continue; else {fl=1; break;}
} else if (key[n]==LTE) { if (val> arg[m]) continue; else {fl=1; break;}
} else if (key[n]==EQU) { if (val!=arg[m]) continue; else {fl=1; break;}
} else if (key[n]==EQV) { if (val!=vvo[i+1][j]) continue; else {
i++; fl=1; break; }
} else if (key[n]==EQW) { // check value against values in following vec
fl=0; // assume it's not going to match
for (p=0;p<nv[i+1];p++) if (val==vvo[i+1][p]) {fl=1; break;}
if (fl==1) break; else { i++; continue; }
} else if (key[n]==EQX) { // check value against values in sorted vec
fl=0; // assume it's not going to match
lt=0; rt=nv[i+1]-1;
while (lt <= rt) {
p = (lt+rt)/2;
if (val>vvo[i+1][p]) lt=p+1; else if (val<vvo[i+1][p]) rt=p-1; else {fl=1; break;}
}
if (fl==1) break; else { i++; continue; }
} else if (key[n]==EQY) { // check value against values in sorted vec
printf("EQY not implemented for slor()\n"); hxe();
} else if (key[n]==NEQ) { if (val==arg[m]) continue; else {fl=1; break;}
} else if (key[n]==IBE) { if ((val< arg[m])||(val>=arg[m+1])) {
continue; } else {fl=1; break;} // IBE="[)" include-bracket-exclude
} else if (key[n]==EBI) { if ((val<=arg[m])||(val> arg[m+1])) {
continue; } else {fl=1; break;} // "(]" : exclude-bracket-include
} else if (key[n]==IBI) { if ((val< arg[m])||(val> arg[m+1])) {
continue; } else {fl=1; break;} // "[]" : include-bracket-include
} else if (key[n]==EBE) { if ((val<=arg[m])||(val>=arg[m+1])) {
continue; } else {fl=1; break;} // "()" : exclude-bracket-exclude
} else {printf("vecst::slor ERR4 %g\n",key[n]); hoc_execerror("Unknown key",0);}
}
if (fl) ind[k++]=j; // all equal
}
vector_resize((IvocVect*)vv, k);
return (double)k;
}
ENDVERBATIM
:* src.whi(valvec,indvec[,&i0,&i1,...]) returns index of first one for each val
VERBATIM
static double whi (void* vv) {
int i, j, nx, na, nb, cnt; double *x, *val, *ind;
nx = vector_instance_px(vv, &x);
i = vector_arg_px(1, &val);
na = vector_arg_px(2, &ind);
if (i!=na) {printf("vecst:whi() takes 2 eq length vecs:%d %d\n",i,na); hxe();}
scrset(na);
for (i=0;i<na;i++) {scr[i]=0; ind[i]=-1.;}
for (i=0,cnt=0;i<nx;i++) for (j=0;j<na;j++) {
if (x[i]==val[j]) {
if (scr[j]) printf("WARNING %g found mult times (%g,%d)\n",val[j],ind[j],i); else {
ind[j]=(double)i; scr[j]=1; cnt++;
}
}
}
for (nb=3;ifarg(nb);nb++) {} // count args
nb--;
if (nb>2) {
if (nb-2!=na) {printf("vecst:whi() wrong #args:%d %d\n",na,nb-2); hxe();}
for (i=3,j=0;j<na;i++,j++) *(hoc_pgetarg(i)) = ind[j];
}
return (double)cnt/na; // % found
}
ENDVERBATIM
:* v.iwr(FILEOBJ[,skipsz]) write Vector as integers to FileObj
: FILEOBJ must be open for writing
: skipsz is a flag to skip writing the # of ints to file
VERBATIM
static double iwr (void* vv) {
int i, j, nx; size_t r;
double *x;
FILE* f;
f = hoc_obj_file_arg(1);
nx = vector_instance_px(vv, &x);
scrset(nx);
for (i=0;i<nx;i++) scr[i]=(int)x[i]; // copy into integer array
if(!ifarg(2) || !((int)*getarg(2))) r=fwrite(&nx,sizeof(int),1,f); // write out the size
r=fwrite(scr,sizeof(int),nx,f);
return (double)nx;
}
ENDVERBATIM
:* v.ird() read integers
VERBATIM
static double ird (void* vv) {
int i, j, nx, n; size_t r;
double *x;
FILE* f;
f = hoc_obj_file_arg(1);
nx = vector_instance_px(vv, &x);
r=fread(&n,sizeof(int),1,f); // size
if (n>scrsz) {
if (scrsz>0) { free(scr); scr=(unsigned int *)NULL; }
scrsz=n+10000;
scr=(unsigned int *)ecalloc(scrsz, sizeof(int));
}
if (n!=nx) {
nx=vector_buffer_size((IvocVect*)vv);
if (n<=nx) {
vector_resize((IvocVect*)vv, n); nx=n;
} else {
printf("%d > %d :: ",n,nx);
hoc_execerror("Vector max capacity too small for ird ", 0);
}
}
r=fread(scr,sizeof(int),n,f);
for (i=0;i<nx;i++) x[i]=(double)scr[i];
return (double)n;
}
ENDVERBATIM
:* v.fread2()
VERBATIM
static double fread2 (void* vv) {
int i, j, nx, n, type, maxsz; size_t r;
double *x;
FILE* fp;
BYTEHEADER
fp = hoc_obj_file_arg(1);
nx = vector_instance_px(vv, &x);
maxsz=vector_buffer_size((IvocVect*)vv);
n = (int)*getarg(2);
type = (int)*getarg(3);
if (n>maxsz) {
printf("%d > %d :: ",n,maxsz);
hoc_execerror("Vector max capacity too small for fread2 ", 0);
} else {
vector_resize((IvocVect*)vv, n);
}
if (type==6 || type==16) { // unsigned ints
unsigned int *xs;
if (n>scrsz) {
if (scrsz>0) { free(scr); scr=(unsigned int *)NULL; }
scrsz=n+10000;
scr=(unsigned int *)ecalloc(scrsz, sizeof(int));
}
xs=(unsigned int*)scr;
r=fread(xs,sizeof(int),n,fp);
if (type==16) BYTESWAP_FLAG=1;
for (i=0;i<n;i++) {
BYTESWAP(scr[i],int)
x[i]=(double)scr[i];
}
return (double)n;
} if (type==3 || type==13) { // straight float reads
float *xf = (float *)malloc(n * (unsigned)sizeof(float));
r=fread(xf,sizeof(float),n,fp);
if (type==13) BYTESWAP_FLAG=1;
for (i=0;i<n;i++) {
BYTESWAP(xf[i],float)
x[i]=(double)xf[i];
}
free((char *)xf);
} else hoc_execerror("Type unsupported in fread2 ", 0);
return 0;
}
ENDVERBATIM
:* v.revec() -- append() except that sets vector to size 0 before appending
VERBATIM
static double revec (void* vv) {
int i,j,k, nx, ny; double *x, *y;
nx = vector_instance_px((IvocVect*)vv, &x);
if (nx==0) x=vector_newsize((IvocVect*)vv,nx=100);
for (i=1,k=0;ifarg(i);i++,k++) {
if (hoc_is_double_arg(i)) {
if (k>=nx) x=vector_newsize((IvocVect*)vv,nx*=4);
x[k]=*getarg(i);
} else {
ny=vector_arg_px(i, &y);
if (k+ny>=nx) x=vector_newsize((IvocVect*)vv,nx=2*(nx+ny));
for (j=0;j<ny;j++,k++) x[k]=y[j];
k--; // back up one
}
}
vector_resize((IvocVect*)vv,k);
return 0;
}
ENDVERBATIM
:* v.has(val[,outvec]) -- a contains that returns the results
VERBATIM
static double has (void* vv) {
int i, j, nx, ny;
double *x, *y, val; IvocVect* vc;
nx = vector_instance_px((IvocVect*)vv, &x);
val=*getarg(1);
ny=0;
if (ifarg(2)) if (hoc_is_object_arg(2)) {
ny=vector_arg_px(2, &y); vc=vector_arg(2);
if (ny==0) y=vector_newsize(vc,ny=100);
}
for (i=0,j=0;i<nx;i++) if (x[i]==val) {
if (ifarg(2)) {
if (ny) {
// append index to vector like indvwhere()
if (j>=ny) y=vector_newsize(vc,ny*=4);
y[j++]=(double)i;
} else {
*(hoc_pgetarg(2)) = (double)i;
return 1.0;
}
} else return 1;
}
if (j>0) vector_resize((IvocVect*)vc,j); // only fall through here when doing indvwhere
return (double)j;
}
ENDVERBATIM
:* ind.insct(v1,v2)
: return v1 intersect v2
VERBATIM
static double insct (void* vv) {
int i, j, k, nx, nv1, nv2, maxsz;
double *x, *v1, *v2;
nx = vector_instance_px((IvocVect*)vv, &x);
if (maxsz==0) maxsz=1000;
maxsz=vector_buffer_size((IvocVect*)vv);
x=vector_newsize((IvocVect*)vv, maxsz);
nv1 = vector_arg_px(1, &v1);
nv2 = vector_arg_px(2, &v2);
for (i=0,k=0;i<nv1;i++) for (j=0;j<nv2;j++) if (v1[i]==v2[j]) {
if (k==maxsz) x=vector_newsize((IvocVect*)vv, maxsz*=2);
x[k++]=v1[i];
}
vector_resize((IvocVect*)vv, k);
return (double)k;
}
ENDVERBATIM
:* ind.linsct(vlist,this_many)
: return indices that show up this_many times or more in the vectors in vlist
VERBATIM
static double linsct (void* vv) {
int i,j,k,nx,maxsz,min,cnt,lt,rt,p,iv,jv,jj,fl; ListVec* pL;
double *x, val;
nx = vector_instance_px((IvocVect*)vv, &x);
maxsz=vector_buffer_size((IvocVect*)vv);
if (maxsz==0) maxsz=1000;
x=vector_newsize((IvocVect*)vv, maxsz);
pL = AllocListVec(*hoc_objgetarg(1));
min= (int)*getarg(2);
for (iv=0;iv<pL->isz;iv++) {
if (!ismono1(pL->pv[iv],pL->plen[iv],2)){printf("linsct() ERRA not monotonic %d\n",iv); hxe();}
if (pL->pv[iv][0]<0){printf("linsct() ERRB neg value in %d is %g\n",iv,pL->pv[iv][0]);hxe();}
}
for (iv=0,k=0;iv<=pL->isz-min+1;iv++) for (j=0;j<pL->plen[iv];j++) {
val=pL->pv[iv][j];
for (i=0,fl=0;i<k;i++) if (val==x[i]) {fl=1; break;}
if (fl) continue; // already on the list
for (jv=iv+1,cnt=1;jv<pL->isz;jv++) {
fl=lt=0; rt=pL->plen[jv]-1;
while (lt <= rt) {
p = (lt+rt)/2;
if (val>pL->pv[jv][p]) lt=p+1; else if (val<pL->pv[jv][p]) rt=p-1; else {
fl=1; break;}
}
if (fl) cnt++;
if (cnt>=min) {
if (k==maxsz) x=vector_newsize((IvocVect*)vv, maxsz*=2);
x[k++]=val;
break;
}
}
}
vector_resize((IvocVect*)vv, k);
return (double)k;
}
ENDVERBATIM
:* vdest.vfill(vsrc)
: fill vdest with multiple instances of vsrc until reach size
VERBATIM
static double vfill (void* vv) {
int i, nx, nv1;
double *x, *v1;
nx = vector_instance_px(vv, &x);
nv1 = vector_arg_px(1, &v1);
for (i=0;i<nx;i++) x[i]=v1[i%nv1];
return 0;
}
ENDVERBATIM
:* vec.cull(src,key)
: remove numbers in vec that are found in the key
VERBATIM
static double cull (void* vv) {
int i, j, k, nx, nv1, nv2, flag;
double *x, *v1, *v2, val;
nx = vector_instance_px((IvocVect*)vv, &x);
nv1 = vector_arg_px(1, &v1);
if (hoc_is_double_arg(2)) { val=*getarg(2); nv2=0; } else nv2=vector_arg_px(2, &v2);
x=vector_newsize((IvocVect*)vv,nx=nv1);
for (i=0,k=0;i<nv1;i++) {
flag=1;
if (nv2) { for (j=0;j<nv2;j++) if (v1[i]==v2[j]) flag=0;
} else if (v1[i]==val ) flag=0;
if (flag) x[k++]=v1[i];
}
vector_resize((IvocVect*)vv, k);
return (double)k;
}
ENDVERBATIM
:* dest.redundout(src[,INDFLAG])
: flag redundant numbers; must sort src first
: with indflag set just returns indices of locations rather than values
VERBATIM
static double redundout (void* vv) {
int i, j, nx, nv1, maxsz, ncntr, indflag, cntflag;
double *x, *v1, *cntr, val;
void *vc;
if (ifarg(2)) indflag=(int)*getarg(2); else indflag=0;
if (ifarg(3)) { cntflag=1;
ncntr = vector_arg_px(3, &cntr); vc=vector_arg(3);
ncntr = vector_buffer_size((IvocVect*)vc); vector_resize((IvocVect*)vc, ncntr);
for (i=0;i<ncntr;i++) cntr[i]=1.; // will be at least 1 of each #
} else cntflag=0;
nx = vector_instance_px(vv, &x);
maxsz=vector_buffer_size((IvocVect*)vv); vector_resize((IvocVect*)vv, maxsz);
nv1 = vector_arg_px(1, &v1);
val=v1[0]; x[0]=(indflag?0:val);
if (cntflag) {
for (j=1,i=1;i<nv1&&j<maxsz&&j<ncntr;i++) {
if (v1[i]!=val) { val=v1[i]; x[j++]=(indflag?i:val); } else cntr[j-1]+=1;
}
} else {
for (j=1,i=1;i<nv1&&j<maxsz;i++) if (v1[i]!=val) { val=v1[i]; x[j++]=(indflag?i:val); }
}
if (j>=maxsz) {
printf("\tredundout WARNING: ran out of room: %d<needed\n",maxsz);
} else { vector_resize((IvocVect*)vv, j); }
if (cntflag) if (j>=ncntr) {
printf("\tredundout WARNING: cntr ran out of room: %d<needed\n",ncntr);
} else { vector_resize((IvocVect*)vc, j); }
return (double)j;
}
ENDVERBATIM
:* ind.mredundout(veclistA[,INDFLAG,veclistB])
: check redundancy across multiple parallel vectors veclistA
: with indflag 1, returns index of matchs in ind but does not alter vecs in veclistA
: will also remove from veclistB in parallel
: leaves the last of a series of matches
: with indflag set just returns indices of locations rather than values
: NB using indices will to .remove match items will give results that differ from
: direct use (last vs first of a series -- will be seen in the other columns -- ie veclistB)
VERBATIM
static double mredundout (void* vv) {
int i, j, k, m, p, q, maxsz, ns, nx, av[VRRY], bv[VRRY], num, numb, indflag, match;
Object *ob, *ob2;
double *x, *avo[VRRY], *bvo[VRRY], val[VRRY];
IvocVect *vva[VRRY],*vvb[VRRY];
nx = vector_instance_px((IvocVect*)vv, &x);
ob = *hoc_objgetarg(1);
if (ifarg(2)) indflag=(int)*getarg(2); else indflag=0;