Skip to content

Commit 104e25b

Browse files
Asiek777pradeep
authored andcommitted
Getting Started Integer F# example
1 parent 809b162 commit 104e25b

5 files changed

Lines changed: 103 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ Examples/Unified/FSharp/obj/
2121
/packages/FSharp.Core.4.6.2
2222
/Examples/GettingStarted/Integer/CSharp/bin
2323
/Examples/GettingStarted/Integer/CSharp/obj
24+
/Examples/GettingStarted/Integer/FSharp/obj
25+
/Examples/GettingStarted/Integer/FSharp/bin/Debug/netcoreapp2.2

ArrayFire.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GettingStarted", "GettingSt
2727
EndProject
2828
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Integer (CSharp)", "Examples\GettingStarted\Integer\CSharp\Integer (CSharp).csproj", "{CF93F274-DA85-4845-81DB-C719B95665DA}"
2929
EndProject
30+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Integer (FSharp)", "Examples\GettingStarted\Integer\FSharp\Integer (FSharp).fsproj", "{751A6367-32AF-479A-8221-5DB0BB7C000B}"
31+
EndProject
3032
Global
3133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3234
Debug|Any CPU = Debug|Any CPU
@@ -97,6 +99,14 @@ Global
9799
{CF93F274-DA85-4845-81DB-C719B95665DA}.Release|Any CPU.Build.0 = Release|Any CPU
98100
{CF93F274-DA85-4845-81DB-C719B95665DA}.Release|x64.ActiveCfg = Release|Any CPU
99101
{CF93F274-DA85-4845-81DB-C719B95665DA}.Release|x64.Build.0 = Release|Any CPU
102+
{751A6367-32AF-479A-8221-5DB0BB7C000B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
103+
{751A6367-32AF-479A-8221-5DB0BB7C000B}.Debug|Any CPU.Build.0 = Debug|Any CPU
104+
{751A6367-32AF-479A-8221-5DB0BB7C000B}.Debug|x64.ActiveCfg = Debug|Any CPU
105+
{751A6367-32AF-479A-8221-5DB0BB7C000B}.Debug|x64.Build.0 = Debug|Any CPU
106+
{751A6367-32AF-479A-8221-5DB0BB7C000B}.Release|Any CPU.ActiveCfg = Release|Any CPU
107+
{751A6367-32AF-479A-8221-5DB0BB7C000B}.Release|Any CPU.Build.0 = Release|Any CPU
108+
{751A6367-32AF-479A-8221-5DB0BB7C000B}.Release|x64.ActiveCfg = Release|Any CPU
109+
{751A6367-32AF-479A-8221-5DB0BB7C000B}.Release|x64.Build.0 = Release|Any CPU
100110
EndGlobalSection
101111
GlobalSection(SolutionProperties) = preSolution
102112
HideSolutionNode = FALSE
@@ -110,6 +120,7 @@ Global
110120
{E1B97271-6364-4D9E-972A-A65156674BF4} = {0292AF78-CBCD-4005-9A62-3399F43F22BE}
111121
{FAAB6802-F422-4F69-B543-5A68A81245FD} = {45CBAB24-008E-4178-A16A-9FBBE040CDBE}
112122
{CF93F274-DA85-4845-81DB-C719B95665DA} = {FAAB6802-F422-4F69-B543-5A68A81245FD}
123+
{751A6367-32AF-479A-8221-5DB0BB7C000B} = {FAAB6802-F422-4F69-B543-5A68A81245FD}
113124
EndGlobalSection
114125
GlobalSection(ExtensibilityGlobals) = postSolution
115126
SolutionGuid = {E3A0DE14-88D3-4AEC-B6F6-97A6CA052C53}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.2</TargetFramework>
6+
<RootNamespace>HelloWorld__FSharp_</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Compile Include="Program.fs" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\..\..\src\Wrapper\ArrayFire.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Learn more about F# at http://fsharp.org
2+
// See the 'F# Tutorial' project for more help.
3+
4+
open System
5+
open System.Numerics
6+
open System.Collections.Generic
7+
open ArrayFire
8+
9+
[<EntryPoint>]
10+
let main argv =
11+
12+
Device.SetBackend(Backend.DEFAULT)
13+
Device.PrintInfo()
14+
printfn "\n=== ArrayFire signed(s32) / unsigned(u32) Integer Example ===\n"
15+
16+
let h_A = array2D[ [ 1; 2; 4 ]; [ -1; 2; 0 ]; [ 4; 2; 3 ] ]
17+
let h_B = array2D[ [ 2; 3; -5 ]; [ 6; 0; 10 ]; [ -12; 0; 1 ] ]
18+
//printfn "Array 2D is %A" h_A.GetType()
19+
let A = Data.CreateArray(h_A)
20+
let B = Data.CreateArray(h_B)
21+
printfn "--\nSub-refencing and Sub-assignment\n"
22+
23+
Util.Print(A, "A");
24+
Util.Print(A.Rows(0, 0), "A's first row")
25+
Util.Print(A.Cols(0, 0), "A's first column")
26+
A.[Util.Seq(0, 0), Util.Seq(0, 0)] <- Data.CreateArray([|100|])
27+
A.[Util.Seq(1, 1), Util.Seq(2, 2)] <- Data.CreateArray([|100|])
28+
Util.Print(A, "A")
29+
Util.Print(B, "B")
30+
A.[Util.Seq(1, 1), Util.Span] <- B.[Util.Seq(2, 2), Util.Span]
31+
Util.Print(A, "A")
32+
Util.Print(B, "B")
33+
let C = A + B
34+
printf "--Bit-wise operations\n"
35+
Util.Print(A &&& B, "A &&& B")
36+
Util.Print(A ||| B, "A ||| B")
37+
Util.Print(A ^^^ B, "A ^^^ B")
38+
39+
printfn "\n--Transpose\n"
40+
Util.Print(A, "A")
41+
Util.Print(Matrix.Transpose(A, false), "Matrix.Transpose(A)")
42+
43+
printfn "\n--Sum along columns\n"
44+
Util.Print(A, "A")
45+
Util.Print(Algorithm.Sum(A), "Algorithm.Sum(A)")
46+
47+
printfn "\n--Product along columns\n"
48+
Util.Print(A, "A")
49+
Util.Print(Algorithm.Product(A), "Algorithm.Product(A)")
50+
51+
printfn "\n--Minimum along columns\n"
52+
Util.Print(A, "A")
53+
Util.Print(Algorithm.Min(A), "Algorithm.Min(A)")
54+
55+
printfn "\n--Maximum along columns\n"
56+
Util.Print(A, "A")
57+
Util.Print(Algorithm.Max(A), "Algorithm.Max(A)")
58+
59+
printfn "\n--Minimum along columns with index\n"
60+
Util.Print(A, "A")
61+
62+
let mutable idx = null
63+
let outArray = Algorithm.Min(A, &idx)
64+
Util.Print(outArray, "output")
65+
Util.Print(idx, "indexes")
66+
67+
0 // return an integer exit code

0 commit comments

Comments
 (0)