Skip to content

Commit 48211a3

Browse files
authored
Merge pull request #11 from ajroetker/modernize-tool-run-001
Apply Go modernize tool fixes
2 parents 60fb20c + 8b9834b commit 48211a3

9 files changed

Lines changed: 25 additions & 30 deletions

File tree

internal/cmd/dtypes_codegen/enums.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func generateEnums(contents string) {
148148
if len(matches) == 0 {
149149
panicf("failed to match PJRT_Buffer_Types enum from pjrt_c_api.h")
150150
}
151-
for _, line := range strings.Split(matches[2], "\n") {
151+
for line := range strings.SplitSeq(matches[2], "\n") {
152152
if line == "" {
153153
continue
154154
}

internal/cmd/pjrt_codegen/enums.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func generateEnums(contents string) {
6363
continue
6464
}
6565
var eEntry *enumEntry
66-
for _, line := range strings.Split(matches[2], "\n") {
66+
for line := range strings.SplitSeq(matches[2], "\n") {
6767
if line == "" {
6868
continue
6969
}

internal/pool/pool_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ func TestPool(t *testing.T) {
3333
var wg sync.WaitGroup
3434
wg.Add(numGoroutines)
3535

36-
for i := 0; i < numGoroutines; i++ {
36+
for range numGoroutines {
3737
go func() {
3838
defer wg.Done()
39-
for j := 0; j < numIterations; j++ {
39+
for range numIterations {
4040
node := pool.Get()
4141

4242
// Simulate work

internal/shapeinference/shapeinference.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ func Concatenate(inputs []shapes.Shape, axis int) (output shapes.Shape, err erro
828828
rank, i, currentShape.Rank())
829829
}
830830

831-
for d := 0; d < rank; d++ {
831+
for d := range rank {
832832
if d == axis {
833833
// For the concatenation axis, add dimensions (handling dynamic dims)
834834
if output.Dimensions[d] != shapes.DimUnknown && currentShape.Dimensions[d] != shapes.DimUnknown {
@@ -987,7 +987,7 @@ func Slice(operand shapes.Shape, starts, limits, strides []int) (output shapes.S
987987
Dimensions: make([]int, rank),
988988
}
989989

990-
for axis := 0; axis < rank; axis++ {
990+
for axis := range rank {
991991
start, limit, stride := starts[axis], limits[axis], strides[axis]
992992
dimSize := operand.Dimensions[axis]
993993

@@ -1170,7 +1170,7 @@ func ReduceWindow(inputs, initialValues []shapes.Shape, reductionInputs, reducti
11701170
// Each output dimension is calculated orthogonally to the others.
11711171
outputDims := make([]int, rank)
11721172
operand := inputs[0]
1173-
for i := 0; i < rank; i++ {
1173+
for i := range rank {
11741174
inputDim := operand.Dimensions[i]
11751175
windowDim := windowDimensions[i]
11761176
if windowDim < 1 {
@@ -1550,10 +1550,10 @@ func DotGeneral(
15501550
// Check that all sizes are positive or dynamic (negative for dynamic dimensions is allowed)
15511551
// Note: Sizes can be negative when dimensions are dynamic. We only validate that non-dynamic sizes are positive.
15521552
// The actual validation happens at runtime when concrete dimensions are known.
1553-
_ = batchSize // May be negative (dynamic), validated at runtime
1554-
_ = lhsCrossSize // May be negative (dynamic), validated at runtime
1553+
_ = batchSize // May be negative (dynamic), validated at runtime
1554+
_ = lhsCrossSize // May be negative (dynamic), validated at runtime
15551555
_ = contractingSize // May be negative (dynamic), validated at runtime
1556-
_ = rhsCrossSize // May be negative (dynamic), validated at runtime
1556+
_ = rhsCrossSize // May be negative (dynamic), validated at runtime
15571557

15581558
// Reshape result to recover batch and cross dimensions.
15591559
resultingDims := make([]int, 0, len(batchDims)+len(lhsCrossDims)+len(rhsCrossDims))

pkg/installer/cpu.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func detectGlibcVersion() (major int, minor int, err error) {
5050
if lddErr != nil {
5151
return 0, 0, errors.Wrap(lddErr, "failed to run ldd --version")
5252
}
53-
lines := strings.Split(string(lddBytes), "\n")
54-
for _, line := range lines {
53+
lines := strings.SplitSeq(string(lddBytes), "\n")
54+
for line := range lines {
5555
matches := glibcVersionRegex.FindStringSubmatch(line)
5656
if len(matches) == 3 {
5757
major, _ = strconv.Atoi(matches[1])

pkg/installer/pip.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ func (info *PipPackageInfo) ParseDependencies() ([]PipDependency, error) {
109109

110110
// Handle multiple comma-separated specifiers
111111
// Example: "<10.0,>=9.8"
112-
specParts := strings.Split(cleanSpec, ",")
112+
specParts := strings.SplitSeq(cleanSpec, ",")
113113

114-
for _, part := range specParts {
114+
for part := range specParts {
115115
part = strings.TrimSpace(part)
116116
if part == "" {
117117
continue
@@ -192,7 +192,7 @@ func PipCompareVersion(v1, v2 string) int {
192192
minLen := min(len(v1Parts), len(v2Parts))
193193

194194
// Compare common parts
195-
for i := 0; i < minLen; i++ {
195+
for i := range minLen {
196196
var n1, n2 int
197197
fmt.Sscanf(v1Parts[i], "%d", &n1)
198198
fmt.Sscanf(v2Parts[i], "%d", &n2)
@@ -261,4 +261,3 @@ func PipPackageLinuxAMD64() *regexp.Regexp {
261261
func PipPackageLinuxAMD64Glibc231() *regexp.Regexp {
262262
return pipPackageLinuxAMD64Glibc231
263263
}
264-

pkg/stablehlo/value.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package stablehlo
33
import (
44
"fmt"
55
"io"
6+
"strings"
67

78
"github.com/gomlx/go-xla/pkg/types/shapes"
89
"github.com/pkg/errors"
@@ -51,15 +52,15 @@ func (v *Value) String() string {
5152
// ConvertToValidName replaces any characters not in { "0"-"9", "a"-"z", "A-Z", "_" } to a "_",
5253
// making it a valid name for values and function arguments.
5354
func ConvertToValidName(name string) string {
54-
var result string
55+
var result strings.Builder
5556
for _, c := range name {
5657
if (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' {
57-
result += string(c)
58+
result.WriteString(string(c))
5859
} else {
59-
result += "_"
60+
result.WriteString("_")
6061
}
6162
}
62-
return result
63+
return result.String()
6364
}
6465

6566
// WithQuantization sets the quantization parameters for this value.

pkg/types/shapes/dtype.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ func UnsafeSliceForDType(dtype dtypes.DType, unsafePtr unsafe.Pointer, len int)
125125

126126
// Pre-generate constant reflect.TypeOf for convenience.
127127
var (
128-
float32Type = reflect.TypeOf(float32(0))
129-
float64Type = reflect.TypeOf(float64(0))
130-
float16Type = reflect.TypeOf(float16.Float16(0))
131-
bfloat16Type = reflect.TypeOf(bfloat16.BFloat16(0))
128+
float32Type = reflect.TypeFor[float32]()
129+
float64Type = reflect.TypeFor[float64]()
130+
float16Type = reflect.TypeFor[float16.Float16]()
131+
bfloat16Type = reflect.TypeFor[bfloat16.BFloat16]()
132132
)
133133

134134
// CastAsDType casts a numeric value to the corresponding for the DType.

pkg/types/shapes/shape.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,7 @@ func (s Shape) Size() (size int) {
182182
//
183183
// Notice scalars are not zero in size -- they have size one, but rank zero.
184184
func (s Shape) IsZeroSize() bool {
185-
for _, d := range s.Dimensions {
186-
if d == 0 {
187-
return true
188-
}
189-
}
190-
return false
185+
return slices.Contains(s.Dimensions, 0)
191186

192187
}
193188

0 commit comments

Comments
 (0)