Helper for IndicesValid()
| 288 | |
| 289 | // Helper for IndicesValid() |
| 290 | inline Status IndexValid(const TTypes<int64>::ConstMatrix& ix_t, |
| 291 | int n) const { |
| 292 | bool valid = true; |
| 293 | bool different = false; |
| 294 | bool increasing = true; |
| 295 | if (n == 0) { |
| 296 | for (int di = 0; di < dims_; ++di) { |
| 297 | if (ix_t(n, di) < 0 || ix_t(n, di) >= shape_[di]) valid = false; |
| 298 | } |
| 299 | different = true; |
| 300 | } else { |
| 301 | for (int di = 0; di < dims_; ++di) { |
| 302 | if (ix_t(n, di) < 0 || ix_t(n, di) >= shape_[di]) valid = false; |
| 303 | int64 diff = ix_t(n, order_[di]) - ix_t(n - 1, order_[di]); |
| 304 | if (diff > 0) different = true; |
| 305 | if (!different && diff < 0) increasing = false; |
| 306 | } |
| 307 | } |
| 308 | if (TF_PREDICT_FALSE(!valid || !increasing || !different)) { |
| 309 | string index = strings::StrCat("indices[", n, "] = ["); |
| 310 | for (int di = 0; di < dims_; ++di) { |
| 311 | strings::StrAppend(&index, ix_t(n, di), di < dims_ - 1 ? "," : "]"); |
| 312 | } |
| 313 | if (!valid) { |
| 314 | return errors::InvalidArgument(index, |
| 315 | " is out of bounds: need 0 <= index < [", |
| 316 | str_util::Join(shape_, ","), "]"); |
| 317 | } |
| 318 | if (!increasing) { |
| 319 | return errors::InvalidArgument( |
| 320 | index, |
| 321 | " is out of order. Many sparse ops require sorted indices.\n" |
| 322 | " Use `tf.sparse.reorder` to create a correctly ordered copy." |
| 323 | "\n\n"); |
| 324 | } |
| 325 | if (!different) { |
| 326 | return errors::InvalidArgument(index, " is repeated"); |
| 327 | } |
| 328 | } |
| 329 | return Status::OK(); |
| 330 | } |
| 331 | |
| 332 | // Helper for ToDense<T>() |
| 333 | template <typename T> |
no test coverage detected