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

Method ScanFloat1AttributeParallelWithPoolSize

modeling/mesh.go:601–639  ·  view source on GitHub ↗
(atr string, size int, f func(i int, v float64))

Source from the content-addressed store, hash-verified

599}
600
601func (m Mesh) ScanFloat1AttributeParallelWithPoolSize(atr string, size int, f func(i int, v float64)) Mesh {
602 m.requireV1Attribute(atr)
603
604 if size < 1 {
605 panic(fmt.Errorf("unable to scan float1, invalid worker pool size: %d", size))
606 }
607
608 if size == 1 {
609 return m.ScanFloat1Attribute(atr, f)
610 }
611
612 var wg sync.WaitGroup
613
614 data := m.v1Data[atr]
615 workSize := int(math.Floor(float64(len(data)) / float64(size)))
616 for i := 0; i < size; i++ {
617 wg.Add(1)
618
619 jobSize := workSize
620
621 // Make sure to clean up potential last cell due to rounding error of
622 // division of number of CPUs
623 if i == size-1 {
624 jobSize = len(data) - (workSize * i)
625 }
626
627 go func(start, size int) {
628 defer wg.Done()
629 end := start + size
630 for i := start; i < end; i++ {
631 f(i, data[i])
632 }
633 }(workSize*i, jobSize)
634 }
635
636 wg.Wait()
637
638 return m
639}
640
641func (m Mesh) ModifyFloat3Attribute(atr string, f func(i int, v vector3.Float64) vector3.Float64) Mesh {
642 m.requireV3Attribute(atr)

Callers 1

Calls 3

requireV1AttributeMethod · 0.95
ScanFloat1AttributeMethod · 0.95
AddMethod · 0.65

Tested by

no test coverage detected