forked from fsharp/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray3.fs
More file actions
executable file
·168 lines (141 loc) · 6.27 KB
/
Copy patharray3.fs
File metadata and controls
executable file
·168 lines (141 loc) · 6.27 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
163
164
165
166
167
168
//----------------------------------------------------------------------------
//
// Copyright (c) 2002-2012 Microsoft Corporation.
//
// This source code is subject to terms and conditions of the Apache License, Version 2.0. A
// copy of the license can be found in the License.html file at the root of this distribution.
// By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Apache License, Version 2.0.
//
// You must not remove this notice, or any other, from this software.
//----------------------------------------------------------------------------
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[,,]) n1 n2 n3 = array.[n1,n2,n3]
[<CompiledName("Set")>]
let set (array: 'T[,,]) n1 n2 n3 x = array.[n1,n2,n3] <- x
[<CompiledName("ZeroCreate")>]
let zeroCreate (n1:int) (n2:int) (n3:int) =
if n1 < 0 then invalidArg "n1" (SR.GetString(SR.inputMustBeNonNegative))
if n2 < 0 then invalidArg "n2" (SR.GetString(SR.inputMustBeNonNegative))
if n3 < 0 then invalidArg "n3" (SR.GetString(SR.inputMustBeNonNegative))
(# "newarr.multi 3 !0" type ('T) n1 n2 n3 : 'T[,,] #)
[<CompiledName("Create")>]
let create (n1:int) (n2:int) (n3:int) (x:'T) =
let arr = (zeroCreate n1 n2 n3 : 'T[,,])
for i = 0 to n1 - 1 do
for j = 0 to n2 - 1 do
for k = 0 to n3 - 1 do
arr.[i,j,k] <- x
arr
[<CompiledName("Initialize")>]
let init n1 n2 n3 f =
let arr = (zeroCreate n1 n2 n3 : 'T[,,])
for i = 0 to n1 - 1 do
for j = 0 to n2 - 1 do
for k = 0 to n3 - 1 do
arr.[i,j,k] <- f i j k
arr
[<CompiledName("Iterate")>]
let iter f 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
f array.[i,j,k]
[<CompiledName("Map")>]
let map f 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] <- f array.[i,j,k]
res
[<CompiledName("IterateIndexed")>]
let iteri f 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
f i j k array.[i,j,k]
[<CompiledName("MapIndexed")>]
let mapi f 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] <- f 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 (n1:int) (n2:int) (n3:int) (n4:int) =
if n1 < 0 then invalidArg "n1" (SR.GetString(SR.inputMustBeNonNegative))
if n2 < 0 then invalidArg "n2" (SR.GetString(SR.inputMustBeNonNegative))
if n3 < 0 then invalidArg "n3" (SR.GetString(SR.inputMustBeNonNegative))
if n4 < 0 then invalidArg "n4" (SR.GetString(SR.inputMustBeNonNegative))
(# "newarr.multi 4 !0" type ('T) n1 n2 n3 n4 : 'T[,,,] #)
[<CompiledName("Create")>]
let create n1 n2 n3 n4 (x:'T) =
let arr = (zeroCreate n1 n2 n3 n4 : 'T[,,,])
for i = 0 to n1 - 1 do
for j = 0 to n2 - 1 do
for k = 0 to n3 - 1 do
for m = 0 to n4 - 1 do
arr.[i,j,k,m] <- x
arr
[<CompiledName("Initialize")>]
let init n1 n2 n3 n4 f =
let arr = (zeroCreate n1 n2 n3 n4 : 'T[,,,])
for i = 0 to n1 - 1 do
for j = 0 to n2 - 1 do
for k = 0 to n3 - 1 do
for m = 0 to n4 - 1 do
arr.[i,j,k,m] <- f i j k m
arr
[<CompiledName("Get")>]
let get (array: 'T[,,,]) n1 n2 n3 n4 = array.[n1,n2,n3,n4]
[<CompiledName("Set")>]
let set (array: 'T[,,,]) n1 n2 n3 n4 x = array.[n1,n2,n3,n4] <- x