FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
arrayfire-rust/examples/conway.rs at master · arrayfire/arrayfire-rust · GitHub
arrayfire
arrayfire-rust
Repository navigation
Code
Issues
27
(27)
Pull requests
4
(4)
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
arrayfire-rust
/
examples
/
conway.rs
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (25 loc) · 974 Bytes
Breadcrumbs
arrayfire-rust
/
examples
/
conway.rs
Copy path
File metadata and controls
29 lines (25 loc) · 974 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
use
arrayfire
::
*
;
fn
main
(
)
{
set_device
(
0
)
;
info
(
)
;
conways_game_of_life
(
)
;
}
fn
normalise
(
a
:
&
Array
<
f32
>
)
->
Array
<
f32
>
{
a /
(
max_all
(
&
abs
(
a
)
)
.
0
as
f32
)
}
fn
conways_game_of_life
(
)
{
let
h_kernel =
[
1.0
,
1.0
,
1.0
,
1.0
,
0.0
,
1.0
,
1.0
,
1.0
,
1.0
]
;
let
kernel =
Array
::
new
(
&
h_kernel
,
Dim4
::
new
(
&
[
3
,
3
,
1
,
1
]
)
)
;
let
s =
constant
::
<
f32
>
(
0.5
,
Dim4
::
new
(
&
[
1
,
1
,
1
,
1
]
)
)
;
let
mut
state =
gt
(
&
randu
::
<
f32
>
(
Dim4
::
new
(
&
[
256
,
256
,
3
,
1
]
)
)
,
&
s
,
false
)
;
let
c0 =
constant
::
<
f32
>
(
2.0
,
Dim4
::
new
(
&
[
1
,
1
,
1
,
1
]
)
)
;
let
c1 =
constant
::
<
f32
>
(
3.0
,
Dim4
::
new
(
&
[
1
,
1
,
1
,
1
]
)
)
;
let
win =
Window
::
new
(
512
,
512
,
"Game of Life"
.
to_string
(
)
)
;
while
!win
.
is_closed
(
)
{
let
n_hood =
convolve2
(
&
state
,
&
kernel
,
ConvMode
::
DEFAULT
,
ConvDomain
::
SPATIAL
)
;
let
c0 =
&
eq
(
&
n_hood
,
&
c0
,
false
)
;
let
c1 =
&
eq
(
&
n_hood
,
&
c1
,
false
)
;
state = state
*
c0 + c1
;
win
.
draw_image
(
&
normalise
(
&
state
.
cast
::
<
f32
>
(
)
)
,
None
)
;
}
}
Back
|
FazBrowse Home
|
New Git URL