VectorAdd 两个向量对应元素相加 对应 Python: a + b (用于叠加噪声)
(a, b []float32)
| 16 | // VectorAdd 两个向量对应元素相加 |
| 17 | // 对应 Python: a + b (用于叠加噪声) |
| 18 | func VectorAdd(a, b []float32) []float32 { |
| 19 | if len(a) != len(b) { |
| 20 | panic("VectorAdd: vectors must have the same length") |
| 21 | } |
| 22 | |
| 23 | result := make([]float32, len(a)) |
| 24 | for i := 0; i < len(a); i++ { |
| 25 | result[i] = a[i] + b[i] |
| 26 | } |
| 27 | return result |
| 28 | } |
| 29 | |
| 30 | // VectorSub 两个向量对应元素相减 |
| 31 | // 对应 Python: a - b (用于计算差异向量) |
no outgoing calls
no test coverage detected