Skip to content
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

First implementation of real-valued linspace. #420

Merged
merged 94 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
affa81a
Add linspace submodule to stdlib_stats
ejovo13 May 31, 2021
7d7a992
Verify that linspace generates the proper spread
ejovo13 May 31, 2021
415e79d
Add linspace and object dependencies
ejovo13 May 31, 2021
b42b4fc
libspace function source code
ejovo13 May 31, 2021
4db9cca
Add linspace to public api
ejovo13 May 31, 2021
3040135
Update test to include negative integer for elements requested
ejovo13 May 31, 2021
4257b4e
Fix manual dependency
ejovo13 May 31, 2021
87fde22
Add real conversions to integer arithmetic
ejovo13 May 31, 2021
3db3357
Refactor stdlib_stats_linspace -> stdlib_linalg_linspace;
ejovo13 May 31, 2021
6e42249
Make linspace public and add DEFAULT_LINSPACE_LENGTH parameter
ejovo13 May 31, 2021
b08ba8c
Fix whitespace indentation that I interrupted
ejovo13 May 31, 2021
48a619d
Refactor linspace manual dependencies
ejovo13 May 31, 2021
f997c59
Remove linspace public export
ejovo13 May 31, 2021
51c9b1d
Remove linspace from stdlib_linalg
ejovo13 May 31, 2021
9c57100
Refactor linspace interface to stdlib_math
ejovo13 May 31, 2021
acd695e
Remove linspace test from linalgebra folder
ejovo13 May 31, 2021
875a582
Add logspace and lnspace functions in stdlib_math
ejovo13 May 31, 2021
598287b
Modify function behvaior on input n = 1
ejovo13 May 31, 2021
f8dbe00
Fix printed function call
ejovo13 Jun 1, 2021
8b1e0ff
Fix manual object dependencies
ejovo13 Jun 2, 2021
8d12f5e
Add complex support for linspace function
ejovo13 Jun 2, 2021
46f17f6
Add single precision complex testing
ejovo13 Jun 2, 2021
d3a5154
Update src/stdlib_linalg.fypp
ejovo13 Jun 4, 2021
213b302
Update src/stdlib_linalg.fypp
ejovo13 Jun 4, 2021
dc47698
Update src/stdlib_linalg.fypp
ejovo13 Jun 4, 2021
37b6bea
Update src/stdlib_math_logspace.fypp
ejovo13 Jun 4, 2021
98f72d8
Update src/stdlib_stats.fypp
ejovo13 Jun 4, 2021
973bd3c
Change open unit option to newunit
ejovo13 Jun 4, 2021
c1dc924
Add lnspace and logspace tests to manual makefile
ejovo13 Jun 4, 2021
7fe8ebf
Update src/stdlib_math_lnspace.fypp
ejovo13 Jun 4, 2021
4284b60
Add linspace specs
ejovo13 Jun 6, 2021
501f360
Remove lnspace
ejovo13 Jun 6, 2021
6f93e38
Remove lnspace, add support for int types in linspace
ejovo13 Jun 6, 2021
2843ffd
Remove lnspace, add support for int types in linspace
ejovo13 Jun 6, 2021
b19d447
Add integer type tests to test_linspace.f90
ejovo13 Jun 6, 2021
3dd576f
Add specification link and remove unused variables
ejovo13 Jun 6, 2021
8f39ad5
Remove unused preprocessor variables
ejovo13 Jun 6, 2021
e62f3fc
Remove lnspace test from Makefile.manual
ejovo13 Jun 6, 2021
c62fc0f
Update src/stdlib_math.fypp
ejovo13 Jun 7, 2021
f15f028
Update doc/specs/stdlib_math.md
ejovo13 Jun 7, 2021
828fe9e
Update doc/specs/stdlib_math.md
ejovo13 Jun 7, 2021
f0246a0
Update doc/specs/stdlib_math.md
ejovo13 Jun 7, 2021
48e8682
Update doc/specs/stdlib_math.md
ejovo13 Jun 7, 2021
abe8dab
Update src/stdlib_math.fypp
ejovo13 Jun 7, 2021
9a57f56
Update src/stdlib_math.fypp
ejovo13 Jun 7, 2021
044c377
Made qp euler's number public
ejovo13 Jun 7, 2021
bff9948
Merge branch 'lin_log_space' of github.com:ejovo13/stdlib into lin_lo…
ejovo13 Jun 7, 2021
5705c89
Remove trailing white spaces
ejovo13 Jun 7, 2021
8e5a598
Edit linspace specs, start logspace specs
ejovo13 Jun 8, 2021
0123296
Expand logspace interface to complex values
ejovo13 Jun 8, 2021
d50e7d0
Merge branch 'master' into lin_log_space
ejovo13 Jul 10, 2021
59bdc5c
Remove double generator loop from interface and implementation
ejovo13 Jul 10, 2021
cf69f12
Kill double generator in implementation
ejovo13 Jul 10, 2021
db0f976
Remove redundant dependencies
ejovo13 Jul 11, 2021
718357e
Clean up obsolete generic logspace combinations
ejovo13 Jul 11, 2021
c490f83
Merge branch 'fortran-lang:master' into lin_log_space
ejovo13 Jul 11, 2021
fa76f6a
Remove obsolete fypp variable
ejovo13 Jul 11, 2021
ef38147
Complete support for integer start/endpoints
ejovo13 Jul 11, 2021
e3793e7
Fix euler's number precision allignment
ejovo13 Jul 11, 2021
078dbbb
Merge branch 'lin_log_space' of github.com:ejovo13/stdlib into lin_lo…
ejovo13 Jul 11, 2021
abf52e2
remove obsolete fypp variables
ejovo13 Jul 11, 2021
ecee7a7
https://github.com/fortran-lang/stdlib/pull/420/files#r667540472
ejovo13 Jul 11, 2021
4a890e0
Make DEFAULT_LINSPACE_PUBLIC for more robust testing
ejovo13 Jul 12, 2021
482791b
Revamp testing
ejovo13 Jul 12, 2021
4799aae
Add logspace spec links
ejovo13 Jul 12, 2021
66341b4
Clarify wording of specs
ejovo13 Jul 12, 2021
df0b73a
Make variables public for more rigorous testing
ejovo13 Jul 12, 2021
adbcab9
Invigorate testing procedures
ejovo13 Jul 12, 2021
269c0cc
Fix manual dependencies
ejovo13 Jul 12, 2021
6098d8c
Update doc/specs/stdlib_math.md
ejovo13 Jul 12, 2021
96ffcc1
Update doc/specs/stdlib_math.md
ejovo13 Jul 12, 2021
1b39346
Update doc/specs/stdlib_math.md
ejovo13 Jul 12, 2021
ad1f2ed
Update doc/specs/stdlib_math.md
ejovo13 Jul 12, 2021
347890a
Update doc/specs/stdlib_math.md
ejovo13 Jul 12, 2021
6167af7
Update doc/specs/stdlib_math.md
ejovo13 Jul 12, 2021
3b62495
Update doc/specs/stdlib_math.md
ejovo13 Jul 12, 2021
316e349
Update src/stdlib_math.fypp
ejovo13 Jul 12, 2021
f9a6623
Update src/tests/math/test_linspace.f90
ejovo13 Jul 12, 2021
e292347
Update src/tests/math/test_linspace.f90
ejovo13 Jul 12, 2021
905dc28
Update src/stdlib_math.fypp
ejovo13 Jul 12, 2021
4780d27
Update src/stdlib_math.fypp
ejovo13 Jul 12, 2021
9c4dcef
Update src/stdlib_math.fypp
ejovo13 Jul 12, 2021
efa82b2
Add more comprehensive documentation
ejovo13 Jul 12, 2021
d428ad8
Add appropriate tolerance level
ejovo13 Jul 12, 2021
dd4e935
Update src/stdlib_math.fypp
ejovo13 Jul 12, 2021
2caeab3
Update doc/specs/stdlib_math.md
ejovo13 Jul 14, 2021
105d92d
Update doc/specs/stdlib_math.md
ejovo13 Jul 14, 2021
17c81f8
Update doc/specs/stdlib_math.md
ejovo13 Jul 14, 2021
646bee8
Update doc/specs/stdlib_math.md
ejovo13 Jul 14, 2021
50a0242
Update doc/specs/stdlib_math.md
ejovo13 Jul 14, 2021
6e45165
Update src/stdlib_math.fypp
jvdp1 Jul 20, 2021
f9b2640
Update src/stdlib_math.fypp
jvdp1 Jul 20, 2021
5708e01
Merge branch 'fortran-lang:master' into lin_log_space
ejovo13 Jul 20, 2021
f51b67f
Clean up format statements
ejovo13 Jul 20, 2021
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
191 changes: 188 additions & 3 deletions doc/specs/stdlib_math.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ title: math

#### Description

Returns a value which lies in the given interval [`xmin`, `xmax`] (interval is `xmin` and `xmax` inclusive) and is closest to the input value `x`.
Returns a value which lies in the given interval [`xmin`, `xmax`] (interval is `xmin` and `xmax` inclusive) and is closest to the input value `x`.

#### Syntax

Expand All @@ -35,8 +35,8 @@ Elemental function.

#### Argument(s)

`x`: scalar of either `integer` or `real` type. This argument is `intent(in)`.
`xmin`: scalar of either `integer` or `real` type. This argument is `intent(in)`.
`x`: scalar of either `integer` or `real` type. This argument is `intent(in)`.
`xmin`: scalar of either `integer` or `real` type. This argument is `intent(in)`.
`xmax`: scalar of either `integer` or `real` type, which must be greater than or equal to `xmin`. This argument is `intent(in)`.

Note: All arguments must have same `type` and same `kind`.
Expand Down Expand Up @@ -90,3 +90,188 @@ program demo_clip_real
! clipped_value <- 3.02500010
end program demo_clip_real
```

### `linspace` - Create a linearly spaced rank one array

#### Description

Returns a linearly spaced rank 1 array from [`start`, `end`]. Optionally, you can specify the length of the returned array by passing `n`.
jvdp1 marked this conversation as resolved.
Show resolved Hide resolved

#### Syntax

`res = [[stdlib_math(module):linspace(interface)]] (start, end [, n])`

#### Status

Experimental

#### Class

Function.

#### Argument(s)

`start`: Shall be scalar of any numeric type or kind. This argument is `intent(in)`.
`end`: Shall be the same `type` and `kind` as `start`. This argument is `intent(in)`.
`n`: Shall be an integer specifying the length of the output. This argument is `optional` and `intent(in)`.

#### Output value or Result value

The output is a rank 1 array whose length is either 100 (default value) or `n`.

If `n` == 1, return a rank 1 array whose only element is `end`.
If `n` <= 0, return a rank 1 array with length 0.

If `start`/`end` are `real` or `complex` types, the `result` will be of the same type and kind as `start`/`end`.
If `start`/`end` are `integer` types, the `result` will default to a `real(dp)` array.

#### Examples

##### Example 1:

Here inputs are of type `complex` and kind `dp`
```fortran
program demo_linspace_complex
use stdlib_math, only: linspace
use stdlib_kinds, only: dp
implicit none

complex(dp) :: start = complex(10.0_dp, 5.0_dp)
complex(dp) :: end = complex(-10.0_dp, 15.0_dp)

complex(dp) :: z(11)

z = linspace(start, end, 11)
end program demo_linspace_complex
```

##### Example 2:

Here inputs are of type `integer` and kind `int16`, with the result defaulting to `real(dp)`.
```fortran
program demo_linspace_int16
use stdlib_math, only: linspace
use stdlib_kinds, only: int16, dp
implicit none

integer(int16) :: start = 10_int16
integer(int16) :: end = 23_int16

real(dp) :: r(15)

r = linspace(start, end, 15)
end program demo_linspace_int16
```

### `logspace` - Create a logarithmically spaced rank one array

#### Description

Returns a logarithmically spaced rank 1 array from [`base`^`start`, `base`^`end`]. The default size of the array is 50. Optionally, you can specify the length of the returned array by passing `n`. You can also specify the `base` used to compute the range (default 10).

#### Syntax

`res = [[stdlib_math(module):logspace(interface)]] (start, end [, n [, base]])`

#### Status

Experimental

#### Class

Function.

#### Argument(s)

`start`: Shall be a scalar of any numeric type. All kinds are supported for real and complex arguments. For integers, only the default kind is currently implemented. This argument is `intent(in)`.
`end`: Shall be the same `type` and `kind` as `start`. This argument is `intent(in)`.
`n`: Shall be an integer specifying the length of the output. This argument is `optional` and `intent(in)`.
`base` : Shall be a scalar of any numeric type. All kinds are supported for real and complex arguments. For integers, only the default kind is currently implemented. This argument is `optional` and `intent(in)`.

#### Output value or Result value

The output is a rank 1 array whose length is either 50 (default value) or `n`.

If `n` == 1, return a rank 1 array whose only element is `base`^`end`.
If `n` <= 0, return a rank 1 array with length 0

The `type` and `kind` of the output is dependent on the `type` and `kind` of the passed parameters.

For function calls where the `base` is not specified: `logspace(start, end)`/`logspace(start, end, n)`, the `type` and `kind` of
the output follows the same scheme as above for `linspace`.
>If `start`/`end` are `real` or `complex` types, the `result` will be the same type and kind as `start`/`end`.
>If `start`/`end` are integer types, the `result` will default to a `real(dp)` array.

For function calls where the `base` is specified, the `type` and `kind` of the result is in accordance with the following table:

| `start`/`end` | `n` | `base` | `output` |
| ------------- | --- | ------ | -------- |
| `real(KIND)` | `Integer` | `real(KIND)` | `real(KIND)` |
| " " | " " | `complex(KIND)` | `complex(KIND)` |
| " " | " " | `Integer` | `real(KIND)` |
| `complex(KIND)` | " " | `real(KIND)` | `complex(KIND)` |
| " " | " " | `complex(KIND)` | `complex(KIND)` |
| " " | " " | `Integer` | `complex(KIND)` |
| `Integer` | " " | `real(KIND)` | `real(KIND)` |
| " " | " " | `complex(KIND)` | `complex(KIND)` |
| " " | " " | `Integer` | `Integer` |

#### Examples

##### Example 1:

Here inputs are of type `complex` and kind `dp`. `n` and `base` is not specified and thus default to 50 and 10, respectively.
```fortran
program demo_logspace_complex
use stdlib_math, only: logspace
use stdlib_kinds, only: dp
implicit none

complex(dp) :: start = (10.0_dp, 5.0_dp)
complex(dp) :: end = (-10.0_dp, 15.0_dp)

complex(dp) :: z(11) ! Complex values raised to complex powers results in complex values

z = logspace(start, end, 11)
end program demo_logspace_complex
```

##### Example 2:

Here inputs are of type `integer` and default kind. `base` is not specified and thus defaults to 10.
```fortran
program demo_logspace_int
use stdlib_math, only: logspace
use stdlib_kinds, only: dp
implicit none

integer :: start = 10
integer :: end = 23
integer :: n = 15

real(dp) :: r(n) ! Integer values raised to real powers results in real values

r = logspace(start, end, n)
end program demo_logspace_int
```

##### Example 3:

Here `start`/`end` are of type `real` and double precision. `base` is type `complex` and also double precision.
```fortran
program demo_logspace_rstart_cbase
use stdlib_math, only: logspace
use stdlib_kinds, only: dp
implicit none

real(dp) :: start = 0.0_dp
real(dp) :: end = 3.0_dp
integer :: n = 4
complex(dp) :: base = (0.0_dp, 1.0_dp)

complex(dp) :: z(n) ! complex values raised to real powers result in complex values

z = logspace(start, end, n, base)

end program demo_logspace_rstart_cbase
```
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ set(fppFiles
stdlib_quadrature_simps.fypp
stdlib_stats_distribution_PRNG.fypp
stdlib_math.fypp
stdlib_math_linspace.fypp
stdlib_math_logspace.fypp
stdlib_string_type.fypp
)

Expand Down
7 changes: 7 additions & 0 deletions src/Makefile.manual
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ SRCFYPP =\
stdlib_stats_moment_scalar.fypp \
stdlib_stats_var.fypp \
stdlib_math.fypp \
stdlib_math_linspace.fypp \
stdlib_math_logspace.fypp \
stdlib_stats_distribution_PRNG.fypp \
stdlib_string_type.fypp

Expand Down Expand Up @@ -73,6 +75,7 @@ stdlib_error.o: stdlib_optval.o
stdlib_specialfunctions.o: stdlib_kinds.o
stdlib_specialfunctions_legendre.o: stdlib_kinds.o stdlib_specialfunctions.o
stdlib_io.o: \
stdlib_ascii.o \
stdlib_error.o \
stdlib_optval.o \
stdlib_kinds.o
Expand Down Expand Up @@ -141,4 +144,8 @@ stdlib_strings.o: stdlib_ascii.o \
stdlib_string_type.o \
stdlib_optval.o
stdlib_math.o: stdlib_kinds.o
stdlib_math_linspace.o: \
stdlib_math.o
stdlib_math_logspace.o: \
stdlib_math_linspace.o
stdlib_linalg_outer_product.o: stdlib_linalg.o
Loading