Skip to content

Commit 777f15c

Browse files
authored
Merge pull request #1 from numericalalgorithmsgroup/master
merging from upstream
2 parents 1fbb3e6 + 1afe071 commit 777f15c

File tree

3 files changed

+66
-43
lines changed

3 files changed

+66
-43
lines changed

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
install:
2-
- sudo apt-get install -y pandoc
2+
# The version of pandoc that ships with Ubuntu at the time of writing doesn't have the --metadata-file switch
3+
- wget https://github.com/jgm/pandoc/releases/download/2.7.1/pandoc-2.7.1-1-amd64.deb
4+
- sudo dpkg -i pandoc-2.7.1-1-amd64.deb
35
- sudo apt-get install -y texlive-latex-base
46
- sudo apt-get install -y texlive-latex-recommended
57
- sudo apt-get install -y texlive-fonts-recommended
68

79
script:
810
"pandoc --metadata-file=./pandoc_latex.yml Readme.md -o Readme.pdf"
11+
12+
deploy:
13+
provider: pages
14+
skip-cleanup: true
15+
github-token: $ghtok # Set in the settings page of your repository, as a secure variable
16+
keep-history: true
17+
on:
18+
branch: master

Readme.md

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
# Using the NAG Library for Python witk Kdb+ and PyQ
1+
# Using the NAG Library for Python with Kdb+ and PyQ
22

3-
Christopher Brandt <br>
4-
Numerical Algorithms Group (NAG), Inc. <br>
5-
Lisle, IL, USA <br>
6-
April 3, 2019
3+
Christopher Brandt, Numerical Algorithms Group Inc.
74

85
## 1 Background
96

10-
This paper provides detailed instructions on how to use the [NAG Library for *Python*](https://www.nag.co.uk/numeric/py/nagdoc_latest/index.html) with [kdb+](https://kx.com/) and [PyQ](https://code.kx.com/q/interfaces/pyq/). The NAG Library contains more than 1,700 mathematical and statistical routines, and is accessible by numerous programming languages (including Python, C++, Java, Fortran, etc.). PyQ is an extension to kdb+ featuring zero-copy sharing of data between Python and the q programming language. The enclosed examples will illustrate how to access routines within the NAG Library for *Python* using data stored in kdb+.
7+
This paper provides detailed instructions on how to use the [NAG Library for *Python*](https://www.nag.com/numeric/py/nagdoc_latest/index.html) with [kdb+](https://code.kx.com/v2/) and [PyQ](https://code.kx.com/q/interfaces/pyq/). The NAG Library contains more than 1,800 mathematical and statistical routines, and is accessible by numerous programming languages (including Python, C++, Java, Fortran, etc.). PyQ is an extension to kdb+ featuring zero-copy sharing of data between Python and the q programming language. The enclosed examples will illustrate how to access routines within the NAG Library for *Python* using data stored in kdb+.
118

129
## 2 Setting Up the Workspace
1310

@@ -16,23 +13,24 @@ Installation for both the NAG Library for *Python* and the PyQ extension to kdb+
1613
To install the NAG Library for *Python*:
1714

1815
```
19-
$ python -m pip install --extra-index-url https:nag/com/downloads/py/naginterfaces_nag naginterfaces
16+
$ python -m pip install --extra-index-url
17+
https:nag/com/downloads/py/naginterfaces_nag naginterfaces
2018
```
2119
To install PyQ from Kx:
2220
```
2321
$ python -m pip install pyq
2422
```
25-
Both the NAG Library for *Python* and kdb+ are commercial software packages that require active licenses for their respective usage. To obtain a temporary license for the NAG Library for Python, please contact NAG support at [support@nag.com](mailto:support@nag.com).
23+
Both the NAG Library for *Python* and kdb+ are commercial software packages that require active licenses for their respective usage. To obtain a temporary license for the NAG Library for *Python*, please contact NAG support at [support@nag.com](mailto:support@nag.com).
2624

2725
## 3 Examples
2826

29-
The following three examples demonstrate how to call the NAG Library for *Python* routines using kdb+ and PyQ. These examples were carefully selected, as they cover techniques found in the majority of usage cases a customer will encounter across all 1,700+ routines within the library. If your usage case falls outside of these three examples, please contact [NAG support](mailto:support@nag.com) for assistance.
27+
The following three examples demonstrate how to call the NAG Library for *Python* routines using kdb+ and PyQ. These examples were carefully selected, as they cover techniques found in the majority of usage cases a customer will encounter across all 1,800+ routines within the Library. If your usage case falls outside of these three examples, please contact [NAG support](mailto:support@nag.com) for assistance.
3028

3129
### 3.1 Example One: BLAS Routine DAXPY
3230

3331
Our first example demonstrates how to perform the linear algebra operation
3432

35-
$$ y \coloneqq \alpha x + b $$
33+
$$ y \coloneqq \alpha x + b. $$
3634

3735
Below is the NAG Library for *Python* signature for this routine.
3836

@@ -46,26 +44,26 @@ Below is the NAG Library for *Python* signature for this routine.
4644
Returns: y: float, ndarray, shape(n)
4745
```
4846

49-
Within our terminal, we begin by starting a PyQ interaction session.
47+
Within our terminal, we begin by initiating a PyQ interactive session.
5048

5149
```
5250
$ pyq
5351
```
5452

55-
Next, we import PyQ and the NAG Library for *Python*.
53+
Next, we import PyQ and the BLAS module of the NAG Library for *Python*.
5654

5755
```
5856
>>> from pyq import q
5957
>>> from naginterfaces.library import blas
6058
```
6159

62-
We then enter a q environment and define our parameers as q objects.
60+
We then enter a q environment and define our parameters as q objects.
6361

6462
```
6563
>>> q()
6664
q) alpha:0.5f
67-
q) x:(2.0, 2.0, 2.0, 2.0f)
68-
q) y:(4.0, 4.0, 4.0, 4.0f)
65+
q) x:4#2 2 2 2f
66+
q) y:4#4 4 4 4f
6967
```
7068

7169
Finally, we exit the q environment and invoke the NAG routine.
@@ -87,10 +85,11 @@ where $W$ is a diagonal matrix of weights.
8785
The NAG Library for *Python* signature for this routine is below.
8886

8987
```
90-
naginterfaces.library.correg.bounded(g,opt,alpha=None,w=None,errtol=0.0,maxits=0,maxit=200)
88+
naginterfaces.library.correg.corrmat_nearest_bounded(
89+
g,opt,alpha=None,w=None,errtol=0.0,maxits=0,maxit=200)
9190
9291
Parameters: g: float, array-like, shape(n,n)
93-
opt:str, length 1
92+
opt: str, length 1
9493
alpha: None or float, optional
9594
w: None or float, array-like, shape(n), optional
9695
errtol: float, optional
@@ -103,31 +102,36 @@ Returns: x: float, ndarray, shape(n,n)
103102
nrmgrd: float
104103
```
105104

106-
Within our interactive PyQ session, we again begin by entering a q environment and defining our parameters as q objects.
105+
Within our interactive PyQ session, we begin by importing the Correlation and Regression Analysis module of the NAG Library for *Python*.
106+
107+
```
108+
>>> from naginterfaces.library import correg
109+
```
110+
111+
Next, we enter a q environment and define our parameters as q objects.
107112

108113
```
109114
>>> q()
110115
q) alpha:0.5f
111-
q) x:(2.0, 2.0, 2.0, 2.0f)
112-
q) g:(2.0, -1.0, 0.0, 0.0f; -1.0, 2.0, -1.0, 0.0f;
113-
0.0, -1.0, 2.0, -1.0f; 0.0, 0.0, -1.0, 2.0f)
116+
q) x:4#2 2 2 2f
117+
q) g:4 4#2 -1 0 0 -1 2 -1 0 0 -1 2 -1 0 0 -1 2f
114118
q) opt:”B”
115-
q) alpha = 0.02f
116-
q) w:(100.0, 20.0, 20.0, 20.0f)
119+
q) alpha:0.02f
120+
q) w:4#100 20 20 20f
117121
```
118122

119123
We then exit the q environment and invoke the NAG routine.
120124

121125
```
122126
q) \
123-
>>> x = correg.corrmat_nearest_bounded(q.g, str(q.opt),
124-
float(q.alpha), q.w)
127+
>>> x, feval, itera, nrmgrd = correg.corrmat_nearest_bounded(
128+
q.g, str(q.opt), float(q.alpha), q.w)
125129
>>> x # display solution
126130
```
127131

128132
### 3.3 Example Three: Numerical Integration
129133

130-
With our final example, we demonstrate how to incorporate a user-defined callback function with a NAG Library for *Python* routine. This example approximates the definite integal
134+
With our final example, we demonstrate how to incorporate a user-defined callback function with a NAG Library for *Python* routine. This example approximates the definite integral
131135

132136
$$ \int_{a}^{b} f(x) dx. $$
133137

@@ -150,47 +154,53 @@ Returns: result: float
150154
abserr: float
151155
```
152156

153-
We start by entering a q environment and defining our parameters as q objects.
157+
We start by importing the Quadrature module of the NAG Library for *Python*.
158+
159+
```
160+
>>> from naginterfaces.library import quad
161+
```
162+
163+
Next, we enter a q environment and define our parameters as q objects.
154164

155165
```
156166
>>> q()
157-
q) a:0.0f
158-
q) b:2.0f
159-
q) epsabs:0.0f
167+
q) a:0f
168+
q) b:2f
169+
q) epsabs:0f
160170
q) epsrel:0.0001f
161171
```
162172

163-
Next, we exit the q environment and define an integrable Python function. To satisfy this parameter we may use either a Python function or a lambda expression.
173+
We then exit the q environment and define an integrable Python function. To satisfy this parameter we may use either a Python function or a lambda expression.
164174

165175
```
166176
q) \
167-
>>> f(x):
168-
... return x*x
177+
>>> def f(x):
178+
return x*x
169179
...
170180
```
171181

172-
With our problem now fully defined, we invoke the NAG Library routine to compute our solution.
182+
With our problem now fully defined, we invoke the NAG routine to compute our solution.
173183

174184
```
175-
>>> result, error = quad.dim1_fin_smooth(f,float(q.a),float(q.b),
176-
float(q.epsabs),float(q.epsrel))
185+
>>> result, error = quad.dim1_fin_smooth(
186+
f, float(q.a), float(q.b), float(q.epsabs), float(q.epsrel))
177187
>>> result # 2.6666666666666667
178188
>>> error # 1.4802973661668755e-14
179189
```
180190

181191
## 4 Additional Usage Cases
182192

183-
NAG recently published the technical report [Using the NAG Library with Kdb+ in a Pure Q Environment](https://www.nag.com/doc/techrep/pdf/tr1_18.pdf) discussing how to call the NAG Library using the new Foreign Function Interface (FFI) from Kx.
184-
185-
Additionally, the NAG Blog titled [Calling the NAG C Library from Kdb+](http://blog.nag.com/2013/05/calling-nag-c-library-from-kdb.html) details how to incorporate the NAG Library with kdb+ within a C++ program. We speculate that among our shared clients, a mixture of these methods will be employed.
193+
NAG recently published the technical report [Using the NAG Library with Kdb+ in a Pure Q Environment](https://www.nag.com/doc/techrep/pdf/tr1_18.pdf) discussing how to call the NAG Library using the new [Foreign Function Interface (FFI)](https://code.kx.com/q/interfaces/ffi/) from Kx. Additionally, the NAG Blog titled [Calling the NAG C Library from Kdb+](http://blog.nag.com/2013/05/calling-nag-c-library-from-kdb.html) details how to incorporate the NAG Library with kdb+ within a C++ program. We speculate that among our shared clients, a mixture of these methods will be employed.
186194

187-
If your desired usage case happens to fall outside of those described within our current publications, please contact NAG support at support@nag.com for asisstance with your application.
195+
If your desired usage case happens to fall outside of those described within our current publications, please contact NAG support at support@nag.com for assistance with your application.
188196

189197
## 5 Links
190198

199+
* NAG Library for *Python* Manual [https://www.nag.com/numeric/py/nagdoc_latest/index.html](https://www.nag.com/numeric/py/nagdoc_latest/index.html)
200+
* Get Going with Kdb+ [https://code.kx.com/v2/](https://code.kx.com/v2/)
191201
* Using Python with kdb+ (PyQ) [https://code.kx.com/q/interfaces/pyq/](https://code.kx.com/q/interfaces/pyq/)
192-
* Kdb+ and Python: embedPy and PyQ [https://kx.com/blog/kdb-python-embedpy-pyq/]([https://kx.com/blog/kdb-python-embedpy-pyq/)
202+
* Kdb+ and Python: embedPy and PyQ [https://kx.com/blog/kdb-python-embedpy-pyq/](https://kx.com/blog/kdb-python-embedpy-pyq/)
193203
* Using the NAG Library with Kdb+ in a Pure Q Environment [https://www.nag.com/doc/techrep/pdf/tr1_18.pdf](https://www.nag.com/doc/techrep/pdf/tr1_18.pdf)
204+
* Using Foreign Functions with Kdb+ (FFI) [https://code.kx.com/q/interfaces/ffi/](https://code.kx.com/q/interfaces/ffi/)
194205
* Calling the NAG C Library from Kdb+ [http://blog.nag.com/2013/05/calling-nag-c-library-from-kdb.html](http://blog.nag.com/2013/05/calling-nag-c-library-from-kdb.html)
195-
* NAG Library for Python Manual [https://www.nag.com/numeric/py/nagdoc_latest/index.html](https://www.nag.com/numeric/py/nagdoc_latest/index.html)
196206
* NAG GitHub Organisation [https://github.com/numericalalgorithmsgroup/](https://github.com/numericalalgorithmsgroup/)

pandoc_latex.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
22
header-includes: |
33
\usepackage{mathtools}
4+
\hypersetup{colorlinks=false,
5+
allbordercolors={0 0 0},
6+
pdfborderstyle={/S/U/W 1}}
47
---

0 commit comments

Comments
 (0)