-
Notifications
You must be signed in to change notification settings - Fork 210
feat: add vector operation on koalabear extension #679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import ( | ||
fr "{{ .FieldPackagePath }}" | ||
"github.com/consensys/gnark-crypto/utils/cpu" | ||
) | ||
|
||
// Vector represents a vector of E4 elements | ||
type Vector []E4 | ||
|
||
func (vector *Vector) Add(a, b Vector) { | ||
if len(a) != len(b) || len(a) != len(*vector) { | ||
panic("vector.Add: vectors don't have the same length") | ||
} | ||
|
||
for i := range a { | ||
(*vector)[i].Add(&a[i], &b[i]) | ||
} | ||
} | ||
|
||
func (vector *Vector) AddMixed(a Vector, b fr.Vector) { | ||
if len(a) != len(b) || len(a) != len(*vector) { | ||
panic("vector.AddMixed: vectors don't have the same length") | ||
} | ||
for i := range a { | ||
(*vector)[i].Set(&a[i]) | ||
(*vector)[i].B0.A0.Add(&(*vector)[i].B0.A0, &b[i]) | ||
} | ||
} | ||
|
||
func (vector *Vector) ScalarMul(a Vector, b *E4) { | ||
if len(a) != len(*vector) { | ||
panic("vector.ScalarMul: vectors don't have the same length") | ||
} | ||
|
||
for i := range a { | ||
(*vector)[i].Mul(&a[i], b) | ||
} | ||
} | ||
|
||
func (vector *Vector) Sub(a, b Vector) { | ||
if len(a) != len(b) || len(a) != len(*vector) { | ||
panic("vector.Sub: vectors don't have the same length") | ||
} | ||
|
||
for i := range a { | ||
(*vector)[i].Sub(&a[i], &b[i]) | ||
} | ||
} | ||
|
||
func (vector *Vector) SubMixed(a Vector, b fr.Vector) { | ||
if len(a) != len(b) || len(a) != len(*vector) { | ||
panic("vector.SubMixed: vectors don't have the same length") | ||
} | ||
for i := range a { | ||
(*vector)[i].Set(&a[i]) | ||
(*vector)[i].B0.A0.Sub(&(*vector)[i].B0.A0, &b[i]) | ||
} | ||
} | ||
|
||
func (vector *Vector) Mul(a, b Vector) { | ||
if len(a) != len(b) || len(a) != len(*vector) { | ||
panic("vector.Mul: vectors don't have the same length") | ||
} | ||
|
||
for i := range a { | ||
(*vector)[i].Mul(&a[i], &b[i]) | ||
} | ||
} | ||
|
||
func (vector *Vector) MulMixed(a Vector, b fr.Vector) { | ||
if len(a) != len(b) || len(a) != len(*vector) { | ||
panic("vector.MulMixed: vectors don't have the same length") | ||
} | ||
for i := range a { | ||
(*vector)[i].Set(&a[i]) | ||
(*vector)[i].MulByElement(&(*vector)[i], &b[i]) | ||
} | ||
} | ||
|
||
func (vector *Vector) MulAcc(scale []fr.Element, alpha *E4) { | ||
N := len(*vector) | ||
if N != len(scale) { | ||
panic("MulAccE4: len(res) != len(scale)") | ||
} | ||
if !cpu.SupportAVX512 || N%4 != 0 { | ||
var tmp E4 | ||
for i := 0; i < N; i++ { | ||
tmp.MulByElement(alpha, &scale[i]) | ||
(*vector)[i].Add(&(*vector)[i], &tmp) | ||
} | ||
return | ||
} | ||
|
||
mulAccE4_avx512(alpha, &scale[0], &(*vector)[0], uint64(N)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that mean that we hard-cast vectors of base-field elements into vectors of extension field elements?