Commits

Fazlul Shahriar committed 3f49625

add more methods on Matrix

R=fhs
CC=fhs
http://codereview.appspot.com/3298043

Comments (0)

Files changed (1)

 	return v
 }
 
+func (m *Matrix) GetCol(j int) *Vector {
+	if 0 > j || j > m.Size2 {
+		return nil
+	}
+	v := NewVector(m.Size1)
+	C.gsl_matrix_get_row(v.toGSL(), m.toGSL(), C.size_t(j))
+	return v
+}
+
+func (m *Matrix) SetRow(i int, v *Vector) {
+	C.gsl_matrix_set_row(m.toGSL(), C.size_t(i), v.toGSL())
+}
+
+func (m *Matrix) SetCol(j int, v *Vector) {
+	C.gsl_matrix_set_col(m.toGSL(), C.size_t(j), v.toGSL())
+}
+
 // Matrix operations
 
 func (m *Matrix) Add(n *Matrix) {
 	C.gsl_matrix_add_constant(m.toGSL(), C.double(x))
 }
 
+// Finding maximum and minimum elements of matrices
+
+func (m *Matrix) Max() float64 {
+	return float64(C.gsl_matrix_max(m.toGSL()))
+}
+
+func (m *Matrix) Min() float64 {
+	return float64(C.gsl_matrix_min(m.toGSL()))
+}
+
+func (m *Matrix) Minmax() (min, max float64) {
+	C.gsl_matrix_minmax(m.toGSL(),
+		(*C.double)(unsafe.Pointer(&min)),
+		(*C.double)(unsafe.Pointer(&max)))
+	return
+}
+
+func (m *Matrix) MaxIndex() (imax, jmax int) {
+	var i, j C.size_t
+	C.gsl_matrix_max_index(m.toGSL(), &i, &j)
+	imax = int(i)
+	jmax = int(j)
+	return
+}
+
+func (m *Matrix) MinIndex() (imin, jmin int) {
+	var i, j C.size_t
+	C.gsl_matrix_min_index(m.toGSL(), &i, &j)
+	imin = int(i)
+	jmin = int(j)
+	return
+}
+
+func (m *Matrix) MinmaxIndex() (imin, jmin, imax, jmax int) {
+	var is, js, ib, jb C.size_t
+	C.gsl_matrix_minmax_index(m.toGSL(), &is, &js, &ib, &jb)
+	imin, jmin = int(is), int(js)
+	imax, jmax = int(ib), int(jb)
+	return
+}
+
+
 // Matrix properties
 
 func (m *Matrix) Isnull() bool {