Turbulence::Turbulence(int gens, int seed) { _gens = gens; _sz = 1 << (_gens - 1); _seed = seed; _mag = 1; _x0 = _x1 = _y0 = _y1 = _z0 = _z1 = 0; _timeOff = 0; _off[0] = _off[1] = _off[2] = 0; float* xbuf = new float[_sz*_sz]; float* ybuf = new float[_sz*_sz]; float* zbuf = new float[_sz*_sz]; mkimg(xbuf, _sz); _seed++; mkimg(ybuf, _sz); _seed++; mkimg(zbuf, _sz); // "Normalize" them to proper spherical magnitudes, and calculate // range information for the packing. for(int i=0; i<_sz*_sz; i++) { float n = cubenorm(xbuf[i], ybuf[i], zbuf[i]); xbuf[i] *= n; ybuf[i] *= n; zbuf[i] *= n; _x0 = xbuf[i] < _x0 ? xbuf[i] : _x0; _x1 = xbuf[i] > _x1 ? xbuf[i] : _x1; _y0 = ybuf[i] < _y0 ? ybuf[i] : _y0; _y1 = ybuf[i] > _y1 ? ybuf[i] : _y1; _z0 = zbuf[i] < _z0 ? zbuf[i] : _z0; _z1 = zbuf[i] > _z1 ? zbuf[i] : _z1; } // Pack into 3 byte tuples for storage. _data = new unsigned char[3*_sz*_sz]; for(int i=0; i<_sz*_sz; i++) { float x = xbuf[i], y = ybuf[i], z = zbuf[i]; unsigned char* tuple = _data + 3*i; tuple[0] = f2cu((x - _x0) / (_x1 - _x0)); tuple[1] = f2cu((y - _y0) / (_y1 - _y0)); tuple[2] = f2cu((z - _z0) / (_z1 - _z0)); } delete[] xbuf; delete[] ybuf; delete[] zbuf; }
void mkqcow2(const char *file, unsigned size_mb) { return mkimg(file, "qcow2", size_mb); }
int main(int argc, char **argv) { //test_resize("data/bad.jpg"); //test_box(); //test_convolutional_layer(); if(argc < 2){ fprintf(stderr, "usage: %s <function>\n", argv[0]); return 0; } gpu_index = find_int_arg(argc, argv, "-i", 0); if(find_arg(argc, argv, "-nogpu")) { gpu_index = -1; } #ifndef GPU gpu_index = -1; #else if(gpu_index >= 0){ cuda_set_device(gpu_index); } #endif if (0 == strcmp(argv[1], "average")){ average(argc, argv); } else if (0 == strcmp(argv[1], "yolo")){ run_yolo(argc, argv); } else if (0 == strcmp(argv[1], "super")){ run_super(argc, argv); } else if (0 == strcmp(argv[1], "lsd")){ run_lsd(argc, argv); } else if (0 == strcmp(argv[1], "detector")){ run_detector(argc, argv); } else if (0 == strcmp(argv[1], "detect")){ float thresh = find_float_arg(argc, argv, "-thresh", .5); char *filename = (argc > 4) ? argv[4]: 0; char *outfile = find_char_arg(argc, argv, "-out", 0); int fullscreen = find_arg(argc, argv, "-fullscreen"); test_detector("cfg/coco.data", argv[2], argv[3], filename, thresh, .5, outfile, fullscreen); } else if (0 == strcmp(argv[1], "cifar")){ run_cifar(argc, argv); } else if (0 == strcmp(argv[1], "go")){ run_go(argc, argv); } else if (0 == strcmp(argv[1], "rnn")){ run_char_rnn(argc, argv); } else if (0 == strcmp(argv[1], "coco")){ run_coco(argc, argv); } else if (0 == strcmp(argv[1], "classify")){ predict_classifier("cfg/imagenet1k.data", argv[2], argv[3], argv[4], 5); } else if (0 == strcmp(argv[1], "classifier")){ run_classifier(argc, argv); } else if (0 == strcmp(argv[1], "regressor")){ run_regressor(argc, argv); } else if (0 == strcmp(argv[1], "isegmenter")){ run_isegmenter(argc, argv); } else if (0 == strcmp(argv[1], "segmenter")){ run_segmenter(argc, argv); } else if (0 == strcmp(argv[1], "art")){ run_art(argc, argv); } else if (0 == strcmp(argv[1], "tag")){ run_tag(argc, argv); } else if (0 == strcmp(argv[1], "3d")){ composite_3d(argv[2], argv[3], argv[4], (argc > 5) ? atof(argv[5]) : 0); } else if (0 == strcmp(argv[1], "test")){ test_resize(argv[2]); } else if (0 == strcmp(argv[1], "nightmare")){ run_nightmare(argc, argv); } else if (0 == strcmp(argv[1], "rgbgr")){ rgbgr_net(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "reset")){ reset_normalize_net(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "denormalize")){ denormalize_net(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "statistics")){ statistics_net(argv[2], argv[3]); } else if (0 == strcmp(argv[1], "normalize")){ normalize_net(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "rescale")){ rescale_net(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "ops")){ operations(argv[2]); } else if (0 == strcmp(argv[1], "speed")){ speed(argv[2], (argc > 3 && argv[3]) ? atoi(argv[3]) : 0); } else if (0 == strcmp(argv[1], "oneoff")){ oneoff(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "oneoff2")){ oneoff2(argv[2], argv[3], argv[4], atoi(argv[5])); } else if (0 == strcmp(argv[1], "print")){ print_weights(argv[2], argv[3], atoi(argv[4])); } else if (0 == strcmp(argv[1], "partial")){ partial(argv[2], argv[3], argv[4], atoi(argv[5])); } else if (0 == strcmp(argv[1], "average")){ average(argc, argv); } else if (0 == strcmp(argv[1], "visualize")){ visualize(argv[2], (argc > 3) ? argv[3] : 0); } else if (0 == strcmp(argv[1], "mkimg")){ mkimg(argv[2], argv[3], atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), argv[7]); } else if (0 == strcmp(argv[1], "imtest")){ test_resize(argv[2]); } else { fprintf(stderr, "Not an option: %s\n", argv[1]); } return 0; }
void mrqcof(float **y, float **sig, struct image *psf, float a[], int ia[], int ma, double **alpha, double beta[], double *chisq, void (*funcs)(int x, int y, float *, float [], int [], int, struct fitpars *), struct fitpars *fpar, struct convpars *cpar) { extern struct image *mask; extern struct sampars sample; extern struct image model; extern unsigned long *pos; extern struct derivs df; struct fitpars *fptr; struct derivs *dptr; char name[80]; int ix, iy, j,k,l,m,mfit=0; float ymod,wt,sig2i,dy,*dyda; dyda=vector(1,ma); for (j=1;j<=ma;j++) if (ia[j]==1) mfit++; for (j=1;j<=mfit;j++) { for (k=1;k<=j;k++) alpha[j][k]=0.0; beta[j]=0.0; } mkmodel (&model, &df, fpar, cpar, 0); #if CKIMG sprintf (model.name, "gal+psf-model.fits"); /* Output image */ writefits ("test.fits", &model, "gal + PSF", 0); fptr = fpar; dptr = &df; while (fptr != NULL) { for (j=0; j<= NPARS; j++){ if (fptr->ia[j] == 1 || j==0) { sprintf (name, "deriv%d.fits", j); mkimg (dptr->dpm[j], dptr->naxes, name, "small.fits"); }; }; fptr = fptr->next; dptr = dptr->next; }; #endif sample.nmask = 0; *chisq=0.0; for (iy=1; iy<= model.naxes[2]; iy++) { for (ix=1;ix<=model.naxes[1];ix++) { if (mask->z[iy][ix] < 1.) { /* Calculate chi^2 only */ (*funcs)(ix,iy,&ymod,dyda,ia,ma,fpar); /* for unflagged */ sig2i=1.0/(sig[iy][ix]*sig[iy][ix]); /* pixels */ dy=y[iy][ix]-ymod; for (j=0,l=1;l<=ma;l++) { if (ia[l]==1) { wt=dyda[l]*sig2i; for (j++,k=0,m=1;m<=l;m++) if (ia[m]==1) alpha[j][++k] += wt*dyda[m]; beta[j] += dy*wt; }; }; *chisq += dy*dy*sig2i; } else sample.nmask++; /* count up the number of flagged pixels */ }; }; for (j=2;j<=mfit;j++) for (k=1;k<j;k++) alpha[k][j]=alpha[j][k]; free_vector(dyda,1,ma); }