<commit_before>package numgo

import (
	"log"
	"numgo/mat"
	"os"
	"testing"
)

func TestMatI(t *testing.T) {
	var (
		row = 4
	)
	m := mat.I(row)
	for i := 0; i < row; i++ {
		for j := 0; j < row; j++ {
			if i == j {
				if m[i][j] != 1.0 {
					t.Errorf("mat.I[%d,%d] == %f, want 1.0", i, j, m[i][j])
				}
			} else {
				if m[i][j] != 0.0 {
					t.Errorf("mat.I[%d,%d] == %f, want 0.0", i, j, m[i][j])
				}
			}
		}
	}
}

func TestMatOnes(t *testing.T) {
	var (
		row = 12
		col = 7
	)
	o := mat.Ones(row, col)
	for i := 0; i < row; i++ {
		for j := 0; j < col; j++ {
			if o[i][j] != 1.0 {
				t.Errorf("mat.Ones[%d][%d]: expected 1.0, got %f", i, j, o[i][j])
			}
		}
	}
}

func TestMatCol(t *testing.T) {
	var (
		row = 3
		col = 4
	)
	m := mat.Inc(row, col)
	for i := 1; i < col; i++ {
		got := mat.Col(i, m)
		if len(got) != row {
			t.Errorf("mat.Col: got.NumRows == %d, want %d", len(got), row)
		}
		for j := 0; j < row; j++ {
			if got[j] != m[j][i] {
				t.Errorf("At index %v Col(%v, m), got %f, want %f", j, i, got[j], m[j][i-1])
			}
		}
		got = mat.Col(-i, m)
		want := mat.Col(col-i, m)
		for j := 0; j < row; j++ {
			if got[j] != want[j] {
				t.Errorf("At index %v Col(%v, m), got %f, want %f", j, i-col, got[j], want[j])
			}
		}
	}
	a1 := mat.Col(-1, m)
	a2 := mat.Col(3, m)
	for i := 0; i < len(a1); i++ {
		if a1[i] != a2[i] {
			t.Errorf("mat.Col: at index %d, Col(-1, m) is %f, expected %f", i, a1[i], a2[i])
		}
	}
}

func BenchmarkMatCol(b *testing.B) {
	n := mat.Inc(1721, 311)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_ = mat.Col(211, n)
	}
}

func TestMatRow(t *testing.T) {
	var (
		row = 3
		col = 4
	)
	m := mat.Inc(row, col)
	got := mat.Row(2, m)
	want := []float64{8.0, 9.0, 10.0, 11.0}
	for i := 0; i < col; i++ {
		if got[i] != want[i] {
			t.Errorf("Mat.Row at index %d: want %f, got %f", i, want[i], got[i])
		}
	}
	a1 := mat.Row(-1, m)
	a2 := mat.Row(2, m)
	for i := 0; i < len(a1); i++ {
		if a1[i] != a2[i] {
			t.Errorf("mat.Col: at index %d, Col(-1, m) is %f, expected %f", i, a1[i], a2[i])
		}
	}
}

func BenchmarkMatRow(b *testing.B) {
	n := mat.Inc(1721, 311)<commit_msg>More programmatic testing of mat functions<commit_after>package numgo

import (
	"log"
	"numgo/mat"
	"os"
	"testing"
)

func TestMatI(t *testing.T) {
	var (
		row = 4
	)
	m := mat.I(row)
	for i := 0; i < row; i++ {
		for j := 0; j < row; j++ {
			if i == j {
				if m[i][j] != 1.0 {
					t.Errorf("mat.I[%d,%d] == %f, want 1.0", i, j, m[i][j])
				}
			} else {
				if m[i][j] != 0.0 {
					t.Errorf("mat.I[%d,%d] == %f, want 0.0", i, j, m[i][j])
				}
			}
		}
	}
}

func TestMatOnes(t *testing.T) {
	var (
		row = 12
		col = 7
	)
	o := mat.Ones(row, col)
	for i := 0; i < row; i++ {
		for j := 0; j < col; j++ {
			if o[i][j] != 1.0 {
				t.Errorf("mat.Ones[%d][%d]: expected 1.0, got %f", i, j, o[i][j])
			}
		}
	}
}

func TestMatCol(t *testing.T) {
	var (
		row = 3
		col = 4
	)
	m := mat.Inc(row, col)
	for i := 1; i < col; i++ {
		got := mat.Col(i, m)
		if len(got) != row {
			t.Errorf("mat.Col: got.NumRows == %d, want %d", len(got), row)
		}
		for j := 0; j < row; j++ {
			if got[j] != m[j][i] {
				t.Errorf("At index %v Col(%v, m), got %f, want %f", j, i, got[j], m[j][i-1])
			}
		}
		got = mat.Col(-i, m)
		want := mat.Col(col-i, m)
		for j := 0; j < row; j++ {
			if got[j] != want[j] {
				t.Errorf("At index %v Col(%v, m), got %f, want %f", j, i-col, got[j], want[j])
			}
		}
	}
}

func BenchmarkMatCol(b *testing.B) {
	n := mat.Inc(1721, 311)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_ = mat.Col(211, n)
	}
}

func TestMatRow(t *testing.T) {
	var (
		row = 3
		col = 4
	)
	m := mat.Inc(row, col)
	for i := 1; i < row; i++ {
		got := mat.Row(-i, m)
		want := mat.Row(row-i, m)
		for j := 0; j < col; j++ {
			if got[j] != want[j] {
				t.Errorf("At index %v Row(%v, m), got %f, want %f", j, i-col, got[j], want[j])
			}
		}
	}
}

func BenchmarkMatRow(b *testing.B) {
	n := mat.Inc(1721, 311)
{'fraction_non_alphanumeric': 0.2554540842212075, 'fraction_numerical': 0.03297818366311517, 'mean_word_length': 2.2968227424749164, 'pattern_counts': {'":': 0, '<': 24, '<?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': '3171144', 'n_tokens_mistral': 2272, 'n_tokens_neox': 2012, 'n_words': 516}