1919from .implementation_postfix import Implementation
2020from .module import Module
2121
22+ _REFERENCE_IMPLEMENTATIONS = {"numpy" , "python" }
23+
2224
2325def read_configs ( # noqa: C901: TODO: move modules into config
2426 benchmarks : set [str ] = None ,
@@ -207,6 +209,7 @@ def read_frameworks(
207209 postfix
208210 for postfix in framework .postfixes
209211 if postfix .postfix in implementations
212+ or postfix .postfix in _REFERENCE_IMPLEMENTATIONS
210213 ]
211214
212215 if len (framework .postfixes ) == 0 :
@@ -215,24 +218,6 @@ def read_frameworks(
215218 config .frameworks .append (framework )
216219
217220
218- def read_implementation_postfixes (
219- config : Config , impl_postfix_file : str
220- ) -> None :
221- """Read and populate implementation postfix configuration file.
222-
223- Args:
224- config: Configuration object where settings should be populated.
225- impl_postfix_file: Path to the configuration file.
226- """
227- with open (impl_postfix_file ) as file :
228- file_contents = file .read ()
229-
230- implementation_postfixes = tomli .loads (file_contents )
231- for impl in implementation_postfixes ["implementations" ]:
232- implementation = Implementation .from_dict (impl )
233- config .implementations .append (implementation )
234-
235-
236221def read_precision_dtypes (config : Config , precision_dtypes_file : str ) -> None :
237222 """Read and populate dtype_obj data types file.
238223
@@ -341,13 +326,15 @@ def read_benchmark_implementations(
341326 ]
342327
343328 setup_init (config , modules )
329+ set_default_reference_implementation_postfix (config , modules )
344330
345331 for module in modules :
346332 module_name , postfix = discover_module_name_and_postfix (module , config )
347333
348334 if (
349335 implementations
350336 and (postfix not in implementations )
337+ and (postfix != config .reference_implementation_postfix )
351338 or (config .init and config .init .module_name .endswith (module_name ))
352339 ):
353340 continue
@@ -382,6 +369,34 @@ def read_benchmark_implementations(
382369 )
383370
384371
372+ def set_default_reference_implementation_postfix (
373+ config : Benchmark ,
374+ modules : set [str ] = None ,
375+ ):
376+ """Sets reference implementation postfix if not set.
377+
378+ It will set it to 'numpy' or 'python' with priority to 'numpy' depending on
379+ the available modules.
380+
381+ Args:
382+ config: Benchmark configuration object where settings should be
383+ populated.
384+ modules: List of modules in benchmark implementation dir.
385+ """
386+ if config .reference_implementation_postfix :
387+ return
388+
389+ postfixes = {
390+ discover_module_name_and_postfix (module , config )[1 ]
391+ for module in modules
392+ }
393+
394+ for postfix in _REFERENCE_IMPLEMENTATIONS :
395+ if postfix in postfixes :
396+ config .reference_implementation_postfix = postfix
397+ break
398+
399+
385400def get_benchmark_index (configs : list [Benchmark ], module_name : str ) -> int :
386401 """Finds configuration index by module name."""
387402 return next (
0 commit comments