Fix ffi utils in Python 2.7
diff --git a/torch/_utils.py b/torch/_utils.py
index 9adba52..18e6f97 100644
--- a/torch/_utils.py
+++ b/torch/_utils.py
@@ -38,7 +38,7 @@
# Taken from python 3.5 docs
-def _accumulate(iterable):
+def _accumulate(iterable, fn=lambda x, y: x + y):
'Return running totals'
# _accumulate([1,2,3,4,5]) --> 1 3 6 10 15
# _accumulate([1,2,3,4,5], operator.mul) --> 1 2 6 24 120
@@ -49,6 +49,6 @@
return
yield total
for element in it:
- total += element
+ total = fn(total, element)
yield total
diff --git a/torch/utils/ffi/__init__.py b/torch/utils/ffi/__init__.py
index 77ee058..434ff5a 100644
--- a/torch/utils/ffi/__init__.py
+++ b/torch/utils/ffi/__init__.py
@@ -6,6 +6,7 @@
from string import Template
import torch
import torch.cuda
+from torch._utils import _accumulate
try:
import cffi
@@ -75,12 +76,14 @@
if not module:
target_dir = name
else:
- target_dir = reduce(lambda path, segment: os.path.join(path, segment),
- fullname.split('.'))
+ target_dir = reduce(os.path.join, fullname.split('.'))
try:
os.makedirs(target_dir)
except FileExistsError:
pass
+ for dirname in _accumulate(fullname.split('.'), os.path.join):
+ init_file = os.path.join(dirname, '__init__.py')
+ open(init_file, 'a').close() # Create file if it doesn't exist yet
return name, target_dir