File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -927,6 +927,25 @@ def gcd_right(a: "hurwitzint", b: OP_TYPES) -> "hurwitzint":
927927 return a .gcd_right (b )
928928
929929
930- def prod_left (x : Iterator [object ], start : object = 1 ):
930+ def prod_right (x : Iterator [OP_TYPES ], unit : Union [ "hurwitzint" , None ] = None ):
931931 """Simply a helper method to match existing Python prod syntax"""
932- return functools .reduce (operator .mul , x , 1 ) * start
932+ product : hurwitzint = hurwitzint (1 , 0 , 0 , 0 )
933+ for sub_x in x :
934+ product = sub_x * product
935+
936+ if unit is None :
937+ unit = hurwitzint (1 , 0 , 0 , 0 )
938+
939+ return unit * product
940+
941+
942+ def prod_left (x : Iterator [OP_TYPES ], unit : Union ["hurwitzint" , None ] = None ):
943+ """Simply a helper method to match existing Python prod syntax"""
944+ primes : hurwitzint = hurwitzint (1 , 0 , 0 , 0 )
945+ for sub_x in x :
946+ primes *= sub_x
947+
948+ if unit is None :
949+ unit = hurwitzint (1 , 0 , 0 , 0 )
950+
951+ return primes * unit
Original file line number Diff line number Diff line change 1- from math import isqrt , prod
1+ from math import isqrt
22from pathlib import Path
33from typing import Union
44
55from hurwitz import HurwitzQuaternion
66
77import quatint .quat
88
9- from quatint .quat import hurwitzint , prod_left
9+ from quatint .quat import hurwitzint , prod_left , prod_right
1010
1111def test_compiled_tests ():
1212 """Verify that we are running these tests with a compiled version of hurwitzint"""
@@ -344,7 +344,7 @@ def test_main(self):
344344 """Validate factor works as expected."""
345345 factors = self .b_int .factor_right ()
346346
347- ans = prod ( reversed ( factors .primes ), start = factors .unit )
347+ ans = prod_right ( factors .primes , unit = factors .unit )
348348
349349 self .assert_equal (self .b_int , ans )
350350
@@ -356,6 +356,6 @@ def test_main(self):
356356 """Validate factor works as expected."""
357357 factors = self .b_int .factor_left ()
358358
359- ans = prod_left (factors .primes , start = factors .unit )
359+ ans = prod_left (factors .primes , unit = factors .unit )
360360
361361 self .assert_equal (self .b_int , ans )
You can’t perform that action at this time.
0 commit comments