// Mat4x2FromRows builds a new matrix from row vectors.
// The resulting matrix will still be in column major order, but this can be
// good for hand-building matrices.
193961
func Mat4x2FromRows(row0, row1, row2, row3 Vec2) Mat4x2 {
	return Mat4x2{row0[0], row1[0], row2[0], row3[0], row0[1], row1[1], row2[1], row3[1]}
}
531850
func (m Mat4x2) Rows() (row0, row1, row2, row3 Vec2) {
	return m.Row(0), m.Row(1), m.Row(2), m.Row(3)
}
952604
func (m *Mat4x2) SetRow(row int, v Vec2) {
	m[row+0], m[row+4] = v[0], v[1]
}
1116577
func (m Mat3x2) Abs() Mat3x2 {
	return Mat3x2{Abs(m[0]), Abs(m[1]), Abs(m[2]), Abs(m[3]), Abs(m[4]), Abs(m[5])}
}
688849
func (m Mat4x3) Rows() (row0, row1, row2, row3 Vec3) {
	return m.Row(0), m.Row(1), m.Row(2), m.Row(3)
}
295796
func (m *Matrix) Arrays() [][]float64 {
	rows, cols := m.Size()
	a := make([][]float64, rows)

	for row := 0; row < rows; row++ {
		a[row] = make([]float64, cols)

		for col := 0; col < cols; col++ {
			a[row][col] = m.Get(row, col)
		}
	}
	return a
}
267980
func (m *Mat2) SetRow(row int, v Vec2) {
	m[row+0], m[row+2] = v[0], v[1]
}
16072
func createFromBool(data [][]bool) []*TabulateRow {
	rows := make([]*TabulateRow, len(data))
	for index_1, arr := range data {
		row := make([]string, len(arr))
		for index, el := range arr {
			row[index] = strconv.FormatBool(el)
		}
		rows[index_1] = &TabulateRow{Elements: row}
	}
	return rows
}
255682
func Mat3FromRows(row0, row1, row2 Vec3) Mat3 {
	return Mat3{row0[0], row1[0], row2[0], row0[1], row1[1], row2[1], row0[2], row1[2], row2[2]}
}
798677
func (m1 Mat3x2) Mul2x4(m2 Mat2x4) Mat3x4 {
	return Mat3x4{
		m1[0]*m2[0] + m1[3]*m2[1],
		m1[1]*m2[0] + m1[4]*m2[1],
		m1[2]*m2[0] + m1[5]*m2[1],
		m1[0]*m2[2] + m1[3]*m2[3],
		m1[1]*m2[2] + m1[4]*m2[3],
		m1[2]*m2[2] + m1[5]*m2[3],
		m1[0]*m2[4] + m1[3]*m2[5],
		m1[1]*m2[4] + m1[4]*m2[5],
		m1[2]*m2[4] + m1[5]*m2[5],
		m1[0]*m2[6] + m1[3]*m2[7],
		m1[1]*m2[6] + m1[4]*m2[7],
		m1[2]*m2[6] + m1[5]*m2[7],
	}
}
1154341
func (mat *T) MultMatrix(m *T) *T {
	// iterate over the rows of mat
	for i := range mat {
		row := vec4.T{mat[0][i], mat[1][i], mat[2][i], mat[3][i]}
		mat[0][i] = vec4.Dot4(&row, &m[0])
		mat[1][i] = vec4.Dot4(&row, &m[1])
		mat[2][i] = vec4.Dot4(&row, &m[2])
		mat[3][i] = vec4.Dot4(&row, &m[3])
	}
	return mat
}
724523
func (m Mat3x4) Cols() (col0, col1, col2, col3 Vec3) {
	return m.Col(0), m.Col(1), m.Col(2), m.Col(3)
}
636717
func (m *Matrix) Pivotize() *Matrix {
	pv := make([]int, m.stride)

	for i := range pv {
		pv[i] = i
	}

	for j, dx := 0, 0; j < m.stride; j++ {
		row := j
		max := m.elements[dx]
		for i, ixcj := j, dx; i < m.stride; i++ {
			if m.elements[ixcj] > max {
				max = m.elements[ixcj]
				row = i
			}
			ixcj += m.stride
		}
		if j != row {
			pv[row], pv[j] = pv[j], pv[row]
		}
		dx += m.stride + 1
	}
	p := Zero(m.stride, m.stride)
	for r, c := range pv {
		p.elements[r*m.stride+c] = 1
	}
	return p
}
208012
func (m Mat4x3) Col(col int) Vec4 {
	return Vec4{m[col*4+0], m[col*4+1], m[col*4+2], m[col*4+3]}
}
479535
func (m Mat3x4) Row(row int) Vec4 {
	return Vec4{m[row+0], m[row+3], m[row+6], m[row+9]}
}
880261
func (m1 Mat2x3) Mul3x1(m2 Vec3) Vec2 {
	return Vec2{
		m1[0]*m2[0] + m1[2]*m2[1] + m1[4]*m2[2],
		m1[1]*m2[0] + m1[3]*m2[1] + m1[5]*m2[2],
	}
}
857903
func Mat3x4FromRows(row0, row1, row2 Vec4) Mat3x4 {
	return Mat3x4{row0[0], row1[0], row2[0], row0[1], row1[1], row2[1], row0[2], row1[2], row2[2], row0[3], row1[3], row2[3]}
}