Loading Script within a statement / matrix question

I have a script (script.q) that accepts 2 variables (VB1 & VB2) and outputs a table (tb).<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

<o:p></o:p>

I want to load the script with various combinations of VB1 & VB2, each time inserting the results in tb. <o:p></o:p>

So the resulting tb would look like:<o:p></o:p>

VB1 VB2 output <o:p></o:p>

1 1 100.654<o:p></o:p>

1 2 102.2<o:p></o:p>

2 1 104.2<o:p></o:p>

2 2 98.5 <o:p></o:p>

<o:p> </o:p>

<o:p> </o:p>

A laborious and inefficient approach would be to use a do statement:<o:p></o:p>

<o:p> </o:p>

do[15; VB1:1+1?2; VB2:1+1?2; \l script.q] /then filter tb for distinct combinations of VB1 & VB2.<o:p></o:p>

<o:p> </o:p>

But \l isn’t recognized within the function & this is obviously a slow and ineffective method.

<o:p> </o:p>

Does anyone know a more efficient way of producing the output from the matrix of VB1 & VB2?

<o:p> </o:p>

Thanks,

Jake

Hi Jake,

Few suggestions:

  1. Do not use a script to call a function, use a function. f[vb1;vb2], loaded from a script if you want. Cutting out file reading/parsing overhead.
  2. Vectorize the function to work on lists of data rather than individual entries. f[1 1 2 2; 1 2 1 2]

Note: you can call “\l” from within a function by using the alternative: system “l script.q”.

Regards,
Ryan

On 2/14/2013 4:44 PM, Jake wrote:

I have a script (script.q)
that?accepts?2 variables (VB1?& VB2) and outputs a table (tb).<o:p></o:p>

?<o:p></o:p>

I want to load the
script with various combinations of VB1 & VB2, each
time inserting the results in tb.?<o:p></o:p>

So the resulting tb
would look like:<o:p></o:p>

VB1? ??VB2???????output <o:p></o:p>

? 1??? 1??? 100.654<o:p></o:p>

? 1??? 2??? 102.2<o:p></o:p>

? 2??? 1??? 104.2<o:p></o:p>

? 2??? 2??? ?? 98.5?<o:p></o:p>

<o:p>?</o:p>

<o:p>?</o:p>

A laborious and
inefficient approach would be to use a do statement:<o:p></o:p>

<o:p>?</o:p>

do[15; VB1:1+1?2;
VB2:1+1?2; \l script.q]? ??/then filter tb for
distinct combinations of VB1 & VB2.<o:p></o:p>

<o:p>?</o:p>

But ?\l ??isn?t recognized within the function & this
is obviously a slow and ineffective method.

<o:p>?</o:p>

Does anyone
know a more efficient way of producing the output from the
matrix of VB1 & VB2?

<o:p>?</o:p>

Thanks,

Jake


You received this message because you are subscribed to the Google Groups “Kdb+ Personal Developers” group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
?
?

-- 

TimeStored.com - KDB+ Software, Training, Consulting

Thanks Ryan.

I think I understand what you are suggesting, but I can’tget it to work. Can you be more specific?

<o:p></o:p>

I think I want to pass the values [1 1 2 2;1 2 1 2] into vb1& vb2 for each script.q right?

<o:p></o:p>

<o:p> </o:p>

Should I define  f:{[vb1;vb2]}  within the script?<o:p></o:p>

Then call  f[1 1 2 2;12 12]  within the script? Or in the qconsole?<o:p></o:p>

<o:p> </o:p>

On Thursday, February 14, 2013 10:52:49 AM UTC-6, Ryan Hamilton wrote:

Hi Jake,

Few suggestions:

  1. Do not use a script to call a function, use a function. f[vb1;vb2], loaded from a script if you want. Cutting out file reading/parsing overhead.
  2. Vectorize the function to work on lists of data rather than individual entries. f[1 1 2 2; 1 2 1 2]

Note: you can call “\l” from within a function by using the alternative: system “l script.q”.

Regards,
Ryan

On 2/14/2013 4:44 PM, Jake wrote:

I have a script (script.q) that�accepts�2 variables (VB1�& VB2) and outputs a table (tb).

�

I want to load the script with various combinations of VB1 & VB2, each time inserting the results in tb.�

So the resulting tb would look like:

VB1� ��VB2�������output

� 1������� 1��������� 100.654

� 1������� 2��������� 102.2

� 2������� 1��������� 104.2

� 2������� 2������� �� 98.5�

�

�

A laborious and inefficient approach would be to use a do statement:

�

do[15; VB1:1+1?2; VB2:1+1?2; \l script.q]� ��/then filter tb for distinct combinations of VB1 & VB2.

�

But �\l ��isn�t recognized within the function & this is obviously a slow and ineffective method.

�

Does anyone know a more efficient way of producing the output from the matrix of VB1 & VB2?

�

Thanks,

Jake


You received this message because you are subscribed to the Google Groups “Kdb+ Personal Developers” group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbpl…@googlegroups.com.
To post to this group, send email to personal…@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
�
�

TimeStored.com - KDB+ Software, Training, Consulting