void AccuracyLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { Dtype accuracy = 0; const Dtype* bottom_data = bottom[0]->cpu_data(); const Dtype* bottom_label = bottom[1]->cpu_data(); int num = bottom[0]->num(); int dim = bottom[0]->count() / bottom[0]->num(); vector<Dtype> maxval(top_k_+1); vector<int> max_id(top_k_+1); for (int i = 0; i < num; ++i) { // Top-k accuracy std::vector<std::pair<Dtype, int> > bottom_data_vector; for (int j = 0; j < dim; ++j) { bottom_data_vector.push_back( std::make_pair(bottom_data[i * dim + j], j)); } std::partial_sort( bottom_data_vector.begin(), bottom_data_vector.begin() + top_k_, bottom_data_vector.end(), std::greater<std::pair<Dtype, int> >()); // check if true label is in top k predictions for (int k = 0; k < top_k_; k++) { if (bottom_data_vector[k].second == static_cast<int>(bottom_label[i])) { ++accuracy; break; } } } // LOG(INFO) << "Accuracy: " << accuracy; top[0]->mutable_cpu_data()[0] = accuracy / num; // Accuracy layer should not be used as a loss function. }
void vec2Dc::print(const wchar_t* file) const { const vec2Dc& v = *this; wchar_t format[32] = L"%4d"; unsigned char max = maxval(); if (max >= 100) wcscpy(format, L"%4d"); else if(max >= 10) wcscpy(format, L"%3d"); else wcscpy(format, L"%2d"); if (file) { FILE *fp = _wfopen(file, L"wt"); if (fp != 0) { fwprintf(fp, L"\n vec: %p\n", this); for (unsigned int y = 0; y < height(); y++) { for (unsigned int x = 0; x < width(); x++) fwprintf(fp, format, v(y, x)); fwprintf(fp, L"\n"); } fclose(fp); } } else { wprintf(L"\n vec: %p\n", this); for (unsigned int y = 0; y < height(); y++) { for (unsigned int x = 0; x < width(); x++) wprintf(format, v(y, x)); wprintf(L"\n"); } } }
int main() { int test; int n,right,i,max; char str1[1000] ,str2 [1000]; scanf ("%d" ,&test); while (test--) { right=0; max=0; scanf ("%d" ,&n); scanf ("%s" ,str1); scanf ("%s" ,str2); for (i=0;i<n;i++) { if (str2[i] == str1[i]) right++; } for (i=0;i<n+1;i++) { scanf ("%llu" ,&price[i]); } if (right == n) printf ("%llu\n" ,price[right]); else printf ("%llu\n" ,price[maxval(right)]); } return 0; }
/* --- Function: int treeheight(AvlTreeNode node, int depth) --- */ static int treeheight(AvlTreeNode node, int depth) { if (!node) return depth; else return maxval(treeheight(node->left, depth+1), treeheight(node->right, depth+1)); }
void AccuracyLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { Dtype accuracy = 0; const Dtype* bottom_data = bottom[0]->cpu_data(); const Dtype* bottom_label = bottom[1]->cpu_data(); const int dim = bottom[0]->count() / outer_num_; const int num_labels = bottom[0]->shape(label_axis_); vector<Dtype> maxval(top_k_+1); vector<int> max_id(top_k_+1); if (top.size() > 1) { caffe_set(nums_buffer_.count(), Dtype(0), nums_buffer_.mutable_cpu_data()); caffe_set(top[1]->count(), Dtype(0), top[1]->mutable_cpu_data()); } int count = 0; for (int i = 0; i < outer_num_; ++i) { for (int j = 0; j < inner_num_; ++j) { const int label_value = static_cast<int>(bottom_label[i * inner_num_ + j]); if (has_ignore_label_ && label_value == ignore_label_) { continue; } if (top.size() > 1) ++nums_buffer_.mutable_cpu_data()[label_value]; DCHECK_GE(label_value, 0); DCHECK_LT(label_value, num_labels); // Top-k accuracy std::vector<std::pair<Dtype, int> > bottom_data_vector; for (int k = 0; k < num_labels; ++k) { bottom_data_vector.push_back(std::make_pair( bottom_data[i * dim + k * inner_num_ + j], k)); } std::partial_sort( bottom_data_vector.begin(), bottom_data_vector.begin() + top_k_, bottom_data_vector.end(), std::greater<std::pair<Dtype, int> >()); // check if true label is in top k predictions for (int k = 0; k < top_k_; k++) { if (bottom_data_vector[k].second == label_value && (threshold_ <= 0 || bottom_data_vector[k].first >= threshold_ )) { ++accuracy; if (top.size() > 1) ++top[1]->mutable_cpu_data()[label_value]; break; } } ++count; } } // LOG(INFO) << "Accuracy: " << accuracy; top[0]->mutable_cpu_data()[0] = accuracy / count; if (top.size() > 1) { for (int i = 0; i < top[1]->count(); ++i) { top[1]->mutable_cpu_data()[i] = nums_buffer_.cpu_data()[i] == 0 ? 0 : top[1]->cpu_data()[i] / nums_buffer_.cpu_data()[i]; } } // Accuracy layer should not be used as a loss function. }
static SANE_Status st400_set_window( ST400_Device *dev ) { unsigned short xoff, yoff; SANE_Byte th; struct { /* 10byte command */ SANE_Byte cmd, lun, reserved1[4], tr_len[3], ctrl; /* 40byte window struct */ SANE_Byte reserved2[6], wd_len[2], winnr, reserved3; SANE_Byte x_res[2], y_res[2]; /* resolution: 200, 300, 400 */ SANE_Byte x_ul[2], y_ul[2]; /* upper left corner */ SANE_Byte width[2], height[2]; SANE_Byte reserved4, threshold; SANE_Byte reserved5, halftone; /* ht: 0 or 2 */ SANE_Byte bitsperpixel, reserved6[13]; /* bpp: 1 or 8 */ } scsi_cmd; /* The PC/Amiga source uses reserved5 to indicate A4/A5 paper size * (values 4 and 5), but a comment implies that this is only for the * scanning program and the value is ignored by the scanner. */ SANE_Status status; memset(&scsi_cmd, 0, sizeof(scsi_cmd)); scsi_cmd.cmd = CMD_SET_WINDOW; set24(scsi_cmd.tr_len, 40); set16(scsi_cmd.wd_len, 32); /* These offsets seem to be required to avoid damaging the scanner: * If a scan with 0/0 as the top left corner is started, the scanner * seems to try to move the carriage over the bottom end (not a * pretty sound). */ xoff = (11L * dev->val[OPT_RESOLUTION]) / 100; yoff = 6; th = (double)maxval(dev->model->bits) * SANE_UNFIX(dev->val[OPT_THRESHOLD]) / 100.0; scsi_cmd.winnr = 1; set16(scsi_cmd.x_res, (unsigned short)dev->val[OPT_RESOLUTION]); set16(scsi_cmd.y_res, (unsigned short)dev->val[OPT_RESOLUTION]); set16(scsi_cmd.x_ul, dev->x + xoff); set16(scsi_cmd.y_ul, dev->wy + yoff); set16(scsi_cmd.width, dev->w); set16(scsi_cmd.height, dev->wh); scsi_cmd.threshold = th; scsi_cmd.halftone = (dev->val[OPT_DEPTH] == 1) ? 0 : 2; scsi_cmd.bitsperpixel = dev->val[OPT_DEPTH]; DBG(DSCSI, "SCSI: sending SET_WINDOW (x=%hu y=%hu w=%hu h=%hu wy=%hu wh=%hu th=%d\n", dev->x, dev->y, dev->w, dev->h, dev->wy, dev->wh, (int)th); status = sanei_scsi_cmd(dev->fd, &scsi_cmd, sizeof(scsi_cmd), 0, 0); DBG(DSCSI, "SCSI: result=%s\n", sane_strstatus(status)); return status; }
void shot_ker_depth_onestep_fd2(sf_complex *wld_z,float *v_z,float w,int signn, float a1,float b1,float a2,float b2,struct shot_ker_par_type ker_par) /*< onestep fd2 >*/ { int op,nref,nx,ny,is2d; float dref; sf_complex *tmp_fft,*add_wld,*tmp_wld; int ix,iy; float w_v0_z,maxvz,minvz; float *v0_z,*v_zw,*v_zw0; nref=ker_par.nref; nx=ker_par.nx; ny=ker_par.ny; is2d=ker_par.is2d; op=ker_par.op; //! op:1:ssf 2:fd 3:ffd v0_z=ker_par.v0_z; v_zw=ker_par.v_zw; v_zw0=ker_par.v_zw0; add_wld=ker_par.add_wld; tmp_wld=ker_par.tmp_wld; tmp_fft=sf_complexalloc(nx*2); maxvz=maxval(v_z,nx*ny); minvz=minval(v_z,nx*ny); dref=(maxvz-minvz)/(nref+1); if ( fabs(maxvz-minvz)<50.0 ) { ///?????????????wait nref=1; v0_z[0]=0.5*(maxvz+minvz); } else{ v0_z[0]=minvz; v0_z[nref-1]=maxvz; dref=(v0_z[nref-1]-v0_z[0])/(float)(nref-1); v0_z[1]=(minvz+maxvz)*0.5; } for (iy=0;iy<ny;iy++) for(ix=0;ix<nx;ix++) v_zw[i2(iy,ix,nx)]=v_z[i2(iy,ix,nx)]/w; if (op == 2){ if (is2d){ vector_value_c(tmp_fft,sf_cmplx(0.0,0.0),nx); rowc(wld_z,tmp_fft,0,nx,1); //tmp_fft=wld_z(1,:); kissfft(tmp_fft,nx,+1); rowc(wld_z,tmp_fft,0,nx,0); //wld_z(1,:)=tmp_fft(:); } w_v0_z=w/(0.75*minvz+0.25*maxvz); li_filter_fd2(wld_z,w_v0_z,a1,b1,a2,b2,ker_par,signn); if (is2d){ rowc(wld_z,tmp_fft,0,nx,1); //tmp_fft=tmp_wld(:,1); kissfft(tmp_fft,nx,-1); rowc(wld_z,tmp_fft,0,nx,0); //tmp_wld(:,1)=tmp_fft(:); } w_v0_z=0.0; shot_ker_ssf(wld_z,w_v0_z,w,v_z,ker_par,signn); ker_par.ax=a1*ker_par.dz/(2.0*ker_par.dx*ker_par.dx); ker_par.ay=a1*ker_par.dz/(2.0*ker_par.dy*ker_par.dy); ker_par.bx=b1/(ker_par.dx*ker_par.dx); ker_par.by=b1/(ker_par.dy*ker_par.dy); shot_ker_fd(wld_z,v_zw,v_zw,ker_par,signn); ker_par.ax=a2*ker_par.dz/(2.0*ker_par.dx*ker_par.dx); ker_par.ay=a2*ker_par.dz/(2.0*ker_par.dy*ker_par.dy); ker_par.bx=b2/(ker_par.dx*ker_par.dx); ker_par.by=b2/(ker_par.dy*ker_par.dy); shot_ker_fd(wld_z,v_zw,v_zw,ker_par,signn); } free(tmp_fft); }
void Object:: AddLine(const Line & line) { m_local.push_back(shared_ptr<Line>(new Line(line))); if( ! m_local_bb) m_local_bb.reset(new BBox(line)); m_local_bb->Update(line); const double rad(sqrt(maxval(sqr(line.X0()) + sqr(line.Y0()), sqr(line.X1()) + sqr(line.Y1())))); if(rad > m_radius) m_radius = rad; }
void setTimer(TIMEVAL value) { // printf("setTimer(TIMEVAL value=%d)\n", value); // TIMEVAL is us whereas setitimer wants ns... long tv_nsec = 1000 * (maxval(value,1)%1000000); time_t tv_sec = value/1000000; struct itimerspec timerValues; timerValues.it_value.tv_sec = tv_sec; timerValues.it_value.tv_nsec = tv_nsec; timerValues.it_interval.tv_sec = 0; timerValues.it_interval.tv_nsec = 0; timer_settime (timer, 0, &timerValues, NULL); }
void shot_ker_depth_onestep_impulse(sf_complex *wld_z,float *v_z,float w,int signn, float ep,float dl, struct shot_ker_par_type ker_par) /*< onestep impulse >*/ { int op,nref,nx,ny,is2d; float dref; sf_complex *tmp_fft,*add_wld,*tmp_wld; int ix,iy; float w_v0_z,maxvz,minvz; float *v0_z,*v_zw,*v_zw0; nref=ker_par.nref; nx=ker_par.nx; ny=ker_par.ny; is2d=ker_par.is2d; op=ker_par.op; //! op:1:ssf 2:fd 3:ffd v0_z=ker_par.v0_z; v_zw=ker_par.v_zw; v_zw0=ker_par.v_zw0; add_wld=ker_par.add_wld; tmp_wld=ker_par.tmp_wld; tmp_fft=sf_complexalloc(nx*2); maxvz=maxval(v_z,nx*ny); minvz=minval(v_z,nx*ny); dref=(maxvz-minvz)/(nref+1); if ( fabs(maxvz-minvz)<50.0 ) { ///?????????????wait nref=1; v0_z[0]=0.5*(maxvz+minvz); } else{ v0_z[0]=minvz; v0_z[nref-1]=maxvz; dref=(v0_z[nref-1]-v0_z[0])/(float)(nref-1); v0_z[1]=(minvz+maxvz)*0.5; } for (iy=0;iy<ny;iy++) for(ix=0;ix<nx;ix++) v_zw[i2(iy,ix,nx)]=v_z[i2(iy,ix,nx)]/w; if (op == 2){ w_v0_z=0.0; shot_ker_ssf(wld_z,w_v0_z,w,v_z,ker_par,signn); shot_ker_fd(wld_z,v_zw,v_zw,ker_par,signn); } else{ if (is2d){ vector_value_c(tmp_fft,sf_cmplx(0.0,0.0),nx); rowc(wld_z,tmp_fft,0,nx,1); //tmp_fft=wld_z(1,:); kissfft(tmp_fft,nx,+1); rowc(wld_z,tmp_fft,0,nx,0); //wld_z(1,:)=tmp_fft(:); } w_v0_z=w/v0_z[0]; shot_phase_shift_vti(wld_z,w_v0_z,ep,dl,ker_par,signn); if (is2d){ rowc(wld_z,tmp_fft,0,nx,1); //tmp_fft=tmp_wld(:,1); kissfft(tmp_fft,nx,-1); rowc(wld_z,tmp_fft,0,nx,0); //tmp_wld(:,1)=tmp_fft(:); } } free(tmp_fft); }
void TestForward() { LayerParameter layer_param; PoolingParameter* pooling_param = layer_param.mutable_pooling_param(); pooling_param->add_kernel_size(2); pooling_param->add_kernel_size(2); pooling_param->add_kernel_size(2); pooling_param->add_stride(2); pooling_param->add_stride(2); pooling_param->add_stride(2); pooling_param->set_axis(1); PoolingLayer<TypeParam> layer(layer_param); layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_); int_tp d = blob_bottom_->shape(2); int_tp h = blob_bottom_->shape(3); int_tp w = blob_bottom_->shape(4); TypeParam *bottom_data = blob_bottom_->mutable_cpu_data(); std::vector<TypeParam> maxval(8 * 8); for (int_tp cd = 0; cd < d; ++cd) { for (int_tp ch = 0; ch < h; ++ch) { for (int_tp cw = 0; cw < w; ++cw) { for (int batch = 0; batch < 8; batch ++) { bottom_data[batch * 64 + cw + ch * w + cd * w * h] = cw + ch * w + cd * w * h; } maxval[cw/2 + (ch/2)*2 + (cd/2)*4] = std::max(bottom_data[cw + ch * w + cd * w * h], maxval[cw/2 + (ch/2)*2 + (cd/2)*4]); } } } layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_); const TypeParam *top_data = blob_top_->cpu_data(); for (int i = 0; i < 2*2*2 * 8; ++i) { EXPECT_EQ(maxval[i % 8], top_data[i]); } }
void AccuracyLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { Dtype accuracy = 0; const Dtype* bottom_data = bottom[0]->cpu_data(); const Dtype* bottom_label = bottom[1]->cpu_data(); int num = bottom[0]->num(); int dim = bottom[0]->channels(); int height = bottom[0]->height(); int width = bottom[0]->width(); int gt_label; int nKnownPixels=0; vector<Dtype> maxval(top_k_+1); vector<int> max_id(top_k_+1); for (int i = 0; i < num; ++i) { // Top-k accuracy for (int h = 0; h < height; ++h){ for (int w = 0; w < width; ++w){ gt_label=static_cast<int>(bottom_label[ (i * height + h) * width + w ]); if (gt_label==255) continue; ++nKnownPixels; std::vector<std::pair<Dtype, int> > bottom_data_vector; for (int j = 0; j < dim; ++j) { bottom_data_vector.push_back( std::make_pair(bottom_data[((i * dim + j) * height + h)*width + w], j)); } std::partial_sort( bottom_data_vector.begin(), bottom_data_vector.begin() + top_k_, bottom_data_vector.end(), std::greater<std::pair<Dtype, int> >()); // check if true label is in top k predictions for (int k = 0; k < top_k_; k++) { if (bottom_data_vector[k].second == gt_label) { ++accuracy; break; } } } } } // LOG(INFO) << "Accuracy: " << accuracy; top[0]->mutable_cpu_data()[0] = accuracy / Dtype(nKnownPixels); // Accuracy layer should not be used as a loss function. }
void MaxPoolLayer::maxpool(const mat& image, mat& output, mat& index) { const int ow = (image.n_cols - spatial) / stride + 1; const int oh = (image.n_rows - spatial) / stride + 1; output = mat(1, ow * oh); output.zeros(); index = mat(1, ow * oh * 2); index.zeros(); for (int i = 0 ; i < oh ; ++i) { for (int j = 0 ; j < ow ; ++j) { mat subimage = image.submat(i, j, i+spatial-1, j+spatial-1); int row = 0, col = 0; const double val = maxval(subimage, row, col); output(0, i*ow+j) = val; index(0, i*ow*2+j) = row; index(0, i*ow*2+j+1) = col; } } }
void EltwiseAccuracyLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { Dtype accuracy = 0; const Dtype* bottom_data = bottom[0]->cpu_data(); const Dtype* bottom_label = bottom[1]->cpu_data(); int num = bottom[0]->num(); int dim = bottom[0]->count() / bottom[0]->num(); int spatial_dim = bottom[0]->height() * bottom[0]->width(); int channels = bottom[0]->channels(); int ignored_pixel_num = 0; vector<Dtype> maxval(top_k_+1); vector<int> max_id(top_k_+1); for (int i = 0; i < num; ++i) { for (int j = 0; j < spatial_dim; j++){ const int label_value = static_cast<int>(bottom_label[i * spatial_dim + j]); if (has_ignore_label_ && label_value == ignore_label_) { ignored_pixel_num++; continue; } // Top-k accuracy std::vector<std::pair<Dtype, int> > bottom_data_vector; for (int k = 0; k < channels; ++k) { bottom_data_vector.push_back( std::make_pair(bottom_data[i * dim + k * spatial_dim + j], k)); } std::partial_sort( bottom_data_vector.begin(), bottom_data_vector.begin() + top_k_, bottom_data_vector.end(), std::greater<std::pair<Dtype, int> >()); // check if true label is in top k predictions for (int k = 0; k < top_k_; k++) { if (bottom_data_vector[k].second == label_value) { ++accuracy; break; } } } } // LOG(INFO) << "EltwiseAccuracy: " << eltwise_accuracy; top[0]->mutable_cpu_data()[0] = accuracy / (num * spatial_dim - ignored_pixel_num); // Accuracy layer should not be used as a loss function. }
void shot_image_decompose(float *image_hx,float *image_hz,int nx,int nz,float rotate_angle,struct shot_image_par_type image_par) /*< decompose >*/ { int ix,iz; int iblock,pointmove; float *tmp_image_hx,*tmp_image_hz; float tmpmax; for(iz=54;iz<55;iz++){ for(ix=635;ix<636;ix++){ //for(iz=0;iz<nz;iz++){ // for(ix=0;ix<nx;ix++){ iblock=iz*nx+ix; pointmove=image_par.nhx*image_par.nhy*iblock; tmp_image_hx=image_hx+pointmove; tmp_image_hz=image_hz+pointmove; shot_image_decompose_1imagepoint(tmp_image_hx,tmp_image_hz,nx,nz,rotate_angle,image_par); tmpmax=maxval(tmp_image_hz,image_par.nhx); if (tmpmax>10000000.0) sf_warning("ix=%d,iz=%d,max=%f",ix,iz,tmpmax); } } }
void TestStatisticLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { phase_ = Caffe::phase(); const Dtype* bottom_data = bottom[0]->cpu_data(); const Dtype* bottom_label = bottom[1]->cpu_data(); int num = bottom[0]->num(); int dim = bottom[0]->count() / bottom[0]->num(); vector<Dtype> maxval(top_k_+1); vector<int> max_id(top_k_+1); for (int i = 0; i < num; ++i) { // Top-k accuracy std::vector<std::pair<Dtype, int> > bottom_data_vector; for (int j = 0; j < dim; ++j) { bottom_data_vector.push_back( std::make_pair(bottom_data[i * dim + j], j)); } std::partial_sort( bottom_data_vector.begin(), bottom_data_vector.begin() + top_k_, bottom_data_vector.end(), std::greater<std::pair<Dtype, int> >()); // layout of line // true_label prob_0 label_0 prob_1 label_1 prob_2 label_2 prob_3 label_3 if (phase_ == Caffe::TEST) { std::cout << "[>>] "; } else { std::cout << "[<<] "; } std::cout << static_cast<float>(bottom_label[i]) << "; "; for (int k = 0; k < top_k_; k ++) { std::cout << bottom_data_vector[k].first << "; "; std::cout << bottom_data_vector[k].second << "; "; } std::cout << std::endl; } }
void triplica(intervallo *primo, int n, int ind, double f1, double f2, int *nint, double *xdir, double *fdir){ int i; intervallo *secondo, *terzo; secondo = (intervallo *)malloc(sizeof(intervallo)); terzo = (intervallo *)malloc(sizeof(intervallo)); alloca_intervallo(n, secondo); alloca_intervallo(n, terzo); terzo->next = primo->next; secondo->next = terzo; primo->next = secondo; for(i=0;i<n;i++){ secondo->cent[i] = primo->cent[i]; terzo->cent[i] = primo->cent[i]; } secondo->cent[ind] = secondo->cent[ind] + 1.0*primo->dimen[ind]/3.0; terzo->cent[ind] = terzo->cent[ind] - 1.0*primo->dimen[ind]/3.0; for(i=0;i<n;i++){ secondo->dimen[i] = primo->dimen[i]; terzo->dimen[i] = primo->dimen[i]; } primo->dimen[ind] = primo->dimen[ind]/3.0; secondo->dimen[ind] = secondo->dimen[ind]/3.0; terzo->dimen[ind] = terzo->dimen[ind]/3.0; primo->maxdim = maxval(n,primo->dimen); primo->diam = norma(n,primo->dimen)/2.0; secondo->maxdim = maxval(n,secondo->dimen); secondo->diam = norma(n,secondo->dimen)/2.0; terzo->maxdim = maxval(n,terzo->dimen); terzo->diam = norma(n,terzo->dimen)/2.0; secondo->fint = f1; if(f1 < *fdir){ *fdir = f1; for(i=0;i<n;i++) xdir[i] = secondo->cent[i]; } terzo->fint = f2; if(f2 < *fdir){ *fdir = f2; for(i=0;i<n;i++) xdir[i] = terzo->cent[i]; } secondo->flagloc = 0; terzo->flagloc = 0; secondo->flagdiv = 1; terzo->flagdiv = 1; secondo->flagcon = 0; terzo->flagcon = 0; secondo->id = *nint+1; terzo->id = *nint+2; //printf("secondo: %f id: %d cent: %f %f \n",f1,secondo->id,secondo->cent[0],secondo->cent[1]); //printf(" terzo: %f id: %d cent: %f %f \n",f2, terzo->id, terzo->cent[0], terzo->cent[1]); secondo = NULL; terzo = NULL; }
void TestBackward() { LayerParameter layer_param; PoolingParameter* pooling_param = layer_param.mutable_pooling_param(); pooling_param->add_kernel_size(2); pooling_param->add_kernel_size(2); pooling_param->add_kernel_size(2); pooling_param->add_stride(2); pooling_param->add_stride(2); pooling_param->add_stride(2); pooling_param->set_axis(1); PoolingLayer<TypeParam> layer(layer_param); layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_); int_tp d = blob_bottom_->shape(2); int_tp h = blob_bottom_->shape(3); int_tp w = blob_bottom_->shape(4); TypeParam *bottom_data = blob_bottom_->mutable_cpu_data(); std::vector<TypeParam> maxval(8); for (int_tp cd = 0; cd < d; ++cd) { for (int_tp ch = 0; ch < h; ++ch) { for (int_tp cw = 0; cw < w; ++cw) { bottom_data[cw + ch * w + cd * w * h] = cw + ch * w + cd * w * h; maxval[cw/2 + (ch/2)*2 + (cd/2)*4] = std::max(bottom_data[cw + ch * w + cd * w * h], maxval[cw/2 + (ch/2)*2 + (cd/2)*4]); } } } layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_); TypeParam *top_diff = blob_top_->mutable_cpu_diff(); for (int i = 0; i < 2*2*2; ++i) { top_diff[i] = maxval[i]; } std::vector<bool> prop_down; prop_down.push_back(true); layer.Backward(this->blob_top_vec_, prop_down, this->blob_bottom_vec_); const TypeParam *bottom_diff = blob_bottom_->cpu_diff(); for (int_tp cd = 0; cd < d; ++cd) { for (int_tp ch = 0; ch < h; ++ch) { for (int_tp cw = 0; cw < w; ++cw) { if (maxval[cw/2 + (ch/2)*2 + (cd/2)*4] == cw + ch * w + cd * w * h) { EXPECT_EQ(maxval[cw/2 + (ch/2)*2 + (cd/2)*4], bottom_diff[cw + ch * w + cd * w * h]); } else { EXPECT_EQ(0, bottom_diff[cw + ch * w + cd * w * h]); } } } } }
void AccuracyLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { Dtype accuracy = 0; const Dtype* bottom_data = bottom[0]->cpu_data(); const Dtype* bottom_label = bottom[1]->cpu_data(); const int dim = bottom[0]->count() / outer_num_; const int num_labels = bottom[0]->shape(label_axis_); vector<Dtype> maxval(top_k_+1); vector<int> max_id(top_k_+1); int count = 0; if (this->layer_param_.accuracy_param().type() ==1) { for (int i = 0; i < outer_num_; ++i) { for (int j = 0; j < inner_num_; ++j) { const int label_value = static_cast<int>(bottom_label[i * inner_num_ + j]); if (has_ignore_label_ && label_value == ignore_label_) { continue; } DCHECK_GE(label_value, 0); DCHECK_LT(label_value, num_labels); // Top-k accuracy std::vector<std::pair<Dtype, int> > bottom_data_vector; for (int k = 0; k < num_labels; ++k) { bottom_data_vector.push_back(std::make_pair( bottom_data[i * dim + k * inner_num_ + j], k)); } std::partial_sort( bottom_data_vector.begin(), bottom_data_vector.begin() + top_k_, bottom_data_vector.end(), std::greater<std::pair<Dtype, int> >()); // check if true label is in top k predictions for (int k = 0; k < top_k_; k++) { if (bottom_data_vector[k].second == label_value) { ++accuracy; break; } } ++count; } } // LOG(INFO) << "Accuracy: " << accuracy; top[0]->mutable_cpu_data()[0] = accuracy / count; // Accuracy layer should not be used as a loss function. }else{ #define POS_W 2 // dim = num_labels, inner_num_ = 1, outer_num_ = batch num, // LOG(INFO)<<"outer_num_: " << outer_num_ << " inner_num_: " << inner_num_ << " dim:" << dim <<" num_labels: " << num_labels; for (int i = 0; i < outer_num_; ++i) { for (int j = 0; j < inner_num_; ++j) { const int label_value = static_cast<int>(bottom_label[i * inner_num_ + j]); if (has_ignore_label_ && label_value == ignore_label_) { continue; } DCHECK_GE(label_value, 0); DCHECK_LT(label_value, num_labels); for (int k = 0; k < num_labels; ++k) { if (label_value == (k+1)) {// positive for class j // prob += max(Dtype(0), 1-bottom_data[i * dim + j]); // prob += max(Dtype(0), 2-2*bottom_data[i * dim + k * inner_num_ + j]); if (bottom_data[i * dim + k * inner_num_ + j] > 0) { ++accuracy; } } else {// negative for class j // prob += max(Dtype(0), 1+bottom_data[i * dim + k * inner_num_ + j]); if (bottom_data[i * dim + k * inner_num_ + j] < 0) { ++accuracy; } } } ++count; } } (top)[0]->mutable_cpu_data()[0] = num_labels - accuracy / count; } }
int main(int argc, char *argv[]) { if (argc != 3) { fprintf(stderr, "Usage: %s file_in.dat result.png\n", argv[0]); return 1; } char *file_in = argv[1]; char *file_out = argv[2]; int bytes = 256 * 256 * sizeof(int); unsigned int *points = (unsigned int *)calloc(1, bytes); FILE *fhi = fopen(file_in, "rb"); if (!fhi) { fprintf(stderr, "Failed to open %s\n", file_in); return 1; } FILE *fho = fopen(file_out, "wb"); if (!fho) { fprintf(stderr, "Failed to create %s\n", file_out); return 1; } while(!feof(fhi)) { int x = fgetc(fhi); int y = fgetc(fhi); if (x < 0 || y < 0) // EOF probably break; points[y * 256 + x]++; } fclose(fhi); unsigned int c_max = 0, c_min = 1 << 31; for(int index=0; index<(256*256); index++) { if (points[index] > c_max) c_max = points[index]; if (points[index] < c_min) c_min = points[index]; } double div = double(c_max) - double(c_min); bytes = 256 * 256 * 3; unsigned char *result = (unsigned char *)calloc(1, bytes); for(int y=0; y<256; y++) { for(int x=0; x<256; x++) { if (points[y * 256 + x] == 0) continue; double val = double(points[y * 256 + x] - c_min) / div; result[y * 256 * 3 + x * 3 + 0] = result[y * 256 * 3 + x * 3 + 2] = 0; result[y * 256 * 3 + x * 3 + 1] = (unsigned char)maxval(minval(255.0, val * 255.0), 0.0); } } png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_infop info_ptr = png_create_info_struct(png_ptr); png_set_IHDR (png_ptr, info_ptr, 256, 256, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); unsigned char *row_pointers[256]; for(int y=0; y<256; y++) row_pointers[y] = &result[y * 256 * 3]; png_init_io(png_ptr, fho); png_set_rows(png_ptr, info_ptr, row_pointers); png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); fclose(fho); return 0; }
T boundval(T lower_bound, T value, T upper_bound) { return maxval(minval(value, upper_bound), lower_bound); }
SANE_Status sane_read( SANE_Handle handle, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenP ) { ST400_Device *dev = handle; SANE_Status status; size_t r, i; SANE_Byte val; DBG(DCODE, "sane_read(%p, %p, %d, %p)\n", handle, buf, (int)maxlen, (void *) lenP); *lenP = 0; if( !dev->status.scanning ) return SANE_STATUS_INVAL; if( dev->status.eof ) return SANE_STATUS_EOF; status = SANE_STATUS_GOOD; while( maxlen > 0 ) { if( dev->bytes_in_buffer == 0 ) { status = st400_fill_backend_buffer(dev); if( status == SANE_STATUS_EOF ) return SANE_STATUS_GOOD; if( status != SANE_STATUS_GOOD ) { *lenP = 0; return status; } } r = min((SANE_Int) dev->bytes_in_buffer, maxlen); if( dev->val[OPT_DEPTH] == 1 || dev->model->bits == 8 ) { /* This is simple. We made sure the scanning are is aligned to * 8 pixels (see sane_get_parameters()), so we can simply copy * the stuff - only need to invert it. */ for( i = 0; i < r; i++ ) *buf++ = ~(*dev->bufp++); } else { SANE_Byte mv; /* The scanner sends bytes with 6bit-values (0..63), where 0 means * white. To convert to 8bit, we invert the values (so 0 means * black) and then shift them two bits to the left and replicate * the most- significant bits in the lowest two bits of the * 8bit-value: * bit-pattern x x 5 4 3 2 1 0 becomes 5 4 3 2 1 0 5 4 * This is more accurate than simply shifting the values two bits * to the left (e.g. 6bit-white 00111111 gets converted to 8bit- * white 11111111 instead of almost-white 11111100) and is still * reasonably fast. */ mv = (SANE_Byte)maxval(dev->model->bits); /* Note: this works with any bit depth <= 8 */ for( i = 0; i < r; i++ ) { val = mv - *dev->bufp++; val <<= (8 - dev->model->bits); val += (val >> dev->model->bits); *buf++ = val; } } maxlen -= r; dev->bytes_in_buffer -= r; *lenP += r; } return status; }
namespace utils { constexpr char const invalid_hexdigit = maxval( char() ); constexpr char const invalid_octdigit = maxval( char() ); }
void shot_ker_depth_onestep(sf_complex *wld_z,float *v_z,float w,int signn, struct shot_ker_par_type ker_par) { int op,nref,nx,ny,is2d; float wvx,dref; sf_complex *tmp_fft,*add_wld,*tmp_wld; int iref,ix,iy,ivx; float w_v0_z,maxvz,minvz; float *v0_z,*v_zw,*v_zw0; nref=ker_par.nref; nx=ker_par.nx; ny=ker_par.ny; is2d=ker_par.is2d; op=ker_par.op; //! op:1:ssf 2:fd 3:ffd v0_z=ker_par.v0_z; v_zw=ker_par.v_zw; v_zw0=ker_par.v_zw0; //old tmp_fft=ker_par.tmp_fft; add_wld=ker_par.add_wld; tmp_wld=ker_par.tmp_wld; tmp_fft=sf_complexalloc(nx*2); //old !v0_z(1)=minval(v_z);//!v0_z(nref)=maxval(v_z);//!dref=(v0_z(nref)-v0_z(1))/(nref-1) maxvz=maxval(v_z,nx*ny); minvz=minval(v_z,nx*ny); dref=(maxvz-minvz)/(nref+1); if ( fabs(maxvz-minvz)<50.0 ) { ///?????????????wait nref=1; v0_z[0]=0.5*(maxvz+minvz); } else{ v0_z[0]=minvz; v0_z[nref-1]=maxvz; dref=(v0_z[nref-1]-v0_z[0])/(float)(nref-1); v0_z[1]=(minvz+maxvz)*0.5; //old v0_z(2)=(minval(v_z)+maxval(v_z))*0.5; //! do iref=1,nref //! v0_z(iref)=iref*dref //! end do } //old!v0_z(2)=0.5*v0_z(1)+0.5*v0_z(3);//!v0_z(1)=0.5*v0_z(1)+0.5*v0_z(2);//!v0_z(3)=0.5*v0_z(3)+0.5*v0_z(2) //old v0_z[0]=0.5*(v0_z[0]+v0_z[1]); v0_z[2]=0.5*(v0_z[1]+v0_z[2]); dref=v0_z[1]-v0_z[0]; //old nref=1; v0_z[0]=minvz; //old printf("nx=%d,ny=%d\n",nx,ny); for (iy=0;iy<ny;iy++) for(ix=0;ix<nx;ix++) v_zw[i2(iy,ix,nx)]=v_z[i2(iy,ix,nx)]/w; if (op == 2){ w_v0_z=0.0; shot_ker_ssf(wld_z,w_v0_z,w,v_z,ker_par,signn); shot_ker_fd(wld_z,v_zw,v_zw,ker_par,signn); if (is2d){ vector_value_c(tmp_fft,sf_cmplx(0.0,0.0),nx); rowc(wld_z,tmp_fft,0,nx,1); //tmp_fft=wld_z(1,:); kissfft(tmp_fft,nx,+1); rowc(wld_z,tmp_fft,0,nx,0); //wld_z(1,:)=tmp_fft(:); } w_v0_z=w/(0.75*minvz+0.25*maxvz); li_filter_new(wld_z,w_v0_z,ker_par,signn); if (is2d){ rowc(wld_z,tmp_fft,0,nx,1); //tmp_fft=tmp_wld(:,1); kissfft(tmp_fft,nx,-1); rowc(wld_z,tmp_fft,0,nx,0); //tmp_wld(:,1)=tmp_fft(:); } } else{ if (is2d){ //printf("nx in fft nx=%d\n",nx); vector_value_c(tmp_fft,sf_cmplx(0.0,0.0),nx); //printf("in before iso max0=%f\n",maxvalc(wld_z,nx)); rowc(wld_z,tmp_fft,0,nx,1); //tmp_fft=wld_z(1,:); kissfft(tmp_fft,nx,+1); rowc(wld_z,tmp_fft,0,nx,0); //wld_z(1,:)=tmp_fft(:); //printf("in iso max0=%f\n",maxvalc(wld_z,nx)); } else{ //printf ("bbbbb iam 3d"); for(iy=0;iy<ny;iy++){ rowc(wld_z,tmp_fft,iy,nx,1); //tmp_fft=wld_z(1,:); kissfft(tmp_fft,nx,+1); rowc(wld_z,tmp_fft,iy,nx,0); //wld_z(1,:)=tmp_fft(:); } if (ny!=1){ for(ix=0;ix<nx;ix++){ colc(wld_z,tmp_fft,ix,nx,ny,1); kissfft(tmp_fft,ny,+1); colc(wld_z,tmp_fft,ix,nx,ny,0); // wait tmp_fftx tmp_ffty } } } for( iy=0;iy<ny;iy++) for(ix=0;ix<nx;ix++) add_wld[i2(iy,ix,nx)]=sf_cmplx(0.0,0.0); //add_wld=0.0; for( iref=0;iref<nref;iref++){ matrix_equ_c(tmp_wld,wld_z,ny,nx);//tmp_wld=wld_z; w_v0_z=w/v0_z[iref]; shot_phase_shift(tmp_wld,w_v0_z,ker_par,signn); //shot_phase_shift_vti(tmp_wld,w_v0_z,0.4,0.2,ker_par,signn); if (is2d){ rowc(tmp_wld,tmp_fft,0,nx,1); //tmp_fft=tmp_wld(:,1); kissfft(tmp_fft,nx,-1); rowc(tmp_wld,tmp_fft,0,nx,0); //tmp_wld(:,1)=tmp_fft(:); } else{ if (ny!=1){ for(ix=0;ix<nx;ix++){ colc(tmp_wld,tmp_fft,ix,nx,ny,1); kissfft(tmp_fft,ny,-1); colc(tmp_wld,tmp_fft,ix,nx,ny,0); // wait tmp_fftx tmp_ffty } } for(iy=0;iy<ny;iy++){ rowc(tmp_wld,tmp_fft,iy,nx,1); //tmp_fft=wld_z(1,:); kissfft(tmp_fft,nx,-1); rowc(tmp_wld,tmp_fft,iy,nx,0); //wld_z(1,:)=tmp_fft(:); } } shot_ker_ssf(tmp_wld,w_v0_z,w,v_z,ker_par,signn); if (op==3){ for( iy=0;iy<ny;iy++) for(ix=0;ix<nx;ix++) v_zw0[i2(iy,ix,nx)]=v_zw[i2(iy,ix,nx)]-v0_z[iref]/w; shot_ker_fd(tmp_wld,v_zw0,v_zw,ker_par,signn); } if ( nref==1) vector_cp_c(add_wld,tmp_wld,ny*nx); //add_wld=tmp_wld; else{ for(iy=0;iy<ny;iy++){ for(ix=0;ix<nx;ix++){ ivx=(int)((v_z[i2(iy,ix,nx)]-v0_z[0])/dref); //wait ??? wvx=(v_z[i2(iy,ix,nx)]-(v0_z[0]+(float)(ivx)*dref))/dref; //wait ??? if (v_z[i2(iy,ix,nx)] >= v0_z[nref-1]){ if (iref==nref-1) add_wld[i2(iy,ix,nx)]+=tmp_wld[i2(iy,ix,nx)]; } else{ if (v_z[i2(iy,ix,nx)] <= v0_z[0]){ if (iref==0) add_wld[i2(iy,ix,nx)]+=tmp_wld[i2(iy,ix,nx)]; } else{ if (ivx==iref) add_wld[i2(iy,ix,nx)] += tmp_wld[i2(iy,ix,nx)]*(1-wvx); if (ivx+1==iref) add_wld[i2(iy,ix,nx)] += tmp_wld[i2(iy,ix,nx)]*wvx; } } } } } } vector_cp_c(wld_z,add_wld,ny*nx); //wld_z=add_wld; } free(tmp_fft); }
void shot_ker_depth_onestep_ani_phaseshift(sf_complex *wld_z,float *v_z,float w,float ep,float dl,float phi, float f,int signn, struct shot_ker_par_type ker_par){ int op,nref,nx,ny,is2d; float wvx,dref; sf_complex *tmp_fft,*add_wld,*tmp_wld; int iref,ix,iy,ivx; float w_v0_z,maxvz,minvz; float *v0_z,*v_zw,*v_zw0; nref=ker_par.nref; nx=ker_par.nx; ny=ker_par.ny; is2d=ker_par.is2d; op=ker_par.op; //! op:1:ssf 2:fd 3:ffd v0_z=ker_par.v0_z; v_zw=ker_par.v_zw; v_zw0=ker_par.v_zw0; tmp_fft=ker_par.tmp_fft; add_wld=ker_par.add_wld; tmp_wld=ker_par.tmp_wld; maxvz=maxval(v_z,nx*ny); minvz=minval(v_z,nx*ny); dref=(maxvz-minvz)/(nref+1); if ( fabs(maxvz-minvz)<50.0 ) { ///?????????????wait nref=1; v0_z[0]=0.5*(maxvz+minvz); } else{ v0_z[0]=minvz; v0_z[nref-1]=maxvz; dref=(v0_z[nref-1]-v0_z[0])/(float)(nref-1); v0_z[1]=(minvz+maxvz)*0.5; } for (iy=0;iy<ny;iy++) for(ix=0;ix<nx;ix++) v_zw[i2(iy,ix,nx)]=v_z[i2(iy,ix,nx)]/w; if (op == 2){ w_v0_z=0.0; shot_ker_ssf(wld_z,w_v0_z,w,v_z,ker_par,signn); shot_ker_fd(wld_z,v_zw,v_zw,ker_par,signn); } else{ if (is2d){ rowc(wld_z,tmp_fft,0,nx,1); //tmp_fft=wld_z(1,:); kissfft(tmp_fft,nx,+1); rowc(wld_z,tmp_fft,0,nx,0); //wld_z(1,:)=tmp_fft(:); } else{ for(iy=0;iy<ny;iy++){ rowc(wld_z,tmp_fft,iy,nx,1); //tmp_fft=wld_z(1,:); kissfft(tmp_fft,nx,+1); rowc(wld_z,tmp_fft,iy,nx,0); //wld_z(1,:)=tmp_fft(:); } for(ix=0;ix<nx;ix++){ colc(wld_z,tmp_fft,ix,nx,ny,1); kissfft(tmp_fft,ny,+1); colc(wld_z,tmp_fft,ix,nx,ny,0); // wait tmp_fftx tmp_ffty } } for( iy=0;iy<ny;iy++) for(ix=0;ix<nx;ix++) add_wld[i2(iy,ix,nx)]=sf_cmplx(0.0,0.0); //add_wld=0.0; for( iref=0;iref<nref;iref++){ matrix_equ_c(tmp_wld,wld_z,ny,nx);//tmp_wld=wld_z; w_v0_z=w/v0_z[iref]; shot_phase_shift_ani(tmp_wld,w_v0_z,ep,dl,phi,f,ker_par,signn); if (is2d){ rowc(tmp_wld,tmp_fft,0,nx,1); //tmp_fft=tmp_wld(:,1); kissfft(tmp_fft,nx,-1); rowc(tmp_wld,tmp_fft,0,nx,0); //tmp_wld(:,1)=tmp_fft(:); } else{ for(ix=0;ix<nx;ix++){ colc(tmp_wld,tmp_fft,ix,nx,ny,1); kissfft(tmp_fft,ny,-1); colc(tmp_wld,tmp_fft,ix,nx,ny,0); // wait tmp_fftx tmp_ffty } for(iy=0;iy<ny;iy++){ rowc(tmp_wld,tmp_fft,iy,nx,1); //tmp_fft=wld_z(1,:); kissfft(tmp_fft,nx,-1); rowc(tmp_wld,tmp_fft,iy,nx,0); //wld_z(1,:)=tmp_fft(:); } } //shot_ker_ssf(tmp_wld,w_v0_z,w,v_z,ker_par,signn); if (op==3){ for( iy=0;iy<ny;iy++) for(ix=0;ix<nx;ix++) v_zw0[i2(iy,ix,nx)]=v_zw[i2(iy,ix,nx)]-v0_z[iref]/w; shot_ker_fd(tmp_wld,v_zw0,v_zw,ker_par,signn); } if ( nref==1) vector_cp_c(add_wld,tmp_wld,ny*nx); //add_wld=tmp_wld; else{ for(iy=0;iy<ny;iy++){ for(ix=0;ix<nx;ix++){ ivx=(int)((v_z[i2(iy,ix,nx)]-v0_z[0])/dref); //wait ??? wvx=(v_z[i2(iy,ix,nx)]-(v0_z[0]+(float)(ivx)*dref))/dref; //wait ??? if (v_z[i2(iy,ix,nx)] >= v0_z[nref-1]){ if (iref==nref-1) add_wld[i2(iy,ix,nx)]+=tmp_wld[i2(iy,ix,nx)]; } else{ if (v_z[i2(iy,ix,nx)] <= v0_z[0]){ if (iref==0) add_wld[i2(iy,ix,nx)]+=tmp_wld[i2(iy,ix,nx)]; } else{ if (ivx==iref) add_wld[i2(iy,ix,nx)] += tmp_wld[i2(iy,ix,nx)]*(1-wvx); if (ivx+1==iref) add_wld[i2(iy,ix,nx)] += tmp_wld[i2(iy,ix,nx)]*wvx; } } } } } } vector_cp_c(wld_z,add_wld,ny*nx); //wld_z=add_wld; } }
int main(int argc, char **argv) { struct shot_data_par_type data_par; struct shot_plane_par_type plane_par; struct shot_image_par_type image_par; struct shot_ker_par_type ker_par; struct shot_rotate_par_type rotate_par; sf_file velocity,wave; float mig_dx,mig_dy,mig_dz,mig_min_x,mig_min_y,fd_a,fd_b,trick,w; int op,mig_nz,mig_nx,mig_ny,tmp_mig_nx; int mig_nx_rotate,mig_nz_rotate,mig_ny_rotate; float rotate_angle; float epvalue,dlvalue; int i_sy,i_sx,iw,iz; float *vel,*ep,*dl,*image_z,*image,*image_rotate,*v_z; sf_complex *wld_s,*wld_r,*wld_s_z0,*wld_r_z0,*wld_s_tilt,*wld_r_tilt; float *image_1hx,**image_rotate_allhx,**image_rotate_allhz; int ixz,ihx; int data_nsy, ix; int mig_size,image_size; float dkx; int bx,ex,nx_iz; float ttmprotate=1.0; float t; bool vti; float a1,b1,a2,b2; sf_init(argc,argv); if (!sf_getfloat("t",&t)) t=0.8; if (!sf_getfloat("ep",&epvalue)) epvalue=0.4; if (!sf_getfloat("dl",&dlvalue)) dlvalue=0.2; if (!sf_getbool("vti",&vti)) vti=true; a1=0.040315157; b1=0.873981642; a2=0.457289566; b2=0.222691983; a1=0.659558; b1=0.790347; a2=0.030433; b2=1.692681; velocity_init(&velocity); //velocity_ani_init(&eps, &dlt); data_par=shot_data_init(); sf_warning("nsy=%d nsx=%d",data_par.nsy,data_par.nsx); shot_data_wavelet(data_par); image_par=shot_image_grab_par(); mig_dx=data_par.dhx; mig_dy=data_par.dhy; mig_grab_par(&op,&mig_nz,&mig_dz,&fd_a,&fd_b,&trick); shot_image_init(mig_dx,mig_dy,mig_dz,mig_nz,&image_par); wave = sf_output("wave"); sf_putfloat(wave,"d1",mig_dx); sf_putfloat(wave,"d2",mig_dy); sf_putfloat(wave,"d3",mig_dz); data_nsy=data_par.nsy; /* data_nsx=data_par.nsx; */ for(i_sy=0;i_sy< data_nsy;i_sy++){ for(i_sx=0;i_sx< 1;i_sx++){ shot_data_plane_grab_mig_par(i_sx,i_sy,&mig_min_x,&mig_min_y,&tmp_mig_nx,&mig_ny,data_par,&plane_par ); mig_nx=tmp_mig_nx; sf_warning("nx---------------%d",mig_nx); rotate_angle=asin( (i_sx*data_par.dsx+data_par.osx)*1500.0); rotate_angle=-50.0/180.0*SF_PI; rotate_angle=0.0/180.0*SF_PI; rotate_par=shot_rotate_init(rotate_angle,tmp_mig_nx,mig_nz,mig_dx,mig_dz); sf_warning("nx=%d,nz=%d,ny=%d",rotate_par.nx_rotate,rotate_par.nz_rotate,rotate_par.ny_rotate); mig_nx_rotate=rotate_par.nx_rotate; mig_ny_rotate=rotate_par.ny_rotate; mig_nz_rotate=rotate_par.nz_rotate; mig_size=mig_nx_rotate*mig_ny_rotate; image_size=mig_size*image_par.nhy*image_par.nhx*mig_nz_rotate; ker_par=shot_ker_p_init(op,mig_nx_rotate,mig_ny_rotate,mig_dx,mig_dy,mig_dz,fd_a,fd_b,trick,1,ttmprotate); vel=sf_floatalloc(mig_size*mig_nz_rotate); wld_s=sf_complexalloc(SF_MAX(mig_size,mig_nx*mig_ny_rotate)); wld_r=sf_complexalloc(SF_MAX(mig_size,mig_nx*mig_ny_rotate)); ep=sf_floatalloc(mig_size*mig_nz_rotate); dl=sf_floatalloc(mig_size*mig_nz_rotate); sf_warning("nz_s_rotate=%d",rotate_par.nz_s_rotate); //if (0.0!=rotate_angle){ wld_s_z0=sf_complexalloc(mig_size*rotate_par.nz_s_rotate); wld_r_z0=sf_complexalloc(mig_size*rotate_par.nz_s_rotate); //} image=sf_floatalloc(image_size); vector_value_f(image,0.0,image_size); sf_putint(wave,"n2",mig_nx_rotate); sf_putfloat(wave,"o2",0.0); sf_putint(wave,"n1",mig_nz_rotate); if (rotate_par.rotate_angle>=0.0) sf_putfloat(wave,"o2",mig_min_x); else sf_putfloat(wave,"o2",mig_min_x+(mig_nx-1)*mig_dx); velocity_read(velocity,vel,wave,rotate_par.rotate_angle,rotate_par.ix_rotate_center); veltranspose(vel,mig_ny_rotate,mig_nx_rotate,mig_nz_rotate); for(iw=0;iw<data_par.nw; iw++){ w=iw*data_par.dw+data_par.ow; sf_warning("iw=%d w=%f;",iw,w); shot_plane_source(mig_min_x,mig_min_y,mig_nx,mig_ny,iw,i_sx,i_sy,wld_s,data_par,plane_par); shot_plane_receiver(mig_min_x,mig_min_y,mig_nx,mig_ny,iw,i_sx,i_sy,wld_r,data_par,plane_par); shot_rotate_data_rotate(wld_r,wld_r_z0,&rotate_par); shot_rotate_data_rotate(wld_s,wld_s_z0,&rotate_par); vector_value_c(wld_s,sf_cmplx(0.0,0.0),mig_size); vector_value_c(wld_r,sf_cmplx(0.0,0.0),mig_size); //wld_r=0.0 wld_s=0.0 for(iz=0;iz<mig_nz_rotate;iz++){ image_z=image+mig_size*image_par.nhy*image_par.nhx*iz; if (iz <rotate_par.nz_s_rotate){ for(ix=0;ix<mig_nx_rotate;ix++) wld_s[ix]+=wld_s_z0[i2(iz,ix,mig_nx_rotate)]; //wld_s+=wld_s_z0(iz,:,:); for(ix=0;ix<mig_nx_rotate;ix++) wld_r[ix]+=wld_r_z0[i2(iz,ix,mig_nx_rotate)]; //wld_r+=wld_r_z0(iz,:,:); } if ( 0.0!=rotate_angle){ shot_rotate_get_bx_ex_iz(&dkx,&bx,&ex,iz,20,rotate_par); nx_iz=ex-bx+1; ker_par.dkx=dkx; ker_par.nx=nx_iz; v_z=vel+iz*mig_size+bx; wld_s_tilt=wld_s+bx; wld_r_tilt=wld_r+bx; image_z+=image_par.nhy*image_par.nhx*bx; /* ep_z=ep+iz*mig_size+bx; dl_z=dl+iz*mig_size+bx; */ } else{ v_z=vel+iz*mig_size; wld_s_tilt=wld_s; wld_r_tilt=wld_r; /* ep_z=ep+iz*mig_size; dl_z=dl+iz*mig_size; */ nx_iz=mig_nx_rotate; } if (vti) shot_ker_depth_onestep_impulse(wld_s_tilt,v_z,w,-1,epvalue,dlvalue,ker_par); else shot_ker_depth_onestep_fd2(wld_s_tilt,v_z,w,-1,a1,b1,a2,b2,ker_par); //shot_ker_depth_onestep(wld_s_tilt,v_z,w,-1,ker_par); //shot_ker_depth_onestep(wld_r_tilt,v_z,w,+1,ker_par); vector_value_c(wld_r,sf_cmplx(cosf(w*t),sinf(w*t)),mig_nx_rotate); //printf("max=%f\n",maxvalc(wld_r,mig_nx_rotate)); shot_image_cross_tilt(wld_s_tilt,wld_r_tilt,image_z,mig_nx_rotate,mig_ny_rotate,image_par,nx_iz); } } sf_warning("."); shot_ker_release(&ker_par); free(wld_s); free(wld_r);free(vel); free(ep); free(dl); if (0.0!=rotate_angle){ free(wld_s_z0); free(wld_r_z0); } image_rotate=sf_floatalloc(mig_nx*mig_nz); image_1hx=sf_floatalloc(mig_size*mig_nz_rotate); image_rotate_allhx=sf_floatalloc2(image_par.nhx,mig_nx*mig_nz); for (ihx=0;ihx<image_par.nhx;ihx++){ //printf("ihx=%d\n",ihx); for(ixz=0;ixz<mig_size*mig_nz_rotate;ixz++) image_1hx[ixz]=image[i2(ixz,ihx,image_par.nhx)]; shot_rotate_image_rotate(image_1hx,image_rotate,rotate_par); for(ixz=0;ixz<mig_nx*mig_nz;ixz++) image_rotate_allhx[ixz][ihx]=image_rotate[ixz]*1.0; } free(image); //rotate image //stat=auxputch ("rotate_angle","f",&rotate_angle,"Image_hx"); if (rotate_angle !=0.0){ image_rotate_allhz=sf_floatalloc2(mig_nx*mig_nz, image_par.nhx); shot_image_decompose(*image_rotate_allhx, *image_rotate_allhz,mig_nx,mig_nz,rotate_angle,image_par); sf_warning("ishot=%d,maxhx=%f,maxhz=%f", i_sx, maxval(*image_rotate_allhx,mig_nx*mig_nz*image_par.nhx), maxval(*image_rotate_allhz,mig_nx*mig_nz*image_par.nhx)); shot_image_stack(*image_rotate_allhz,mig_min_x,mig_min_y,mig_nx,mig_ny,image_par.imagez,image_par); free(*image_rotate_allhz); free(image_rotate_allhz); } shot_image_stack(*image_rotate_allhx,mig_min_x,mig_min_y,mig_nx,mig_ny,image_par.imagex,image_par); free(image_rotate); // rite image free(image_1hx); free(*image_rotate_allhx); free(image_rotate_allhx); shot_rotate_release(&rotate_par); } } shot_data_release(&data_par); shot_image_release(&image_par); exit(0); }
void AccuracyLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { std::ofstream of; of.open("/media/DATA/BigVision/NLTK/caffe/tags_classifier/hierarchical_classification/result.txt", ios::app); // Dtype accuracy = 0; const Dtype* bottom_data = bottom[0]->cpu_data(); const Dtype* bottom_label = bottom[1]->cpu_data(); const int dim = bottom[0]->count() / outer_num_; const int num_labels = bottom[0]->shape(label_axis_); vector<Dtype> maxval(top_k_+1); vector<int> max_id(top_k_+1); int count = 0; int true_positive = 0; int true_negative = 0; int false_positive = 0; int false_negative = 0; const int auc_pts = 20; vector<int> auc_tp(2 * auc_pts + 1, 0); vector<int> auc_tn(2 * auc_pts + 1, 0); vector<int> auc_fp(2 * auc_pts + 1, 0); vector<int> auc_fn(2 * auc_pts + 1, 0); for (int i = 0; i < outer_num_; ++i) { for (int j = 0; j < inner_num_; ++j) { const int label_value = static_cast<int>(bottom_label[i * inner_num_ + j]); if (has_ignore_label_ && label_value == ignore_label_) { continue; } DCHECK_GE(label_value, 0); DCHECK_LT(label_value, num_labels); // Top-k accuracy std::vector<std::pair<Dtype, int> > bottom_data_vector; for (int k = 0; k < num_labels; ++k) { bottom_data_vector.push_back(std::make_pair( bottom_data[i * dim + k * inner_num_ + j], k)); } std::partial_sort( bottom_data_vector.begin(), bottom_data_vector.begin() + top_k_, bottom_data_vector.end(), std::greater<std::pair<Dtype, int> >()); // check if true label is in top k predictions count++; if (label_value == 0) { if (bottom_data_vector[0].second == 0) { true_negative++; } else { false_positive++; } } else { if (bottom_data_vector[0].second == 0) { false_negative++; } else { true_positive++; } } //for (int k = 0; k < 1; k++) {//top_k_ modified for binary classifier //} for (int k = 0; k < 2 * auc_pts + 1; k++) { int p = k - auc_pts; Dtype inc = (1 - exp(-p)) / (1 + exp(-p)); bottom_data_vector.clear(); for (int l = 0; l < num_labels; l++) { bottom_data_vector.push_back(std::make_pair( bottom_data[i * dim + l * inner_num_ + j], l)); } bottom_data_vector[1].first += inc; // LOG(INFO) << "first: " << bottom_data_vector[0].first << ", second: " << bottom_data_vector[1].first; std::partial_sort( bottom_data_vector.begin(), bottom_data_vector.begin() + top_k_, bottom_data_vector.end(), std::greater<std::pair<Dtype, int> >()); if (label_value == 0) { if (bottom_data_vector[0].second == 0) { auc_tn[k]++; } else { auc_fp[k]++; } } else { if (bottom_data_vector[0].second == 0) { auc_fn[k]++; } else { auc_tp[k]++; } } } } if (i==0) { //LOG(INFO) << "correct: " << correct << ", error: " << error; //LOG(INFO) << "positive1: " << positive1 << ", negative1: " <<negative1; //LOG(INFO) << "positive2: " << positive2 << ", negative2: " <<negative2; } } //LOG(INFO) << "accuracy: " << accuracy << ", count: " <<count; //LOG(INFO) << "accuracy rate: " << accuracy / count; // LOG(INFO) << "Accuracy: " << accuracy; top[0]->mutable_cpu_data()[0] = Dtype(true_positive) / (true_positive + false_negative); top[0]->mutable_cpu_data()[1] = Dtype(true_negative) / (true_negative + false_positive); top[0]->mutable_cpu_data()[2] = Dtype(false_positive) / (true_negative + false_positive); top[0]->mutable_cpu_data()[3] = Dtype(false_negative) / (true_positive + false_negative); top[0]->mutable_cpu_data()[4] = Dtype(true_positive) / (true_positive + false_positive); top[0]->mutable_cpu_data()[5] = Dtype(true_negative) / (true_negative + false_negative); int l = auc_pts; top[0]->mutable_cpu_data()[6] = Dtype(sqrt(Dtype(true_positive * true_negative) / ((true_positive + false_negative) * (true_negative + false_positive)))); //int l = auc_pts / 2; //of << Dtype(sqrt(Dtype(auc_tp[l] * auc_tn[l]) / ((auc_tp[l] + auc_fn[l]) * (auc_tn[l] + auc_fp[l])))) << std::endl; /*for(int i = 0; i < 2 * auc_pts + 1; i++) { of << Dtype(auc_tp[i]) / (auc_tp[i] + auc_fn[i]) << " "; of << Dtype(auc_fp[i]) / (auc_fp[i] + auc_tn[i]) << " "; of << std::endl; } of << std::endl;*/ //LOG(INFO) << "Write in result.txt"; /*for (int i = 0; i < auc_pts; i++) { of << auc_tp[i] << " " << auc_fn[i] << " " << auc_tn[i] << " " << auc_fp[i] << std::endl; } of << std::endl;*/ // Accuracy layer should not be used as a loss function. }
void direct(int n, double *lb, double *ub, int maxint, double fglob, double *xbest, double *fbest, double funct(int, double*)){ int i, nf, maxnf, nint, nconv, nelim; int halt, trovato, nmaxdimen; intervallo *primo, *start, *curr; vertice *convexhull, *currch; double fdir, toldiam, tolglob, eps; double maxdiam, mindiam, maxdimen, minder; double *xdir; char ch; xdir = (double *)malloc(n*sizeof(double)); mod_box.lb = (double *)malloc(n*sizeof(double)); mod_box.ub = (double *)malloc(n*sizeof(double)); mod_box.xtemp = (double *)malloc(n*sizeof(double)); mod_box.xbar = (double *)malloc(n*sizeof(double)); mod_suddividi.vetf1 = (double *)malloc(n*sizeof(double)); mod_suddividi.vetf2 = (double *)malloc(n*sizeof(double)); mod_suddividi.xsud = (double *)malloc(n*sizeof(double)); mod_suddividi.ysud = (double *)malloc(n*sizeof(double)); mod_suddividi.mask = (int *)malloc(n*sizeof(int )); for(i=0;i<n;i++) { mod_box.lb[i]=lb[i]; mod_box.ub[i]=ub[i]; xbest[i] = (ub[i]+lb[i])/2.0; xdir[i] = xbest[i]; //printf("mb.lb[%d]=%f mb.ub[%d]=%f xbest[%d]=%f\n", // i,mod_box.lb[i],i,mod_box.ub[i],i,xbest[i]); } printf("\n"); primo = (intervallo *)malloc(sizeof(intervallo)); alloca_intervallo(n, primo); start = primo; /*for(i=0;i<4000000;i++){ primo->next = (intervallo *)malloc(sizeof(intervallo)); primo = primo->next; alloca_intervallo(n, primo); }*/ for(i=0;i<n;i++) { primo->cent[i] = 0.5; primo->dimen[i] = 1.0; } primo->maxdim = 1.0; primo->der = 0.0; primo->diam = norma(n,primo->dimen)/2.0; primo->flagloc = 0; primo->flagdiv = 1; primo->flagcon = 0; primo->id = 1; unscalevars(n,primo->cent,xbest); *fbest = funct(n,xbest); fdir = *fbest; primo->fint = fdir; primo->next = NULL; nf = 1; nint = 1; nconv = 1; nelim = 1; toldiam = 0.0 *sqrt((double)n)/2.0; tolglob = 1.e-4; eps = 1.e-4; //maxnf = 2000000000; halt = 0; trovato = 0; //printf("fbest = %f, nf = %d\n\n",*fbest,nf); while(!halt){ curr = start; maxdiam = curr->diam; mindiam = curr->diam; maxdimen = curr->dimen[0]; for(i=1;i<n;i++) { if(maxdimen < curr->dimen[i]) maxdimen = curr->dimen[i]; } nmaxdimen= 0; while (curr != NULL){ if(maxdiam < curr->diam) maxdiam = curr->diam; if(mindiam > curr->diam) mindiam = curr->diam; if(maxdimen< maxval(n,curr->dimen)){ maxdimen = maxval(n,curr->dimen); nmaxdimen = 1; } else if(maxdimen == maxval(n,curr->dimen)){ nmaxdimen = nmaxdimen + 1; } curr = curr->next; } if( ((*fbest-fglob)/(1.0 > fglob ? 1.0 : fglob)) < tolglob){ trovato = 1; } else { trovato = 0; } //if( (nf > maxnf) || (nint > maxint) || trovato ){ if( (nint > maxint) || trovato ){ halt = 1; break; } convexhull = NULL; //printf("st %f\n",start->fint); ricintervallo(start,&convexhull,&nconv); //if(convexhull == NULL) printf("convexhull vuoto !!\n"); riduciconvexhull(convexhull,&nelim,eps,toldiam,fdir); //printf("nconv = %d nelim = %d\n\n",nconv,nelim); //printf("cv = %f\n\n",convexhull->inter->fint); currch = convexhull; for(i=1; i<=nelim; i++){ currch = currch->next; } //printf("inizio suddivisioni\n\n"); while (currch != NULL){ //printf("currch id %d sta su conv.hull\n",currch->inter->id); if(currch->inter->flagdiv) suddividi(currch->inter,n,&nf,&nint,xdir,&fdir,funct); currch = currch->next; } //printf("fine suddivisioni\n\n"); unscalevars(n,xdir,xbest); *fbest = fdir; /*!------------------------------------------- ! dealloca la lista che memorizza gli ! intervalli sul convex hull !------------------------------------------- */ currch = convexhull; while (currch != NULL){ currch->inter->flagcon = 0; currch = currch->next; convexhull->inter = NULL; convexhull->next = NULL; free(convexhull); convexhull = currch; } //printf("fbest=%f nf=%d nconv=%d nelim=%d diam=%f DIAM=%f\n",fdir,nf,nconv,nelim,mindiam,maxdiam); //scanf("%c",&ch); } printf("\nDIRECT has satisfied the stopping condition.\n"); //printf("a"); //deallocate DIRECT structures deallocalistaint(start); //printf("b"); free(xdir); free(mod_box.lb); free(mod_box.ub); //printf("c"); free(mod_box.xtemp); free(mod_box.xbar); free(mod_suddividi.vetf1); free(mod_suddividi.vetf2); //printf("d"); free(mod_suddividi.xsud); free(mod_suddividi.ysud); free(mod_suddividi.mask); //printf("e"); }
void shot_image_decompose_1imagepoint(float *image_hx,float *image_hz,int nx,int nz,float rotate_angle, struct shot_image_par_type image_par) /*< one image point >*/ { float *image_dip,*sincx_table; int i_ihz,i_ihx,ihdip,ihx,ihz,ii_hz,ii_hx,iwx; float hx,hz,whx,whz,ohx,hdip,ddx; float sincz[8],sincx[8]; float *i0sinc; float dwx; int nit=8; dwx=0.0005; sincx_table=image_par.sincx_table; image_dip=sf_floatalloc(image_par.nhx*nit); //wait ohx ohx=-image_par.dx*image_par.nhx/2; ddx=image_par.dx/(float)(nit); vector_value_f(image_dip,0.0,image_par.nhx*nit); for(ihdip=0;ihdip<image_par.nhx*nit;ihdip++){ hdip=(int)(ihdip)*ddx+ohx; ihx=(int)((hdip-ohx)/image_par.dx); whx=(hdip-(ohx+(float)(ihx)*image_par.dx))/image_par.dx; iwx=(int)(whx/dwx); //wwx=(whx- ((float)(iwx)*dwx))/dwx; i0sinc=sincx_table+8*iwx; for(i_ihx=0;i_ihx<8;i_ihx++) sincx[i_ihx]=i0sinc[i_ihx]; //sincx[i_ihx-1]=(1-wwx)*sincx_table[i2(iwx,i_ihx-1,8)]+wwx*sincx_table[i2(iwx+1,i_ihx-1,8)]; for(i_ihx=1;i_ihx<=8;i_ihx++){ ii_hx=i_ihx+ihx-4; if (ii_hx>=0 && ii_hx < image_par.nhx ) image_dip[ihdip]+=sincx[i_ihx-1]*image_hx[ii_hx]; } //for(i_ihx) }//for(ihdip) printf("maxhdip=%f\n",maxval(image_dip,image_par.nhx*nit)); vector_value_f(image_hx,0.0,image_par.nhx*image_par.nhy); vector_value_f(image_hz,0.0,image_par.nhx*image_par.nhy); for(ihdip=0;ihdip<image_par.nhx*nit;ihdip++){ hdip=ohx+(float)(ihdip)*ddx; if (hdip==0){ hx=0.0; hz=0.0; } else{ hx=hdip/cos(rotate_angle); hz=hdip/sin(rotate_angle); } ihx=(int)((hx-ohx)/image_par.dx); ihz=(int)((hz-ohx)/image_par.dx); if (ihx >= 0 && ihx<image_par.nhx ){ whx=( hx-(ohx+(float)(ihx)*image_par.dx) )/image_par.dx; iwx=(int)(whx/dwx); //wwx=(whx- ((float)(iwx)*dwx))/dwx; i0sinc=sincx_table+8*iwx; for(i_ihx=0;i_ihx<8;i_ihx++) sincx[i_ihx]=i0sinc[i_ihx]; //sincx[i_ihx-1]=(1-wwx)*sincx_table[i2(iwx,i_ihx-1,8)]+wwx*sincx_table[i2(iwx+1,i_ihx-1,8)]; //sincx(:)=(1-wwx)*sincx_table(:,iwx)+wwx*sincx_table(:,iwx+1); for(i_ihx=1;i_ihx<=8;i_ihx++){ ii_hx=i_ihx+ihx-4; if (ii_hx >=0 && ii_hx < image_par.nhx ) image_hx[ii_hx]+= sincx[i_ihx-1]*image_dip[ihdip]; }//for(i_ihx) } if (ihz >=0 && ihz <image_par.nhx ){ whz=( hz-(ohx+(float)(ihz)*image_par.dx) )/image_par.dx; iwx=(int)(whz/dwx); //wwx=(whz-((float)(iwx)*dwx))/dwx; i0sinc=sincx_table+8*iwx; for(i_ihx=0;i_ihx<8;i_ihx++) sincz[i_ihx]=i0sinc[i_ihx]; //sincz[i_ihx-1]=(1-wwx)*sincx_table[i2(iwx,i_ihx-1,8)]+wwx*sincx_table[i2(iwx+1,i_ihx-1,8)]; for(i_ihz=1;i_ihz<=8;i_ihz++){ ii_hz=i_ihz+ihz-4; if (ii_hz >0 && ii_hz <= image_par.nhx ) image_hz[ii_hz]+= sincz[i_ihz-1]*image_dip[ihdip]; if (ihdip==125) printf("i_ihz=%d,imagehz=%f,sinc=%f,imagedip=%f\n",i_ihz,image_hz[ii_hz],sincz[i_ihz-1],image_dip[ihdip]); }//for(i_ihz) } printf("iz=%d,maxhz=%f\n",ihdip,maxval(image_hz,image_par.nhx)); }// for(ihdip) free(image_dip); }
dsp_linknode* duscr_csc (int m,int n,double* val,int n_val,int* indx,int n_indx,int* pntrb,int n_pntrb,int* pntre,int n_pntre,int prpty,int* istat) { int options,base,nnz; bool COPY; char message; DSPMAT* dsp_data; dsp_linknode* dsp_l; int i; options=*istat; *istat=-1; //if not changed later,routine has failed dsp_l=new_dsp(istat); if(*istat!=0) {//then *istat=blas_error_memalloc; return NULL; }//end if dsp_data=accessdata_dsp(dsp_l,istat); if(*istat!=0) {//then *istat=blas_error_param; return NULL; }//end if dsp_data->FIDA=CSC_FORMAT; dsp_data->M=m; dsp_data->K=n; set_descra(dsp_data->DESCRA,prpty,istat); get_descra(dsp_data->DESCRA,'b',&message,istat); if (message=='C') base=C_BASE; else //Assuming F base base=F_BASE; set_infoa(dsp_data->INFOA,'b',base,istat); nnz=maxval(pntre,n_pntre)-base; set_infoa(dsp_data->INFOA,'n',nnz,istat); if((nnz!=n_indx)||(n!=n_pntrb)||(minval(indx,n_indx)<base)||(maxval(indx,n_indx)>m-1+base)||(n!=n_pntre)||(nnz!=n_val)) {//then BLAS_usds(dsp_l,3); *istat=blas_error_param; return NULL; } //init the size of array in dsp dsp_data->n_A=n_val; dsp_data->n_IA1=n_indx; dsp_data->n_PB=n_pntrb; dsp_data->n_PE=n_pntre; dsp_data->n_BP1=0; dsp_data->n_BP2=0; dsp_data->n_IA2=0; if(options>0) {//then // decision rule whether or not to copy COPY=TRUE; if(COPY) {//then options=-1; //copy }else{ options=0; //reference }//end if }//end if if (options==0) {//then set_infoa(dsp_data->INFOA,'c',REF_OF_SOURCE,istat); if (*istat!=0) { *istat=blas_error_param; return NULL; } // create reference to original matrix dsp_data->A=val; dsp_data->IA1=indx; dsp_data->PB=pntrb; dsp_data->PE=pntre; *istat=0; }else{ // The additional required memory is DEALLOCATED later in USDS// set_infoa(dsp_data->INFOA,'c',COP_OF_SOURCE,istat); if (*istat!=0) {// *istat=blas_error_param; return NULL; } // copy original data dsp_data->A=(double*)aligned_malloc(sizeof(double)*n_val); dsp_data->IA1=(int*)aligned_malloc(sizeof(int)*n_indx); dsp_data->PB=(int*)aligned_malloc(sizeof(int)*n_pntrb); dsp_data->PE=(int*)aligned_malloc(sizeof(int)*n_pntre); if (*istat!=0) {// *istat=blas_error_memalloc; return NULL; } for(i=0;i<dsp_data->n_A;i++) dsp_data->A[i]=val[i]; for(i=0;i<dsp_data->n_IA1;i++) dsp_data->IA1[i]=indx[i]; for(i=0;i<dsp_data->n_PB;i++) dsp_data->PB[i]=pntrb[i]; for(i=0;i<dsp_data->n_PE;i++) dsp_data->PE[i]=pntre[i]; *istat=1; } if(*istat>=0) { *istat=0; return dsp_l; } else return NULL; }