Algorithm-Classifier-IsolationForest
view release on metacpan or search on metacpan
lib/Algorithm/Classifier/IsolationForest.pm view on Meta::CPAN
my $share = $shares[$w];
next unless $share > 0;
pipe( my $rh, my $wh ) or croak "pipe failed: $!";
my $pid = fork();
croak "fork failed: $!" unless defined $pid;
if ( $pid == 0 ) {
# child
close $rh;
binmode $wh;
if ( defined $self->{seed} ) {
srand( $self->{seed} + $w * 1009 );
}
# Deliberately never _build_forest_openmp here, even when
# use_openmp_fit is on: if this process (or the parent that
# fork()ed us) already ran any OpenMP region before this
# fork -- including plain score_samples()/predict() with
# the default use_openmp -- libgomp's thread pool exists
# but its worker threads didn't survive the fork. A child
# starting its own #pragma omp parallel region then tries
lib/Algorithm/Classifier/IsolationForest.pm view on Meta::CPAN
}
$trees = \@t;
}
print $wh Storable::freeze($trees);
close $wh;
# _exit so we don't run parent END/DESTROY in the child.
POSIX::_exit(0);
} ## end if ( $pid == 0 )
close $wh;
binmode $rh;
push @procs, { pid => $pid, rh => $rh, share => $share };
} ## end for my $w ( 0 .. $workers - 1 )
# Collect from each pipe in worker order so the canonical tree
# ordering is deterministic (worker 0's trees first, then 1's, ...).
my @all_trees;
for my $p (@procs) {
my $buf;
{
local $/;
lib/Algorithm/Classifier/IsolationForest/App/Command/pack.pm view on Meta::CPAN
my $want = $n_pts * $n_feats * 8;
read( $fh, $bytes, $want ) == $want
or die "'$path' truncated: wanted $want bytes, got " . ( defined $bytes ? length($bytes) : 0 ) . "\n";
close $fh;
return ( $n_pts, $n_feats, $bytes );
} ## end sub _read_packed
sub _write_packed {
my ( $path, $n_pts, $n_feats, $bytes ) = @_;
my $hdr = pack( 'a8 v v V V', MAGIC, VERSION, 0, $n_pts, $n_feats );
write_file( $path, { 'atomic' => 1, 'binmode' => ':raw' }, $hdr . $bytes );
}
# Helper used by the other commands so they all read the same format
# the same way. Returns ($n_pts, $n_feats, $bytes_str).
sub read_packed_file { _read_packed(@_) }
# Cheap, allocation-light magic check so consumer commands can peek at
# a path without slurping the whole file.
sub is_packed_file {
my ($path) = @_;
( run in 0.856 second using v1.01-cache-2.11-cpan-9581c071862 )