Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
d8bc9dbd
Commit
d8bc9dbd
authored
Jul 08, 2019
by
Adam Procter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Add a few more toy dynamic examples"
This reverts commit
6d123d6e
.
parent
6d123d6e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
189 deletions
+0
-189
dynamic.in.cpp
test/dynamic.in.cpp
+0
-189
No files found.
test/dynamic.in.cpp
View file @
d8bc9dbd
...
...
@@ -456,192 +456,3 @@ NGRAPH_TEST(dynamic_${BACKEND_NAME}, reshape)
ASSERT_EQ
(
results
,
data
);
}
}
static
void
axpy_test
(
const
PartialShape
&
input_pshape
,
const
std
::
vector
<
Shape
>&
input_shapes
)
{
auto
a
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
input_pshape
);
auto
x
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
input_pshape
);
auto
y
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
input_pshape
);
auto
axpy
=
a
*
x
+
y
;
auto
f
=
make_shared
<
Function
>
(
NodeVector
{
axpy
},
ParameterVector
{
a
,
x
,
y
});
auto
backend
=
runtime
::
Backend
::
create
(
"${BACKEND_NAME}"
,
true
);
auto
ex
=
backend
->
compile
(
f
);
auto
t_r
=
backend
->
create_dynamic_tensor
(
element
::
f32
,
input_pshape
);
for
(
auto
&
shape
:
input_shapes
)
{
vector
<
float
>
inputs
(
shape_size
(
shape
));
for
(
size_t
i
=
0
;
i
<
shape_size
(
shape
);
i
++
)
{
inputs
[
i
]
=
i
;
}
auto
t_a
=
backend
->
create_tensor
(
element
::
f32
,
shape
);
auto
t_x
=
backend
->
create_tensor
(
element
::
f32
,
shape
);
auto
t_y
=
backend
->
create_tensor
(
element
::
f32
,
shape
);
copy_data
(
t_a
,
inputs
);
copy_data
(
t_x
,
inputs
);
copy_data
(
t_y
,
inputs
);
ex
->
call_with_validate
({
t_r
},
{
t_a
,
t_x
,
t_y
});
ASSERT_EQ
(
t_r
->
get_shape
(),
shape
);
auto
results
=
read_vector
<
float
>
(
t_r
);
vector
<
float
>
expected_values
(
shape_size
(
shape
));
for
(
size_t
i
=
0
;
i
<
shape_size
(
shape
);
i
++
)
{
expected_values
[
i
]
=
(
i
*
i
)
+
i
;
}
EXPECT_TRUE
(
test
::
all_close_f
(
results
,
expected_values
));
}
}
NGRAPH_TEST
(
dynamic_
$
{
BACKEND_NAME
},
axpy
)
{
// Test with shape {?, 3, 3}.
axpy_test
(
PartialShape
{
Dimension
::
dynamic
(),
3
,
3
},
{
Shape
{
2
,
3
,
3
},
Shape
{
5
,
3
,
3
}});
// Test with shape {?, ?, ?}.
axpy_test
(
PartialShape
::
dynamic
(
3
),
{
Shape
{
2
,
3
,
3
},
Shape
{
5
,
3
,
3
},
Shape
{
2
,
5
,
2
},
Shape
{
8
,
1
,
8
}});
// Test with shape ?. (Rank unknown.)
axpy_test
(
PartialShape
::
dynamic
(),
{
Shape
{
2
,
3
,
3
},
Shape
{
5
,
3
,
3
},
Shape
{
2
,
5
,
2
},
Shape
{
8
,
1
,
8
},
Shape
{
5
},
Shape
{
8
,
2
},
Shape
{
8
,
2
,
8
,
2
},
Shape
{
2
,
3
,
4
,
5
,
2
}});
}
static
void
to_vector_test
(
const
PartialShape
&
input_pshape
,
const
std
::
vector
<
Shape
>&
input_shapes
)
{
auto
x
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
input_pshape
);
shared_ptr
<
Node
>
x_new_shape
=
make_shared
<
op
::
ShapeOf
>
(
x
);
x_new_shape
=
make_shared
<
op
::
Product
>
(
x_new_shape
,
AxisSet
{
0
});
x_new_shape
=
make_shared
<
op
::
Reshape
>
(
x_new_shape
,
AxisVector
{},
Shape
{
1
});
auto
x_reshaped
=
make_shared
<
op
::
DynReshape
>
(
x
,
x_new_shape
);
auto
f
=
make_shared
<
Function
>
(
NodeVector
{
x_reshaped
},
ParameterVector
{
x
});
auto
backend
=
runtime
::
Backend
::
create
(
"${BACKEND_NAME}"
,
true
);
auto
ex
=
backend
->
compile
(
f
);
auto
t_r
=
backend
->
create_dynamic_tensor
(
element
::
f32
,
PartialShape
::
dynamic
(
1
));
for
(
auto
&
shape
:
input_shapes
)
{
vector
<
float
>
inputs
(
shape_size
(
shape
));
for
(
size_t
i
=
0
;
i
<
shape_size
(
shape
);
i
++
)
{
inputs
[
i
]
=
i
;
}
auto
t_x
=
backend
->
create_tensor
(
element
::
f32
,
shape
);
copy_data
(
t_x
,
inputs
);
ex
->
call_with_validate
({
t_r
},
{
t_x
});
ASSERT_EQ
(
t_r
->
get_shape
(),
Shape
(
shape_size
(
shape
)));
auto
results
=
read_vector
<
float
>
(
t_r
);
EXPECT_TRUE
(
test
::
all_close_f
(
results
,
inputs
));
}
}
// Disabled for now because constant folding does not handle "Product" yet.
NGRAPH_TEST
(
DISABLED_dynamic_
$
{
BACKEND_NAME
},
to_vector
)
{
// Test with shape {?, 3, 3}.
to_vector_test
(
PartialShape
{
Dimension
::
dynamic
(),
3
,
3
},
{
Shape
{
2
,
3
,
3
},
Shape
{
5
,
3
,
3
}});
// Test with shape {?, ?, ?}.
to_vector_test
(
PartialShape
::
dynamic
(
3
),
{
Shape
{
2
,
3
,
3
},
Shape
{
5
,
3
,
3
},
Shape
{
2
,
5
,
2
},
Shape
{
8
,
1
,
8
}});
// Test with shape ?. (Rank unknown.)
to_vector_test
(
PartialShape
::
dynamic
(),
{
Shape
{
2
,
3
,
3
},
Shape
{
5
,
3
,
3
},
Shape
{
2
,
5
,
2
},
Shape
{
8
,
1
,
8
},
Shape
{
5
},
Shape
{
8
,
2
},
Shape
{
8
,
2
,
8
,
2
},
Shape
{
2
,
3
,
4
,
5
,
2
}});
}
static
void
reverse_shape_test
(
const
PartialShape
&
input_pshape
,
const
std
::
vector
<
Shape
>&
input_shapes
)
{
auto
x
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
input_pshape
);
shared_ptr
<
Node
>
x_new_shape
=
make_shared
<
op
::
ShapeOf
>
(
x
);
x_new_shape
=
make_shared
<
op
::
Reverse
>
(
x_new_shape
,
AxisSet
{
0
});
auto
x_reshaped
=
make_shared
<
op
::
DynReshape
>
(
x
,
x_new_shape
);
auto
f
=
make_shared
<
Function
>
(
NodeVector
{
x_reshaped
},
ParameterVector
{
x
});
auto
backend
=
runtime
::
Backend
::
create
(
"${BACKEND_NAME}"
,
true
);
auto
ex
=
backend
->
compile
(
f
);
auto
t_r
=
backend
->
create_dynamic_tensor
(
element
::
f32
,
PartialShape
::
dynamic
());
for
(
auto
&
shape
:
input_shapes
)
{
vector
<
float
>
inputs
(
shape_size
(
shape
));
for
(
size_t
i
=
0
;
i
<
shape_size
(
shape
);
i
++
)
{
inputs
[
i
]
=
i
;
}
auto
t_x
=
backend
->
create_tensor
(
element
::
f32
,
shape
);
copy_data
(
t_x
,
inputs
);
ex
->
call_with_validate
({
t_r
},
{
t_x
});
Shape
expected_shape
=
shape
;
std
::
reverse
(
expected_shape
.
begin
(),
expected_shape
.
end
());
ASSERT_EQ
(
t_r
->
get_shape
(),
expected_shape
);
auto
results
=
read_vector
<
float
>
(
t_r
);
EXPECT_TRUE
(
test
::
all_close_f
(
results
,
inputs
));
}
}
// Disabled for now because constant folding does not handle "Reverse" yet.
NGRAPH_TEST
(
DISABLED_dynamic_
$
{
BACKEND_NAME
},
reverse_shape
)
{
// Test with shape {?, 3, 3}.
reverse_shape_test
(
PartialShape
{
Dimension
::
dynamic
(),
3
,
3
},
{
Shape
{
2
,
3
,
3
},
Shape
{
5
,
3
,
3
}});
// Test with shape {?, ?, ?}.
reverse_shape_test
(
PartialShape
::
dynamic
(
3
),
{
Shape
{
2
,
3
,
3
},
Shape
{
5
,
3
,
3
},
Shape
{
2
,
5
,
2
},
Shape
{
8
,
1
,
8
}});
// Test with shape ?. (Rank unknown.)
reverse_shape_test
(
PartialShape
::
dynamic
(),
{
Shape
{
2
,
3
,
3
},
Shape
{
5
,
3
,
3
},
Shape
{
2
,
5
,
2
},
Shape
{
8
,
1
,
8
},
Shape
{
5
},
Shape
{
8
,
2
},
Shape
{
8
,
2
,
8
,
2
},
Shape
{
2
,
3
,
4
,
5
,
2
}});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment