-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathstdlib_math_logspace.fypp
105 lines (93 loc) · 3.58 KB
/
stdlib_math_logspace.fypp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#:include "common.fypp"
#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES
submodule (stdlib_math) stdlib_math_logspace
implicit none
contains
#!=========================================================
#!= logspace(start, end) =
#!=========================================================
#:for k1, t1 in RC_KINDS_TYPES
#:set RName = rname("logspace", 1, t1, k1, "default")
module procedure ${RName}$
res = logspace(start, end, DEFAULT_LOGSPACE_LENGTH, real(DEFAULT_LOGSPACE_BASE, ${k1}$))
end procedure
#:endfor
#! Integer support
#:set RName = rname("logspace", 1, "integer(int32)", "int32", "default")
module procedure ${RName}$
res = logspace(start, end, DEFAULT_LOGSPACE_LENGTH, DEFAULT_LOGSPACE_BASE)
end procedure
#!=========================================================
#!= logspace(start, end, n) =
#!=========================================================
#:for k1, t1 in RC_KINDS_TYPES
#:set RName = rname("logspace", 1, t1, k1, "n")
module procedure ${RName}$
res = logspace(start, end, n, real(DEFAULT_LOGSPACE_BASE, ${k1}$))
end procedure
#:endfor
#! Integer support
#:set RName = rname("logspace", 1, "integer(int32)", "int32", "n")
module procedure ${RName}$
res = logspace(start, end, n, DEFAULT_LOGSPACE_BASE)
end procedure
#!=========================================================
#!= logspace(start, end, n, base) =
#!=========================================================
#:for k1, t1 in RC_KINDS_TYPES
#:set RName = rname("logspace", 1, t1, k1, "n_rbase")
module procedure ${RName}$
${t1}$ :: exponents(max(n, 0))
exponents = linspace(start, end, n)
#: if t1[0] == 'r'
res = base ** exponents
#: else
res = cmplx(base, kind=${k1}$) ** cmplx(exponents, kind=${k1}$)
#: endif
end procedure
#:set RName = rname("logspace", 1, t1, k1, "n_cbase")
module procedure ${RName}$
${t1}$ :: exponents(max(n, 0))
exponents = linspace(start, end, n)
#: if t1[0] == 'r'
res = real(base ** cmplx(exponents, kind=${k1}$))
#: else
res = base ** cmplx(exponents, kind=${k1}$)
#: endif
end procedure
#:set RName = rname("logspace", 1, t1, k1, "n_ibase")
module procedure ${RName}$
${t1}$ :: exponents(max(n, 0))
exponents = linspace(start, end, n)
#: if t1[0] == 'r'
res = base ** exponents
#: else
res = cmplx(base, kind=${k1}$) ** cmplx(exponents, kind=${k1}$)
#: endif
end procedure
#:endfor
#! Integer support:
! Generate logarithmically spaced sequence from ${k1}$ base to the powers
! of ${k1}$ start and end. [base^start, ... , base^end]
! RName = ${RName}$
#:for k1 in REAL_KINDS
#:set RName = rname("logspace", 1, "integer(int32)", "int32", "n_r" + str(k1) + "base")
module procedure ${RName}$
integer :: exponents(max(n, 0))
exponents = linspace(start, end, n)
res = base ** exponents
end procedure
#:set RName = rname("logspace", 1, "integer(int32)", "int32", "n_c" + str(k1) + "base")
module procedure ${RName}$
integer :: exponents(max(n, 0))
exponents = linspace(start, end, n)
res = base ** exponents
end procedure
#:endfor
#:set RName = rname("logspace", 1, "integer(int32)", "int32", "n_ibase")
module procedure ${RName}$
integer :: exponents(max(n, 0))
exponents = linspace(start, end, n)
res = base ** exponents
end procedure
end submodule