Skip to content

Commit

Permalink
Address LGTM alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
sesevgen committed Nov 16, 2018
1 parent 05f6dd9 commit 7648ac1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
3 changes: 0 additions & 3 deletions miprometheus/helpers/problem_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

import os
import argparse
import urllib.request
import sys
import time
#import json

from miprometheus.problems.problem_factory import ProblemFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@
"""Script for generating a COG dataset"""

import errno
import functools
import gzip
import itertools
import json
import multiprocessing
import os
import random
import shutil
import traceback

import numpy as np

from miprometheus.problems.seq_to_seq.vqa.cog.cog_utils import stim_generator as sg
import miprometheus.problems.seq_to_seq.vqa.cog.cog_utils.task_bank as task_bank


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def set_outputs_from_tasks(n_epoch, tasks, objsets,
for epoch_now in range(n_epoch):
for task, objset in zip(tasks, objsets):
target = task(objset, epoch_now)
if target is const.INVALID:
if target == const.INVALID:
# For invalid target, no loss is used. Everything remains zero.
pass
elif isinstance(target, sg.Loc):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ def render_target(movie, target):
frame[:] = np.array(image)[:]

else:
if target_now is const.INVALID:
if target_now == const.INVALID:
string = 'invalid'
elif isinstance(target_now, bool):
string = 'true' if target_now else 'false'
Expand Down Expand Up @@ -976,7 +976,7 @@ def another_attr(attr):
return another_shape(attr)
elif isinstance(attr, Space):
return another_loc(attr)
elif attr is const.INVALID:
elif attr == const.INVALID:
return attr
else:
raise TypeError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"""

from collections import defaultdict
import copy
import random

from miprometheus.problems.seq_to_seq.vqa.cog.cog_utils import constants as const
Expand Down Expand Up @@ -233,7 +232,7 @@ def __str__(self):

def __call__(self, objset, epoch_now):
del objset
del epoch_now
#del epoch_now

def set_child(self, child):
"""Set operators as children."""
Expand Down Expand Up @@ -383,7 +382,7 @@ def get_expected_input(self, should_be, objset, epoch_now):
a = getattr(self, attr_type)
attr = a(objset, epoch_now)
# If the input is successfully evaluated
if attr is not const.INVALID and attr.has_value:
if attr != const.INVALID and attr.has_value:
if attr_type == 'loc':
attr = attr.get_space_to(self.space_type)
attr_new_object.append(attr)
Expand Down Expand Up @@ -436,7 +435,7 @@ def get_expected_input(self, should_be, objset, epoch_now):
a = getattr(self, attr_type)
attr = a(objset, epoch_now)
if isinstance(a, Operator):
if attr is const.INVALID:
if attr == const.INVALID:
# Can not be evaluated yet, then randomly choose one
attr = sg.random_attr(attr_type)
attr_expected_in.append(attr)
Expand Down Expand Up @@ -511,7 +510,7 @@ def __call__(self, objset, epoch_now):
else:
objs = self.objs

if objs is const.INVALID:
if objs == const.INVALID:
return const.INVALID
elif len(objs) != 1:
# Ambiguous or non-existent
Expand Down Expand Up @@ -602,7 +601,7 @@ def __call__(self, objset, epoch_now):
objs = self.objs(objset, epoch_now)
else:
objs = self.objs
if objs is const.INVALID:
if objs == const.INVALID:
return const.INVALID
elif len(objs) != 1:
# Ambiguous or non-existent
Expand All @@ -613,10 +612,10 @@ def __call__(self, objset, epoch_now):

def get_expected_input(self, should_be):
raise NotImplementedError()
if should_be is None:
should_be = sg.random_attr(self.attr_type)
objs = sg.Object([should_be])
return [objs]
#if should_be is None:
# should_be = sg.random_attr(self.attr_type)
#objs = sg.Object([should_be])
#return [objs]


class Exist(Operator):
Expand Down Expand Up @@ -704,7 +703,7 @@ def __str__(self):

def __call__(self, objset, epoch_now):
statement_true = self.statement(objset, epoch_now)
if statement_true is const.INVALID:
if statement_true == const.INVALID:
if self.invalid_as_false:
statement_true = False
else:
Expand Down Expand Up @@ -799,7 +798,7 @@ def __call__(self, objset, epoch_now):
attr1 = self.attr1(objset, epoch_now)
attr2 = self.attr2(objset, epoch_now)

if (attr1 is const.INVALID) or (attr2 is const.INVALID):
if (attr1 == const.INVALID) or (attr2 == const.INVALID):
return const.INVALID
else:
return attr1 == attr2
Expand All @@ -812,8 +811,8 @@ def get_expected_input(self, should_be, objset, epoch_now):
attr1_value = self.attr1(objset, epoch_now)
attr2_value = self.attr2(objset, epoch_now)

attr1_fixed = attr1_value is not const.INVALID
attr2_fixed = attr2_value is not const.INVALID
attr1_fixed = attr1_value != const.INVALID
attr2_fixed = attr2_value != const.INVALID

if attr1_fixed:
assert attr1_value.has_value
Expand Down

0 comments on commit 7648ac1

Please sign in to comment.