Tensor extends BaseTensor { public int[] indexToCoor( int index , int []storage ) { if( storage == null ) { storage = createCoor(); } for (int i = 0; i < storage.length; i++) { storage[i] = index / strides[i]; index -= storage[i]*strides[i]; } return storage; }  abstract double getDouble( int ...coordinate ); abstract Object getData(); abstract void setData( Object data ); void reshape(int... shape); void reshape( int length0 ); void reshape( int length1 , int length0); void reshape( int length2 , int length1 , int length0 ); void reshape( int length3 , int length2 , int length1 , int length0 ); void reshape( int length4 , int length3 , int length2 , int length1 , int length0 ); void reshape(); int idx(int ...coordinate ); int idx(int axis0 ); int idx(int axis1, int axis0 ); int idx(int axis2, int axis1 , int axis0 ); int idx(int axis3, int axis2 , int axis1 , int axis0 ); int idx(int axis4, int axis3 , int axis2 , int axis1 , int axis0 ); void computeStrides(); int stride( int index ); void copyShape( int shape[] ); int length(int dimension ); int length(); abstract T create( int ...shape ); T createLike(); int[] createCoor(); int[] indexToCoor( int index , int []storage ); void setTo( T original ); abstract void zero(); T copy(); boolean isSub(); T subtensor(int startIndex, int[] shape); public int startIndex; public boolean subtensor; public int strides; }
@Test public void indexToCoor() { Dummy tensor = new Dummy(); tensor.reshape(10,5,6); int index = tensor.idx(3,4,1); int[] found = tensor.indexToCoor(index,null); assertEquals(3,found.length); assertEquals(3,found[0]); assertEquals(4,found[1]); assertEquals(1,found[2]); }