def calculate_batch(batch_size, length):
	"""
	Calculate the batch size for the data of given length.

	Parameters
	----------
	batch_size : int, float, default=None
		Batch size for training. Must be one of:
		 - int : Use `batch_size`.
		 - float : Use `batch_size * n_samples`.
		 - None : Use `n_samples`.

	length : int
		Length of the data to be batched.

	Returns
	-------
	batch : int
		Actual batch size.
	"""
	if batch_size is None : return length
	elif isinstance(batch_size, int) and batch_size > 0 and \
			batch_size <= length:
		return batch_size
	elif isinstance(batch_size, float) and 0 < batch_size <= 1:
		return int(batch_size * length)
	else:
		raise ValueError("Batch size must be None, an int less than %d," % length,
							"or a float within (0,1]")