Skip to content

Instantly share code, notes, and snippets.

@run4flat
run4flat / Blocks.pm
Last active December 25, 2015 19:08
Basic use of C::Blocks
use strict;
use warnings;
package C::Blocks;
use Devel::Declare;
sub import {
my $class = shift;
my $caller = caller;
@run4flat
run4flat / An-Explanation.pod
Last active December 18, 2015 09:19
Lexically scoping method calls for a specific class in Perl.

GOAL

Lexically Scoped Methods for a specific class (aiming at PDL).

Why?

In PDL, we have a lot of methods that only make sense for certain analyses, yet when we use a PDL module that defines a set of functions, the module almost always imports its functions into the PDL package. For example, it is rarely useful to apply a one-dimensional Fourier transform to an image, but if any of my code says

@run4flat
run4flat / comments.mkd
Last active December 17, 2015 07:59
tentative feedback to reddit

djimbob, c'mon. FUDDING on Perl 4 is hardly helpful for the OP. If you're going to argue Python against Perl, you should argue Python 3 vs Perl 5.16. This is 2013, after all.

Python is a modern well-designed multi-paradigm programming language.

Sorta. Of course, Python has its warts, like join being a string method and not a list method, and reverse working in-place instead of returning a new list. And, Ruby and Perl are also well-designed multi-paradigm programming languages, and they have their warts, too. As far as a scientist is concerned, Perl and Python differentiate from Ruby because they have N-dimensional libraries, PDL and numpy, respectively, that make them as performant as Matlab (for 99.9% of uses, that is). If the OP is looking for a scripting glue language, he/she should give careful thought to Python or Perl. (Some will also throw R or Matlab into the mix, but I don't think they're well designed languages, just popular ones.)

Python code reads beautifully.

Nope. Check out (the most up-

@run4flat
run4flat / FuncND.pm.PL
Created March 13, 2013 18:45
First cut at PDL::FuncND.pm.PL for Diab
use strict;
use warnings;
# Generates FuncND.pm. Call with
# perl FuncND.pm.PL FuncND.pm
my $out_filename = $ARGV[0];
open my $out_fh, '>', $out_filename;
@run4flat
run4flat / Prima.pm
Last active December 14, 2015 20:29
First cut at PDL::Demos::Prima
use strict;
use warnings;
############################################################################
package PDL::Demos::Prima;
############################################################################
# It's a shame that PDL::Demos::Routines is in a file called
# PDL::Demos::Screen. Oh well.
use PDL::Demos::Screen;
@run4flat
run4flat / Minimal.c
Last active December 13, 2015 21:08
C code auto-generated from XS code that gives trouble when compiled with nvcc.
/*
* This file was generated automatically by ExtUtils::ParseXS version 3.18 from the
* contents of Minimal.xs. Do not edit this file, edit Minimal.xs instead.
*
* ANY CHANGES MADE HERE WILL BE LOST!
*
*/
#line 1 "lib/CUDA/Minimal.xs"
#include "EXTERN.h"
@run4flat
run4flat / piddlebot.pl
Created February 14, 2013 21:55
Piddlebot, used on irc.perl.org#pdl
#!/usr/bin/perl
use warnings;
use strict;
use POE;
use POE::Component::IRC::State;
use constant CHANNEL => '#pdl';
# Load the current piddlebot functions:
use piddlebot;
my $last_modified = (stat('piddlebot.pm'))[9];
@run4flat
run4flat / matmult_pdl_thr.pl
Created February 13, 2013 03:55
Multicore matrix multiplication using PDL::Parallel::threads
#!/usr/bin/env perl
##
## Usage:
## perl matmult_pdl_thr.pl 1024 ## Default size is 512: $c = $a * $b
##
## by David Mertens
## based on code by Mario Roy
#################
@run4flat
run4flat / add-labels-via-full-plot-call.pl
Created January 21, 2013 17:54
Adding axis labels via single plot() function call.
use PDL::Graphics::Prima::Simple;
plot(
-data => ds::Pair($time, $temp,
plotType => ppair::Lines,
),
x => { label => 'Days into the Future' },
y => { label => 'Temperature (Degrees Fahrenheit)' },
);
@run4flat
run4flat / add-forecast-lables-via-method-calls.pl
Created January 21, 2013 17:48
Adding axis labels via method calls in the plot object.
use PDL::Graphics::Prima::Simple;
my ($window, $plot) = line_plot $time, $temp;
$plot->x->label('Days into the Future');
$plot->y->label('Temperature (Degrees Fahrenheit)');
$plot->title("Forecast for $zip_code");
$window->execute;