@@ -335,7 +335,7 @@ DevNotes
335
335
- TODO refactor relationship and common fields between (CCW, FMd, CPT, CalcFactor)
336
336
"""
337
337
function _buildCalcFactorLambdaSample (
338
- destVarVals:: AbstractVector ,
338
+ # destVarVals::AbstractVector,
339
339
ccwl:: CommonConvWrapper ,
340
340
smpid:: Integer ,
341
341
target, # partials no longer on coordinates at this level # = view(destVarVals[smpid], ccwl.partialDims), # target = view(ccwl.varValsAll[ccwl.varidx[]][smpid], ccwl.partialDims),
@@ -373,17 +373,23 @@ function _buildCalcFactorLambdaSample(
373
373
# reset the residual vector
374
374
fill! (ccwl. res, 0.0 ) # Roots->xDim | Minimize->zDim
375
375
376
+ _getindex_anyn (vec, n) = begin
377
+ len = length (vec)
378
+ # 1:len or any random element in that range
379
+ getindex (vec, n <= len ? n : rand (1 : len) )
380
+ end
381
+
376
382
# build static lambda
377
383
unrollHypo! = if _slack === nothing
378
384
# DESIGN DECISION WAS MADE THAT CALCFACTOR CALLS DO NOT DO INPLACE CHANGES TO ARGUMENTS, INSTEAD USING ISBITSTYPEs!!!!!!!!!
379
- () -> cf (measurement_[smpid], map (vvh -> getindex (vvh, smpid), varValsHypo)... )
385
+ () -> cf (measurement_[smpid], map (vvh -> _getindex_anyn (vvh, smpid), varValsHypo)... )
380
386
else
381
387
# slack is used to shift the residual away from the natural "zero" tension position of a factor,
382
388
# this is useful when calculating factor gradients at a variety of param locations resulting in "non-zero slack" of the residual.
383
389
# see `IIF.calcFactorResidualTemporary`
384
390
# NOTE this minus operation assumes _slack is either coordinate or tangent vector element (not a manifold or group element)
385
391
() ->
386
- cf (measurement_[smpid], map (vvh -> getindex (vvh, smpid), varValsHypo)... ) .- _slack
392
+ cf (measurement_[smpid], map (vvh -> _getindex_anyn (vvh, smpid), varValsHypo)... ) .- _slack
387
393
end
388
394
389
395
return unrollHypo!, target
@@ -408,7 +414,7 @@ DevNotes
408
414
- TODO perhaps consolidate perturbation with inflation or nullhypo
409
415
"""
410
416
function _solveCCWNumeric! (
411
- destVarVals:: AbstractVector ,
417
+ # destVarVals::AbstractVector,
412
418
ccwl:: Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}} ,
413
419
_slack = nothing ;
414
420
perturb:: Real = 1e-10 ,
@@ -437,7 +443,7 @@ function _solveCCWNumeric!(
437
443
end
438
444
# build the pre-objective function for this sample's hypothesis selection
439
445
unrollHypo!, _ = _buildCalcFactorLambdaSample (
440
- destVarVals,
446
+ # destVarVals,
441
447
ccwl,
442
448
smpid,
443
449
target,
@@ -477,7 +483,7 @@ function _solveCCWNumeric!(
477
483
478
484
# Check for NaNs
479
485
if sum (isnan .(retval)) != 0
480
- @error " $(ccwl. usrfnc!) , ccw.thrid_= $(thrid) , got NaN, smpid = $(smpid) , r=$(retval) \n "
486
+ @error " $(ccwl. usrfnc!) , got NaN, smpid = $(smpid) , r=$(retval) \n "
481
487
return nothing
482
488
end
483
489
@@ -486,7 +492,7 @@ function _solveCCWNumeric!(
486
492
ccwl. varValsAll[][sfidx][smpid][ccwl. partialDims] .= retval
487
493
else
488
494
# copyto!(ccwl.varValsAll[sfidx][smpid], retval)
489
- copyto! (destVarVals [smpid][ccwl. partialDims], retval)
495
+ copyto! (ccwl . varValsAll[][sfidx] [smpid][ccwl. partialDims], retval)
490
496
end
491
497
492
498
return nothing
498
504
#
499
505
500
506
function _solveCCWNumeric! (
501
- destVarVals:: AbstractVector ,
507
+ # destVarVals::AbstractVector,
502
508
ccwl:: Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}} ,
503
509
_slack = nothing ;
504
510
perturb:: Real = 1e-10 ,
@@ -509,7 +515,7 @@ function _solveCCWNumeric!(
509
515
# _checkErrorCCWNumerics(ccwl, testshuffle)
510
516
511
517
#
512
- thrid = Threads. threadid ()
518
+ # thrid = Threads.threadid()
513
519
514
520
smpid = ccwl. particleidx[]
515
521
# cannot Nelder-Mead on 1dim, partial can be 1dim or more but being conservative.
@@ -518,10 +524,10 @@ function _solveCCWNumeric!(
518
524
# build the pre-objective function for this sample's hypothesis selection
519
525
# SUPER IMPORTANT ON PARTIALS, RESIDUAL FUNCTION MUST DEAL WITH PARTIAL AND WILL GET FULL VARIABLE POINTS REGARDLESS
520
526
unrollHypo!, target = _buildCalcFactorLambdaSample (
521
- destVarVals,
527
+ # destVarVals,
522
528
ccwl,
523
529
smpid,
524
- view (destVarVals , smpid), # SUPER IMPORTANT, this `target` is mem pointer that will be updated by optim library
530
+ view (ccwl . varValsAll[][ccwl . varidx[]] , smpid), # SUPER IMPORTANT, this `target` is mem pointer that will be updated by optim library
525
531
ccwl. measurement,
526
532
_slack,
527
533
)
@@ -540,7 +546,7 @@ function _solveCCWNumeric!(
540
546
541
547
# do the parameter search over defined decision variables using Minimization
542
548
sfidx = ccwl. varidx[]
543
- X = destVarVals [smpid]
549
+ X = ccwl . varValsAll[][ccwl . varidx[]] [smpid]
544
550
retval = _solveLambdaNumeric (
545
551
getFactorType (ccwl),
546
552
_hypoObj,
@@ -558,7 +564,7 @@ function _solveCCWNumeric!(
558
564
# end
559
565
560
566
# FIXME insert result back at the correct variable element location
561
- destVarVals [smpid] = retval
567
+ ccwl . varValsAll[][ccwl . varidx[]] [smpid] = retval
562
568
563
569
return nothing
564
570
end
0 commit comments