utils

package
v0.0.0-...-36fcdf9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package utils holds small utility types and functions used internally in stablehlo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DTypeToStableHLO

func DTypeToStableHLO(dtype dtypes.DType) string

func NormalizeIdentifier

func NormalizeIdentifier(name string) string

NormalizeIdentifier converts the name of an identifier (function name or function input parameter name) to a valid one: only letters, digits, and underscores are allowed.

Invalid characters are replaced with underscores. If the name starts with a digit, it is prefixed with an underscore.

func SortedKeys

func SortedKeys[T cmp.Ordered](set Set[T]) []T

SortedKeys returns the keys of the set in sorted order.

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase converts a string from CamelCase to snake_case.

Types

type Set

type Set[T comparable] map[T]struct{}

Set implements a Set for the key type T.

func MakeSet

func MakeSet[T comparable](size ...int) Set[T]

MakeSet returns an empty Set of the given type. Size is optional, and if given will reserve the expected size.

func SetWith

func SetWith[T comparable](elements ...T) Set[T]

SetWith creates a Set[T] with the given elements inserted.

func (Set[T]) Add

func (s Set[T]) Add(s2 Set[T]) Set[T]

Add returns the union of s and s2.

func (Set[T]) Clone

func (s Set[T]) Clone() Set[T]

Clone returns a copy of the set.

func (Set[T]) Equal

func (s Set[T]) Equal(s2 Set[T]) bool

Equal returns whether s and s2 have the exact same elements.

func (Set[T]) Has

func (s Set[T]) Has(key T) bool

Has returns true if Set s has the given key.

func (Set[T]) Insert

func (s Set[T]) Insert(keys ...T)

Insert keys into set.

func (Set[T]) Sub

func (s Set[T]) Sub(s2 Set[T]) Set[T]

Sub returns s - s2, that is, all elements in `s` that are not in `s2`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL