# What methods should be defined for a type to be \`\<:AbstractMatrix\`

**URL:** <https://discourse.julialang.org/t/what-methods-should-be-defined-for-a-type-to-be-abstractmatrix/5415>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 16, 2017, 4:59pm UTC](https://discourse.julialang.org/t/what-methods-should-be-defined-for-a-type-to-be-abstractmatrix/5415 "2017-08-16T16:59:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [August 16, 2017, 4:59pm UTC](https://discourse.julialang.org/t/what-methods-should-be-defined-for-a-type-to-be-abstractmatrix/5415/1 "2017-08-16T16:59:30Z")

</div>

I want to define a type of block diagonal matrix where the diagonal blocks are the same (usually small, always square) size. If there are `k` blocks, each of size `m×m` it seems reasonable to use a length `k` vector of `StaticArrays.MMatrix{m,m}` to store such arrays.

What methods should be defined if I want this type to be a subtype of `AbstractMatrix`?

---

<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:** [August 16, 2017, 5:09pm UTC](https://discourse.julialang.org/t/what-methods-should-be-defined-for-a-type-to-be-abstractmatrix/5415/2 "2017-08-16T17:09:23Z")

</div>

`size(::BlockDiagonal)` and `getindex(::BlockDiagonal, ::Int, ::Int)` are all you need to get started. Everything else is just optimizations. See [https://docs.julialang.org/en/stable/manual/interfaces/#man-interface-array-1](https://docs.julialang.org/en/stable/manual/interfaces/#man-interface-array-1) for more details.
