Changes in / [510277d:376b0ee] in sasmodels
- Location:
- sasmodels
- Files:
-
- 4 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/details.py
rce99754 r767dca8 193 193 #print("off:",offset) 194 194 195 # Check that we ar en't using too many polydispersity loops195 # Check that we arn't using too many polydispersity loops 196 196 num_active = np.sum(length > 1) 197 197 max_pd = model_info.parameters.max_pd … … 318 318 parameter set in the vector. 319 319 """ 320 _, dispersity, weight = zip(*mesh)320 value, dispersity, weight = zip(*mesh) 321 321 #weight = [w if len(w)>0 else [1.] for w in weight] 322 322 weight = np.vstack([v.flatten() for v in meshgrid(*weight)]) -
sasmodels/kernel_iq.c
r6aee3ab r4991048 13 13 // NOTE: the following macros are defined in generate.py: 14 14 // 15 // MAX_PD : the maximum number of dispersity loops allowed for this model, 16 // which will be at most modelinfo.MAX_PD. 15 // MAX_PD : the maximum number of dispersity loops allowed 17 16 // NUM_PARS : the number of parameters in the parameter table 18 17 // NUM_VALUES : the number of values to skip at the start of the … … 283 282 #endif 284 283 285 // ** Fill in the local values table ** 286 // Storage for the current parameter values. 287 // These will be updated as we walk the dispersity mesh. 284 // Storage for the current parameter values. These will be updated as we 285 // walk the dispersity mesh. 288 286 ParameterBlock local_values; 289 // values[0] is scale 290 // values[1] is background 291 #ifdef USE_OPENMP 292 #pragma omp parallel for 293 #endif 294 for (int i=0; i < NUM_PARS; i++) { 295 local_values.vector[i] = values[2+i]; 296 //if (q_index==0) printf("p%d = %g\n",i, local_values.vector[i]); 297 } 298 //if (q_index==0) printf("NUM_VALUES:%d NUM_PARS:%d MAX_PD:%d\n", NUM_VALUES, NUM_PARS, MAX_PD); 299 //if (q_index==0) printf("start:%d stop:%d\n", pd_start, pd_stop); 300 301 // ** Precompute magnatism values ** 287 302 288 #if defined(MAGNETIC) && NUM_MAGNETIC>0 303 289 // Location of the sld parameters in the parameter vector. … … 316 302 #endif // MAGNETIC 317 303 318 // ** Fill in the initial results ** 304 // Fill in the initial variables 305 // values[0] is scale 306 // values[1] is background 307 #ifdef USE_OPENMP 308 #pragma omp parallel for 309 #endif 310 for (int i=0; i < NUM_PARS; i++) { 311 local_values.vector[i] = values[2+i]; 312 //if (q_index==0) printf("p%d = %g\n",i, local_values.vector[i]); 313 } 314 //if (q_index==0) printf("NUM_VALUES:%d NUM_PARS:%d MAX_PD:%d\n", NUM_VALUES, NUM_PARS, MAX_PD); 315 //if (q_index==0) printf("start:%d stop:%d\n", pd_start, pd_stop); 316 319 317 // If pd_start is zero that means that we are starting a new calculation, 320 318 // and must initialize the result to zero. Otherwise, we are restarting … … 338 336 for (int q_index=0; q_index < nq; q_index++) result[q_index] = 0.0; 339 337 } 340 338 //if (q_index==0) printf("start %d %g %g\n", pd_start, pd_norm, result[0]); 341 339 #endif // !USE_OPENCL 342 340 … … 392 390 PD_OPEN(0,1) 393 391 394 // ... main loop body ... 395 APPLY_PROJECTION // convert jitter values to spherical coords 396 BUILD_ROTATION // construct the rotation matrix qxy => qabc 397 for each q 398 FETCH_Q // set qx,qy from the q input vector 399 APPLY_ROTATION // convert qx,qy to qa,qb,qc 400 CALL_KERNEL // scattering = Iqxy(qa, qb, qc, p1, p2, ...) 392 ... main loop body ... 401 393 402 394 ++step; // increment counter representing position in dispersity mesh … … 420 412 */ 421 413 422 423 // ** prepare inner loops ** 424 414 // Define looping variables 415 #define PD_INIT(_LOOP) \ 416 const int n##_LOOP = details->pd_length[_LOOP]; \ 417 const int p##_LOOP = details->pd_par[_LOOP]; \ 418 global const double *v##_LOOP = pd_value + details->pd_offset[_LOOP]; \ 419 global const double *w##_LOOP = pd_weight + details->pd_offset[_LOOP]; \ 420 int i##_LOOP = (pd_start/details->pd_stride[_LOOP])%n##_LOOP; 421 422 // Jump into the middle of the dispersity loop 423 #define PD_OPEN(_LOOP,_OUTER) \ 424 while (i##_LOOP < n##_LOOP) { \ 425 local_values.vector[p##_LOOP] = v##_LOOP[i##_LOOP]; \ 426 const double weight##_LOOP = w##_LOOP[i##_LOOP] * weight##_OUTER; 427 428 // create the variable "weight#=1.0" where # is the outermost level+1 (=MAX_PD). 429 #define _PD_OUTERMOST_WEIGHT(_n) const double weight##_n = 1.0; 430 #define PD_OUTERMOST_WEIGHT(_n) _PD_OUTERMOST_WEIGHT(_n) 431 432 // Close out the loop 433 #define PD_CLOSE(_LOOP) \ 434 if (step >= pd_stop) break; \ 435 ++i##_LOOP; \ 436 } \ 437 i##_LOOP = 0; 438 439 // The main loop body is essentially: 440 // 441 // BUILD_ROTATION // construct the rotation matrix qxy => qabc 442 // for each q 443 // FETCH_Q // set qx,qy from the q input vector 444 // APPLY_ROTATION // convert qx,qy to qa,qb,qc 445 // CALL_KERNEL // scattering = Iqxy(qa, qb, qc, p1, p2, ...) 446 // 425 447 // Depending on the shape type (radial, axial, triaxial), the variables 426 // and calling parameters in the loop body will be slightly different. 427 // Macros capture the differences in one spot so the rest of the code 428 // is easier to read. The code below both declares variables for the 429 // inner loop and defines the macros that use them. 448 // and calling parameters will be slightly different. These macros 449 // capture the differences in one spot so the rest of the code is easier 450 // to read. 430 451 431 452 #if defined(CALL_IQ) … … 465 486 // psi and dpsi are only for IQ_ABC, so they are processed here. 466 487 const double psi = values[details->theta_par+4]; 467 local_values.table.psi = 0.;468 488 #define BUILD_ROTATION() qabc_rotation(&rotation, theta, phi, psi, dtheta, dphi, local_values.table.psi) 469 489 #define APPLY_ROTATION() qabc_apply(rotation, qx, qy, &qa, &qb, &qc) … … 481 501 const double theta = values[details->theta_par+2]; 482 502 const double phi = values[details->theta_par+3]; 483 // Make sure jitter angle defaults to zero if there is no jitter distribution484 local_values.table.theta = 0.;485 local_values.table.phi = 0.;486 503 // The "jitter" angles (dtheta, dphi, dpsi) are stored with the 487 504 // dispersity values and copied to the local parameter table as … … 506 523 #endif // !spherosymmetric projection 507 524 508 // ** define looping macros **509 510 // Define looping variables511 #define PD_INIT(_LOOP) \512 const int n##_LOOP = details->pd_length[_LOOP]; \513 const int p##_LOOP = details->pd_par[_LOOP]; \514 global const double *v##_LOOP = pd_value + details->pd_offset[_LOOP]; \515 global const double *w##_LOOP = pd_weight + details->pd_offset[_LOOP]; \516 int i##_LOOP = (pd_start/details->pd_stride[_LOOP])%n##_LOOP;517 518 // Jump into the middle of the dispersity loop519 #define PD_OPEN(_LOOP,_OUTER) \520 while (i##_LOOP < n##_LOOP) { \521 local_values.vector[p##_LOOP] = v##_LOOP[i##_LOOP]; \522 const double weight##_LOOP = w##_LOOP[i##_LOOP] * weight##_OUTER;523 524 // create the variable "weight#=1.0" where # is the outermost level+1 (=MAX_PD).525 #define _PD_OUTERMOST_WEIGHT(_n) const double weight##_n = 1.0;526 #define PD_OUTERMOST_WEIGHT(_n) _PD_OUTERMOST_WEIGHT(_n)527 528 // Close out the loop529 #define PD_CLOSE(_LOOP) \530 if (step >= pd_stop) break; \531 ++i##_LOOP; \532 } \533 i##_LOOP = 0;534 525 535 526 // ====== construct the loops ======= … … 546 537 int step = pd_start; 547 538 548 // *** define loops for each of 0, 1, 2, ..., modelinfo.MAX_PD-1 ***549 550 539 // define looping variables 551 540 #if MAX_PD>4 … … 582 571 PD_OPEN(0,1) 583 572 #endif 573 584 574 585 575 //if (q_index==0) {printf("step:%d of %d, pars:",step,pd_stop); for (int i=0; i < NUM_PARS; i++) printf("p%d=%g ",i, local_values.vector[i]); printf("\n");} … … 682 672 #endif // !USE_OPENCL 683 673 684 // ** clear the macros in preparation for the next kernel **674 // clear the macros in preparation for the next kernel 685 675 #undef PD_INIT 686 676 #undef PD_OPEN -
sasmodels/modelinfo.py
r6aee3ab re3571cb 30 30 TestCondition = Tuple[ParameterSetUser, TestInput, TestValue] 31 31 32 # If MAX_PD changes, need to change the loop macros in kernel_iq.c 33 MAX_PD = 5 #: Maximum number of simultaneously polydisperse parameters 32 MAX_PD = 4 #: Maximum number of simultaneously polydisperse parameters 34 33 35 34 # assumptions about common parameters exist throughout the code, such as: -
sasmodels/product.py
rce99754 r1f35235 101 101 model_info.composition = ('product', [p_info, s_info]) 102 102 model_info.control = p_info.control 103 model_info.hidden = p_info.hidden104 if getattr(p_info, 'profile', None) is not None:105 profile_pars = set(p.id for p in p_info.parameters.kernel_parameters)106 def profile(**kwargs):107 # extract the profile args108 kwargs = dict((k, v) for k, v in kwargs.items() if k in profile_pars)109 return p_info.profile(**kwargs)110 else:111 profile = None112 model_info.profile = profile113 model_info.profile_axes = p_info.profile_axes114 115 103 # TODO: delegate random to p_info, s_info 116 104 #model_info.random = lambda: {} … … 279 267 weight = values[nvalues + call_details.num_weights: nvalues + 2*call_details.num_weights] 280 268 npars = model_info.parameters.npars 281 # Note: changed from pairs ([v], [w]) to triples (p, [v], [w]), but the 282 # dispersion mesh code doesn't actually care about the nominal parameter 283 # value, p, so set it to None. 284 pairs = [(None, value[offset:offset+length], weight[offset:offset+length]) 269 pairs = [(value[offset:offset+length], weight[offset:offset+length]) 285 270 for p, offset, length 286 271 in zip(model_info.parameters.call_parameters[2:2+npars], -
sasmodels/sasview_model.py
r17db833 ra9bc435 205 205 structure_factor._model_info) 206 206 ConstructedModel = make_model_from_info(model_info) 207 return ConstructedModel(form_factor.multiplicity) 207 return ConstructedModel(form_factor.multiplicity) 208 208 209 209 … … 673 673 #call_details.show() 674 674 #print("pairs", pairs) 675 #for k, p in enumerate(self._model_info.parameters.call_parameters):676 # print(k, p.name, *pairs[k])677 675 #print("params", self.params) 678 676 #print("values", values) … … 680 678 result = calculator(call_details, values, cutoff=self.cutoff, 681 679 magnetic=is_magnetic) 682 #print("result", result)683 680 self._intermediate_results = getattr(calculator, 'results', None) 684 681 calculator.release() … … 764 761 return self.multiplicity, [self.multiplicity], [1.0] 765 762 else: 766 # For hidden parameters use default values. This sets 767 # scale=1 and background=0 for structure factors 763 # For hidden parameters use the default value. 768 764 default = self._model_info.parameters.defaults.get(par.name, np.NaN) 769 return default,[default], [1.0]765 return [default], [1.0] 770 766 elif par.polydisperse: 771 767 value = self.params[par.name] … … 780 776 else: 781 777 value = self.params[par.name] 782 return value, [value ], [1.0]778 return value, [value if par.relative_pd else 0.0], [1.0] 783 779 784 780 def test_cylinder(): … … 798 794 Model = _make_standard_model('hardsphere') 799 795 model = Model() 800 value2d = model.evalDistribution([0.1, 0.1])801 value1d = model.evalDistribution(np.array([0.1*np.sqrt(2)]))802 #print("hardsphere", value1d, value2d)803 if np.isnan(value1d) or np.isnan(value2d):804 raise ValueError("hardsphere returns nan")805 806 def test_product():807 # type: () -> float808 """809 Test that 2-D hardsphere model runs and doesn't produce NaN.810 """811 S = _make_standard_model('hayter_msa')()812 P = _make_standard_model('cylinder')()813 model = MultiplicationModel(P, S)814 796 value = model.evalDistribution([0.1, 0.1]) 815 797 if np.isnan(value): 816 raise ValueError(" cylinder*hatyer_msareturns null")798 raise ValueError("hardsphere returns null") 817 799 818 800 def test_rpa(): … … 868 850 if __name__ == "__main__": 869 851 print("cylinder(0.1,0.1)=%g"%test_cylinder()) 870 #test_product()871 #test_structure_factor()872 #print("rpa:", test_rpa())873 852 #test_empty_distribution()
Note: See TracChangeset
for help on using the changeset viewer.