-
Notifications
You must be signed in to change notification settings - Fork 1
/
vector_blas.t
61 lines (48 loc) · 1.74 KB
/
vector_blas.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
import "terraform"
local blas = require("blas")
local concepts = require("concepts")
local err = require("assert")
local Integral = concepts.Integral
local BLASNumber = concepts.BLASNumber
local function BLASVectorBase(V)
local T = V.eltype
local BLASVector = concepts.BLASVector(T)
local Number = concepts.Number
assert(BLASVector(V),
"Type " .. tostring(V) .. " does not implement the BLASVector interface")
terraform V:copy(x : &X) where {X : BLASVector}
var ny, ydata, incy = self:getblasinfo()
var nx, xdata, incx = x:getblasinfo()
err.assert(ny == nx)
blas.copy(ny, xdata, incx, ydata, incy)
end
terraform V:swap(x : &X) where {X : BLASVector}
var ny, ydata, incy = self:getblasinfo()
var nx, xdata, incx = x:getblasinfo()
err.assert(ny == nx)
blas.swap(ny, xdata, incx, ydata, incy)
end
terraform V:scal(a : S) where {S : Number}
var ny, ydata, incy = self:getblasinfo()
blas.scal(ny, a, ydata, incy)
end
terraform V:axpy(a : S, x : &X) where {S : Number, X : BLASVector}
var ny, ydata, incy = self:getblasinfo()
var nx, xdata, incx = x:getblasinfo()
err.assert(ny == nx)
blas.axpy(ny, a, xdata, incx, ydata, incy)
end
terraform V:dot(x : &X) where {X : BLASVector}
var ny, ydata, incy = self:getblasinfo()
var nx, xdata, incx = x:getblasinfo()
err.assert(ny == nx)
return blas.dot(ny, xdata, incx, ydata, incy)
end
end
return {
BLASVectorBase = BLASVectorBase
}