|
310 | 310 | @test [[1, 2], [3, 4]] ≈ [[1.0-eps(), 2.0+eps()], [3.0+2eps(), 4.0-1e8eps()]]
|
311 | 311 | @test [[1, 2], [3, 4]] ≉ [[1.0-eps(), 2.0+eps()], [3.0+2eps(), 4.0-1e9eps()]]
|
312 | 312 | @test [[1,2, [3,4]], 5.0, [6im, [7.0, 8.0]]] ≈ [[1,2, [3,4]], 5.0, [6im, [7.0, 8.0]]]
|
| 313 | + |
| 314 | +# Issue 22042 |
| 315 | +# Minimal modulo number type - but not subtyping Number |
| 316 | +struct ModInt{n} |
| 317 | + k |
| 318 | + ModInt{n}(k) where {n} = new(mod(k,n)) |
| 319 | +end |
| 320 | + |
| 321 | +Base.:+(a::ModInt{n}, b::ModInt{n}) where {n} = ModInt{n}(a.k + b.k) |
| 322 | +Base.:-(a::ModInt{n}, b::ModInt{n}) where {n} = ModInt{n}(a.k - b.k) |
| 323 | +Base.:*(a::ModInt{n}, b::ModInt{n}) where {n} = ModInt{n}(a.k * b.k) |
| 324 | +Base.:-(a::ModInt{n}) where {n} = ModInt{n}(-a.k) |
| 325 | +Base.inv(a::ModInt{n}) where {n} = ModInt{n}(invmod(a.k, n)) |
| 326 | +Base.:/(a::ModInt{n}, b::ModInt{n}) where {n} = a*inv(b) |
| 327 | + |
| 328 | +Base.zero(::Type{ModInt{n}}) where {n} = ModInt{n}(0) |
| 329 | +Base.zero(::ModInt{n}) where {n} = ModInt{n}(0) |
| 330 | +Base.one(::Type{ModInt{n}}) where {n} = ModInt{n}(1) |
| 331 | +Base.one(::ModInt{n}) where {n} = ModInt{n}(1) |
| 332 | + |
| 333 | +# Needed for pivoting: |
| 334 | +Base.abs(a::ModInt{n}) where {n} = a |
| 335 | +Base.:<(a::ModInt{n}, b::ModInt{n}) where {n} = a.k < b.k |
| 336 | +Base.transpose(a::ModInt{n}) where {n} = a # see Issue 20978 |
| 337 | + |
| 338 | +A = [ ModInt{2}(1) ModInt{2}(0) ; ModInt{2}(1) ModInt{2}(1) ] |
| 339 | +b = [ ModInt{2}(1), ModInt{2}(0) ] |
| 340 | + |
| 341 | +@test A*(A\b) == b |
| 342 | +@test_nowarn lufact( A, Val{true} ) |
0 commit comments