本文介绍了未定义的子例程& PDL :: divide的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以下代码中尝试Perl的PDL:

I'm trying Perl's PDL in the following code:

#!/usr/bin/perl  -w
use strict;
use PDL::Core qw(pdl);
use PDL::Math qw(isfinite);
use PDL::Primitive qw(statsover);


my $div = 4;
my @array1 = (0..10);
my $pdl_array = log(pdl(@array1)/$div);
$pdl_array->where(!isfinite($pdl_array)) .= 0;
my($mean,$stdev) = statsover($pdl_array);
die $pdl_array,"\n",$mean," ",$stdev,"\n";

我收到此错误:

在./compare_const.pl第10行调用的未定义子例程& PDL :: divide.

Undefined subroutine &PDL::divide called at ./compare_const.pl line 10.

请问有什么提示吗?

推荐答案

PDL在设计上是不寻常的,因此具有不寻常且有些脆弱的导入机制.每个PDL模块通过将新方法直接插入PDL的功能中,为PDL添加功能.包.该决定是在PDL v2的设计之初就做出的,并且在随后的十年中一直没有改变. (即使以向后兼容的方式,也没有理由不能更改它,但是没有一个PDL开发人员为此预留了时间.)

PDL is unusual in its design, and therefore has an unusual and somewhat fragile import mechanism. Each PDL module adds functionality to PDL by inserting a new method directly into PDL's package. This decision was made very early in the design of PDL v2, and has not been changed in the intervening decade. (There's no reason it couldn't be changed, even in a backward compatible way, but none of the PDL developers have set aside the time to do so.)

因此,您必须加载少量模块以确保PDL具有其必需的基本功能.如果您看一下PDL的导入功能,您会注意到它将大量程序包显式加载到调用者的名称空间中.这样做的原因很不错-跨多个模块拆分功能以保持发行版合理--但是该实现与常见的Perl做法不符.这就是为什么您将特定功能导入名称空间的尝试失败的原因.

As a result, you must load a handful of modules to ensure that PDL has its requisite, basic functionality. If you take a look at PDL's import function, you'll notice that it explicitly loads a number of packages into the caller's namespace. The reason for this is good---splitting functionality across multiple modules to keep the distribution sane---but the implementation is not aligned with common Perl practices. This is why your attempt to import specific functions into your namespace failed.

已经说明了解决方案.用单个use PDL替换所有use PDL::...语句:

The solution has already been explained. Either replace all of your use PDL::... statements with a single use PDL:

use strict;
use warnings;
use PDL;

my $div = 4;
...

或说use PDL::Lite(以确保PDL的软件包完整),然后将特定功能导入到您的(主)软件包中

or say use PDL::Lite (to ensure that PDL's package is complete) and then import the specific functions into your (main) package

use strict;
use warnings;

use PDL::Lite;
use PDL::Core qw(pdl);
use PDL::Math qw(isfinite);
use PDL::Primitive qw(statsover);

my $div = 4;
...

这篇关于未定义的子例程& PDL :: divide的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:10