This repository was archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 313
Expand file tree
/
Copy patharray3.fs
More file actions
executable file
·162 lines (135 loc) · 6.5 KB
/
array3.fs
File metadata and controls
executable file
·162 lines (135 loc) · 6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace Microsoft.FSharp.Collections
open System.Diagnostics
open Microsoft.FSharp.Collections
open Microsoft.FSharp.Core
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
open Microsoft.FSharp.Core.Operators
open Microsoft.FSharp.Core.Operators.Checked
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
[<RequireQualifiedAccess>]
module Array3D =
let inline checkNonNull argName arg =
match box arg with
| null -> nullArg argName
| _ -> ()
[<CompiledName("Length1")>]
let length1 (array: 'T[,,]) = (# "ldlen.multi 3 0" array : int #)
[<CompiledName("Length2")>]
let length2 (array: 'T[,,]) = (# "ldlen.multi 3 1" array : int #)
[<CompiledName("Length3")>]
let length3 (array: 'T[,,]) = (# "ldlen.multi 3 2" array : int #)
[<CompiledName("Get")>]
let get (array: 'T[,,]) index1 index2 index3 = array.[index1,index2,index3]
[<CompiledName("Set")>]
let set (array: 'T[,,]) index1 index2 index3 value = array.[index1,index2,index3] <- value
[<CompiledName("ZeroCreate")>]
let zeroCreate length1 length2 length3 =
if length1 < 0 then invalidArgInputMustBeNonNegative "n1" length1
if length2 < 0 then invalidArgInputMustBeNonNegative "n2" length2
if length3 < 0 then invalidArgInputMustBeNonNegative "n3" length3
(# "newarr.multi 3 !0" type ('T) length1 length2 length3 : 'T[,,] #)
[<CompiledName("Create")>]
let create length1 length2 length3 (initial:'T) =
let arr = (zeroCreate length1 length2 length3 : 'T[,,])
for i = 0 to length1 - 1 do
for j = 0 to length2 - 1 do
for k = 0 to length3 - 1 do
arr.[i,j,k] <- initial
arr
[<CompiledName("Initialize")>]
let init length1 length2 length3 initializer =
let arr = (zeroCreate length1 length2 length3 : 'T[,,])
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(initializer)
for i = 0 to length1 - 1 do
for j = 0 to length2 - 1 do
for k = 0 to length3 - 1 do
arr.[i,j,k] <- f.Invoke(i, j, k)
arr
[<CompiledName("Iterate")>]
let iter action array =
checkNonNull "array" array
let len1 = length1 array
let len2 = length2 array
let len3 = length3 array
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
for k = 0 to len3 - 1 do
action array.[i,j,k]
[<CompiledName("Map")>]
let map mapping array =
checkNonNull "array" array
let len1 = length1 array
let len2 = length2 array
let len3 = length3 array
let res = (zeroCreate len1 len2 len3 : 'b[,,])
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
for k = 0 to len3 - 1 do
res.[i,j,k] <- mapping array.[i,j,k]
res
[<CompiledName("IterateIndexed")>]
let iteri action array =
checkNonNull "array" array
let len1 = length1 array
let len2 = length2 array
let len3 = length3 array
let f = OptimizedClosures.FSharpFunc<_,_,_,_,_>.Adapt(action)
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
for k = 0 to len3 - 1 do
f.Invoke(i, j, k, array.[i,j,k])
[<CompiledName("MapIndexed")>]
let mapi mapping array =
checkNonNull "array" array
let len1 = length1 array
let len2 = length2 array
let len3 = length3 array
let res = (zeroCreate len1 len2 len3 : 'b[,,])
let f = OptimizedClosures.FSharpFunc<_,_,_,_,_>.Adapt(mapping)
for i = 0 to len1 - 1 do
for j = 0 to len2 - 1 do
for k = 0 to len3 - 1 do
res.[i,j,k] <- f.Invoke(i, j, k, array.[i,j,k])
res
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
[<RequireQualifiedAccess>]
module Array4D =
[<CompiledName("Length1")>]
let length1 (array: 'T[,,,]) = (# "ldlen.multi 4 0" array : int #)
[<CompiledName("Length2")>]
let length2 (array: 'T[,,,]) = (# "ldlen.multi 4 1" array : int #)
[<CompiledName("Length3")>]
let length3 (array: 'T[,,,]) = (# "ldlen.multi 4 2" array : int #)
[<CompiledName("Length4")>]
let length4 (array: 'T[,,,]) = (# "ldlen.multi 4 3" array : int #)
[<CompiledName("ZeroCreate")>]
let zeroCreate length1 length2 length3 length4 =
if length1 < 0 then invalidArgInputMustBeNonNegative "n1" length1
if length2 < 0 then invalidArgInputMustBeNonNegative "n2" length2
if length3 < 0 then invalidArgInputMustBeNonNegative "n3" length3
if length4 < 0 then invalidArgInputMustBeNonNegative "n4" length4
(# "newarr.multi 4 !0" type ('T) length1 length2 length3 length4 : 'T[,,,] #)
[<CompiledName("Create")>]
let create length1 length2 length3 length4 (initial:'T) =
let arr = (zeroCreate length1 length2 length3 length4 : 'T[,,,])
for i = 0 to length1 - 1 do
for j = 0 to length2 - 1 do
for k = 0 to length3 - 1 do
for m = 0 to length4 - 1 do
arr.[i,j,k,m] <- initial
arr
[<CompiledName("Initialize")>]
let init length1 length2 length3 length4 initializer =
let arr = (zeroCreate length1 length2 length3 length4 : 'T[,,,])
let f = OptimizedClosures.FSharpFunc<_,_,_,_,_>.Adapt(initializer)
for i = 0 to length1 - 1 do
for j = 0 to length2 - 1 do
for k = 0 to length3 - 1 do
for m = 0 to length4 - 1 do
arr.[i,j,k,m] <- f.Invoke(i, j, k, m)
arr
[<CompiledName("Get")>]
let get (array: 'T[,,,]) index1 index2 index3 index4 = array.[index1,index2,index3,index4]
[<CompiledName("Set")>]
let set (array: 'T[,,,]) index1 index2 index3 index4 value = array.[index1,index2,index3,index4] <- value