-
Notifications
You must be signed in to change notification settings - Fork 4
/
matmul.go
44 lines (40 loc) · 942 Bytes
/
matmul.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package numgo
import "github.com/Kunde21/numgo/internal"
//Matrix and vector multiplication implementations
// - Dot Product
// - Cross Product
// - Tensor Product
// DotProd calculates the dot (scalar) product of two vectors.
// NOTE: Only implemented on 1-D arrays, and other sizes are NOOP
func (a *Array64) DotProd(b *Array64) *Array64 {
switch {
case a.valRith(b, "DotProd"):
return a
case len(a.shape) == 1:
return &Array64{
shape: []int{1},
strides: []int{1, 1},
data: []float64{asm.DotProd(a.data, b.data)},
err: nil,
debug: "",
stack: "",
}
}
return a
}
func (a *Array64) MatProd(b *Array64) *Array64 {
switch {
case a.valRith(b, "MatProd"):
return a
case len(a.shape) == 1 && len(b.shape) == 1:
return &Array64{
shape: []int{1},
strides: []int{1, 1},
data: []float64{asm.DotProd(a.data, b.data)},
err: nil,
debug: "",
stack: "",
}
}
return a
}