AI-TensorFlow-Libtensorflow
view release on metacpan or search on metacpan
lib/AI/TensorFlow/Libtensorflow/Lib.pm view on Meta::CPAN
$ffi->type('opaque' => 'TF_CheckpointReader');
$ffi->type('opaque' => 'TF_AttrBuilder');
$ffi->type('opaque' => 'TF_ShapeAndType');
$ffi->type('opaque' => 'TF_ShapeAndTypeList');
$ffi->type('opaque' => 'TF_WritableFileHandle');
$ffi->type('opaque' => 'TF_StringStream');
$ffi->type('opaque' => 'TF_Thread');
$ffi->type('opaque' => 'TF_KernelBuilder');
$ffi->type('opaque' => 'TF_OpKernelConstruction');
$ffi->type('opaque' => 'TF_OpKernelContext');
$ffi->type('opaque' => 'TF_VariableInputLockHolder');
$ffi->type('opaque' => 'TF_CoordinationServiceAgent');
$ffi->type('opaque' => 'TF_Shape');
$ffi->type('object(AI::TensorFlow::Libtensorflow::Status)' => 'TF_Status');
$ffi->load_custom_type('::PtrObject', 'TF_Tensor' => 'AI::TensorFlow::Libtensorflow::Tensor');
$ffi->load_custom_type('::PtrObject', 'TF_TString' => 'AI::TensorFlow::Libtensorflow::TString');
$ffi->type('object(AI::TensorFlow::Libtensorflow::Eager::ContextOptions)', 'TFE_ContextOptions');
$ffi->type('object(AI::TensorFlow::Libtensorflow::Eager::Context)', 'TFE_Context');
## Callbacks for deallocation
# For TF_Buffer
$ffi->type('(opaque,size_t)->void' => 'data_deallocator_t');
# For TF_Tensor
$ffi->type('(opaque,size_t,opaque)->void' => 'tensor_deallocator_t');
$ffi;
};
}
sub mangler_default {
my $target = (caller)[0];
my $prefix = 'TF';
if( $target =~ /::Eager::/ ) {
$prefix = 'TFE';
}
sub {
my ($name) = @_;
"${prefix}_$name";
}
}
sub mangler_for_object {
my ($class, $object_name) = @_;
sub {
my ($name) = @_;
# constructor and destructors
return "TF_New${object_name}" if $name eq 'New';
return "TF_Delete${object_name}" if $name eq 'Delete';
return "TF_${object_name}$name";
};
}
sub arg(@) {
my $arg = AI::TensorFlow::Libtensorflow::Lib::_Arg->new(
type => shift,
id => shift,
);
return $arg, @_;
}
# from FFI::Platypus::Type::StringArray
use constant _pointer_incantation =>
$^O eq 'MSWin32' && do { require Config; $Config::Config{archname} =~ /MSWin32-x64/ }
? 'Q'
: 'L!';
use constant _size_of_pointer => FFI::Platypus->new( api => 2 )->sizeof('opaque');
use constant _pointer_buffer => "P" . _size_of_pointer;
package # hide from PAUSE
AI::TensorFlow::Libtensorflow::Lib::_Arg {
use Class::Tiny qw(type id);
use overload
q{""} => 'stringify',
eq => 'eq';
sub stringify { $_[0]->type }
sub eq {
my ($self, $other, $swap) = @_;
"$self" eq "$other";
}
}
1;
( run in 0.622 second using v1.01-cache-2.11-cpan-99c4e6809bf )