func (u *ΔUpdater) Update() { qin := u.in.Array() qout := u.out.Array() q0 := u.q0.Array() qinMul := u.in.Multiplier() qoutMul := u.out.Multiplier() q0Mul := u.q0.Multiplier() COMP := u.in.NComp() pre := make([]float64, COMP) for ii := 0; ii < COMP; ii++ { qoutMul[ii] = qinMul[ii] pre[ii] = -q0Mul[ii] / qinMul[ii] //0? } switch COMP { case 1: gpu.Madd(qout.Component(0), qin.Component(0), q0.Component(0), pre[0]) case 3: gpu.VecMadd(qout, qin, q0, pre) default: panic(InputErrF("Δ is not implemented for NComp: ", COMP)) } }
func (u *SumUpdater) addTerms() { // TODO: optimize for 0,1,2 or more parents sum := u.sum parents := u.parents if sum.IsSpaceDependent() { for i := range parents { parent := parents[i] weight := u.weight[i] parMul := make([]float64, sum.NComp()) for c := 0; c < sum.NComp(); c++ { parMul[c] = weight * parent.Multiplier()[c] / sum.Multiplier()[c] } switch sum.NComp() { case 1: gpu.Madd(sum.array.Component(0), sum.array.Component(0), parent.array.Component(0), parMul[0]) case 3: gpu.VecMadd(sum.Array(), sum.Array(), parent.Array(), parMul) default: panic(InputErr("sum is not implemented for NComp: " + fmt.Sprint(sum.NComp()))) } } } else { for p, parent := range parents { for c := range sum.multiplier { sum.multiplier[c] += parent.multiplier[c] * u.weight[p] } } } }