Offset returns the "flat" 1D array index into an element at the given n-dimensional index. No checking is done on the length or size of the index values relative to the shape of the tensor.
(index []int)
| 132 | // Offset returns the "flat" 1D array index into an element at the given n-dimensional index. |
| 133 | // No checking is done on the length or size of the index values relative to the shape of the tensor. |
| 134 | func (sh *Shape) Offset(index []int) int { |
| 135 | var offset int |
| 136 | for i, v := range index { |
| 137 | offset += v * sh.Strides[i] |
| 138 | } |
| 139 | return offset |
| 140 | } |
| 141 | |
| 142 | // Index returns the n-dimensional index from a "flat" 1D array index. |
| 143 | func (sh *Shape) Index(offset int) []int { |
no outgoing calls
no test coverage detected