tensor() now pregenerates index array for further optimization