1
1
#:include "common.fypp"
2
2
#:set IR_KINDS_TYPES = INT_KINDS_TYPES + REAL_KINDS_TYPES
3
+ #:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES
4
+ ! #:set ICR_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES + INT_KINDS_TYPES
3
5
4
6
module stdlib_math
5
7
use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp
6
8
7
9
implicit none
8
10
private
9
- public :: clip, linspace, logspace, lnspace, EULERS_NUMBER_DP, EULERS_NUMBER_SP
11
+ public :: clip, linspace, logspace, EULERS_NUMBER_DP, EULERS_NUMBER_SP
10
12
11
13
integer, parameter :: DEFAULT_LINSPACE_LENGTH = 100
12
14
integer, parameter :: DEFAULT_LOGSPACE_LENGTH = 50
@@ -29,7 +31,7 @@ module stdlib_math
29
31
!! Create rank 1 array of linearly spaced elements
30
32
!! If the number of elements is not specified, create an array with size 100. If n is a negative value,
31
33
!! return an array with size 0. If n = 1, return end
32
- #:for k1, t1 in REAL_KINDS_TYPES
34
+ #:for k1, t1 in RC_KINDS_TYPES
33
35
#:set RName = rname("linspace_default", 1, t1, k1)
34
36
module function ${RName}$(start, end) result(res)
35
37
${t1}$, intent(in) :: start
@@ -39,7 +41,7 @@ module stdlib_math
39
41
end function ${RName}$
40
42
#:endfor
41
43
42
- #:for k1, t1 in REAL_KINDS_TYPES
44
+ #:for k1, t1 in RC_KINDS_TYPES
43
45
#:set RName = rname("linspace_n", 1, t1, k1)
44
46
module function ${RName}$(start, end, n) result(res)
45
47
${t1}$, intent(in) :: start
@@ -50,25 +52,32 @@ module stdlib_math
50
52
end function ${RName}$
51
53
#:endfor
52
54
53
- ! Add support for complex linspace
54
- #:for k1, t1 in CMPLX_KINDS_TYPES
55
- #:set RName = rname("clinspace_default", 1, t1, k1)
55
+
56
+ ! Add suport for integer linspace
57
+ !! Version: Experimental
58
+ !!
59
+ !! Create rank 1 array of linearly spaced elements from start to end.
60
+ !! If the number of elements is not specified, create an array with size 100. If n is a negative value,
61
+ !! return an array with size 0. If n = 1, return end. When dealing with integers as the `start` and `end`
62
+ !! paramaters, the return type is always a double precision real.
63
+ #:for k1, t1 in INT_KINDS_TYPES
64
+ #:set RName = rname("linspace_default", 1, t1, k1)
56
65
module function ${RName}$(start, end) result(res)
57
66
${t1}$, intent(in) :: start
58
- ${t1}$, intent(in) :: end
59
-
60
- ${t1}$ :: res(DEFAULT_LINSPACE_LENGTH)
67
+ ${t1}$, intent(in) :: end
68
+
69
+ real(dp) :: res(DEFAULT_LINSPACE_LENGTH)
61
70
end function ${RName}$
62
71
#:endfor
63
-
64
- #:for k1, t1 in CMPLX_KINDS_TYPES
65
- #:set RName = rname("clinspace_n ", 1, t1, k1)
72
+
73
+ #:for k1, t1 in INT_KINDS_TYPES
74
+ #:set RName = rname("linspace_n ", 1, t1, k1)
66
75
module function ${RName}$(start, end, n) result(res)
67
76
${t1}$, intent(in) :: start
68
- ${t1}$, intent(in) :: end
77
+ ${t1}$, intent(in) :: end
69
78
integer, intent(in) :: n
70
-
71
- ${t1}$ :: res(n)
79
+
80
+ real(dp) :: res(n)
72
81
end function ${RName}$
73
82
#:endfor
74
83
@@ -108,52 +117,26 @@ module stdlib_math
108
117
#:for k2, t2 in IR_KINDS_TYPES
109
118
#! k2, t2 correspond to the kind/type of the base that is passed
110
119
#:set RName = rname("logspace_n_base", 1, k1, k2)
111
- ! Need another function where base is not optional, otherwise the compiler can not differentiate between
112
- ! generic calls to logspace_n where a base is not present
120
+ #! ================================================================ !#
121
+ #! Need another function where base is not optional, otherwise the
122
+ #! compiler can not differentiate between
123
+ #! generic calls to logspace_n where a base is not present
124
+ #! ================================================================ !#
113
125
module function ${RName}$(start, end, n, base) result(res)
126
+ ! Generate logarithmically spaced sequence from ${k2}$ base to the powers
127
+ ! of ${k1}$ start and end. [base^start, ... , base^end]
114
128
${t1}$, intent(in) :: start
115
129
${t1}$, intent(in) :: end
116
130
integer, intent(in) :: n
117
131
${t2}$, intent(in) :: base
118
132
119
133
${t1}$ :: res(n)
134
+
120
135
end function ${RName}$
136
+ #:endfor
121
137
#:endfor
122
- #:endfor
123
- end interface
124
-
125
- interface lnspace
126
- !! Version: Experimental
127
- !!
128
- !! Create rank 1 array of **natural** logarithmically spaced elements from e**start to e**end.
129
- !! If the number of elements is not specified, create an array with size 50. If n is a negative value,
130
- !! return an array with size 0. If n = 1, return e**end.
131
- #:for k1, t1 in REAL_KINDS_TYPES
132
- #:set RName = rname("lnspace_default", 1, t1, k1)
133
- module function ${RName}$(start, end) result(res)
134
-
135
- ${t1}$, intent(in) :: start
136
- ${t1}$, intent(in) :: end
137
-
138
- ${t1}$ :: res(DEFAULT_LOGSPACE_LENGTH)
139
-
140
- end function ${RName}$
141
- #:endfor
142
-
143
- #:for k1, t1 in REAL_KINDS_TYPES
144
- #:set RName = rname("lnspace_n", 1, t1, k1)
145
- module function ${RName}$(start, end, n) result(res)
146
- ${t1}$, intent(in) :: start
147
- ${t1}$, intent(in) :: end
148
- integer, intent(in) :: n
149
-
150
- ${t1}$ :: res(n)
151
- end function ${RName}$
152
- #:endfor
153
-
154
- end interface
155
-
156
138
139
+ end interface
157
140
158
141
contains
159
142
0 commit comments