From 2072e3fcc85ea5ad6158cfce2a7c5da326f5c4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=B9=BF?= Date: Wed, 31 Dec 2025 15:34:04 +0800 Subject: [PATCH] =?UTF-8?q?```=20feat(matrix):=20=E6=B7=BB=E5=8A=A0NewVect?= =?UTF-8?q?or=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加NewVector函数用于创建向量矩阵,接受float64切片并返回 列向量形式的矩阵。 fix(matrix): 修正矩阵乘法错误信息格式 修正矩阵乘法操作中形状不匹配错误信息的格式,确保 错误信息正确显示矩阵的形状。 refactor(matrix): 清理代码格式 移除文件末尾多余的空白行,保持代码格式整洁。 ``` --- matrix.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/matrix.go b/matrix.go index 3c82841..4c28431 100644 --- a/matrix.go +++ b/matrix.go @@ -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 -} \ No newline at end of file +}