When using BPML, external wall should be treated as PECs for simplicity no matter how many the maximum sigma is. The best way to do that is setting initial field value on external wall to be zero, and then don't update field value of any point on the wall.
That is to say, it could be written as
Saving a few of computing resource.
Monday, February 1, 2010
Friday, January 29, 2010
Injecting one module into another in Python
Here is a simple code snippet to do that. Saving it to an individual file and import it in other module to use it.
Using exec statement is also good, but need to pass globals() or locals() dictionary to the function executing exec statement.
Doing dirty things in Python is really not easy...:/
Using exec statement is also good, but need to pass globals() or locals() dictionary to the function executing exec statement.
Doing dirty things in Python is really not easy...:/
Labels:
programming,
python
Wednesday, December 30, 2009
Assign initial value to a pointer
Today I suddenly got an idea. Most of time when we use pointer, we create a variable, and assign initial value to it, and then take its address become the value of a new pointer for succeeding use. But we create a redundant identifier here.
In fact, we could always create a fundamental type pointer and assign initial value to it through dereference operator like this snippet.
and no redundant variable here.
But when we define a simple struct like this.
We should assign initial value through arrow operator like third and fourth line in below snippet. Using brace to assign value as the same as first snippet is wrong syntax.
With a complex struct definition, this way increases many redundant code. Using brace to assignment initial value without creating redundant identifier could be done like this.
But I consider writing
In fact, we could always create a fundamental type pointer and assign initial value to it through dereference operator like this snippet.
and no redundant variable here.
But when we define a simple struct like this.
We should assign initial value through arrow operator like third and fourth line in below snippet. Using brace to assign value as the same as first snippet is wrong syntax.
With a complex struct definition, this way increases many redundant code. Using brace to assignment initial value without creating redundant identifier could be done like this.
But I consider writing
(*aPtr) = { 1, 2 };
may be the most intuitive way and it doesn't conflict with other syntax in C.
Labels:
c,
programming
Friday, November 13, 2009
Library for Numerical Computing
Briefly summarize some numerical library here. It looks there are too many useful tools. Either for parallel computing or for matrix, numerical calculating and plotting.
PLOT:
MatPlotLib: it seems to be the most awesome plotting tool among this list
PGPlot: C library, also have binding in Perl, Python,Ruby
PLPlot: cross-platform plot library, also have binding in Perl
Scientific Python
MRPlot
PARALLEL:
MPI Ruby: MPI Ruby binding
PyMPI: MPI integrated Python interpreter
MPI for Python Python MPI binding
Simple Remote Python : SrPy
Parallel Python
CALCULATION:
Perl Data Language: difficult to be categorized. Including calculating, plotting together. include FFTW, PGPlot, PLPlot, and many data processing tool such as HDF. Awesome Environment!
MPMath: Multi-Precision math functions collection.
RNUM
NArray
LibFFTW, also have binding in Perl, Ruby
Ruby DCL
LAPACK
SciPy
NumPy
GNU Scientific Library: C library, also have bindings in Ruby named Ruby/GSL and Ruby-GSL. and Python
RSRuby: bridge between Ruby and R
ARTICLES:
Ruby for Science
PLOT:
MatPlotLib: it seems to be the most awesome plotting tool among this list
PGPlot: C library, also have binding in Perl, Python,Ruby
PLPlot: cross-platform plot library, also have binding in Perl
Scientific Python
MRPlot
PARALLEL:
MPI Ruby: MPI Ruby binding
PyMPI: MPI integrated Python interpreter
MPI for Python Python MPI binding
Simple Remote Python : SrPy
Parallel Python
CALCULATION:
Perl Data Language: difficult to be categorized. Including calculating, plotting together. include FFTW, PGPlot, PLPlot, and many data processing tool such as HDF. Awesome Environment!
MPMath: Multi-Precision math functions collection.
RNUM
NArray
LibFFTW, also have binding in Perl, Ruby
Ruby DCL
LAPACK
SciPy
NumPy
GNU Scientific Library: C library, also have bindings in Ruby named Ruby/GSL and Ruby-GSL. and Python
RSRuby: bridge between Ruby and R
ARTICLES:
Ruby for Science
Sunday, August 30, 2009
Discussion about anonymous function in Perl and Ruby
Just for fun, tonight I write a methods invoking two anonymous functions to iterate a Range with specified condition in Ruby. It looks like
It reminded me that Perl also has the same problem. Even when we declare
Still only first sub keyword could be omitted. That means we should invoke it as
The only difference is Perl omitted the first (sub) and Ruby omitted the last (lambda).
I do want to figure out WHY they could not be designed to accept arbitrary quantity of anonymous functions.
class Range
def each_satisfy()
end
end
And I want to invoke it as
(1..10).each_satisfy(condition_lambda, callback_lambda)
(1..10).each_satsify { |n| ...condition statment... } do |n|
...callback statement...
end
When I try to define its prototype asdef each_satisfy(&condition, &callback)
end
Ruby Interpreter broke with syntax error. So that, finally I write it as
def each_satisfy(condition, &callback)
self.each do |n|
yield n if condition.call n
end
end
and it should be used as
(1..10).each_satsify lambda { |n| ...condition statment... } do |n|
...callback statement...
end
It reminded me that Perl also has the same problem. Even when we declare
sub each_satisfy(&&) {
}
Still only first sub keyword could be omitted. That means we should invoke it as
each_satisfy { ... condition ... } sub {
my ($iter) = @_;
... callback ...
}
The only difference is Perl omitted the first (sub) and Ruby omitted the last (lambda).
I do want to figure out WHY they could not be designed to accept arbitrary quantity of anonymous functions.
Labels:
perl,
programming,
ruby
Sunday, August 23, 2009
LWP, cURL, OpenSSL and Posterous
The fun of programming is there is always subtle mechanism in implementation. It costs time to discover but sometime is deserving. for example.
and
to
$ curl --basic -u <user> http://example.com/api/
$ echo -n "user:pass" | openssl base64 -e
and
to
Labels:
api,
perl,
programming,
webdesign
Monday, August 17, 2009
Posterous API in Perl
Posterous.com is a new (micro)-blog mesh-up system.
You can use it mesh up almost all your (micro)-blog. Post once, Publish Everywhere. And there is still many funny features.
It looks pretty good, so I translated its API to Perl. You can get it from CPAN. Still work in progress, but would be productive soon.
You can use it mesh up almost all your (micro)-blog. Post once, Publish Everywhere. And there is still many funny features.
It looks pretty good, so I translated its API to Perl. You can get it from CPAN. Still work in progress, but would be productive soon.
Labels:
api,
programming,
webservice
Saturday, August 15, 2009
Can't locate Git.pm in @INC
Well, the installation of Github::Import worked well on Linux boxs but always reported "
Git.pm comes with git instead of being a part of CPAN. Building a copy of git-core or copying from other box solve it quickly.
can't locate Git.pm in @INC
" on Macintosh boxs. It is just a little trick and the answer is here.Git.pm comes with git instead of being a part of CPAN. Building a copy of git-core or copying from other box solve it quickly.
Tuesday, July 7, 2009
the roadmap of upgrowth
和長輩們聊天總是很有趣的。即使那是一句老生常談,從長輩提攜的口吻中說出,依然受用。
6/26 的謝師宴,和賴暎杰老師坐在一起,我是這麼問的:「研究遇到瓶頸時,是怎麼面對的。」
「每天都多學會一件事,就不用擔心。」
yep...
6/26 的謝師宴,和賴暎杰老師坐在一起,我是這麼問的:「研究遇到瓶頸時,是怎麼面對的。」
「每天都多學會一件事,就不用擔心。」
yep...
Labels:
mood
Monday, July 6, 2009
Data::Model
Data::Model is a new ORM created by yappo, Its usage style is similar to DataMapper and Jifty::DBI.
Different from most famous equivalent, Data::Model handles multi-database. In order to do that, every model was appointed its database and table name in addition to its schema specification.
Let's see a simple example:
This is a simplest model in Data::Model, Only two DDL in it.
The first,
The second, pass the table name and schema to
Wait... Because Data::Model is too young to do auto_migration, we simply write
Though Data::Model is too young to have some important feature such as validator and hook, even has no ability to handle relation between two table. The prototype is really exciting.
[Chinese Version]
.
Different from most famous equivalent, Data::Model handles multi-database. In order to do that, every model was appointed its database and table name in addition to its schema specification.
Let's see a simple example:
This is a simplest model in Data::Model, Only two DDL in it.
The first,
base_driver( $driver )
specify which database the model would connect to. $driver is a Data::Model::Driver::DBI object. Write those diffusion code in every model is really not perlish, so we extract all possible drivers to MyApp::DB::driver()
.The second, pass the table name and schema to
install_model()
, this step is the same as above two ORM system. and then, all thing done. By the way, columns()
is the best syntax sugar provided by Data::Model::Schema.Wait... Because Data::Model is too young to do auto_migration, we simply write
MyApp::DB::make_schema()
to do that. Finally, we could do simple CRUD in our application. as below.Though Data::Model is too young to have some important feature such as validator and hook, even has no ability to handle relation between two table. The prototype is really exciting.
[Chinese Version]
.
Labels:
perl,
perl module,
tutorial
Subscribe to:
Posts (Atom)