Data-Frame

 view release on metacpan or  search on metacpan

lib/PDL/Logical.pm  view on Meta::CPAN

package PDL::Logical;
$PDL::Logical::VERSION = '0.006005';
# ABSTRACT: PDL subclass for keeping logical data

use 5.016;
use warnings;

use PDL::Lite ();   # PDL::Lite is the minimal to get PDL work
use PDL::Core qw(pdl);

use Ref::Util qw(is_plain_arrayref);
use Safe::Isa;

use parent 'PDL';
use Class::Method::Modifiers;

sub new {
    my ( $class, @args ) = @_;

    my $data;
    if ( @args % 2 != 0 ) {
        $data = shift @args;    # first arg
    }
    my %opt = @args;

    if ( $data->$_DOES('PDL') ) {
        $data = !!$data;
    }
    elsif ( is_plain_arrayref($data) ) {

        # this is faster than Data::Rmap::rmap().
        state $rmap = sub {
            my ($x) = @_;
            is_plain_arrayref($x)
              ? [ map { __SUB__->($_) } @$x ]
              : ( $x ? 1 : 0 );
        };

        $data = pdl( $rmap->($data) );
    }
    else {
        $data = pdl( $data ? 1 : 0 );
    }

    my $self = $class->initialize();
    $self->{PDL} .= $data;

    return $self;
}

sub initialize {
    my ($class) = @_;
    return bless( { PDL => PDL::Core::null }, ref $class || $class );
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

PDL::Logical - PDL subclass for keeping logical data

=head1 VERSION

version 0.006005



( run in 2.405 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )