Caffe2 - Python API
A deep learning, cross platform ML framework
test_pytorch_common.py
1 from __future__ import absolute_import
2 from __future__ import division
3 from __future__ import print_function
4 from __future__ import unicode_literals
5 
6 import functools
7 import os
8 import unittest
9 import sys
10 import torch
11 import torch.autograd.function as function
12 
13 pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
14 sys.path.insert(-1, pytorch_test_dir)
15 
16 from common_utils import *
17 
18 torch.set_default_tensor_type('torch.FloatTensor')
19 
20 
21 def _skipper(condition, reason):
22  def decorator(f):
23  @functools.wraps(f)
24  def wrapper(*args, **kwargs):
25  if condition():
26  raise unittest.SkipTest(reason)
27  return f(*args, **kwargs)
28  return wrapper
29  return decorator
30 
31 
32 skipIfNoCuda = _skipper(lambda: not torch.cuda.is_available(),
33  'CUDA is not available')
34 
35 skipIfTravis = _skipper(lambda: os.getenv('TRAVIS'),
36  'Skip In Travis')
37 
38 
39 def flatten(x):
40  return tuple(function._iter_filter(lambda o: isinstance(o, torch.Tensor))(x))
def is_available()
Definition: __init__.py:45
def set_default_tensor_type(t)
Definition: __init__.py:132