       Re: how to build pattern for a square matrix of reals?

• To: mathgroup at smc.vnet.net
• Subject: [mg98487] Re: how to build pattern for a square matrix of reals?
• From: m.r at inbox.ru
• Date: Fri, 10 Apr 2009 04:59:26 -0400 (EDT)
• References: <grhp95\$mj7\$1@smc.vnet.net>

```sagra... at gmail.com wrote:
> As in subject: how to build a pattern that will specify that given
> argument of a function has to be square matrix of reals?  Tried with
> following for "square matrix" part:
>   f[x_?MatrixQ[#] && Dimensions[#][] == Dimensions[#][]
> &] := ...
> but it doesn't seem to be working...
>
> Thanks.

Regarding the type checking, a fast way to do that is to use MatchQ[#,
_Real]& as the test in MatrixQ. It is recognized as a special case and
for packed arrays it'll be O(1):

In:= m = RandomReal[1, {4*^3, 4*^3}];

In:= Timing[MatchQ[m, {{_Real..}..}]]

Out= {0.906, True}

In:= Timing[MatrixQ[m, MatchQ[#, _Real]&]]

Out= {0., True}

Maxim Rytin
m.r at inbox.ru

```

• Prev by Date: Re: combining contourplot and regionplot
• Next by Date: Re: Simplifying an expression for computational, not aesthetic
• Previous by thread: Re: how to build pattern for a square matrix of reals?
• Next by thread: Re: Re: how to build pattern for a square matrix of reals?