-
Notifications
You must be signed in to change notification settings - Fork 1
/
math_matrix.go
65 lines (50 loc) · 1.18 KB
/
math_matrix.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
54
55
56
57
58
59
60
61
62
63
64
65
// Package bulletproofs
// Copyright 2024 Distributed Lab. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package bulletproofs
import "math/big"
func zeroMatrix(n, m int) [][]*big.Int {
res := make([][]*big.Int, n)
for i := range res {
res[i] = make([]*big.Int, m)
for j := range res[i] {
res[i][j] = bint(0)
}
}
return res
}
func diagInv(x *big.Int, n int) [][]*big.Int {
var res [][]*big.Int = make([][]*big.Int, n)
inv := inv(x)
val := new(big.Int).Set(inv)
for i := 0; i < n; i++ {
res[i] = make([]*big.Int, n)
for j := 0; j < n; j++ {
res[i][j] = bint(0)
if i == j {
res[i][j] = val
val = mul(val, inv)
}
}
}
return res
}
func vectorMulOnMatrix(a []*big.Int, m [][]*big.Int) []*big.Int {
var res []*big.Int
for j := 0; j < len(m[0]); j++ {
var column []*big.Int
for i := 0; i < len(m); i++ {
column = append(column, m[i][j])
}
res = append(res, vectorMul(a, column))
}
return res
}
func matrixMulOnVector(a []*big.Int, m [][]*big.Int) []*big.Int {
var res []*big.Int
for i := 0; i < len(m); i++ {
res = append(res, vectorMul(a, m[i]))
}
return res
}