Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
fsharp
提交
d1316d35
F
fsharp
项目概览
dotNET Platform
/
fsharp
大约 1 年 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
fsharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
d1316d35
编写于
3月 21, 2023
作者:
T
Tomas Grosup
提交者:
GitHub
3月 21, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Array.Parallel.forall , Array.Parallel.exists (#14910)
* Array.Parallel.forall , Array.Parallel.exists
上级
e353fd02
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
129 addition
and
2 deletion
+129
-2
src/FSharp.Core/array.fs
src/FSharp.Core/array.fs
+20
-0
src/FSharp.Core/array.fsi
src/FSharp.Core/array.fsi
+61
-0
tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard20.debug.bsl
...UnitTests/FSharp.Core.SurfaceArea.netstandard20.debug.bsl
+2
-0
tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard20.release.bsl
...itTests/FSharp.Core.SurfaceArea.netstandard20.release.bsl
+3
-0
tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.debug.bsl
...UnitTests/FSharp.Core.SurfaceArea.netstandard21.debug.bsl
+2
-0
tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl
...itTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl
+2
-0
tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs
...s/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs
+35
-0
tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/CollectionModulesConsistency.fs
...rosoft.FSharp.Collections/CollectionModulesConsistency.fs
+4
-2
未找到文件。
src/FSharp.Core/array.fs
浏览文件 @
d1316d35
...
...
@@ -1936,6 +1936,26 @@ module Array =
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Concurrent
[<
CompiledName
(
"Exists"
)>]
let
exists
(
predicate
:
'
T
->
bool
)
(
array
:
'
T
[]
)
=
checkNonNull
"array"
array
Parallel
.
For
(
0
,
array
.
Length
,
(
fun
i
pState
->
if
predicate
array
[
i
]
then
pState
.
Stop
()
)
)
.
IsCompleted
|>
not
[<
CompiledName
(
"ForAll"
)>]
let
forall
(
predicate
:
'
T
->
bool
)
(
array
:
'
T
[]
)
=
// Not exists $condition <==> (opposite of $condition is true forall)
exists
(
predicate
>>
not
)
array
|>
not
[<
CompiledName
(
"TryFindIndex"
)>]
let
tryFindIndex
predicate
(
array
:
_[])
=
checkNonNull
"array"
array
...
...
src/FSharp.Core/array.fsi
浏览文件 @
d1316d35
...
...
@@ -3094,6 +3094,67 @@ module Array =
/// <summary>Provides parallel operations on arrays </summary>
module
Parallel
=
/// <summary>Tests if all elements of the array satisfy the given predicate.</summary>
///
/// <remarks>The predicate is applied to the elements of the input collection in parallel. If any application
/// returns false then the overall result is false and testing of other elements in all threads is stopped at system's earliest convenience.
/// Otherwise, true is returned.</remarks>
///
/// <param name="predicate">The function to test the input elements.</param>
/// <param name="array">The input array.</param>
///
/// <returns>True if all of the array elements satisfy the predicate.</returns>
///
/// <exception cref="T:System.ArgumentNullException">Thrown when the input array is null.</exception>
///
/// <example id="para-forall-1">
/// <code lang="fsharp">
/// let isEven a = a % 2 = 0
///
/// [2; 42] |> Array.Parallel.forall isEven // evaluates to true
///
/// [1; 2] |> Array.Parallel.forall isEven // evaluates to false
/// </code>
/// </example>
[<
CompiledName
(
"ForAll"
)>]
[<
Experimental
(
"Experimental library feature, requires '--langversion:preview'"
)>]
val
forall
:
predicate
:(
'
T
->
bool
)
->
array
:
'
T
[]
->
bool
/// <summary>Tests if any element of the array satisfies the given predicate.</summary>
///
/// <remarks>The predicate is applied to the elements of the input array in parallel. If any application
/// returns true then the overall result is true and testing of other elements in all threads is stopped at system's earliest convenience.
/// Otherwise, <c>false</c> is returned.</remarks>
///
/// <param name="predicate">The function to test the input elements.</param>
/// <param name="array">The input array.</param>
///
/// <returns>True if any result from <c>predicate</c> is true.</returns>
///
/// <exception cref="T:System.ArgumentNullException">Thrown when the input array is null.</exception>
///
/// <example id="para-exists-1">
/// <code lang="fsharp">
/// let input = [| 1; 2; 3; 4; 5 |]
///
/// input |> Array.Parallel.exists (fun elm -> elm % 4 = 0)
/// </code>
/// Evaluates to <c>true</c>
/// </example>
///
/// <example id="para-exists-2">
/// <code lang="fsharp">
/// let input = [| 1; 2; 3; 4; 5 |]
///
/// input |> Array.Parallel.exists (fun elm -> elm % 6 = 0)
/// </code>
/// Evaluates to <c>false</c>
/// </example>
[<
CompiledName
(
"Exists"
)>]
[<
Experimental
(
"Experimental library feature, requires '--langversion:preview'"
)>]
val
exists
:
predicate
:(
'
T
->
bool
)
->
array
:
'
T
[]
->
bool
/// <summary>Returns the first element for which the given function returns <c>True</c>.
/// Returns None if no such element exists.</summary>
///
...
...
tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard20.debug.bsl
浏览文件 @
d1316d35
...
...
@@ -40,6 +40,8 @@ Microsoft.FSharp.Collections.Array4DModule: T[,,,] Create[T](Int32, Int32, Int32
Microsoft
.
FSharp
.
Collections
.
Array4DModule
:
T
[,,,]
Initialize
[
T
](
Int32
,
Int32
,
Int32
,
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
T
]]]])
Microsoft
.
FSharp
.
Collections
.
Array4DModule
:
T
[,,,]
ZeroCreate
[
T
](
Int32
,
Int32
,
Int32
,
Int32
)
Microsoft
.
FSharp
.
Collections
.
Array4DModule
:
Void
Set
[
T
](
T
[,,,],
Int32
,
Int32
,
Int32
,
Int32
,
T
)
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Boolean
Exists
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Boolean
ForAll
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
System
.
Tuple
`
2
[
TKey
,
T
[]][]
GroupBy
[
T
,
TKey
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
TKey
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
System
.
Int32
]
TryFindIndex
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
TResult
]
TryPick
[
T
,
TResult
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
TResult
]],
T
[])
...
...
tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard20.release.bsl
浏览文件 @
d1316d35
...
...
@@ -40,6 +40,9 @@ Microsoft.FSharp.Collections.Array4DModule: T[,,,] Create[T](Int32, Int32, Int32
Microsoft
.
FSharp
.
Collections
.
Array4DModule
:
T
[,,,]
Initialize
[
T
](
Int32
,
Int32
,
Int32
,
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
T
]]]])
Microsoft
.
FSharp
.
Collections
.
Array4DModule
:
T
[,,,]
ZeroCreate
[
T
](
Int32
,
Int32
,
Int32
,
Int32
)
Microsoft
.
FSharp
.
Collections
.
Array4DModule
:
Void
Set
[
T
](
T
[,,,],
Int32
,
Int32
,
Int32
,
Int32
,
T
)
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Boolean
Exists
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Boolean
ForAll
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
System
.
Tuple
`
2
[
TKey
,
T
[]][]
GroupBy
[
T
,
TKey
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
TKey
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
System
.
Int32
]
TryFindIndex
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
TResult
]
TryPick
[
T
,
TResult
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
TResult
]],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
T
]
TryFind
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
...
...
tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.debug.bsl
浏览文件 @
d1316d35
...
...
@@ -40,6 +40,8 @@ Microsoft.FSharp.Collections.Array4DModule: T[,,,] Create[T](Int32, Int32, Int32
Microsoft
.
FSharp
.
Collections
.
Array4DModule
:
T
[,,,]
Initialize
[
T
](
Int32
,
Int32
,
Int32
,
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
T
]]]])
Microsoft
.
FSharp
.
Collections
.
Array4DModule
:
T
[,,,]
ZeroCreate
[
T
](
Int32
,
Int32
,
Int32
,
Int32
)
Microsoft
.
FSharp
.
Collections
.
Array4DModule
:
Void
Set
[
T
](
T
[,,,],
Int32
,
Int32
,
Int32
,
Int32
,
T
)
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Boolean
Exists
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Boolean
ForAll
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
System
.
Tuple
`
2
[
TKey
,
T
[]][]
GroupBy
[
T
,
TKey
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
TKey
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
System
.
Int32
]
TryFindIndex
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
TResult
]
TryPick
[
T
,
TResult
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
TResult
]],
T
[])
...
...
tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl
浏览文件 @
d1316d35
...
...
@@ -40,6 +40,8 @@ Microsoft.FSharp.Collections.Array4DModule: T[,,,] Create[T](Int32, Int32, Int32
Microsoft
.
FSharp
.
Collections
.
Array4DModule
:
T
[,,,]
Initialize
[
T
](
Int32
,
Int32
,
Int32
,
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
System
.
Int32
,
T
]]]])
Microsoft
.
FSharp
.
Collections
.
Array4DModule
:
T
[,,,]
ZeroCreate
[
T
](
Int32
,
Int32
,
Int32
,
Int32
)
Microsoft
.
FSharp
.
Collections
.
Array4DModule
:
Void
Set
[
T
](
T
[,,,],
Int32
,
Int32
,
Int32
,
Int32
,
T
)
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Boolean
Exists
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Boolean
ForAll
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
System
.
Tuple
`
2
[
TKey
,
T
[]][]
GroupBy
[
T
,
TKey
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
TKey
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
System
.
Int32
]
TryFindIndex
[
T
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
System
.
Boolean
],
T
[])
Microsoft
.
FSharp
.
Collections
.
ArrayModule
+
Parallel
:
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
TResult
]
TryPick
[
T
,
TResult
](
Microsoft
.
FSharp
.
Core
.
FSharpFunc
`
2
[
T
,
Microsoft
.
FSharp
.
Core
.
FSharpOption
`
1
[
TResult
]],
T
[])
...
...
tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs
浏览文件 @
d1316d35
...
...
@@ -1120,6 +1120,41 @@ type ArrayModule() =
CheckThrowsArgumentNullException
(
fun
()
->
Array
.
forall
(
fun
x
->
true
)
nullArr
|>
ignore
)
()
[<
Fact
>]
member
this
.
ParallelForAll
()
=
let
inline
assertSame
predicate
array
=
let
seq
=
Array
.
forall
predicate
array
let
para
=
Array
.
Parallel
.
forall
predicate
array
Assert
.
AreEqual
(
seq
,
para
,
sprintf
"%A"
array
)
[|
3
..
2
..
10
|]
|>
assertSame
(
fun
x
->
x
>
15
)
[|
3
..
2
..
10
|]
|>
assertSame
(
fun
x
->
x
<
15
)
[|
"Lists"
;
"are"
;
"commonly"
;
"list"
|]
|>
assertSame
(
fun
(
x
:
string
)
->
x
.
Contains
(
"a"
))
[||]
|>
assertSame
(
fun
(
x
:
string
)
->
x
.
Contains
(
"a"
))
[||]
|>
assertSame
(
fun
(
x
:
string
)
->
x
.
Contains
(
"a"
)
|>
not
)
let
nullArr
=
null
:
string
[]
CheckThrowsArgumentNullException
(
fun
()
->
Array
.
Parallel
.
forall
(
fun
x
->
true
)
nullArr
|>
ignore
)
()
[<
Fact
>]
member
this
.
ParallelExists
()
=
let
inline
assertSame
predicate
array
=
let
seq
=
Array
.
exists
predicate
array
let
para
=
Array
.
Parallel
.
exists
predicate
array
Assert
.
AreEqual
(
seq
,
para
,
sprintf
"%A"
array
)
[|
3
..
2
..
10
|]
|>
assertSame
(
fun
x
->
x
>
2
)
[|
"Lists"
;
"are"
;
"commonly"
;
"list"
|]
|>
assertSame
(
fun
(
x
:
string
)
->
x
.
Contains
(
"a"
))
[||]
|>
assertSame
(
fun
(
x
:
string
)
->
x
.
Contains
(
"a"
))
[||]
|>
assertSame
(
fun
(
x
:
string
)
->
x
.
Contains
(
"a"
)
|>
not
)
let
nullArr
=
null
:
string
[]
CheckThrowsArgumentNullException
(
fun
()
->
Array
.
Parallel
.
exists
(
fun
x
->
true
)
nullArr
|>
ignore
)
()
[<
Fact
>]
member
this
.
ForAll2
()
=
...
...
tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/CollectionModulesConsistency.fs
浏览文件 @
d1316d35
...
...
@@ -227,7 +227,8 @@ let exists<'a when 'a : equality> (xs : 'a []) f =
let
s
=
xs
|>
Seq
.
exists
f
let
l
=
xs
|>
List
.
ofArray
|>
List
.
exists
f
let
a
=
xs
|>
Array
.
exists
f
consistency
"exists"
s
l
a
let
pa
=
xs
|>
Array
.
Parallel
.
exists
f
consistencyIncludingParallel
"exists"
s
l
a
pa
[<
Fact
>]
let
``exists is consistent``
()
=
...
...
@@ -373,7 +374,8 @@ let forall<'a when 'a : equality> (xs : 'a []) f =
let
s
=
xs
|>
Seq
.
forall
f
let
l
=
xs
|>
List
.
ofArray
|>
List
.
forall
f
let
a
=
xs
|>
Array
.
forall
f
consistency
"forall"
s
l
a
let
pa
=
xs
|>
Array
.
Parallel
.
forall
f
consistencyIncludingParallel
"forall"
s
l
a
pa
[<
Fact
>]
let
``forall is consistent``
()
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录