AI-TensorFlow-Libtensorflow
view release on metacpan or search on metacpan
t/upstream/CAPI/014_SetShape.t view on Meta::CPAN
#!/usr/bin/env perl
use Test2::V0;
use lib 't/lib';
use TF_TestQuiet;
use TF_Utils;
use aliased 'AI::TensorFlow::Libtensorflow';
use aliased 'AI::TensorFlow::Libtensorflow::Graph';
use aliased 'AI::TensorFlow::Libtensorflow::Status';
use aliased 'AI::TensorFlow::Libtensorflow::Output';
use AI::TensorFlow::Libtensorflow::DataType qw(INT32);
subtest "(CAPI, SetShape)" => sub {
my $s = Status->New;
my $graph = Graph->New;
my $feed = TF_Utils::Placeholder($graph, $s);
TF_Utils::AssertStatusOK($s);
my $feed_out_0 = Output->New({ oper => $feed, index => 0 });
my $num_dims;
note 'Fetch the shape, it should be completely unknown';
$num_dims = $graph->GetTensorNumDims($feed_out_0, $s);
TF_Utils::AssertStatusOK($s);
is $num_dims, -1, 'Dims are unknown';
note 'Set the shape to be unknown, expect no change';
$graph->SetTensorShape($feed_out_0, undef, $s);
$num_dims = $graph->GetTensorNumDims($feed_out_0, $s);
TF_Utils::AssertStatusOK($s);
is $num_dims, -1, 'Dims are still unknown';
note 'Set the shape to be 2 x Unknown';
my $dims = [2, -1];
$graph->SetTensorShape( $feed_out_0, $dims, $s);
TF_Utils::AssertStatusOK($s);
note 'Fetch the shape and validate it is 2 by -1.';
$num_dims = $graph->GetTensorNumDims($feed_out_0, $s);
TF_Utils::AssertStatusOK($s);
is $num_dims, 2, '2 dimensions';
my $returned_dims;
$returned_dims = $graph->GetTensorShape( $feed_out_0, $s );
TF_Utils::AssertStatusOK($s);
is $returned_dims, $dims, "Got shape [ @$dims ]";
note 'Set to a new valid shape: [2, 3]';
$dims->[1] = 3;
$graph->SetTensorShape( $feed_out_0, $dims, $s);
TF_Utils::AssertStatusOK($s);
note 'Fetch and see that the new value is returned.';
$returned_dims = $graph->GetTensorShape( $feed_out_0, $s );
TF_Utils::AssertStatusOK($s);
is $returned_dims, $dims, "Got shape [ @$dims ]";
note q{
Try to set 'unknown' with unknown rank on the shape and see that
it doesn't change.
};
( run in 2.996 seconds using v1.01-cache-2.11-cpan-56fb94df46f )