如何在Golang中创建块矩阵?

I'm trying to create a block matrix which contains 4 blocks (n*n submatrices).

I tried many things but I can't get it to work.

func newBlocMatrix(A Matrix, B Matrix, C Matrix, D Matrix) (M Matrix) {
    var M Matrix
    // Something here

    // Filled with A, B, C, and D

    return M, nil
}

Any suggestions to fill the matrix M with matrices A, B, C and D?

For simplicity I'll assume Matrix is a square (n*n) [][]int:

package main

import "fmt"

type Matrix [][]int

func Block(a, b, c, d Matrix) Matrix {
    l := len(a)
    s := l * 2
    m := make([][]int, s)
    for i := 0; i < s; i++ {
        m[i] = make([]int, s)
    }
    copy(a, m, 0, 0)
    copy(b, m, 0, l)
    copy(c, m, l, 0)
    copy(d, m, l, l)
    return m
}

func copy(a, m Matrix, x, y int) {
    for i := 0; i < len(a); i++ {
        for j := 0; j < len(a[i]); j++ {
            m[i+x][j+y] = a[i][j]
        }
    }
}

func main() {
    a := Matrix{{1, 2}, {3, 4}}
    b := Matrix{{5, 6}, {7, 8}}
    c := Matrix{{9, 10}, {11, 12}}
    d := Matrix{{13, 14}, {15, 16}}
    m := Block(a, b, c, d)
    fmt.Printf("a: %+v
", a)
    fmt.Printf("b: %+v
", b)
    fmt.Printf("c: %+v
", c)
    fmt.Printf("d: %+v
", d)
    fmt.Printf("m: %+v
", m)
}

Running that prints:

a: [[1 2] [3 4]]
b: [[5 6] [7 8]]
c: [[9 10] [11 12]]
d: [[13 14] [15 16]]
m: [[1 2 5 6] [3 4 7 8] [9 10 13 14] [11 12 15 16]]

Which I believe is what you want.