Inheritance for Matrix Wrapper Type

I want to define a matrix wrapper type in order to store more information than just the content of the matrix itself:

immutable MatWrap{T<:Number,S<:AbstractMatrix} <: AbstractMatrix{T}

Is there a way to automatically inherit all of the matrix operations, including optimized ones (e.g. if the matrix is Hermitian), without redefining all the A_mul_B and friends?

For example if I multiply A*B=C, C should be a MatWrap object.



I guess there isn’t a way…

On a related note, I was wondering why a wrapper like that has such a huge difference on timing:

import Base: *
using BenchmarkTools

immutable MatWrap{T<:Number}

*(A::MatWrap,B::MatWrap) = MatWrap(*,A.stuff)

n = 10
A = MatWrap(rand(n,n),1);
B = MatWrap(rand(n,n),2);

@time for i=1:300000;A*B;end
@time for i=1:300000;*;end

0.615447 seconds (989.79 k allocations: 279.154 MB, 15.86% gc time)
0.142688 seconds (300.14 k allocations: 256.356 MB, 3.06% gc time)

Is that not timed twice? That seems like a huge jump in allocations, indicating something was being compiled or not type-stable in the first timing.

It seems like precompiling by doing A*B in advance accounts for most of the time difference here. I was trying to get a reduced test case for a slightly more complex situation but that isn’t it…

Managed to figure it out, it’s because I had an abstract type on data