// Return the GSL matrix representation of sym. func (sym *SymmetricMatrix) toMatrix() *C.gsl_matrix { // start with a zeroed matrix size := C.size_t(sym.length) matrix := C.gsl_matrix_calloc(size, size) // iterate over sym, setting the corresponding elements in matrix for i, row := range sym.data { for j, val := range row { it, jt := C.size_t(i), C.size_t(j) dval := C.double(val) C.gsl_matrix_set(matrix, it, jt, dval) if i != j { C.gsl_matrix_set(matrix, jt, it, dval) } } } return matrix }
// Convert m to GSL format. func MatrixToGSL(m []vec.Vector, target *C.gsl_matrix) { numFunctions := len(m) dimension := len(m[0]) for i := 0; i < numFunctions; i++ { for j := 0; j < dimension; j++ { it, jt := C.size_t(i), C.size_t(j) C.gsl_matrix_set(target, it, jt, C.double(m[i][j])) } } }
// Convert m to GSL format. func matrixToGSL(m []vec.Vector, target *C.gsl_matrix) { numRows := len(m) numCols := len(m[0]) for i := 0; i < numRows; i++ { for j := 0; j < numCols; j++ { it, jt := C.size_t(i), C.size_t(j) C.gsl_matrix_set(target, it, jt, C.double(m[i][j])) } } }