I should add that 3!:1 and 3!:2 are efficient in time
and space, much more so than ": and ". .  For example, 
for integer arrays:

   x=: 1009 2003 ?...@$ 1e6
   ts=: 6!:2 , 7!:2...@]
   ts '":x'
0.389282 5.03404e7
   ts '3!:1 x'
0.020751 8.38938e6
   */ $ ": x
14146180
   $ 3!:1 x
8084132
   
   ts '".y' [ y=: ": x
2.0132 8.78483e6
   ts '3!:2 y1' [ y1=: 3!:1 x
0.0108416 8.38938e6



----- Original Message -----
From: Roger Hui <[email protected]>
Date: Tuesday, April 6, 2010 7:41
Subject: Re: [Jprogramming] lines in display
To: Programming forum <[email protected]>

> The binary representation 
> http://www.jsoftware.com/help/dictionary/dx003.htm
> provides lossless representation of J arrays
> as a literal vector.  e.g.
> 
>    y=: o. i.2 3
>    a=: 3!:1 y
>    $a
> 72
>    type <'a'
> +----+
> |noun|
> +----+
>    a 1!:2 <'\junk\xxx'
>    y1=: 3!:2 (1!:1) <'\junk\xxx'
>    y - y1  NB. i.e. bit-by-bit identical
> 0 0 0
> 0 0 0
>    y -: y1
> 1
>    y -:!.0 y1  NB. i.e. 0 tolerance,  bit-by-
> bit identical
> 1
> 
> 3!:3 provides a related, more human-readable version of same.
> 
>    2 (3!:3) y
> e200000000000000
> 0000000000000008
> 0000000000000006
> 0000000000000002
> 0000000000000002
> 0000000000000003
> 0000000000000000
> 400921fb54442d18
> 401921fb54442d18
> 4022d97c7f3321d2
> 402921fb54442d18
> 402f6a7a2955385e
> 
> There are also "components files" in the standard libraries.
> 
> 
> 
> ----- Original Message -----
> From: Ian Clark <[email protected]>
> Date: Tuesday, April 6, 2010 2:30
> Subject: Re: [Jprogramming] lines in display
> To: Programming forum <[email protected]>
> 
> > I was afraid that would be the answer.
> > 
> > The inconvenience to my code is negligible. It just needs one more
> > line, with an (if.) in it. What distresses me is my failure to
> > understand why it happens. It makes me suspicious of my whole
> > data-storage approach.
> > 
> > I need to store a 2-D integer array, call it z, in an ascii 
> text file
> > and recover it on reloading the file.
> > Suppose 'a b'=:$z
> > Proviso: z is one of several arrays of mixed data. I want to 
> > retain a
> > visual check on the file contents that they all match-up by rows
> > (numbered: i.a). Without this proviso, a sensible thing to do 
> is to
> > store the contents of z as a vector and reconstruct it from a
> > knowledge of the number of rows, (a).
> > Taking a simple minded approach, however, I can use (":) to 
> > stuff z in
> > a file, and (".) to recover it again from the (2-D) file 
> image. This
> > seems adequate and reliable provided a>1 and b>1. I just 
> > wouldn't have
> > anticipated it breaking down for b=1, which is not an uncommon 
> > case to
> > arise.
> > 
> > Clearly this is not the approach an experienced J-er would 
> take, and
> > I'd like to know what that is.
> > 
> > I don't want to drag this thread off-topic. It just seemed 
> > related in
> > my mind to the problem of predicting the number of display-
> lines 
> > in z
> > -- or do I mean (":z)? Or (". ":z)?
> > 
> > Ian
> > 
> > 
> > On Tue, Apr 6, 2010 at 12:29 AM, Roger Hui 
> <[email protected]> wrote:
> > > It's a feature, an inevitable consequence of numeric
> > > conversion and rank.  If it breaks your code you have
> > > to rewrite your code.
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: Ian Clark <[email protected]>
> > > Date: Monday, April 5, 2010 16:12
> > > Subject: Re: [Jprogramming] lines in display
> > > To: Programming forum <[email protected]>
> > >
> > >> On not quite the same problem but a related one:
> > >>
> > >> If z is an integer table, under what conditions would you expect
> > >> ": z
> > >> to have the same number of rows as z? Under more restricted
> > >> conditions, when is (z -: ". ": z) ?
> > >>
> > >> Clearly you can't expect rank to be preserved if z=: i.1 3 -
> -since
> > >> under ": the information gets lost to enable you to 
> > distinguish it
> > >> from i.3. But what about z=: i.3 1 ?
> > >>
> > >> Consider the following:
> > >>
> > >>    (". ": i.z) ; i.z=: 3 2
> > >> +---+---+
> > >> |0 1|0 1|
> > >> |2 3|2 3|
> > >> |4 5|4 5|
> > >> +---+---+
> > >>    (". ": i.z) ; i.z=: 3 1
> > >> +-----+-+
> > >> |0 1 2|0|
> > >> |     |1|
> > >> |     |2|
> > >> +-----+-+
> > >>
> > >> Is this a bug or a feature? (It's breaking my code, for 
> which 
> > I have
> > >> so far only found an inelegant fix).
> > >>
> > >> Ian
> > >>
> > >>
> > >> On Fri, Apr 2, 2010 at 10:20 PM, Roger Hui 
> > <[email protected]> wrote:
> > >> > If x is a rank 2 or higher numeric array, how many
> > >> > lines are in the display of x?  For example,
> > >> > there are 14 lines in the display of  i. 3 4 5 .
> > >> >
> > >> > I've worked on a related problem on-and-off for years,
> > >> > starting in 1991, and only came to a good answer
> > >> > for this problem just a few days ago.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to