Commit 76cdc527 authored by Janardhan Pulivarthi's avatar Janardhan Pulivarthi
Browse files

resolve 'float' to 'int' conversion, StringIO import, conacat str + byte

parent 8507934f
...@@ -111,7 +111,7 @@ def init_data(task, length, nbr_cases, nclass): ...@@ -111,7 +111,7 @@ def init_data(task, length, nbr_cases, nclass):
"""Data initialization.""" """Data initialization."""
def rand_pair(l, task): def rand_pair(l, task):
"""Random data pair for a task. Total length should be <= l.""" """Random data pair for a task. Total length should be <= l."""
k = (l-1)/2 k = int((l-1)/2)
base = 10 base = 10
if task[0] == "b": base = 2 if task[0] == "b": base = 2
if task[0] == "q": base = 4 if task[0] == "q": base = 4
...@@ -135,7 +135,7 @@ def init_data(task, length, nbr_cases, nclass): ...@@ -135,7 +135,7 @@ def init_data(task, length, nbr_cases, nclass):
def rand_dup_pair(l): def rand_dup_pair(l):
"""Random data pair for duplication task. Total length should be <= l.""" """Random data pair for duplication task. Total length should be <= l."""
k = l/2 k = int(l/2)
x = [np.random.randint(nclass - 1) + 1 for _ in xrange(k)] x = [np.random.randint(nclass - 1) + 1 for _ in xrange(k)]
inp = x + [0 for _ in xrange(l - k)] inp = x + [0 for _ in xrange(l - k)]
res = x + x + [0 for _ in xrange(l - 2*k)] res = x + x + [0 for _ in xrange(l - 2*k)]
......
...@@ -16,10 +16,14 @@ ...@@ -16,10 +16,14 @@
import contextlib import contextlib
import sys import sys
import StringIO
import random import random
import os import os
try:
import StringIO
except ImportError:
from io import StringIO
class ListType(object): class ListType(object):
def __init__(self, arg): def __init__(self, arg):
self.arg = arg self.arg = arg
......
...@@ -43,7 +43,7 @@ _CHAR_MARKER = "_CHAR_" ...@@ -43,7 +43,7 @@ _CHAR_MARKER = "_CHAR_"
_CHAR_MARKER_LEN = len(_CHAR_MARKER) _CHAR_MARKER_LEN = len(_CHAR_MARKER)
_SPEC_CHARS = "" + chr(226) + chr(153) + chr(128) _SPEC_CHARS = "" + chr(226) + chr(153) + chr(128)
_PUNCTUATION = "][.,!?\"':;%$#@&*+}{|><=/^~)(_`,0123456789" + _SPEC_CHARS + "-" _PUNCTUATION = "][.,!?\"':;%$#@&*+}{|><=/^~)(_`,0123456789" + _SPEC_CHARS + "-"
_WORD_SPLIT = re.compile(b"([" + _PUNCTUATION + "])") _WORD_SPLIT = re.compile("([" + _PUNCTUATION + "])")
_OLD_WORD_SPLIT = re.compile(b"([.,!?\"':;)(])") _OLD_WORD_SPLIT = re.compile(b"([.,!?\"':;)(])")
_DIGIT_RE = re.compile(br"\d") _DIGIT_RE = re.compile(br"\d")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment