|
322 | 322 | return _isstored(style, A, Base.to_indices(A, I)...)
|
323 | 323 | end
|
324 | 324 |
|
| 325 | +@interface ::AbstractSparseArrayInterface function getunstoredindex( |
| 326 | + A::AbstractArray, I::Int... |
| 327 | +) |
| 328 | + @_propagate_inbounds_meta |
| 329 | + style = IndexStyle(A) |
| 330 | + |
| 331 | + # canonical linear indexing |
| 332 | + if style == IndexLinear() && length(I) == 1 |
| 333 | + @boundscheck checkbounds(A, I...) |
| 334 | + return zero(eltype(A)) |
| 335 | + end |
| 336 | + |
| 337 | + # canonical cartesian indexing |
| 338 | + if style == IndexCartesian() && length(I) == ndims(A) |
| 339 | + @boundscheck checkbounds(A, I...) |
| 340 | + return zero(eltype(A)) |
| 341 | + end |
| 342 | + |
| 343 | + # non-canonical indexing |
| 344 | + return _getunstoredindex(style, A, Base.to_indices(A, I)...) |
| 345 | +end |
| 346 | + |
| 347 | +# make sure we don't call AbstractArrayInterface defaults |
| 348 | +@interface ::AbstractSparseArrayInterface function getstoredindex( |
| 349 | + A::AbstractArray, I::Int... |
| 350 | +) |
| 351 | + @_propagate_inbounds_meta |
| 352 | + style = IndexStyle(A) |
| 353 | + error_if_canonical_getstoredindex(style, A, I...) |
| 354 | + return _getstoredindex(style, A, Base.to_indices(A, I)...) |
| 355 | +end |
| 356 | + |
| 357 | +for f! in (:setstoredindex!, :setunstoredindex!) |
| 358 | + _f! = Symbol(:_, f!) |
| 359 | + error_if_canonical_setstoredindex = Symbol(:error_if_canonical_, f!) |
| 360 | + @eval begin |
| 361 | + @interface ::AbstractSparseArrayInterface function $f!(A::AbstractArray, v, I::Int...) |
| 362 | + @_propagate_inbounds_meta |
| 363 | + style = IndexStyle(A) |
| 364 | + $error_if_canonical_setstoredindex(style, A, I...) |
| 365 | + return $_f!(style, A, v, Base.to_indices(A, I)...) |
| 366 | + end |
| 367 | + end |
| 368 | +end |
| 369 | + |
325 | 370 | @interface ::AbstractSparseArrayInterface storedlength(A::AbstractArray) =
|
326 | 371 | length(storedvalues(A))
|
327 | 372 | @interface ::AbstractSparseArrayInterface storedpairs(A::AbstractArray) =
|
|
0 commit comments