HyperGP.tensor.sub

Contents

HyperGP.tensor.sub#

sub(x, y, dim_0=0, dim_1=0)[source]#

Elementwise subtraction: \(x - y\).

Parameters:
  • x (Tensor or array_like) – The arrays to perform subtraction. If x1.shape != x2.shape and x1.shape != 0 and x2.shape != 0, then dim_0 or dim_1 should be set to do broadcast operation.

  • y (Tensor or array_like) – The arrays to perform subtraction. If x1.shape != x2.shape and x1.shape != 0 and x2.shape != 0, then dim_0 or dim_1 should be set to do broadcast operation.

  • dim_0 – The dim of x to do broadcast. x.shape[dim_0:] should be equal to y.shape[dim_1:]

  • dim_1 – The dim of y to do broadcast. x.shape[dim_0:] should be equal to y.shape[dim_1:]

Returns:

a new ‘Tensor’ is returned

Examples

import modules

>>> import numpy as np
>>> from HyperGP import Tensor
>>> import time

array initialization

>>> x1 = np.random.uniform(-1, 1, size=(500, 100000))
>>> x2 = np.random.uniform(-1, 1, size=(500, 100000))
>>> x1_t, x2_t = Tensor(x1), Tensor(x2)

runtime test

>>> st = time.time()
>>> ar = [x1 - x2 for i in range(10)]
>>> print("numpy runtime: ", time.time() - st)
>>> st = time.time()
>>> ar = [x1_t - x2_t for i in range(10)]
>>> print("HyperGP runtime: ", time.time() - st)

broadcast operation

>>> ar = [x1 - x2 for i in range(10)]
>>> ar = [HyperGP.sub(x1_t, x2_t, dim_0=1, dim_1=1) for i in range(10)]
>>> for x in ar:
...     x.wait()