-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvector.go
53 lines (44 loc) · 1.07 KB
/
vector.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
45
46
47
48
49
50
51
52
53
package gplot
import (
"gonum.org/v1/gonum/mat"
)
type Vector struct {
*mat.VecDense
}
func Vec(data []float64) Vector {
return newVec(data)
}
func newVec(data []float64) Vector {
vec := mat.NewVecDense(len(data), data)
return Vector{vec}
}
// Gop_Add: func (a vector) + (b vector) vector
func (a Vector) Gop_Add(b Vector) *Vector {
vec := mat.NewVecDense(a.Len(), nil)
vec.AddVec(a, b)
return &Vector{vec}
}
// Gop_Sub: func (a vector) - (b vector) vector
func (a Vector) Gop_Sub(b Vector) *Vector {
vec := mat.NewVecDense(a.Len(), nil)
vec.SubVec(a, b)
return &Vector{vec}
}
// Gop_Mul: func (a vector) * (b vector) vector
func (a Vector) Gop_Mul(b Vector) Vector {
vec := mat.NewVecDense(a.Len(), nil)
vec.MulElemVec(a, b)
return Vector{vec}
}
// Gop_Quo: func (a vector) / (b vector) vector {
func (a Vector) Gop_Quo(b Vector) Vector {
vec := mat.NewVecDense(a.Len(), nil)
vec.DivElemVec(a, b)
return Vector{vec}
}
// Scale a vector
func Scale(a float64, b Vector) Vector {
vec := mat.NewVecDense(b.Len(), nil)
vec.ScaleVec(float64(a), b)
return Vector{vec}
}