def transpose(self, *axes): """ Transpose just the keys of a BoltArraySpark, returning a new BoltArraySpark. Parameters ---------- axes : tuple New proposed axes. """ new = argpack(axes) old = range(self.ndim) istransposeable(new, old) if new == old: return self._barray def f(k): return tuple(k[i] for i in new) newrdd = self._barray._rdd.map(lambda kv: (f(kv[0]), kv[1])) newshape = tuple(self.shape[i] for i in new) + self._barray.values.shape return BoltArraySpark(newrdd, shape=newshape).__finalize__(self._barray)
def transpose(self, *axes): """ Transpose just the values of a BoltArraySpark, returning a new BoltArraySpark. Parameters ---------- axes : tuple New proposed axes. """ new = argpack(axes) old = range(self.ndim) istransposeable(new, old) if new == old: return self._barray def f(v): return v.transpose(new) newrdd = self._barray._rdd.mapValues(f) newshape = self._barray.keys.shape + tuple(self.shape[i] for i in new) return BoltArraySpark(newrdd, shape=newshape).__finalize__(self._barray)
def transpose(self, *axes): p = asarray(argpack(axes)) istransposeable(p, range(self.ndim)) split = self.split # compute the keys/value axes that need to be swapped new_keys, new_values = p[:split], p[split:] swapping_keys = sort(new_values[new_values < split]) swapping_values = sort(new_keys[new_keys >= split]) stationary_keys = sort(new_keys[new_keys < split]) stationary_values = sort(new_values[new_values >= split]) # compute the permutation that the swap causes p_swap = r_[stationary_keys, swapping_values, swapping_keys, stationary_values] # compute the extra permutation (p_x) on top of this that needs to happen to get the full permutation desired p_swap_inv = argsort(p_swap) p_x = p_swap_inv[p] p_keys, p_values = p_x[:split], p_x[split:]-split # perform the swap and the the within key/value permutations arr = self.swap(swapping_keys, swapping_values-split) arr = arr.keys.transpose(tuple(p_keys.tolist())) arr = arr.values.transpose(tuple(p_values.tolist())) return arr
def transpose(self, *axes): p = asarray(argpack(axes)) istransposeable(p, range(self.ndim)) split = self.split # compute the keys/value axes that need to be swapped new_keys, new_values = p[:split], p[split:] swapping_keys = sort(new_values[new_values < split]) swapping_values = sort(new_keys[new_keys >= split]) stationary_keys = sort(new_keys[new_keys < split]) stationary_values = sort(new_values[new_values >= split]) # compute the permutation that the swap causes p_swap = r_[stationary_keys, swapping_values, swapping_keys, stationary_values] # compute the extra permutation (p_x) on top of this that needs to happen to get the full permutation desired p_swap_inv = argsort(p_swap) p_x = p_swap_inv[p] p_keys, p_values = p_x[:split], p_x[split:] - split # perform the swap and the the within key/value permutations arr = self.swap(swapping_keys, swapping_values - split) arr = arr.keys.transpose(tuple(p_keys.tolist())) arr = arr.values.transpose(tuple(p_values.tolist())) return arr
def transpose(self, *axes): new = argpack(axes) old = range(self.ndim) istransposeable(new, old) if new == old: return self._barray def f(v): return v.transpose(new) newrdd = self._barray._rdd.mapValues(f) newshape = self._barray.keys.shape + tuple(self.shape[i] for i in new) return BoltArraySpark(newrdd, shape=newshape).__finalize__(self._barray)
def transpose(self, *axes): new = argpack(axes) old = range(self.ndim) istransposeable(new, old) if new == old: return self._barray def f(k): return tuple(k[i] for i in new) newrdd = self._barray._rdd.map(lambda kv: (f(kv[0]), kv[1])) newshape = tuple(self.shape[i] for i in new) + self._barray.values.shape return BoltArraySpark(newrdd, shape=newshape).__finalize__(self._barray)
def transpose(self, *axes): """ Return an array with the axes transposed. This operation will incur a swap unless the desiured permutation can be obtained only by transpoing the keys or the values. Parameters ---------- axes : None, tuple of ints, or n ints If None, will reverse axis order. """ if len(axes) == 0: p = arange(self.ndim - 1, -1, -1) else: p = asarray(argpack(axes)) istransposeable(p, range(self.ndim)) split = self.split # compute the keys/value axes that need to be swapped new_keys, new_values = p[:split], p[split:] swapping_keys = sort(new_values[new_values < split]) swapping_values = sort(new_keys[new_keys >= split]) stationary_keys = sort(new_keys[new_keys < split]) stationary_values = sort(new_values[new_values >= split]) # compute the permutation that the swap causes p_swap = r_[stationary_keys, swapping_values, swapping_keys, stationary_values] # compute the extra permutation (p_x) on top of this that # needs to happen to get the full permutation desired p_swap_inv = argsort(p_swap) p_x = p_swap_inv[p] p_keys, p_values = p_x[:split], p_x[split:] - split # perform the swap and the the within key/value permutations arr = self.swap(swapping_keys, swapping_values - split) arr = arr.keys.transpose(tuple(p_keys.tolist())) arr = arr.values.transpose(tuple(p_values.tolist())) return arr
def transpose(self, *axes): """ Return an array with the axes transposed. This operation will incur a swap unless the desiured permutation can be obtained only by transpoing the keys or the values. Parameters ---------- axes : None, tuple of ints, or n ints If None, will reverse axis order. """ if len(axes) == 0: p = arange(self.ndim-1, -1, -1) else: p = asarray(argpack(axes)) istransposeable(p, range(self.ndim)) split = self.split # compute the keys/value axes that need to be swapped new_keys, new_values = p[:split], p[split:] swapping_keys = sort(new_values[new_values < split]) swapping_values = sort(new_keys[new_keys >= split]) stationary_keys = sort(new_keys[new_keys < split]) stationary_values = sort(new_values[new_values >= split]) # compute the permutation that the swap causes p_swap = r_[stationary_keys, swapping_values, swapping_keys, stationary_values] # compute the extra permutation (p_x) on top of this that # needs to happen to get the full permutation desired p_swap_inv = argsort(p_swap) p_x = p_swap_inv[p] p_keys, p_values = p_x[:split], p_x[split:]-split # perform the swap and the the within key/value permutations arr = self.swap(swapping_keys, swapping_values-split) arr = arr.keys.transpose(tuple(p_keys.tolist())) arr = arr.values.transpose(tuple(p_values.tolist())) return arr