<commit_before>package mathgl

import (
	"errors"
)

type Matrix struct {
	m,n int // an m x n matrix
	typ VecType
	dat []VecNum
}

func NewMatrix(m,n int, typ VecType) *Matrix {
	return &Matrix{m:m, n:n, typ: typ, dat: make([]VecNum,0,2) }
}

// [1, 1]
// [0, 1] Would be entered as a 2D array [[1,1],[0,1]] -- but converted to RMO
// 
// This may seem confusing, but it's because it's easier to type out and visualize things in CMO
// So it's easier to type write your matrix as a slice in CMO, and pass it into this method
func MatrixOf(typ VecType, el [][]VecNum) (mat *Matrix, err error) {
	mat.typ = typ
	
	mat.m = len(el)
	mat.n = len(el[0])
	mat.dat = make([]VecNum, 0, mat.m * mat.n)
	
	// Row Major Order, like in OpenGL
	for i := 0; i < mat.n; i++ {
		for j := 0; j < mat.m; j++ {
			if !checkType(mat.typ, el[j][i]) {
				return nil, errors.New("Element type does not match matrix")
			}
			mat.dat = append(mat.dat, el[j][i])
		}
	}
	
	return mat, nil
}

// Slice-format data should be in Row Major Order
func MatrixFromSlice(typ VecType, el []VecNum, m,n int) (mat *Matrix, err error) {
	mat.typ = typ
	mat.m = m
	mat.n = n
	
	if mat.m * mat.n != len(el) {
		return nil, errors.New("Matrix dimensions do not match data passed in")
	}<commit_msg>Added support for building a matrix out of row vectors<commit_after>package mathgl

import (
	"errors"
)

type Matrix struct {
	m,n int // an m x n matrix
	typ VecType
	dat []VecNum
}

func NewMatrix(m,n int, typ VecType) *Matrix {
	return &Matrix{m:m, n:n, typ: typ, dat: make([]VecNum,0,2) }
}

// [1, 1]
// [0, 1] Would be entered as a 2D array [[1,1],[0,1]] -- but converted to RMO
// 
// This may seem confusing, but it's because it's easier to type out and visualize things in CMO
// So it's easier to type write your matrix as a slice in CMO, and pass it into this method
func MatrixFromCols(typ VecType, el [][]VecNum) (mat *Matrix, err error) {
	mat.typ = typ
	
	mat.m = len(el)
	mat.n = len(el[0])
	mat.dat = make([]VecNum, 0, mat.m * mat.n)
	
	// Row Major Order, like in OpenGL
	for i := 0; i < mat.n; i++ {
		for j := 0; j < mat.m; j++ {
			if !checkType(mat.typ, el[j][i]) {
				return nil, errors.New("Element type does not match matrix")
			}
			mat.dat = append(mat.dat, el[j][i])
		}
	}
	
	return mat, nil
}

// This function is MatrixOf, except it takes a list of row "vectors" instead of row "vectors" (really slices)
func MatrixFromRows(typ VecType, el [][]VecNum) (mat *Matrix, err error) {
	mat.typ = typ
	
	mat.m = len(el)
	mat.n = len(el[0])
	mat.dat = make([]VecNum, 0, mat.m * mat.n)
	
	// Row Major Order, like in OpenGL
	for i := 0; i < mat.m; i++ {
		for j := 0; j < mat.n; j++ {
			if !checkType(mat.typ, el[j][i]) {
				return nil, errors.New("Element type does not match matrix")
			}
			mat.dat = append(mat.dat, el[j][i])
		}
	}
	
	return mat, nil
}

// Slice-format data should be in Row Major Order
func MatrixFromSlice(typ VecType, el []VecNum, m,n int) (mat *Matrix, err error) {
	mat.typ = typ
	mat.m = m
	mat.n = n
	
	if mat.m * mat.n != len(el) {
		return nil, errors.New("Matrix dimensions do not match data passed in")
	}
{'fraction_non_alphanumeric': 0.15364916773367476, 'fraction_numerical': 0.01088348271446863, 'mean_word_length': 3.0956749672346002, 'pattern_counts': {'":': 0, '<': 9, '<?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': '6141861', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1182, 'n_words': 436}