Skip to content

Commit 2843ffd

Browse files
committed
Remove lnspace, add support for int types in linspace
1 parent 6f93e38 commit 2843ffd

File tree

1 file changed

+34
-51
lines changed

1 file changed

+34
-51
lines changed

src/stdlib_math.fypp

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#:include "common.fypp"
22
#: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
35

46
module stdlib_math
57
use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp
68

79
implicit none
810
private
9-
public :: clip, linspace, logspace, lnspace, EULERS_NUMBER_DP, EULERS_NUMBER_SP
11+
public :: clip, linspace, logspace, EULERS_NUMBER_DP, EULERS_NUMBER_SP
1012

1113
integer, parameter :: DEFAULT_LINSPACE_LENGTH = 100
1214
integer, parameter :: DEFAULT_LOGSPACE_LENGTH = 50
@@ -29,7 +31,7 @@ module stdlib_math
2931
!! Create rank 1 array of linearly spaced elements
3032
!! If the number of elements is not specified, create an array with size 100. If n is a negative value,
3133
!! 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
3335
#:set RName = rname("linspace_default", 1, t1, k1)
3436
module function ${RName}$(start, end) result(res)
3537
${t1}$, intent(in) :: start
@@ -39,7 +41,7 @@ module stdlib_math
3941
end function ${RName}$
4042
#:endfor
4143

42-
#:for k1, t1 in REAL_KINDS_TYPES
44+
#:for k1, t1 in RC_KINDS_TYPES
4345
#:set RName = rname("linspace_n", 1, t1, k1)
4446
module function ${RName}$(start, end, n) result(res)
4547
${t1}$, intent(in) :: start
@@ -50,25 +52,32 @@ module stdlib_math
5052
end function ${RName}$
5153
#:endfor
5254

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)
5665
module function ${RName}$(start, end) result(res)
5766
${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)
6170
end function ${RName}$
6271
#: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)
6675
module function ${RName}$(start, end, n) result(res)
6776
${t1}$, intent(in) :: start
68-
${t1}$, intent(in) :: end
77+
${t1}$, intent(in) :: end
6978
integer, intent(in) :: n
70-
71-
${t1}$ :: res(n)
79+
80+
real(dp) :: res(n)
7281
end function ${RName}$
7382
#:endfor
7483

@@ -108,52 +117,26 @@ module stdlib_math
108117
#:for k2, t2 in IR_KINDS_TYPES
109118
#! k2, t2 correspond to the kind/type of the base that is passed
110119
#: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+
#! ================================================================ !#
113125
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]
114128
${t1}$, intent(in) :: start
115129
${t1}$, intent(in) :: end
116130
integer, intent(in) :: n
117131
${t2}$, intent(in) :: base
118132

119133
${t1}$ :: res(n)
134+
120135
end function ${RName}$
136+
#:endfor
121137
#: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-
156138

139+
end interface
157140

158141
contains
159142

0 commit comments

Comments
 (0)