Index returns the n-dimensional index from a "flat" 1D array index.
(offset int)
| 141 | |
| 142 | // Index returns the n-dimensional index from a "flat" 1D array index. |
| 143 | func (sh *Shape) Index(offset int) []int { |
| 144 | nd := len(sh.Sizes) |
| 145 | index := make([]int, nd) |
| 146 | rem := offset |
| 147 | for i := nd - 1; i >= 0; i-- { |
| 148 | s := sh.Sizes[i] |
| 149 | iv := rem % s |
| 150 | rem /= s |
| 151 | index[i] = iv |
| 152 | } |
| 153 | return index |
| 154 | } |
| 155 | |
| 156 | // String satisfies the fmt.Stringer interface |
| 157 | func (sh *Shape) String() string { |
no outgoing calls
no test coverage detected