Documentation

Overview

    Package f64s provides common operations on float64 slices.

    Index

    Examples

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    func Filter

    func Filter(dst, src []float64, f func(v float64) bool) []float64

      Filter creates a slice with all the elements x_i of src for which f(x_i) is true. Filter uses dst as work buffer, storing elements at the start of the slice. Filter clears dst if a slice is passed, and allocates a new slice if dst is nil.

      Example

        An example of slice filtering

        Code:

        package main
        
        import (
        	"fmt"
        
        	"go-hep.org/x/hep/sliceop/f64s"
        )
        
        func main() {
        	slice := []float64{1, 2, -99, 4, 5, -99, 7}
        	condition := func(x float64) bool { return x > 0 }
        	fmt.Println(f64s.Filter(nil, slice, condition))
        
        }
        
        [1 2 4 5 7]
        

        func Find

        func Find(dst []int, src []float64, f func(v float64) bool) []int

          Find creates a slice with all indices corresponding to elements for which f(x) is true. Find uses dst as work buffer, storing indices at the start of the slice. Find clears dst if a slice is passed, and allocates a new slice if dst is nil.

          Example

            An example of slice finding

            Code:

            package main
            
            import (
            	"fmt"
            
            	"go-hep.org/x/hep/sliceop/f64s"
            )
            
            func main() {
            	slice := []float64{1, 2, -99, 4, 5, -99, 7}
            	condition := func(x float64) bool { return x == -99 }
            	fmt.Println(f64s.Find(nil, slice, condition))
            
            }
            
            [2 5]
            

            func Map

            func Map(dst, src []float64, f func(v float64) float64) []float64

              Map creates a slice with all the elements f(x_i) where x_i are elements from src. Map uses dst as work buffer, storing elements at the start of the slice. Map allocates a new slice if dst is nil. Map will panic if the lengths of src and dst differ.

              Example

                An example of slice mapping

                Code:

                package main
                
                import (
                	"fmt"
                
                	"go-hep.org/x/hep/sliceop/f64s"
                )
                
                func main() {
                	slice := []float64{1, 2, -99, 4, 5, -99, 7}
                	operation := func(x float64) float64 { return x * x }
                	fmt.Println(f64s.Map(nil, slice, operation))
                
                }
                
                [1 4 9801 16 25 9801 49]
                

                func Take

                func Take(dst, src []float64, indices []int) []float64

                  Take creates a sub-slice of src with all elements indiced by the provided indices. Take uses dst as work buffer, storing elements at the start of the slice. Take clears dst if a slice is passed, and allocates a new slice if dst is nil. Take will panic if indices is not sorted or has duplicates. Take will panic if length of indices is larger than length of src. Take will panic if length of indices is different from length of dst.

                  Example

                    An example of taking a sub-slice defined by indices

                    Code:

                    package main
                    
                    import (
                    	"fmt"
                    
                    	"go-hep.org/x/hep/sliceop/f64s"
                    )
                    
                    func main() {
                    	slice := []float64{1, 2, -99, 4, 5, -99, 7}
                    	indices := []int{2, 5}
                    	fmt.Println(f64s.Take(nil, slice, indices))
                    
                    }
                    
                    [-99 -99]
                    

                    Types

                    This section is empty.

                    Source Files