attempted broadcast reorder
@@ -76,31 +76,47 @@ class VectorInterpolator:
grid[angle_loc] = grid_subset_cosin[grid_subset_cosin_order]
grid.insert(angle_loc+1, grid_subset_sin[grid_subset_sin_order])
+
# now copy the data to be interpolated through the extra dimension,
# at the specific angle_loc axes. We'll use broadcast_to to do this,
- # but broad_cast to only works on the 0th dimension. So start by
+ # but we need to do it on the last dimension. So start by
# temporarily moving the target axes there, then broadcasting
- data = np.swapaxes(data,0,angle_loc)
+ data = np.swapaxes(data,-1,angle_loc)
data_dim = list(np.shape(data))
- data_dim.insert(0,data_dim[0])
- data = np.broadcast_to(data,data_dim).copy()
-
- # Now we need to actually copy the data between the first two axes,
- # as broadcast_to doesn't do this
+ data_dim.append(data_dim[0])
+ data = data[..., np.newaxis] * np.ones(data_dim)
+
+ ## now copy the data to be interpolated through the extra dimension,
+ ## at the specific angle_loc axes. We'll use broadcast_to to do this,
+ ## but broad_cast to only works on the 0th dimension. So start by
+ ## temporarily moving the target axes there, then broadcasting
+ #data = np.swapaxes(data,0,angle_loc)
+ #data_dim = list(np.shape(data))
+ #data_dim.insert(0,data_dim[0])
+ #data = np.broadcast_to(data,data_dim).copy()
+
+ ## Now we need to actually copy the data between the first two axes,
+ ## as broadcast_to doesn't do this
for ind in range(data.shape[0]):
- data[ind,...] = data[:,ind,...]
+ data[..., ind] = data[..., :, ind]
- # No re-order the cosin dimension
+ # Now re-order the cosin dimension
data = data[grid_subset_cosin_order, ...]
- # No re-order the sin dimension
+ # Now re-order the sin dimension
data = data[:, grid_subset_sin_order, ...]
- # now re-arrange the axes so they're in the right order again,
- # remembering that we've added a new axis
- dst_axes = np.arange(2,len(data.shape)).tolist()
- dst_axes.insert(angle_loc,0)
- dst_axes.insert(angle_loc+1,1)
- data = np.transpose(data,axes=dst_axes)
+ ## now re-arrange the axes so they're in the right order again,
+ ## remembering that we've added a new axis
+ #dst_axes = np.arange(2,len(data.shape)).tolist()
+ #dst_axes.insert(angle_loc,0)
+ #dst_axes.insert(angle_loc+1,1)
+ #data = np.transpose(data,axes=dst_axes)
+
+ ## now re-arrange the axes so they're in the right order again,
+ dst_axes = np.arange(len(data.shape)-2).tolist()
+ dst_axes.insert(angle_loc, -2)
+ dst_axes.insert(angle_loc+1, -1)
+ data = np.ascontiguousarray(np.transpose(data, axes=dst_axes))
# update the rest of the angle locations
angle_locations += 1
