There are timing variations depending on object size:
isn =: 0=1{.0#,
1e5 timespacex 'numeric 3 4'
1.34292e_6 2176
1e5 timespacex 'num 3 4'
1.08399e_6 1408
1e5 timespacex 'isn 3 4'
1.1718e_6 1536
1e5 timespacex 'numeric 4 5 6 8$3 4'
2.43099e_6 10368
1e5 timespacex 'num 4 5 6 8$3 4'
2.76791e_6 18048
1e5 timespacex 'isn 4 5 6 8$3 4'
2.33889e_6 10112
On Thu, Nov 9, 2017 at 2:17 PM, Raul Miller <[email protected]> wrote:
> This actually looks like a good idea. I was concerned about
> performance, but this kind of thing also seems just as fast as the
> other approach, and a bit more compact:
>
> num=:(1 [ 0+{.@,) ::0:
> numeric=: 0 = 0 {.@{. ,
> 1e4 timespacex 'numeric 3 4'
> 1.0472e_6 2176
> 1e4 timespacex 'num 3 4'
> 9.204e_7 1408
>
> Plus, we don't have to worry about if sparse array default value will
> ever leak in, in some J version.
>
> Thanks,
>
> --
> Raul
>
> On Thu, Nov 9, 2017 at 1:40 PM, Marshall Lochbaum <[email protected]>
> wrote:
> > Actually, the domain error thing gives me an idea:
> >
> > numeric =: (1[[:+''($,)]) :: 0:
> >
> > numeric i.3 5
> > 1
> > numeric <2 3
> > 0
> > numeric 'abcd'
> > 0
> >
> > Reshape to scalar, attempt to apply complex conjugate, and then return
> > 1. If conjugate failed, return 0. You could skip the reshape, yielding
> > ((1[+) :: 0:), but this gives a false positive on empty character arrays
> > and will actually compute the conjugate of a complex argument, which
> > could be slow.
> >
> > Marshall
> >
> > On Thu, Nov 09, 2017 at 01:01:40PM -0500, Raul Miller wrote:
> >> I would be inclined to do something similar:
> >>
> >> numeric=: 0 = 0 {.@{. ,
> >>
> >> That said, it's usually sufficient to rely on domain errors for this
> >> kind of thing.
> >>
> >> Thanks,
> >>
> >> --
> >> Raul
> >>
> >>
> >>
> >>
> >>
> >>
> >> On Thu, Nov 9, 2017 at 12:20 PM, Michael Berry <[email protected]>
> wrote:
> >> > Hello J world,
> >> >
> >> > I have a verb that returns scalar 1 if the argument is numeric of any
> shape
> >> > and scalar 0 otherwise.
> >> > It works fine:
> >> >
> >> > numeric i. 5
> >> >
> >> > 1
> >> >
> >> > numeric 9
> >> >
> >> > 1
> >> >
> >> > numeric i. 2 3 4
> >> >
> >> > 1
> >> >
> >> > numeric 'cat'
> >> >
> >> > 0
> >> >
> >> > numeric 3#<i. 4
> >> >
> >> > 0
> >> >
> >> >
> >> > My definition feels clumsy, however. Can anyone suggest something
> nicer?
> >> >
> >> >
> >> > numeric=: monad : '0 -: 0{ , 1{. 0#y'
> >> >
> >> >
> >> > -Michael
> >> > ------------------------------------------------------------
> ----------
> >> > For information about J forums see http://www.jsoftware.com/
> forums.htm
> >> ----------------------------------------------------------------------
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm