diff --git a/guide/basic.py b/guide/basic.py index c1f1c2f4b..363150b5d 100755 --- a/guide/basic.py +++ b/guide/basic.py @@ -2,6 +2,8 @@ """ demo python script of rabit """ +from __future__ import print_function +from builtins import range import os import sys import numpy as np @@ -14,12 +16,12 @@ rabit.init() n = 3 rank = rabit.get_rank() a = np.zeros(n) -for i in xrange(n): +for i in range(n): a[i] = rank + i -print '@node[%d] before-allreduce: a=%s' % (rank, str(a)) +print('@node[%d] before-allreduce: a=%s' % (rank, str(a))) a = rabit.allreduce(a, rabit.MAX) -print '@node[%d] after-allreduce-max: a=%s' % (rank, str(a)) +print('@node[%d] after-allreduce-max: a=%s' % (rank, str(a))) a = rabit.allreduce(a, rabit.SUM) -print '@node[%d] after-allreduce-sum: a=%s' % (rank, str(a)) +print('@node[%d] after-allreduce-sum: a=%s' % (rank, str(a))) rabit.finalize() diff --git a/guide/broadcast.py b/guide/broadcast.py index defe69eaa..8b8169223 100755 --- a/guide/broadcast.py +++ b/guide/broadcast.py @@ -2,6 +2,7 @@ """ demo python script of rabit """ +from __future__ import print_function import os import sys # add path to wrapper @@ -15,8 +16,8 @@ rank = rabit.get_rank() s = None if rank == 0: s = {'hello world':100, 2:3} -print '@node[%d] before-broadcast: s=\"%s\"' % (rank, str(s)) +print('@node[%d] before-broadcast: s=\"%s\"' % (rank, str(s))) s = rabit.broadcast(s, 0) -print '@node[%d] after-broadcast: s=\"%s\"' % (rank, str(s)) +print('@node[%d] after-broadcast: s=\"%s\"' % (rank, str(s))) rabit.finalize() diff --git a/test/local_recover.py b/test/local_recover.py index e35bd3177..315acbf0d 100755 --- a/test/local_recover.py +++ b/test/local_recover.py @@ -1,4 +1,6 @@ #!/usr/bin/python +from __future__ import print_function +from builtins import range import rabit import numpy as np @@ -13,11 +15,11 @@ if version == 0: model = np.zeros(n) local = np.ones(n) else: - print '[%d] restart from version %d' % (rank, version) + print('[%d] restart from version %d' % (rank, version)) -for i in xrange(version, nround): +for i in range(version, nround): res = rabit.allreduce(data + model+local, rabit.SUM) - print '[%d] iter=%d: %s' % (rank, i, str(res)) + print('[%d] iter=%d: %s' % (rank, i, str(res))) model = res local[:] = i rabit.checkpoint(model, local)