Skip to content

[stdlib_math] Add arange function. #480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve arange func and doc.
  • Loading branch information
zoziha committed Aug 4, 2021
commit 3c7cf6546ba4f90f9b3b4d709e325a619cd23ee4
15 changes: 11 additions & 4 deletions doc/specs/stdlib_math.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ program demo_logspace_rstart_cbase

end program demo_logspace_rstart_cbase
```
## `arange` - Create a vector of the `integer/real` type with evenly spaced values within a given interval.
## `arange`

### Status

Expand All @@ -287,14 +287,20 @@ Pure function.

### Description

Create a vector of the `integer/real` type with evenly spaced values within a given interval.
Create a vector of the `integer/real` type with given fixed spaced values within a given interval.

#### Note

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`.

### Syntax

`result = [[stdlib_math(module):arange(interface)]](start [, end, by])`

### Arguments

All arguments should be the same type and kind.

`start`: Shall be an `integer/real` scalar.
This is an `intent(in)` argument.
The default `start` value is `1`.
Expand All @@ -313,8 +319,9 @@ If `by < 0`, the `by` argument will be corrected to `abs(by)` by the internal pr

### Return value

Return a vector of evenly spaced values.
Return a vector of fixed spaced spaced values.

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

### Example
Expand All @@ -331,7 +338,7 @@ program demo_math_arange

print *, arange(3.0) !! [1.0,2.0,3.0]
print *, arange(0.0,5.0) !! [0.0,1.0,2.0,3.0,4.0,5.0]
print *, arange(0.0,5.0,2.0) !! [0.0,2.0,4.0]
print *, arange(0.0,6.0,2.5) !! [0.0,2.5,5.0]

print *, (1.0,1.0)*arange(3) !! [(1.0,1.0),(2.0,2.0),[3.0,3.0]]

Expand Down
4 changes: 1 addition & 3 deletions src/stdlib_math.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ module stdlib_math
!>
!> `arange` creates a vector of the `integer/real` type
!> with evenly spaced values within a given interval.
!> ([Specification](../page/specs/stdlib_math.html#
!>arange-create-a-vector-of-the-integerreal-type-
!>with-evenly-spaced-values-within-a-given-interval))
!> ([Specification](../page/specs/stdlib_math.html#arange))
interface arange
#:set RI_KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES
#:for k1, t1 in RI_KINDS_TYPES
Expand Down
2 changes: 0 additions & 2 deletions src/stdlib_math_arange.fypp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#:include "common.fypp"
submodule(stdlib_math) stdlib_math_arange

implicit none

contains

#:for k1, t1 in REAL_KINDS_TYPES
Expand Down