# Infinite matrices in Julia?

**URL:** <https://discourse.julialang.org/t/infinite-matrices-in-julia/36278>\
**Category:** General Usage\
**Created:** [March 20, 2020, 8:12pm UTC](https://discourse.julialang.org/t/infinite-matrices-in-julia/36278 "2020-03-20T20:12:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![VikoRifeo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vikorifeo/32/13522_2.png) [@VikoRifeo](https://discourse.julialang.org/u/VikoRifeo)\
**Post date:** [March 20, 2020, 8:12pm UTC](https://discourse.julialang.org/t/infinite-matrices-in-julia/36278/1 "2020-03-20T20:12:18Z")

</div>

I’m trying to subtype `AbstractMatrix` for a matrix which has infinite rows. What should `axes`, `size` and `length` return? Floating-point `Inf` is probably out, because the indices must be integers. I could report it as `typemin(Int):typemax(Int)` (it’s infinite in both positive and negative directions), but then the length will always overflow; I could report the length as `typemax(Int)` on top of that, but at that point my “too many special cases” alarm starts going off. Would it cause problems, though? Or do you think this is too far out of `AbstractMatrix` territory in the first place?

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [March 20, 2020, 8:16pm UTC](https://discourse.julialang.org/t/infinite-matrices-in-julia/36278/2 "2020-03-20T20:16:19Z")

</div>

Welcome! The only advantage to subtyping `AbstractMatrix` is that it allows your object to use code that uses the `::AbstractMatrix` type in its signature. I think you’ll find that the number of functions that are written to accept `::AbstractMatrix` objects and _would still work_ with your infinite matrix to be fairly small. Small enough, in fact, that it’s probably significantly easier to just not implement `size`/`axes`/etc and simply subtype `<: Any` instead.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [March 20, 2020, 9:47pm UTC](https://discourse.julialang.org/t/infinite-matrices-in-julia/36278/3 "2020-03-20T21:47:25Z")

</div>

Checkout [InfiniteArrays.jl](https://github.com/JuliaArrays/InfiniteArrays.jl)
