On Sat, Sep 20, 2008 at 12:56 AM, Alex Rufon <[EMAIL PROTECTED]> wrote:
> Hi.
>
> Here is the translation to J primitives. You can copy and paste it to a
> new IJS window and just delete all the comments. :)
I did that and got:
tomatrix=: ,:^:(1: = [EMAIL PROTECTED])
sids=. temp i.~ LOOKUP_z_=: ~. LOOKUP_z_ ,~. temp=: <'DUV'
masks=. ((<:BOM_USAGE_CLASS) {"1 bomv) e. sids
if. +/ masks do.
wrkbom=. masks # bomv
wrkvbom=. (0,}.$ wrkbom) $ 0
for_data. wrkbom do.
msk=. (+/@,(<: BOM_GEN_MAT_ID) {"1 data) = (<:DUV_GEN_MAT_ID) {"1 DUVV
if. # I. msk do.
temp=. (#I. msk) # tomatrix data
wired=. (<:DUV_CUSTOMER_CODE) {"1 DUVV {~ I. msk
if. 1 = $ wired do.
wired=. +/@, wired
end.
temp=. wired (<:BOM_DESTN_CODE) } "1 temp
wrkvbom=. wrkvbom , tomatrix temp
end.
end.
bomv=. (I. -. masks) { bomv
bomv=. bomv , tomatrix wrkvbom
end.
I still don't understand your data. You have given partial examples of
results that you can produce with your data, but I am missing
critical pieces of information (rank, depth, shapes, data types,
purpose) that I would need to construct my own examples.
I will note that you use temp=: followed by temp=. That should give
you an error but is probably an artifact of how you undid your
definitions.
I note that data, in your loop, is always rank 1 because wrkbom is always
rank 2. I have also assumed that your all-caps names with underlines in
them are all scalars (LOOKUP_z_ does not follow that pattern, but z is not
a capital letter).
My first pass at simplifying this looks like this:
bomv=: ,:^:(1: = [EMAIL PROTECTED]) bomv
LOOKUP_z_=: ~.LOOKUP_z_, <'DUV'
masks=. ((<:BOM_USAGE_CLASS){"1 bomv)e. LOOKUP_z i. <'DUV'
if. +/masks do.
wrkbom=. masks# bomv
wrkvbom=. 0# bomv
for_data. wrkbom do.
sel=. I.((<: BOM_GEN_MAT_ID){"1 data)= (<:DUV_GEN_MAT_ID){"1 DUVV
if. #sel do.
wired=. +/,(<:DUV_CUSTOMER_CODE){"1 sel{ DUVV
wrkvbom=. wrkvbom, wired (<:BOM_DESTN_CODE)}"1 (#sel) # ,:data
end.
end.
bomv=. ((-. masks) # bomv), wrkvbom
end.
Or, lifting constant sub-expressions out of your loop
bomv=: ,:^:(1: = [EMAIL PROTECTED]) bomv
LOOKUP_z_=: ~.LOOKUP_z_, <'DUV'
masks=. ((<:BOM_USAGE_CLASS){"1 bomv)e. LOOKUP_z i. <'DUV'
if. +/masks do.
wrkbom=. masks# bomv
wrkvbom=. 0# bomv
duvgen=. (<:DUV_GEN_MAT_ID){"1 DUVV
duvcus=. (<:DUV_CUSTOMER_CODE){"1 DUVV
bomgen=. <:BOM_GEN_MAT_ID
bomdst=. <:BOM_DESTN_CODE
for_data. wrkbom do.
sel=. I. duvgen = bomgen{"1 data
if. #sel do.
wired=. +/,sel{ duvcus
wrkvbom=. wrkvbom, wired bomdst}"1 (#sel) # ,:data
end.
end.
bomv=. ((-. masks) # bomv), wrkvbom
end.
The next thing I note is that your if. statements should be entirely optional.
The code should work just fine without them (though maybe slower -- I can
not comfortably determine that without any data).
The next thing I note is that you are essentially amending the bomv matrix.
I do not know if your rearranging of bomv is just an artifact of your approach
or it is something that has purpose in the rest of your application.
If you do not need to rearrange bomv, you might be able to speed things up
by using amend's special code to merge your updated results back in.
(Assuming bomv is huge). But if bomv is always like your example:
,:139 1002091 0
then this whole exercise is overkill.
Likely other improvements are possible, but I already have made a number
of changes that I can not test, and I might have broken something. So,
rather than risk losing the thread entirely, I will stop here.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm