-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumGrid.wl
35 lines (25 loc) · 1.18 KB
/
NumGrid.wl
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
BeginPackage["NumGrid`"];
ClearAll[NumGrid];
Begin["`Private`"];
ClearAll[Unload];
Unload[]:=(LibraryUnload[NumGrid`$libraryPath];LibraryUnload[NumGrid`$libraryPath];)
If[FileExistsQ[NumGrid`$libraryPath],
$Types={"A","B","C","D","H","L","S"};
Block[{library=LibraryLoad[NumGrid`$libraryPath]},
{NumGridA,NumGridB,NumGridC,NumGridD,NumGridH,NumGridL,NumGridS}=LibraryFunctionLoad[library,"numgrid_"<>#,{Integer},LibraryDataType["NumericArray","UnsignedInteger32",2]]&/@ToLowerCase[$Types];
ParallelNumGridB=LibraryFunctionLoad[library,"numgrid_b_parallel",{Integer},LibraryDataType["NumericArray","UnsignedInteger32",2]];
]
Options[NumGrid]={Parallelization->False};
NumGrid::invalidType="Type `1` is not valid. Valid types are `2` .";
NumGrid[type_String,n_Integer,OptionsPattern[]]:=Switch[ToUpperCase@type,
"S",NumGridS[n],
"L",NumGridL[n],
"C",NumGridC[n],
"D",NumGridD[n],
"A",NumGridA[n],
"H",NumGridH[n],
"B",If[TrueQ[OptionValue[Parallelization]],ParallelNumGridB[n],NumGridB[n]],
_,Message[NumGrid::invalidType,type,StringRiffle[$Types,", "]];$Failed]
,Print["Variable \"NumGrid`$libraryPath\" is not set. Can not initialize."];$Failed]
End[];
EndPackage[];