# Re: \[personal kdb+\] learning each /: \\: \[off topic\]

**URL:** https://forum.kx.com/t/re-personal-kdb-learning-each-off-topic/7536
**Category:** Community Support
**Tags:** kdb-and-q
**Created:** [January 14, 2012, 6:14am UTC](https://forum.kx.com/t/re-personal-kdb-learning-each-off-topic/7536 "2012-01-14T06:14:00Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![effbiae](https://avatars.discourse-cdn.com/v4/letter/e/ecae2f/32.png) [@effbiae](https://forum.kx.com/u/effbiae)
#### Post date: [January 14, 2012, 6:14am UTC](https://forum.kx.com/t/re-personal-kdb-learning-each-off-topic/7536/1 "2012-01-14T06:14:00Z")

</div>

i’m interested in k, so i studied?q’s implementation of cross.

specializing cross a little:

? cross:{n:#m:&(#x)##y;x[m],'n#y}

? cross[r;r]

(“eaxeax”;“eaxecx”;“eaxedx”;“ecxeax”;“ecxecx”;“ecxedx”;“edxeax”;“edxecx”;"edx..

now, i think cross is a bit more than an idiom (or is it?) ?so do k programmers write their own little library of functions like cross? ?or is such a library simply q?

ta, jack.

---

<div class="post-metadata">

### Author: ![trieder](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@trieder](https://forum.kx.com/u/trieder)
#### Post date: [January 14, 2012, 6:33am UTC](https://forum.kx.com/t/re-personal-kdb-learning-each-off-topic/7536/2 "2012-01-14T06:33:00Z")

</div>

It’s just in q, but I’m sure you can find legacy k code all over if you’re looking for it (though Kx recommends sticking to q for new development). You can call functions from k if you access it via it’s fqn i.e. .q.cross and you’ll see this done in k code periodically.?

---

<div class="post-metadata">

### Author: ![effbiae](https://avatars.discourse-cdn.com/v4/letter/e/ecae2f/32.png) [@effbiae](https://forum.kx.com/u/effbiae)
#### Post date: [January 14, 2012, 7:00am UTC](https://forum.kx.com/t/re-personal-kdb-learning-each-off-topic/7536/3 "2012-01-14T07:00:00Z")

</div>

cheers tim,

i just timed cross and ,:/:?

q)\

? a:!2000

? \t a,/::a

2419

? \t .q.cross[a;a]

2459

but to produce the same result as .q.cross:

? \t ,/a,/::a

2448

hmmm…

---

<div class="post-metadata">

### Author: ![trieder](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@trieder](https://forum.kx.com/u/trieder)
#### Post date: [January 14, 2012, 7:11am UTC](https://forum.kx.com/t/re-personal-kdb-learning-each-off-topic/7536/4 "2012-01-14T07:11:00Z")

</div>

1. .q.cross is different than what you’re typing in (see the code).

2. taskset your process and try again.?

3. If you run them multiple times are their average run times close (malloc)

---

<div class="post-metadata">

### Author: ![effbiae](https://avatars.discourse-cdn.com/v4/letter/e/ecae2f/32.png) [@effbiae](https://forum.kx.com/u/effbiae)
#### Post date: [January 14, 2012, 7:32am UTC](https://forum.kx.com/t/re-personal-kdb-learning-each-off-topic/7536/5 "2012-01-14T07:32:00Z")

</div>

\> 1) .q.cross is different than what you’re typing in (see the code).

yeah, i was comparing ,/:: and .q.cross

\> 2) taskset your process and try again.  
\> 3) If you run them multiple times are their average run times close (mall=  
oc)

$ taskset 01 ~/q/l32/q  
q)\   
\t do[3;.q.cross[a;a]]  
7019  
\t do[3;a,/::a]  
5780

anything i’m missing? .q.cross looks faster… but maybe there’s a  
price for more general code? i don’t know.

---

<div class="post-metadata">

### Author: ![trieder](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@trieder](https://forum.kx.com/u/trieder)
#### Post date: [January 14, 2012, 7:42am UTC](https://forum.kx.com/t/re-personal-kdb-learning-each-off-topic/7536/6 "2012-01-14T07:42:00Z")

</div>

charset=us-ascii  
Message-Id: \<118E27FB-8DB7-4F1E-B723-FFC8C672071C@gmail.com\>  
Cc: “[personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)”   
X-Mailer: iPhone Mail (9A405)  
From: Timothy Rieder   
Subject: Re: [personal kdb+] learning each /: : [off topic]  
Date: Sat, 14 Jan 2012 02:42:01 -0500  
To: “[personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)”   
  
I’d check in another terminal via top that the last CPU q runs on is always t=  
he same (I think col j)  
  
I’ll read the code for cross this weekend at some pt. It’s quite late for me=  
 :-)

---

<div class="post-metadata">

### Author: ![trieder](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@trieder](https://forum.kx.com/u/trieder)
#### Post date: [January 14, 2012, 7:45am UTC](https://forum.kx.com/t/re-personal-kdb-learning-each-off-topic/7536/7 "2012-01-14T07:45:00Z")

</div>

charset=us-ascii  
X-Mailer: iPhone Mail (9A405)  
In-Reply-To:   
Message-Id: \<56014890-97FC-41E6-AF89-08215E59C48C@gmail.com\>  
Date: Sat, 14 Jan 2012 02:45:57 -0500  
To: “[personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)”   
  
Mime-Version: 1.0 (1.0)  
  
One last thing: the way you executed taskset it only locks your q to those c=  
ores. You need to taskset every other process on the box so they don’t run o=  
n the same cores as q.

---

<div class="post-metadata">

### Author: ![effbiae](https://avatars.discourse-cdn.com/v4/letter/e/ecae2f/32.png) [@effbiae](https://forum.kx.com/u/effbiae)
#### Post date: [January 15, 2012, 4:28am UTC](https://forum.kx.com/t/re-personal-kdb-learning-each-off-topic/7536/8 "2012-01-15T04:28:00Z")

</div>

you might have thought my numbers were odd - i got them running on a Pentiu=  
m M.

running on a core2duo (64bit):

q)\   
a:!4000  
\t do[3;a,/::a]  
5519  
\t do[3;.q.cross[a;a]]  
6317  
\t do[3;,/a,/::a]  
7626

so it’s more expensive to use ,/a,/::a instead of .q.cross

but if you don’t need to raze a,/::a, then this appears faster.

annoyingly, i can’t define:  
X:{x,/::y}  
a:!3

and then use X:  
a X a  
'type

so i have to write something like X[a]a, which is just not as nice as  
being able to use infix cross: a cross a .

X:{x,/::y}  
a:!3  
a X a  
'type

---

<div class="post-metadata">

### Author: ![trieder](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@trieder](https://forum.kx.com/u/trieder)
#### Post date: [January 15, 2012, 5:16am UTC](https://forum.kx.com/t/re-personal-kdb-learning-each-off-topic/7536/9 "2012-01-15T05:16:00Z")

</div>

If you put it in the .q namespace you can execute infix. It’s not recommend to put things in there though.

q).q.X:{x,/::y}

q)a X a

0 0 0 1 0 2

1 0 1 1 1 2

2 0 2 1 2 2
