Feel the Heat - A 30 Minutes Welcome

Heat is a flexible and seamless open-source software for high performance data analytics and machine learning in Python.

Our main audience are scientists, engineers and AI enthusiats with computational and numerical problems exceeding the boundaries of a laptop or workstation.

Getting Started

Make sure that you have Heat installed on your system. For detailed description of your options, see our full Getting Started section. For now, this should suffice:

pip install heat

DNDarrays

DNDarrays mimick NumPy’s ndarrays interface as close as possible. On top of that they can also be used to accelerate computations with GPUs or MPI in distributed cluster systems. Let’s try it out:

import heat as ht

The following creates a \(3\times 4\) matrix with zeros.

ht.zeros((3,4,))

Output:

DNDarray([[0., 0., 0., 0.],
          [0., 0., 0., 0.],
          [0., 0., 0., 0.]], dtype=ht.float32, device=cpu:0, split=None)

Or a vector with the numbers from \(0-9\) ascending.

ht.arange(10)

Output:

DNDarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=ht.int32, device=cpu:0, split=None)

The following snippet creates a column vector with \(5\) elements, each position filled with the value \(9\) and the ht.int64 data type.

ht.full((1, 5,), fill_value=9, dtype=ht.int64)

Output:

DNDarray([[9, 9, 9, 9, 9]], dtype=ht.int64, device=cpu:0, split=None)

Finally, let’s load some user defined data.

Note

Heat takes care of automatically inferring the shape, i.e. the tensor dimensions, and data types from the user provided input.

ht.array([[0, 1, 2], [0.1, 0.2, 3]])

Output:

DNDarray([[0.0000, 1.0000, 2.0000],
          [0.1000, 0.2000, 3.0000]], dtype=ht.float32, device=cpu:0, split=None)

Operations

Heat supports several mathematical operations, ranging from simple element-wise functions, binary arithmetic operations, and linear algebra, to more powerful reductions. In the following example we add two matrices of same size.

ht.full((3, 4,), fill_value=9) + ht.ones((3, 4,))

Output:

DNDarray([[10., 10., 10., 10.],
          [10., 10., 10., 10.],
          [10., 10., 10., 10.]], dtype=ht.float32, device=cpu:0, split=None)

Instead of operators, we can also use a functional approach.

ht.add(ht.full((3, 4,), fill_value=9), ht.ones((3, 4,)))

Output:

DNDarray([[10., 10., 10., 10.],
          [10., 10., 10., 10.],
          [10., 10., 10., 10.]], dtype=ht.float32, device=cpu:0, split=None)

If there is no obvious operator for a function, you can also call a method on the DNDarray.

ht.arange(5).sin()

Output:

DNDarray([ 0.0000,  0.8415,  0.9093,  0.1411, -0.7568], dtype=ht.float32, device=cpu:0, split=None)

Just like other numerical computation libraries, Heat supports broadcasting. It describes how two DNDarrays with different dimensions (also called shape) can still be combined in arithmetic operations given certain constraints. For example, we can add a scalar to a matrix.

ht.zeros((3, 4,)) + 5.0

Output:

DNDarray([[5., 5., 5., 5.],
          [5., 5., 5., 5.],
          [5., 5., 5., 5.]], dtype=ht.float32, device=cpu:0, split=None)

The scalar has been element-wise repeated for every entry within the matrix. We can do the same with matrices and vectors as well

ht.zeros((3, 4,)) + ht.arange(4)

Output:

DNDarray([[0., 1., 2., 3.],
          [0., 1., 2., 3.],
          [0., 1., 2., 3.]], dtype=ht.float32, device=cpu:0, split=None)

The vector has been repeated for every row of the left-hand side matrix. A full description of broadcasting rules can be found in NumPy’s manual. While talking about it, Heat is designed as seamless drop-in replacement for NumPy. There still might be cases, e.g. working with native Python code, when you want to convert a DNDarray to an ndarray instead.

ht.arange(5).numpy()

Output:

array([0, 1, 2, 3, 4], dtype=int32)

And vice versa:

import numpy as np
ht.array(np.arange(5))

Output:

DNDarray([0, 1, 2, 3, 4], dtype=ht.int64, device=cpu:0, split=None)

See also

Read up more later on hundreds of other functions in our API reference. Or find out about them interactively by using the help() function in your Python interpreter.