Skip to content

Commit 39297bd

Browse files
committed
Merge branch 'master' into revival_string_list
2 parents cea79e8 + 47d0a00 commit 39297bd

30 files changed

+756
-293
lines changed

CONTRIBUTORS.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Fortran stdlib developers
3+
Copyright (c) 2019-2021 stdlib contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ The following combinations are known to work, but they are not tested in the CI:
9898

9999
Name | Version | Platform | Architecture
100100
--- | --- | --- | ---
101-
GCC Fortran (MinGW) | 8.4.0, 9.3.0, 10.2.0 | Windows 10 | x86_64, i686
101+
GCC Fortran (MinGW) | 9.3.0, 10.2.0, 11.2.0 | Windows 10 | x86_64, i686
102102

103103
We try to test as many available compilers and platforms as possible.
104104
A list of tested compilers which are currently not working and the respective issue are listed below.

doc/specs/stdlib_ascii.md

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -212,42 +212,4 @@ program demo_reverse
212212
implicit none
213213
print'(a)', reverse("Hello, World!") ! returns "!dlroW ,olleH"
214214
end program demo_reverse
215-
```
216-
217-
### `to_string`
218-
219-
#### Status
220-
221-
Experimental
222-
223-
#### Description
224-
225-
Create a character string representing the value of the provided variable.
226-
227-
#### Syntax
228-
229-
`res = [[stdlib_ascii(module):to_string(interface)]] (string)`
230-
231-
#### Class
232-
233-
Pure function.
234-
235-
#### Argument
236-
237-
`val`: shall be an intrinsic integer or logical type. It is an `intent(in)` argument.
238-
239-
#### Result value
240-
241-
The result is an intrinsic character type.
242-
243-
#### Example
244-
245-
```fortran
246-
program demo_string_value
247-
use stdlib_ascii, only : to_string
248-
implicit none
249-
print'(a)', to_string(-3) ! returns "-3"
250-
print'(a)', to_string(.true.) ! returns "T"
251-
print'(a)', to_string(42) ! returns "42"
252-
end program demo_string_value
253-
```
215+
```

doc/specs/stdlib_linalg.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,58 @@ end program demo_diag5
101101

102102
Experimental
103103

104+
### Class
105+
106+
Pure function.
107+
104108
### Description
105109

106-
Construct the identity matrix
110+
Construct the identity matrix.
107111

108112
### Syntax
109113

110-
`I = [[stdlib_linalg(module):eye(function)]](n)`
114+
`I = [[stdlib_linalg(module):eye(function)]](dim1 [, dim2])`
111115

112116
### Arguments
113117

114-
`n`: Shall be a scalar of default type `integer`.
118+
`dim1`: Shall be a scalar of default type `integer`.
119+
This is an `intent(in)` argument.
120+
121+
`dim2`: Shall be a scalar of default type `integer`.
122+
This is an `intent(in)` and `optional` argument.
115123

116124
### Return value
117125

118-
Returns the identity matrix, i.e. a square matrix with ones on the main diagonal and zeros elsewhere. The return value is of type `integer(int8)`.
126+
Return the identity matrix, i.e. a matrix with ones on the main diagonal and zeros elsewhere. The return value is of type `integer(int8)`.
127+
The use of `int8` was suggested to save storage.
128+
129+
#### Warning
130+
131+
Since the result of `eye` is of `integer(int8)` type, one should be careful about using it in arithmetic expressions. For example:
132+
```fortran
133+
real :: A(:,:)
134+
!> Be careful
135+
A = eye(2,2)/2 !! A == 0.0
136+
!> Recommend
137+
A = eye(2,2)/2.0 !! A == diag([0.5, 0.5])
138+
```
119139

120140
### Example
121141

122142
```fortran
123143
program demo_eye1
124144
use stdlib_linalg, only: eye
125145
implicit none
146+
integer :: i(2,2)
126147
real :: a(3,3)
127-
A = eye(3)
148+
real :: b(2,3) !! Matrix is non-square.
149+
complex :: c(2,2)
150+
I = eye(2) !! [1,0; 0,1]
151+
A = eye(3) !! [1.0,0.0,0.0; 0.0,1.0,0.0; 0.0,0.0,1.0]
152+
A = eye(3,3) !! [1.0,0.0,0.0; 0.0,1.0,0.0; 0.0,0.0,1.0]
153+
B = eye(2,3) !! [1.0,0.0,0.0; 0.0,1.0,0.0]
154+
C = eye(2,2) !! [(1.0,0.0),(0.0,0.0); (0.0,0.0),(1.0,0.0)]
155+
C = (1.0,1.0)*eye(2,2) !! [(1.0,1.0),(0.0,0.0); (0.0,0.0),(1.0,1.0)]
128156
end program demo_eye1
129157
```
130158

doc/specs/stdlib_math.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,71 @@ program demo_logspace_rstart_cbase
275275
276276
end program demo_logspace_rstart_cbase
277277
```
278+
## `arange`
279+
280+
### Status
281+
282+
Experimental
283+
284+
### Class
285+
286+
Pure function.
287+
288+
### Description
289+
290+
Creates a one-dimensional `array` of the `integer/real` type with fixed-spaced values of given spacing, within a given interval.
291+
292+
### Syntax
293+
294+
`result = [[stdlib_math(module):arange(interface)]](start [, end, step])`
295+
296+
### Arguments
297+
298+
All arguments should be the same type and kind.
299+
300+
`start`: Shall be an `integer/real` scalar.
301+
This is an `intent(in)` argument.
302+
The default `start` value is `1`.
303+
304+
`end`: Shall be an `integer/real` scalar.
305+
This is an `intent(in)` and `optional` argument.
306+
The default `end` value is the inputted `start` value.
307+
308+
`step`: Shall be an `integer/real` scalar and large than `0`.
309+
This is an `intent(in)` and `optional` argument.
310+
The default `step` value is `1`.
311+
312+
#### Warning
313+
If `step = 0`, the `step` argument will be corrected to `1/1.0` by the internal process of the `arange` function.
314+
If `step < 0`, the `step` argument will be corrected to `abs(step)` by the internal process of the `arange` function.
315+
316+
### Return value
317+
318+
Returns a one-dimensional `array` of fixed-spaced values.
319+
320+
For `integer` type arguments, the length of the result vector is `(end - start)/step + 1`.
321+
For `real` type arguments, the length of the result vector is `floor((end - start)/step) + 1`.
322+
323+
### Example
324+
325+
```fortran
326+
program demo_math_arange
327+
use stdlib_math, only: arange
328+
329+
print *, arange(3) !! [1,2,3]
330+
print *, arange(-1) !! [1,0,-1]
331+
print *, arange(0,2) !! [0,1,2]
332+
print *, arange(1,-1) !! [1,0,-1]
333+
print *, arange(0, 2, 2) !! [0,2]
334+
335+
print *, arange(3.0) !! [1.0,2.0,3.0]
336+
print *, arange(0.0,5.0) !! [0.0,1.0,2.0,3.0,4.0,5.0]
337+
print *, arange(0.0,6.0,2.5) !! [0.0,2.5,5.0]
338+
339+
print *, (1.0,1.0)*arange(3) !! [(1.0,1.0),(2.0,2.0),[3.0,3.0]]
340+
341+
print *, arange(0.0,2.0,-2.0) !! [0.0,2.0]. Not recommended: `step` argument is negative!
342+
print *, arange(0.0,2.0,0.0) !! [0.0,1.0,2.0]. Not recommended: `step` argument is zero!
343+
344+
end program demo_math_arange
345+
```

doc/specs/stdlib_strings.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,72 @@ program demo_count
538538
539539
end program demo_count
540540
```
541+
542+
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
543+
### `to_string`
544+
545+
#### Description
546+
547+
Format or transfer a `integer/real/complex/logical` scalar as a string.
548+
Input a wrong `format` that cause the internal-IO to fail, the result value is a string of `[*]`.
549+
550+
#### Syntax
551+
552+
`string = [[stdlib_strings(module):to_string(interface)]] (value [, format])`
553+
554+
#### Status
555+
556+
Experimental
557+
558+
#### Class
559+
560+
Pure function.
561+
562+
#### Argument
563+
564+
- `value`: Shall be an `integer/real/complex/logical` scalar.
565+
This is an `intent(in)` argument.
566+
- `format`: Shall be a `character(len=*)` scalar like `'(F6.2)'` or just `'F6.2'`.
567+
This is an `intent(in)` and `optional` argument.
568+
Contains the edit descriptor to format `value` into a string, for example `'(F6.2)'` or `'(f6.2)'`.
569+
`to_string` will automatically enclose `format` in a set of parentheses, so passing `F6.2` or `f6.2` as `format` is possible as well.
570+
571+
#### Result value
572+
573+
The result is an `allocatable` length `character` scalar with up to `128` cached `character` length.
574+
575+
#### Example
576+
577+
```fortran
578+
program demo_to_string
579+
use stdlib_strings, only: to_string
580+
581+
!> Example for `complex` type
582+
print *, to_string((1, 1)) !! "(1.00000000,1.00000000)"
583+
print *, to_string((1, 1), '(F6.2)') !! "( 1.00, 1.00)"
584+
print *, to_string((1000, 1), '(ES0.2)'), to_string((1000, 1), '(SP,F6.3)')
585+
!! "(1.00E+3,1.00)""(******,+1.000)"
586+
!! Too narrow formatter for real number
587+
!! Normal demonstration(`******` from Fortran Standard)
588+
589+
!> Example for `integer` type
590+
print *, to_string(-3) !! "-3"
591+
print *, to_string(42, '(I4)') !! " 42"
592+
print *, to_string(1, '(I0.4)'), to_string(2, '(B4)') !! "0001"" 10"
593+
594+
!> Example for `real` type
595+
print *, to_string(1.) !! "1.00000000"
596+
print *, to_string(1., '(F6.2)') !! " 1.00"
597+
print *, to_string(1., 'F6.2') !! " 1.00"
598+
print *, to_string(1., '(SP,ES9.2)'), to_string(1, '(F7.3)') !! "+1.00E+00""[*]"
599+
!! 1 wrong demonstration (`[*]` from `to_string`)
600+
601+
!> Example for `logical` type
602+
print *, to_string(.true.) !! "T"
603+
print *, to_string(.true., '(L2)') !! " T"
604+
print *, to_string(.true., 'L2') !! " T"
605+
print *, to_string(.false., '(I5)') !! "[*]"
606+
!! 1 wrong demonstrations(`[*]` from `to_string`)
607+
608+
end program demo_to_string
609+
```

src/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ set(fppFiles
3232
stdlib_math.fypp
3333
stdlib_math_linspace.fypp
3434
stdlib_math_logspace.fypp
35+
stdlib_math_arange.fypp
3536
stdlib_string_type.fypp
37+
stdlib_string_type_constructor.fypp
38+
stdlib_strings_to_string.fypp
39+
stdlib_strings.fypp
3640
)
3741

3842

@@ -51,7 +55,6 @@ set(SRC
5155
stdlib_error.f90
5256
stdlib_kinds.f90
5357
stdlib_logger.f90
54-
stdlib_strings.f90
5558
stdlib_system.F90
5659
stdlib_specialfunctions.f90
5760
stdlib_specialfunctions_legendre.f90

0 commit comments

Comments
 (0)