<commit_before>// Package matrix provides basic matrix operations.
package matrix

import (
	"fmt"

	"github.com/ready-steady/lapack"
)

// Identity constructs an m-by-m identity matrix.
func Identity(m uint) []float64 {
	a := make([]float64, m*m)
	for i := uint(0); i < m; i++ {
		a[i*m+i] = 1
	}
	return a
}

// Invert computes the inverse of an m-by-m matrix.
func Invert(a []float64, m uint) error {
	ipiv := make([]int, m+1)
	info := 0

	lapack.DGETRF(int(m), int(m), a, int(m), ipiv, &info)
	if info != 0 {
		return fmt.Errorf("LAPACK failed with code %v", info)
	}

	lwork := m * m
	work := make([]float64, lwork)

	lapack.DGETRI(int(m), a, int(m), ipiv, work, int(lwork), &info)
	if info != 0 {
		return fmt.Errorf("LAPACK failed with code %v", info)
	}

	return nil
}
<commit_msg>matrix: implement the dot product<commit_after>// Package matrix provides basic matrix operations.
package matrix

import (
	"fmt"

	"github.com/ready-steady/lapack"
)

// Dot computes the dot product of two m-element vectors.
func Dot(a, b []float64, m uint) float64 {
	return lapack.DDOT(int(m), a, 1, b, 1)
}

// Identity constructs an m-by-m identity matrix.
func Identity(m uint) []float64 {
	a := make([]float64, m*m)
	for i := uint(0); i < m; i++ {
		a[i*m+i] = 1
	}
	return a
}

// Invert computes the inverse of an m-by-m matrix.
func Invert(a []float64, m uint) error {
	ipiv := make([]int, m+1)
	info := 0

	lapack.DGETRF(int(m), int(m), a, int(m), ipiv, &info)
	if info != 0 {
		return fmt.Errorf("LAPACK failed with code %v", info)
	}

	lwork := m * m
	work := make([]float64, lwork)

	lapack.DGETRI(int(m), a, int(m), ipiv, work, int(lwork), &info)
	if info != 0 {
		return fmt.Errorf("LAPACK failed with code %v", info)
	}

	return nil
}

{'fraction_non_alphanumeric': 0.1687715269804822, 'fraction_numerical': 0.01951779563719862, 'mean_word_length': 3.574803149606299, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '176634', 'n_tokens_mistral': 736, 'n_tokens_neox': 688, 'n_words': 216}