glearn.Memory.get_mem#

Memory.get_mem(human_readable=False)#

Reads recorded memory change of the current process.

Note

This method should be called after glearn.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 glearn.Memory.start() is called to the point where glearn.Memory.stop() is called. Hence, this method measures the acquired memory in between these two events in the process.

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

Examples

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

>>> # Create a matrix
>>> from glearn 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)

>>> # Stop tracking memory change from here
>>> mem.stop()

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

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