feat(matrix): 添加NewVector构造函数

添加NewVector函数用于创建向量矩阵,接受float64切片并返回
列向量形式的矩阵。

fix(matrix): 修正矩阵乘法错误信息格式

修正矩阵乘法操作中形状不匹配错误信息的格式,确保
错误信息正确显示矩阵的形状。

refactor(matrix): 清理代码格式

移除文件末尾多余的空白行,保持代码格式整洁。
```
This commit is contained in:
程广 2025-12-31 15:34:04 +08:00
parent 2ff4dcfb0f
commit 2072e3fcc8
1 changed files with 5 additions and 2 deletions

View File

@ -84,6 +84,9 @@ func NewOnes(shape []int) (*Matrix, error) {
}
return NewMatrix(data, shape)
}
func NewVector(data []float64) (*Matrix, error) {
return NewMatrix(data, []int{len(data), 1})
}
// NewIdentity 创建一个单位矩阵
// size: 单位矩阵的大小
@ -197,7 +200,7 @@ func (m *Matrix) MatMul(other *Matrix) (*Matrix, error) {
}
if m.shape[1] != other.shape[0] {
return nil, fmt.Errorf("cannot multiply matrices with shapes [%d,%d] and [%d,%d]",
return nil, fmt.Errorf("cannot multiply matrices with shapes [%d,%d] and [%d,%d]",
m.shape[0], m.shape[1], other.shape[0], other.shape[1])
}
@ -323,4 +326,4 @@ func (m *Matrix) hasSameShape(other *Matrix) bool {
}
return true
}
}