Just got home ...

Hehehehe ... yes, I use 'primitives' a lot. Let me emphasize that ... A LOT. :P 
I find it way much easier to maintain J code this way rather than the actual 
symbols. 

I'll give inverted tables a try with tara ... I sort of used the current excel 
formatting so that I can "edit" data using excel interface. Trying to kill 2 
birds with 1 stone.

Well, regarding the cpu hungry operation ... what I was trying to do was 
transfrom JDB data from this format:
   [data=. 1 2 3 4 5; (;:'aa bb cc dd ee'); 6 7 8 9 10
+---------+----------------+----------+
|1 2 3 4 5|+--+--+--+--+--+|6 7 8 9 10|
|         ||aa|bb|cc|dd|ee||          |
|         |+--+--+--+--+--+|          |
+---------+----------------+----------+

to this format:
   [data=. |:>(< every 1 2 3 4 5); (;:'aa bb cc dd ee'); << every 6 7 8 9 10
+-+--+--+
|1|aa|6 |
+-+--+--+
|2|bb|7 |
+-+--+--+
|3|cc|8 |
+-+--+--+
|4|dd|9 |
+-+--+--+
|5|ee|10|
+-+--+--+

My initial solution, I just boxed each of the numeric items like so:
NB. Find out first which columns are not boxed
   [data=. 1 2 3 4 5; (;:'aa bb cc dd ee'); 6 7 8 9 10
+---------+----------------+----------+
|1 2 3 4 5|+--+--+--+--+--+|6 7 8 9 10|
|         ||aa|bb|cc|dd|ee||          |
|         |+--+--+--+--+--+|          |
+---------+----------------+----------+
   [mask=. I. -. (<'boxed') = datatype each data
0 2
   [temp=. < every each mask { data
+-----------+------------+
|+-+-+-+-+-+|+-+-+-+-+--+|
||1|2|3|4|5|||6|7|8|9|10||
|+-+-+-+-+-+|+-+-+-+-+--+|
+-----------+------------+
NB. Save formatted data back 
   [data=. |:>(temp) mask } data
+-+--+--+
|1|aa|6 |
+-+--+--+
|2|bb|7 |
+-+--+--+
|3|cc|8 |
+-+--+--+
|4|dd|9 |
+-+--+--+
|5|ee|10|
+-+--+--+
NB. Check the datatypes
   datatype each data
+-------+-------+-------+
|integer|literal|integer|
+-------+-------+-------+
|integer|literal|integer|
+-------+-------+-------+
|integer|literal|integer|
+-------+-------+-------+
|integer|literal|integer|
+-------+-------+-------+
|integer|literal|integer|
+-------+-------+-------+

As you can see, the numeric datatypes were maintained ... unfortunately this 
code is soooo slooooowwww when you have a lot of rows of data
temp=. < every each mask { data

To speed it up, I converted the data to strings first before I boxed them like 
so:
   [temp=. cutopen each ": each mask { data
+-----------+------------+
|+-+-+-+-+-+|+-+-+-+-+--+|
||1|2|3|4|5|||6|7|8|9|10||
|+-+-+-+-+-+|+-+-+-+-+--+|
+-----------+------------+

Unfortunately, I lost the non numeric datatype in the end as a result
   datatype each |:>(temp) mask } data
+-------+-------+-------+
|literal|literal|literal|
+-------+-------+-------+
|literal|literal|literal|
+-------+-------+-------+
|literal|literal|literal|
+-------+-------+-------+
|literal|literal|literal|
+-------+-------+-------+
|literal|literal|literal|
+-------+-------+-------+

Is there another way of doing this? Thanks for any help. :) 

r/Alex

P.S.
Just curious, why is converting the numeric array to string faster than keeping 
them as numbers and boxing them?


________________________________________
From: [email protected] [[email protected]] On 
Behalf Of bill lam [[email protected]]
Sent: Tuesday, December 01, 2009 10:53 PM
To: [email protected]
Subject: Re: [Jprogramming] JDB Utilities: Export to Excel

I became J-illiterate when reading your real-file code.  ;-)
Nevertheless tara support inverted table and jdb is inverted table.
and there can have no reason for inefficiency. (untested)


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to