仅从 perl PDL 导出 pdl()

发布于 2024-12-28 21:17:28 字数 671 浏览 3 评论 0原文

我只想从 PDL 导出 pdl() 函数,以避免与其他自动导出的函数(例如 maxmedian)发生命名空间冲突sumintersect 等。但是,当我尝试时

use PDL qw(pdl);

它不起作用,因为上述函数仍然被导出(并且我收到有关重新定义函数的警告)。

另一方面,如果我这样做,

use PDL qw();

碰撞就不会发生。但是,当我尝试通过 PDL::pdl() 在程序中使用 pdl() 函数时,它失败并显示以下错误消息:

Can't call method "new" on unblessed reference at Basic/Core/Core.pm.PL (i.e. PDL::Core.pm) line 934.

另外,我在脚本内尝试过

{
     require PDL;
     pdl();
}

我收到同样的错误消息。

有人可以建议我如何仅导出 pdl() 吗?谢谢!

I want to export only the pdl() function from PDL to avoid namespace collision with other automatically exported functions such as max, median, sum, intersect etc. However, when I tried

use PDL qw(pdl);

it doesn't work as the aforementioned functions still get exported (and I get warnings on functions being redefined).

On the other hand, if I do

use PDL qw();

The collision doesn't happen. But when I try to use the pdl() function in the program via PDL::pdl(), it fails with this error message:

Can't call method "new" on unblessed reference at Basic/Core/Core.pm.PL (i.e. PDL::Core.pm) line 934.

Also, I tried inside the script

{
     require PDL;
     pdl();
}

I get the same error message.

Can someone advice on how I can export pdl() only? Thx!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞陪衬 2025-01-04 21:17:28

实际上,我有点惊讶 use PDL qw() 的作用与 use PDL 不同。事实上,我不明白它是如何做到的:来自 PDL::import 的代码不关注它的参数。为此目的创建了一个名为 PDL::Lite 的不同模块,它相当于:

use PDL::Core '';
use PDL::Ops '';
use PDL::Primitive '';
use PDL::Ufunc '';
use PDL::Basic '';
use PDL::Slices '';
use PDL::Bad '';
use PDL::Version;
use PDL::Lvalue;

删除了通常使用 PDL 中的一些额外内容,并且没有函数被导入。 (PDL::LvaluePDL::Version 不会导出任何内容。)

关于第二个问题,当您使用 PDL::Lite 时,您仍然可以使用 PDL->pdl(1, 2, 3) 获取 pdl 构造函数。您不能说 PDL::pdl(1, 2, 3) 因为构造函数实际上是在 PDL::Core 包中定义的。去算算吧。因此, PDL::Core::pdl(1, 2, 3) 符合您的意思,但不是显而易见的选择。

I'm actually a bit surprised that use PDL qw() does anything different from use PDL. In fact, I don't see how it can: the code from PDL::import doesn't pay attention to its arguments. A different module was created for this very purpose called PDL::Lite, which is equivalent to:

use PDL::Core '';
use PDL::Ops '';
use PDL::Primitive '';
use PDL::Ufunc '';
use PDL::Basic '';
use PDL::Slices '';
use PDL::Bad '';
use PDL::Version;
use PDL::Lvalue;

Some of the extras from the usual use PDL are cut out, and none of the functions are imported. (PDL::Lvalue and PDL::Version do not export anything.)

On to your second question, when you use PDL::Lite, you can still get at the pdl constructor with PDL->pdl(1, 2, 3). You cannot say PDL::pdl(1, 2, 3) because the constructor is actually defined in the PDL::Core package. Go figure. So, PDL::Core::pdl(1, 2, 3) does what you meant, but is not the obvious choice.

想念有你 2025-01-04 21:17:28

概要
使用 PDL; # 相当于以下内容:

 使用 PDL::Core;
   使用 PDL::Ops;
   使用 PDL::Primitive;
   使用 PDL::Ufunc;
   使用 PDL::Basic;
   使用 PDL::Slices;
   使用 PDL::Bad;
   使用 PDL::MatrixOps;
   使用 PDL::数学;
   使用 PDL::版本;
   使用 PDL::IO::Misc;
   使用 PDL::IO::FITS;
   使用 PDL::IO::Pic;
   使用 PDL::Lvalue;

我想如果你只导入 PDL::Core,你只会得到这个模块中的函数。

SYNOPSIS
use PDL; # Is equivalent to the following:

   use PDL::Core;
   use PDL::Ops;
   use PDL::Primitive;
   use PDL::Ufunc;
   use PDL::Basic;
   use PDL::Slices;
   use PDL::Bad;
   use PDL::MatrixOps;
   use PDL::Math;
   use PDL::Version;
   use PDL::IO::Misc;
   use PDL::IO::FITS;
   use PDL::IO::Pic;
   use PDL::Lvalue;

I guess if you only import PDL::Core, you'll get only the functions in this module.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文