MCPcopy Create free account
hub / github.com/EliCDavis/polyform / ModifyFloat2AttributeParallelWithPoolSize

Method ModifyFloat2AttributeParallelWithPoolSize

modeling/mesh.go:715–755  ·  view source on GitHub ↗
(atr string, size int, f func(i int, v vector2.Float64) vector2.Float64)

Source from the content-addressed store, hash-verified

713}
714
715func (m Mesh) ModifyFloat2AttributeParallelWithPoolSize(atr string, size int, f func(i int, v vector2.Float64) vector2.Float64) Mesh {
716 m.requireV2Attribute(atr)
717
718 if size < 1 {
719 panic(fmt.Errorf("unable to modify float2, invalid worker pool size: %d", size))
720 }
721
722 if size == 1 {
723 return m.ModifyFloat2Attribute(atr, f)
724 }
725
726 oldData := m.v2Data[atr]
727 modified := make([]vector2.Float64, len(oldData))
728
729 var wg sync.WaitGroup
730
731 workSize := int(math.Floor(float64(len(oldData)) / float64(size)))
732 for i := 0; i < size; i++ {
733 wg.Add(1)
734
735 jobSize := workSize
736
737 // Make sure to clean up potential last cell due to rounding error of
738 // division of number of CPUs
739 if i == size-1 {
740 jobSize = len(oldData) - (workSize * i)
741 }
742
743 go func(start, size int) {
744 defer wg.Done()
745 end := start + size
746 for i := start; i < end; i++ {
747 modified[i] = f(i, oldData[i])
748 }
749 }(workSize*i, jobSize)
750 }
751
752 wg.Wait()
753
754 return m.SetFloat2Attribute(atr, modified)
755}
756
757func (m Mesh) ModifyFloat1Attribute(atr string, f func(i int, v float64) float64) Mesh {
758 m.requireV1Attribute(atr)

Callers 1

Calls 4

requireV2AttributeMethod · 0.95
ModifyFloat2AttributeMethod · 0.95
SetFloat2AttributeMethod · 0.95
AddMethod · 0.65

Tested by

no test coverage detected