@@ -24,9 +24,11 @@ impl From<MainElementType> for DataType {
24
24
}
25
25
}
26
26
27
+ /// Calculate inner products of with weights.
28
+ ///
27
29
/// Calculate inner product of both main columns and auxiliary columns with weights. Returns one
28
- /// scalar in the form of an extension -field element. Main column can be either a base field
29
- /// element, or an extension -field element.
30
+ /// scalar in the form of an auxiliary -field element. Main column can be either a base field
31
+ /// element, or an auxiliary -field element.
30
32
pub struct InnerProductOfThreeRowsWithWeights {
31
33
main_length : usize ,
32
34
main_element_type : MainElementType ,
@@ -36,24 +38,24 @@ pub struct InnerProductOfThreeRowsWithWeights {
36
38
37
39
impl InnerProductOfThreeRowsWithWeights {
38
40
pub fn new (
39
- base_length : usize ,
40
- base_element_type : MainElementType ,
41
- ext_length : usize ,
41
+ main_length : usize ,
42
+ main_element_type : MainElementType ,
43
+ aux_length : usize ,
42
44
randomizer_length : usize ,
43
45
) -> Self {
44
46
Self {
45
- main_length : base_length ,
46
- main_element_type : base_element_type ,
47
- aux_length : ext_length ,
47
+ main_length,
48
+ main_element_type,
49
+ aux_length,
48
50
randomizer_length,
49
51
}
50
52
}
51
53
52
- pub fn triton_vm_parameters ( base_element_type : MainElementType ) -> Self {
54
+ pub fn triton_vm_parameters ( main_element_type : MainElementType ) -> Self {
53
55
Self {
54
56
main_length : MasterMainTable :: NUM_COLUMNS ,
55
57
aux_length : MasterAuxTable :: NUM_COLUMNS ,
56
- main_element_type : base_element_type ,
58
+ main_element_type,
57
59
// TODO: Use NUM_RANDOMIZERS from TVM here instead, once randomizers
58
60
// are handled correctly in TVM.
59
61
randomizer_length : 0 ,
@@ -69,14 +71,14 @@ impl BasicSnippet for InnerProductOfThreeRowsWithWeights {
69
71
element_type: DataType :: Xfe ,
70
72
length: self . aux_length,
71
73
} ) ) ,
72
- "*ext_row " . to_string( ) ,
74
+ "*aux_row " . to_string( ) ,
73
75
) ,
74
76
(
75
77
DataType :: Array ( Box :: new( ArrayType {
76
78
element_type: self . main_element_type. into( ) ,
77
79
length: self . main_length,
78
80
} ) ) ,
79
- "*base_row " . to_string( ) ,
81
+ "*main_row " . to_string( ) ,
80
82
) ,
81
83
(
82
84
DataType :: Array ( Box :: new( ArrayType {
@@ -94,7 +96,7 @@ impl BasicSnippet for InnerProductOfThreeRowsWithWeights {
94
96
95
97
fn entrypoint ( & self ) -> String {
96
98
format ! (
97
- "tasmlib_array_inner_product_of_three_rows_with_weights_{}_baserowelem " ,
99
+ "tasmlib_array_inner_product_of_three_rows_with_weights_{}_mainrowelem " ,
98
100
self . main_element_type
99
101
)
100
102
}
@@ -104,35 +106,35 @@ impl BasicSnippet for InnerProductOfThreeRowsWithWeights {
104
106
_library : & mut crate :: library:: Library ,
105
107
) -> Vec < triton_vm:: prelude:: LabelledInstruction > {
106
108
let entrypoint = self . entrypoint ( ) ;
107
- let acc_all_base_rows = match self . main_element_type {
109
+ let acc_all_main_rows = match self . main_element_type {
108
110
MainElementType :: Bfe => triton_asm ! [ xb_dot_step; self . main_length] ,
109
111
MainElementType :: Xfe => triton_asm ! [ xx_dot_step; self . main_length] ,
110
112
} ;
111
- let acc_all_ext_rows = triton_asm ! [ xx_dot_step; self . aux_length - self . randomizer_length] ;
113
+ let acc_all_aux_rows = triton_asm ! [ xx_dot_step; self . aux_length - self . randomizer_length] ;
112
114
113
115
triton_asm ! {
114
- // BEFORE: _ *ext_row *base_row *weights
116
+ // BEFORE: _ *aux_row *main_row *weights
115
117
// AFTER: _ [inner_product]
116
118
{ entrypoint} :
117
119
118
120
119
121
push 0
120
122
push 0
121
123
push 0
122
- // _ *ext_row *base_row *weights 0 0 0
124
+ // _ *aux_row *main_row *weights 0 0 0
123
125
124
126
swap 3
125
127
swap 1
126
128
swap 4
127
- // _ *ext_row 0 0 0 *weights *base_row
129
+ // _ *aux_row 0 0 0 *weights *main_row
128
130
129
- { & acc_all_base_rows }
130
- // _ *ext_row acc2 acc1 acc0 *weights_next *garbage0
131
+ { & acc_all_main_rows }
132
+ // _ *aux_row acc2 acc1 acc0 *weights_next *garbage0
131
133
132
134
swap 5
133
- // _ *garbage0 acc2 acc1 acc0 *weights_next *ext_row
135
+ // _ *garbage0 acc2 acc1 acc0 *weights_next *aux_row
134
136
135
- { & acc_all_ext_rows }
137
+ { & acc_all_aux_rows }
136
138
// _ *garbage0 acc2 acc1 acc0 *garbage1 garbage2
137
139
// _ *garbage0 result2 result1 result0 *garbage1 garbage2 <-- rename
138
140
@@ -170,23 +172,23 @@ mod test {
170
172
use super :: * ;
171
173
172
174
#[ test]
173
- fn three_rows_tvm_parameters_xfe_base_test ( ) {
175
+ fn three_rows_tvm_parameters_xfe_main_test ( ) {
174
176
ShadowedFunction :: new ( InnerProductOfThreeRowsWithWeights :: triton_vm_parameters (
175
177
MainElementType :: Xfe ,
176
178
) )
177
179
. test ( )
178
180
}
179
181
180
182
#[ test]
181
- fn three_rows_tvm_parameters_bfe_base_test ( ) {
183
+ fn three_rows_tvm_parameters_bfe_main_test ( ) {
182
184
ShadowedFunction :: new ( InnerProductOfThreeRowsWithWeights :: triton_vm_parameters (
183
185
MainElementType :: Bfe ,
184
186
) )
185
187
. test ( )
186
188
}
187
189
188
190
#[ test]
189
- fn works_with_base_or_ext_column_count_of_zero ( ) {
191
+ fn works_with_main_or_aux_column_count_of_zero ( ) {
190
192
let num_main_columns_is_zero_bfe = InnerProductOfThreeRowsWithWeights {
191
193
main_length : 0 ,
192
194
main_element_type : MainElementType :: Bfe ,
@@ -223,17 +225,17 @@ mod test {
223
225
224
226
#[ proptest( cases = 6 ) ]
225
227
fn three_rows_pbt_pbt (
226
- #[ strategy( arb( ) ) ] base_element_type : MainElementType ,
227
- #[ strategy( 0_usize ..500 ) ] base_length : usize ,
228
- #[ strategy( 0_usize ..500 ) ] ext_length : usize ,
229
- #[ filter( #randomizer_length<#ext_length ) ]
228
+ #[ strategy( arb( ) ) ] main_element_type : MainElementType ,
229
+ #[ strategy( 0_usize ..500 ) ] main_length : usize ,
230
+ #[ strategy( 0_usize ..500 ) ] aux_length : usize ,
231
+ #[ filter( #randomizer_length<#aux_length ) ]
230
232
#[ strategy( 0_usize ..10 ) ]
231
233
randomizer_length : usize ,
232
234
) {
233
235
let snippet = InnerProductOfThreeRowsWithWeights {
234
- main_length : base_length ,
235
- main_element_type : base_element_type ,
236
- aux_length : ext_length ,
236
+ main_length,
237
+ main_element_type,
238
+ aux_length,
237
239
randomizer_length,
238
240
} ;
239
241
ShadowedFunction :: new ( snippet) . test ( )
@@ -247,41 +249,41 @@ mod test {
247
249
) {
248
250
// read stack: _ *e *b *w
249
251
let weights_address = stack. pop ( ) . unwrap ( ) ;
250
- let base_row_address = stack. pop ( ) . unwrap ( ) ;
251
- let extension_row_address = stack. pop ( ) . unwrap ( ) ;
252
+ let main_row_address = stack. pop ( ) . unwrap ( ) ;
253
+ let auxiliary_row_address = stack. pop ( ) . unwrap ( ) ;
252
254
253
255
// read arrays
254
256
let weights_len = self . main_length + self . aux_length - self . randomizer_length ;
255
257
let weights: Vec < XFieldElement > =
256
258
array_from_memory ( weights_address, weights_len, memory) ;
257
- let ext_row : Vec < XFieldElement > = array_from_memory (
258
- extension_row_address ,
259
+ let aux_row : Vec < XFieldElement > = array_from_memory (
260
+ auxiliary_row_address ,
259
261
self . aux_length - self . randomizer_length ,
260
262
memory,
261
263
) ;
262
264
263
265
let ip = match self . main_element_type {
264
266
MainElementType :: Bfe => {
265
- let base_row : Vec < BFieldElement > =
266
- array_from_memory ( base_row_address , self . main_length , memory) ;
267
+ let main_row : Vec < BFieldElement > =
268
+ array_from_memory ( main_row_address , self . main_length , memory) ;
267
269
268
270
// compute inner product
269
- base_row
271
+ main_row
270
272
. iter ( )
271
273
. map ( |b| b. lift ( ) )
272
- . chain ( ext_row )
274
+ . chain ( aux_row )
273
275
. zip_eq ( weights)
274
276
. map ( |( l, r) | l * r)
275
277
. sum :: < XFieldElement > ( )
276
278
}
277
279
MainElementType :: Xfe => {
278
- let base_row : Vec < XFieldElement > =
279
- array_from_memory ( base_row_address , self . main_length , memory) ;
280
+ let main_row : Vec < XFieldElement > =
281
+ array_from_memory ( main_row_address , self . main_length , memory) ;
280
282
281
283
// compute inner product
282
- base_row
284
+ main_row
283
285
. into_iter ( )
284
- . chain ( ext_row )
286
+ . chain ( aux_row )
285
287
. zip_eq ( weights)
286
288
. map ( |( l, r) | l * r)
287
289
. sum :: < XFieldElement > ( )
@@ -301,21 +303,21 @@ mod test {
301
303
_bench_case : Option < BenchmarkCase > ,
302
304
) -> FunctionInitialState {
303
305
let mut rng: StdRng = SeedableRng :: from_seed ( seed) ;
304
- let base_address = rng. gen ( ) ;
305
- let ext_address = rng. gen ( ) ;
306
+ let main_address = rng. gen ( ) ;
307
+ let aux_address = rng. gen ( ) ;
306
308
let weights_address = rng. gen ( ) ;
307
309
308
310
let mut memory: HashMap < BFieldElement , BFieldElement > = HashMap :: default ( ) ;
309
311
310
312
match self . main_element_type {
311
313
MainElementType :: Bfe => {
312
- insert_random_array ( & DataType :: Bfe , base_address , self . main_length , & mut memory)
314
+ insert_random_array ( & DataType :: Bfe , main_address , self . main_length , & mut memory)
313
315
}
314
316
MainElementType :: Xfe => {
315
- insert_random_array ( & DataType :: Xfe , base_address , self . main_length , & mut memory)
317
+ insert_random_array ( & DataType :: Xfe , main_address , self . main_length , & mut memory)
316
318
}
317
319
}
318
- insert_random_array ( & DataType :: Xfe , ext_address , self . aux_length , & mut memory) ;
320
+ insert_random_array ( & DataType :: Xfe , aux_address , self . aux_length , & mut memory) ;
319
321
insert_random_array (
320
322
& DataType :: Xfe ,
321
323
weights_address,
@@ -325,7 +327,7 @@ mod test {
325
327
326
328
let stack = [
327
329
self . init_stack_for_isolated_run ( ) ,
328
- vec ! [ ext_address , base_address , weights_address] ,
330
+ vec ! [ aux_address , main_address , weights_address] ,
329
331
]
330
332
. concat ( ) ;
331
333
@@ -344,7 +346,7 @@ mod benches {
344
346
use super :: * ;
345
347
346
348
#[ test]
347
- fn inner_product_of_three_rows_bench_current_tvm_base_is_bfe ( ) {
349
+ fn inner_product_of_three_rows_bench_current_tvm_main_is_bfe ( ) {
348
350
// This benchmark is for the calculation of the (inside-of-domain) current row element that
349
351
// takes place inside the main-loop where all revealed FRI values are verified.
350
352
ShadowedFunction :: new ( InnerProductOfThreeRowsWithWeights {
@@ -357,7 +359,7 @@ mod benches {
357
359
}
358
360
359
361
#[ test]
360
- fn inner_product_of_three_rows_bench_current_tvm_base_is_xfe ( ) {
362
+ fn inner_product_of_three_rows_bench_current_tvm_main_is_xfe ( ) {
361
363
// This benchmark is for the calculation of the out-of-domain current and next row values.
362
364
ShadowedFunction :: new ( InnerProductOfThreeRowsWithWeights {
363
365
main_length : MasterMainTable :: NUM_COLUMNS ,
0 commit comments