Skip to content

util

fn arange #

fn arange(n int) []int

range returns a list with int values in the interval [0, n)

fn calculate_gflops_gemm #

fn calculate_gflops_gemm(m int, n int, k int, time_ns f64) f64

Calculate GFLOPS for matrix multiplication

fn calculate_gflops_gemv #

fn calculate_gflops_gemv(m int, n int, time_ns f64) f64

Calculate GFLOPS for matrix-vector multiplication

fn col_to_row_major #

fn col_to_row_major(a []f64, m int, n int) [][]f64

Convert column-major matrix (BLAS/LAPACK format) to row-major (V's native format)

fn flatten_row_major #

fn flatten_row_major(a [][]f64) []f64

Flatten row-major matrix to 1D array (row-major order)

fn format_time #

fn format_time(ns f64) string

Format time in appropriate units

fn get_many #

fn get_many[T](arr []T, idxs []int) []T

get_many returns an array containing the values in the given idxs

fn int_ints_map_append #

fn int_ints_map_append(o map[int][]int, key int, item int) map[int][]int

int_ints_map_append appends a new item to a map of slice.

Note: this function creates a new slice in the map if key is not found.

fn lin_space #

fn lin_space(start f64, stop f64, num int) []f64

lin_space returns evenly spaced numbers over a specified closed interval.

fn move_ith_to_end #

fn move_ith_to_end(mut arr []int, i int)

move_ith_to_end removes element at i from the array, and puts it at the end is O(n)(?) because we have to potentially shift all the elements if we remove the first

fn nearly_equal #

fn nearly_equal(a [][]f64, b [][]f64, tol f64) bool

Check if two matrices are approximately equal

fn random_matrix #

fn random_matrix(m int, n int) [][]f64

Generate random matrix (row-major)

fn random_matrix_colmajor #

fn random_matrix_colmajor(m int, n int) []f64

Generate random matrix (column-major, flattened)

fn random_positive_definite #

fn random_positive_definite(n int) []f64

Generate random positive definite matrix (column-major, flattened)

fn random_symmetric #

fn random_symmetric(n int) []f64

Generate random symmetric matrix (column-major, flattened)

fn range #

fn range(start int, stop int, params RangeStep) []int

range returns a list with int values in the interval [start, stop)

fn row_to_col_major #

fn row_to_col_major(a [][]f64) []f64

Convert row-major matrix (V's native format) to column-major (BLAS/LAPACK format)

fn run_benchmark #

fn run_benchmark(config Config, f fn ()) f64

Run benchmark with warmup and iterations

fn str_flts_map_append #

fn str_flts_map_append(o map[string][]f64, key string, item f64) map[string][]f64

str_flts_map_append appends a new item to a map of slice.

Note: this function creates a new slice in the map if key is not found.

fn str_ints_map_append #

fn str_ints_map_append(o map[string][]int, key string, item int) map[string][]int

str_ints_map_append appends a new item to a map of slice.

Note: this function creates a new slice in the map if key is not found.

interface Observer #

interface Observer {
	name() string
mut:
	update()
}

Observer is an interface to objects that need to observe something the data observed by this observer is being update

struct Config #

struct Config {
pub:
	sizes       []int
	iterations  int = 10
	warmup_runs int = 3
}

Benchmark configuration

struct Observable #

struct Observable {
pub mut:
	observers []Observer // list of interested parties
}

Observable indicates that an object is observable; i.e. it has a list of interested observers

fn (Observable) add_observer #

fn (mut o Observable) add_observer(obs Observer)

add_observer adds an object to the list of interested observers

fn (Observable) notify_update #

fn (mut o Observable) notify_update()

notify_update notifies observers of updates

struct RangeStep #

@[params]
struct RangeStep {
pub:
	step int = 1
}