def flat_membw_read_write(a: Resources, membw_read_write_ratio: Optional[float]) -> Resources: """Return resources with replaced memorybandwidth writes and reads """ """with counted flat value.""" dimensions = a.keys() b = a.copy() if ResourceType.MEMBW_READ in dimensions: assert ResourceType.MEMBW_WRITE in dimensions assert type(membw_read_write_ratio) == float del b[ResourceType.MEMBW_READ] del b[ResourceType.MEMBW_WRITE] b[ResourceType.MEMBW_FLAT] = \ a[ResourceType.MEMBW_READ] + membw_read_write_ratio * a[ResourceType.MEMBW_WRITE] return b
def subtract_resources(a: Resources, b: Resources, membw_read_write_ratio: Optional[float] = None) -> Resources: _check_keys(a, b) dimensions = set(a.keys()) c = a.copy() for dimension in dimensions: if dimension not in ( ResourceType.MEMBW_READ, ResourceType.MEMBW_WRITE) or membw_read_write_ratio is None: c[dimension] = a[dimension] - b[dimension] if ResourceType.MEMBW_READ in dimensions and membw_read_write_ratio is not None: assert ResourceType.MEMBW_WRITE in dimensions assert type(membw_read_write_ratio) == float read, write = ResourceType.MEMBW_READ, ResourceType.MEMBW_WRITE c[read] = a[read] - (b[read] + b[write] * membw_read_write_ratio) c[write] = a[write] - (b[write] + b[read] / membw_read_write_ratio) return c