@@ -335,7 +335,7 @@ DevNotes
335335- TODO refactor relationship and common fields between (CCW, FMd, CPT, CalcFactor)
336336"""
337337function _buildCalcFactorLambdaSample (
338- destVarVals:: AbstractVector ,
338+ # destVarVals::AbstractVector,
339339 ccwl:: CommonConvWrapper ,
340340 smpid:: Integer ,
341341 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(
373373 # reset the residual vector
374374 fill! (ccwl. res, 0.0 ) # Roots->xDim | Minimize->zDim
375375
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+
376382 # build static lambda
377383 unrollHypo! = if _slack === nothing
378384 # 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)... )
380386 else
381387 # slack is used to shift the residual away from the natural "zero" tension position of a factor,
382388 # this is useful when calculating factor gradients at a variety of param locations resulting in "non-zero slack" of the residual.
383389 # see `IIF.calcFactorResidualTemporary`
384390 # NOTE this minus operation assumes _slack is either coordinate or tangent vector element (not a manifold or group element)
385391 () ->
386- cf (measurement_[smpid], map (vvh -> getindex (vvh, smpid), varValsHypo)... ) .- _slack
392+ cf (measurement_[smpid], map (vvh -> _getindex_anyn (vvh, smpid), varValsHypo)... ) .- _slack
387393 end
388394
389395 return unrollHypo!, target
@@ -408,7 +414,7 @@ DevNotes
408414- TODO perhaps consolidate perturbation with inflation or nullhypo
409415"""
410416function _solveCCWNumeric! (
411- destVarVals:: AbstractVector ,
417+ # destVarVals::AbstractVector,
412418 ccwl:: Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}} ,
413419 _slack = nothing ;
414420 perturb:: Real = 1e-10 ,
@@ -437,7 +443,7 @@ function _solveCCWNumeric!(
437443 end
438444 # build the pre-objective function for this sample's hypothesis selection
439445 unrollHypo!, _ = _buildCalcFactorLambdaSample (
440- destVarVals,
446+ # destVarVals,
441447 ccwl,
442448 smpid,
443449 target,
@@ -477,7 +483,7 @@ function _solveCCWNumeric!(
477483
478484 # Check for NaNs
479485 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 "
481487 return nothing
482488 end
483489
@@ -486,7 +492,7 @@ function _solveCCWNumeric!(
486492 ccwl. varValsAll[][sfidx][smpid][ccwl. partialDims] .= retval
487493 else
488494 # copyto!(ccwl.varValsAll[sfidx][smpid], retval)
489- copyto! (destVarVals [smpid][ccwl. partialDims], retval)
495+ copyto! (ccwl . varValsAll[][sfidx] [smpid][ccwl. partialDims], retval)
490496 end
491497
492498 return nothing
498504#
499505
500506function _solveCCWNumeric! (
501- destVarVals:: AbstractVector ,
507+ # destVarVals::AbstractVector,
502508 ccwl:: Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}} ,
503509 _slack = nothing ;
504510 perturb:: Real = 1e-10 ,
@@ -509,7 +515,7 @@ function _solveCCWNumeric!(
509515 # _checkErrorCCWNumerics(ccwl, testshuffle)
510516
511517 #
512- thrid = Threads. threadid ()
518+ # thrid = Threads.threadid()
513519
514520 smpid = ccwl. particleidx[]
515521 # cannot Nelder-Mead on 1dim, partial can be 1dim or more but being conservative.
@@ -518,10 +524,10 @@ function _solveCCWNumeric!(
518524 # build the pre-objective function for this sample's hypothesis selection
519525 # SUPER IMPORTANT ON PARTIALS, RESIDUAL FUNCTION MUST DEAL WITH PARTIAL AND WILL GET FULL VARIABLE POINTS REGARDLESS
520526 unrollHypo!, target = _buildCalcFactorLambdaSample (
521- destVarVals,
527+ # destVarVals,
522528 ccwl,
523529 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
525531 ccwl. measurement,
526532 _slack,
527533 )
@@ -540,7 +546,7 @@ function _solveCCWNumeric!(
540546
541547 # do the parameter search over defined decision variables using Minimization
542548 sfidx = ccwl. varidx[]
543- X = destVarVals [smpid]
549+ X = ccwl . varValsAll[][ccwl . varidx[]] [smpid]
544550 retval = _solveLambdaNumeric (
545551 getFactorType (ccwl),
546552 _hypoObj,
@@ -558,7 +564,7 @@ function _solveCCWNumeric!(
558564 # end
559565
560566 # FIXME insert result back at the correct variable element location
561- destVarVals [smpid] = retval
567+ ccwl . varValsAll[][ccwl . varidx[]] [smpid] = retval
562568
563569 return nothing
564570end
0 commit comments