General utils.

zip_safe[source]

zip_safe(*args, **kwargs)

Raises ValueError is len of items are different. Does not work for generators

test_eq(list(zip_safe([1,2],[3,4])), [(1,3),(2,4)])
test_fail(lambda: zip_safe([1,2],[3]))

Torch core

wmean[source]

wmean(w, dim=None)

t = tensor([2., 4.])
w = [.2, .8]
test_close(t.wmean(w), 3.6)
test_close(t.wmean(w, dim=0), 3.6)
test_close(t.to(default_device()).wmean(w), 3.6)
t = tensor([
  [2., 4.],
  [20., 40.],
  [200., 400.],
])
test_close(t.wmean([.2, .8], dim=1), tensor([3.6, 36., 360.]))
test_close(t.wmean([.1, .4, .5], dim=0), tensor([108.2,216.4]))
test_close(t.wmean([.1, .1, .3, .2, .1, .2]), 114.6)

TensorImage

create[source]

create(fn)

tim = TensorImage.create('../examples/styles/abstract.jpg')
tim.show()
<matplotlib.axes._subplots.AxesSubplot at 0x7f75adc08950>