<commit_before>"""
Tools for algorithm engineering.
"""
# extension imports
from _NetworKit import setNumberOfThreads, getMaxNumberOfThreads, getCurrentNumberOfThreads

# local imports
from . import stopwatch

# external imports
import csv

def strongScaling(algorithmClass, threadSequence, inargs, inputTitle=None, repetitions=1, outPath=None):
	""" Evaluate strong scaling, i.e. how the performance varies with the number of threads
		for a fixed input size.
	"""
	algorithm = algorithmClass(*inargs)
	data = []	# collects data about the experiments
	threadsAvailable = getMaxNumberOfThreads()	# remember maximum number of threads and restore later
	for nThreads in threadSequence:
		setNumberOfThreads(nThreads)
		print("set number of threads to {0}".format(getMaxNumberOfThreads()))
		for r in range(repetitions):
			print("running {0}".format(algorithm.toString()))
			timer = stopwatch.Timer()
			result = algorithm.run()
			timer.stop()
			print("elapsed time: {0}".format(timer.elapsed))
			if inputTitle is None:
				try:
					inputTitle = input.toString()
				except:
					inputTitle = str(input)
			# append run data
			data.append({"algo": algorithm.toString(), "input": inputTitle, "threads": nThreads, "time": timer.elapsed})
	setNumberOfThreads(threadsAvailable)
	if outPath:
		with open(outPath, "w") as outFile:
			columns = ["algo", "input", "threads", "time"]
			writer = csv.DictWriter(outFile, fieldnames=columns)
			writer.writeheader()
			for row in data:
				writer.writerow(row)
	return data

def weakScaling(algorithm, threadSequence, inputSequence, inputTitles=None, repetitions=1, outPath=None):<commit_msg>engineering.strongScaling uses kwargs<commit_after>"""
Tools for algorithm engineering.
"""
# extension imports
from _NetworKit import setNumberOfThreads, getMaxNumberOfThreads, getCurrentNumberOfThreads

# local imports
from . import stopwatch

# external imports
import csv

def strongScaling(algorithmClass, threadSequence, inargs, inputTitle=None, repetitions=1, outPath=None):
	""" Evaluate strong scaling, i.e. how the performance varies with the number of threads
		for a fixed input size.
	"""
	algorithm = algorithmClass(**inargs)
	data = []	# collects data about the experiments
	threadsAvailable = getMaxNumberOfThreads()	# remember maximum number of threads and restore later
	for nThreads in threadSequence:
		setNumberOfThreads(nThreads)
		print("set number of threads to {0}".format(getMaxNumberOfThreads()))
		for r in range(repetitions):
			print("running {0}".format(algorithm.toString()))
			timer = stopwatch.Timer()
			result = algorithm.run()
			timer.stop()
			print("elapsed time: {0}".format(timer.elapsed))
			if inputTitle is None:
				try:
					inputTitle = input.toString()
				except:
					inputTitle = str(input)
			# append run data
			data.append({"algo": algorithm.toString(), "input": inputTitle, "threads": nThreads, "time": timer.elapsed})
	setNumberOfThreads(threadsAvailable)
	if outPath:
		with open(outPath, "w") as outFile:
			columns = ["algo", "input", "threads", "time"]
			writer = csv.DictWriter(outFile, fieldnames=columns)
			writer.writeheader()
			for row in data:
				writer.writerow(row)
	return data

def weakScaling(algorithm, threadSequence, inputSequence, inputTitles=None, repetitions=1, outPath=None):
{'fraction_non_alphanumeric': 0.1110773899848255, 'fraction_numerical': 0.0030349013657056147, 'mean_word_length': 5.242424242424242, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2193424', 'n_tokens_mistral': 1077, 'n_tokens_neox': 973, 'n_words': 285}