Skip to content

Commit bac5e86

Browse files
committed
Update arange func and doc:
1. `merge` -> `optval` inside. 2. `by` -> `step` argument name.
1 parent 3c7cf65 commit bac5e86

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

doc/specs/stdlib_math.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,15 @@ Pure function.
287287

288288
### Description
289289

290-
Create a vector of the `integer/real` type with given fixed spaced values within a given interval.
290+
Create a one-dimensional `array` of the `integer/real` type with fixed-spaced values of given spacing, within a given interval.
291291

292292
#### Note
293293

294294
Because of the `i` (`huge(integer :: i) = 2147483647`) index inside the `arange` function , the dimensional maximum length of array created by the `arange` function is `2147483647`.
295295

296296
### Syntax
297297

298-
`result = [[stdlib_math(module):arange(interface)]](start [, end, by])`
298+
`result = [[stdlib_math(module):arange(interface)]](start [, end, step])`
299299

300300
### Arguments
301301

@@ -309,20 +309,20 @@ The default `start` value is `1`.
309309
This is an `intent(in)` and `optional` argument.
310310
The default `end` value is the inputted `start` value.
311311

312-
`by`: Shall be an `integer/real` scalar and large than `0`.
312+
`step`: Shall be an `integer/real` scalar and large than `0`.
313313
This is an `intent(in)` and `optional` argument.
314-
The default `by` value is `1`.
314+
The default `step` value is `1`.
315315

316316
#### Warning
317-
If `by = 0`, the `by` argument will be corrected to `1/1.0` by the internal process of the `arange` function.
318-
If `by < 0`, the `by` argument will be corrected to `abs(by)` by the internal process of the `arange` function.
317+
If `step = 0`, the `step` argument will be corrected to `1/1.0` by the internal process of the `arange` function.
318+
If `step < 0`, the `step` argument will be corrected to `abs(by)` by the internal process of the `arange` function.
319319

320320
### Return value
321321

322-
Return a vector of fixed spaced spaced values.
322+
Return a one-dimensional `array` of fixed-spaced values.
323323

324-
For `integer` type arguments, the length of the result vector is `(end - start)/by + 1`.
325-
For `real` type arguments, the length of the result vector is `floor((end - start)/by) + 1`.
324+
For `integer` type arguments, the length of the result vector is `(end - start)/step + 1`.
325+
For `real` type arguments, the length of the result vector is `floor((end - start)/step) + 1`.
326326

327327
### Example
328328

src/Makefile.manual

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ stdlib_string_type.o: stdlib_ascii.o \
150150
stdlib_strings.o: stdlib_ascii.o \
151151
stdlib_string_type.o \
152152
stdlib_optval.o
153-
stdlib_math.o: stdlib_kinds.o
153+
stdlib_math.o: stdlib_kinds.o \
154+
stdlib_optval.o
154155
stdlib_math_linspace.o: \
155156
stdlib_math.o
156157
stdlib_math_logspace.o: \
157158
stdlib_math_linspace.o
158159
stdlib_math_arange.o: \
159-
stdlib_math.o \
160-
stdlib_kinds.o
160+
stdlib_math.o
161161
stdlib_linalg_outer_product.o: stdlib_linalg.o

src/stdlib_math.fypp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module stdlib_math
66
use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp
7+
use stdlib_optval, only: optval
78

89
implicit none
910
private
@@ -264,15 +265,15 @@ module stdlib_math
264265

265266
!> Version: experimental
266267
!>
267-
!> `arange` creates a vector of the `integer/real` type
268-
!> with evenly spaced values within a given interval.
268+
!> `arange` creates a one-dimensional `array` of the `integer/real` type
269+
!> with fixed-spaced values of given spacing, within a given interval.
269270
!> ([Specification](../page/specs/stdlib_math.html#arange))
270271
interface arange
271272
#:set RI_KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES
272273
#:for k1, t1 in RI_KINDS_TYPES
273-
pure module function arange_${t1[0]}$_${k1}$(start, end, by) result(result)
274+
pure module function arange_${t1[0]}$_${k1}$(start, end, step) result(result)
274275
${t1}$, intent(in) :: start
275-
${t1}$, intent(in), optional :: end, by
276+
${t1}$, intent(in), optional :: end, step
276277
${t1}$, allocatable :: result(:)
277278
end function arange_${t1[0]}$_${k1}$
278279
#:endfor

src/stdlib_math_arange.fypp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,47 @@ contains
66
#:for k1, t1 in REAL_KINDS_TYPES
77
!> `arange` creates a vector of the `${t1}$` type
88
!> with evenly spaced values within a given interval.
9-
pure module function arange_${t1[0]}$_${k1}$(start, end, by) result(result)
9+
pure module function arange_${t1[0]}$_${k1}$(start, end, step) result(result)
1010

1111
${t1}$, intent(in) :: start
12-
${t1}$, intent(in), optional :: end, by
12+
${t1}$, intent(in), optional :: end, step
1313
${t1}$, allocatable :: result(:)
1414

15-
${t1}$ :: start_, end_, by_
15+
${t1}$ :: start_, end_, step_
1616
integer :: i
1717

1818
start_ = merge(start, 1.0_${k1}$, present(end))
19-
end_ = merge(end, start, present(end))
20-
by_ = sign(merge(merge(by, 1.0_${k1}$, by /= 0.0_${k1}$), &
21-
1.0_${k1}$, present(by)), end_ - start_)
19+
end_ = optval(end, start)
20+
step_ = optval(step, 1.0_${k1}$)
21+
step_ = sign(merge(step_, 1.0_${k1}$, step_ /= 0.0_${k1}$), end_ - start_)
2222

23-
allocate(result(floor((end_ - start_)/by_) + 1))
23+
allocate(result(floor((end_ - start_)/step_) + 1))
2424

25-
result = [(start_ + (i - 1)*by_, i=1, size(result), 1)]
25+
result = [(start_ + (i - 1)*step_, i=1, size(result), 1)]
2626

2727
end function arange_${t1[0]}$_${k1}$
2828
#:endfor
2929

3030
#:for k1, t1 in INT_KINDS_TYPES
3131
!> `arange` creates a vector of the `${t1}$` type
3232
!> with evenly spaced values within a given interval.
33-
pure module function arange_${t1[0]}$_${k1}$(start, end, by) result(result)
33+
pure module function arange_${t1[0]}$_${k1}$(start, end, step) result(result)
3434

3535
${t1}$, intent(in) :: start
36-
${t1}$, intent(in), optional :: end, by
36+
${t1}$, intent(in), optional :: end, step
3737
${t1}$, allocatable :: result(:)
3838

39-
${t1}$ :: start_, end_, by_
39+
${t1}$ :: start_, end_, step_
4040
${t1}$ :: i
4141

4242
start_ = merge(start, 1_${k1}$, present(end))
43-
end_ = merge(end, start, present(end))
44-
by_ = sign(merge(merge(by, 1_${k1}$, by /= 0_${k1}$), &
45-
1_${k1}$, present(by) ), end_ - start_)
43+
end_ = optval(end, start)
44+
step_ = optval(step, 1_${k1}$)
45+
step_ = sign(merge(step_, 1_${k1}$, step_ /= 0_${k1}$), end_ - start_)
4646

47-
allocate(result((end_ - start_)/by_ + 1))
47+
allocate(result((end_ - start_)/step_ + 1))
4848

49-
result = [(i, i=start_, end_, by_)]
49+
result = [(i, i=start_, end_, step_)]
5050

5151
end function arange_${t1[0]}$_${k1}$
5252
#:endfor

0 commit comments

Comments
 (0)