def batch(actionLists): '''Internal batcher for lists of actions''' atnTensor, idxTensor = [], [] keyTensor, lenTensor = [], [] #Pack inner set for actionList in actionLists: keys, atns, idxs = [], [], [] for key, atn, idx in actionList: atns.append(np.array(atn)) idxs.append(idx) keys.append(key) idxs = np.array(idxs) keys = np.array(keys) atns, lens = utils.pack(atns) atnTensor.append(atns) idxTensor.append(idxs) keyTensor.append(keys) lenTensor.append(lens) #Pack outer set idxTensor, _ = utils.pack(idxTensor) atnTensor, _ = utils.pack(atnTensor) keyTensor, _ = utils.pack(keyTensor) lenTensor = utils.pack(lenTensor) return atnTensor, idxTensor, keyTensor, lenTensor
def batchInputs(actionLists): atnTensor = [] atnTensorLens = [] atnLens = [] atnLenLens = [] for actions in actionLists: tensor = [] for atn, atnArgList in actions.items(): dat = [] for atnArg in atnArgList: atn, arg = atnArg.action, atnArg.args atnArg = np.array([atn, arg]) dat.append(atnArg) tensor.append(np.array(dat)) tensor, lens = utils.pack(tensor) atnTensor.append(tensor) atnLens.append(lens) atnTensor, atnTensorLens = utils.pack(atnTensor) atnLens, atnLenLens = utils.pack(atnLens) return atnTensor, atnTensorLens, atnLens, atnLenLens
def batch(stims): '''Internal batcher for lists of stimuli''' batch = {} #Process into set of sets for stim in stims: #Outer set for stat, stimSet in stim.items(): if stat not in batch: batch[stat] = [[], defaultdict(list)] #Inner set keys, vals = stimSet batch[stat][0].append(keys) for attr, val in vals.items(): val = np.array(val).reshape(-1) batch[stat][1][attr].append(val) #Pack values for group, stat in batch.items(): keys, stat = stat for attr, vals in stat.items(): vals, _ = utils.pack(vals) batch[group][1][attr] = vals return batch