imate.Memory.read#

Memory.read(human_readable=False)#

Returns the memory used in the current process.

Note

This method should be called after imate.Memory.start() is called.

Parameters:
human_readablebool, default=False

If False, the output is in Bytes. If True, the output is converted to a human readable unit. The unit can be checked by Memory.mem_unit attribute.

Returns:
mem_tupletuple (int, str)

A tuple consists of the amount of acquired memory together with a string indicating the unit in which the memory is reported. If human_readable is False the unit is 'b' indicating Bytes unit. If human_readable is True, other units may be used as follows:

  • "b": indicates Bytes

  • "KB": indicates Kilo-Bytes

  • "MB": indicates Mega-Bytes

  • "GB": indicates Giga-Bytes

  • "TB": indicates Tera-Bytes

  • "PB": indicates Peta-Bytes

  • "EB": indicates Exa-Bytes

  • "ZB": indicates Zetta-Bytes

  • "YB": indicates Yotta-Bytes

Notes

This method reads the difference between the resident memory from when imate.Memory.start() is called to the point where this method is called. Hence, this method measures the acquired memory in between two points.

In contrast, the function imate.Memory.get_resident_memory() returns the current memory that resides in the hardware.

Examples

>>> # Create an object of Memory class
>>> from imate import Memory
>>> mem = Memory()

>>> # Create a matrix
>>> from imate import toeplitz, logdet
>>> A = toeplitz(2, 1, size=1000, gram=True)

>>> # Start tracking memory change from here
>>> mem.start()

>>> # Compute the log-determinant of the matrix
>>> ld = logdet(A)

>>> # Read acquired memory is acquired from start to this point
>>> mem.read()
(679936, 'b')

>>> # Or, read acquired memory in human-readable format
>>> mem.read(human_readable=True)
(664.0, 'Kb')