Skip to content

Commit

Permalink
Update Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
itsubaki committed Oct 14, 2023
1 parent 625470e commit a7e175d
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions matrix/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,12 @@ func BroadcastTo(shape []int, m Matrix) Matrix {
a, b := shape[0], shape[1]

if len(m) == 1 && len(m[0]) == 1 {
out := Zero(a, b)
for i := 0; i < a; i++ {
for j := 0; j < b; j++ {
out[i][j] = m[0][0]
}
out := make([]float64, a*b)
for i := 0; i < a*b; i++ {
out[i] = m[0][0]
}

return out
return Reshape(shape, New(out))
}

if len(m) == 1 {
Expand Down Expand Up @@ -340,10 +338,9 @@ func Reshape(shape []int, m Matrix) Matrix {
b = p * q / a
}

out := New()
out := make(Matrix, a)
for i := 0; i < a; i++ {
begin, end := i*b, (i+1)*b
out = append(out, v[begin:end])
out[i] = v[i*b : (i+1)*b]
}

return out
Expand Down

0 comments on commit a7e175d

Please sign in to comment.