Thursday, August 30, 2012

vim latex setup (most updated)

tried so many times and searched all over google but no one works,
finally find out by myself
so let me put it here:

in sumtrapdf, settings, option, inverse search put:
"C:\Program Files\Vim\vim73\gvim.exe" --remote-silent +%l "%f"

in latex-suite, search in ftplugin/latex-suite/compiler.vim and modify
as follows:

original:
if (has('win32') && (viewer =~? "^ *yap\( \|$\)"))
let execString = 'silent! !start '. viewer.' -s
'.line('.').expand('%').' '.mainfnameRoot

New:
if (has('win32') && (viewer =~? "^ *yap\( \|$\)" || viewer =~? "^sumatrapdf"))
if viewer =~? "^sumatrapdf"
let relativeFile=substitute(expand("%:p"),
Tex_GetMainFileName(':p:h').'/', '','')
let execString = 'silent! !start SumatraPDF
-reuse-instance "'.mainfnameFull.'.'.s:target.'" -forward-search
"'.relativeFile.'" '. line('.')
else
let execString = 'silent! !start '. viewer.' -s
'.line('.').expand('%').' '.mainfnameRoot
endif

in vimrc put:
let g:Tex_DefaultTargetFormat = 'pdf'
let g:Tex_CompileRule_pdf='xelatex --synctex=-1 -src-specials
-interaction=nonstopmode $*'
let g:Tex_ViewRule_pdf='SumatraPDF'
let g:Tex_MultipleCompileFormats='pdf'

Okay, thats it, no bother, forward(\ls) and backword searching (double click)

Monday, August 20, 2012

vim for latex

What you need:

A text editor that can perform an action each time the document has changed
A fast way to recompile LaTeX
A viewer that can quickly reload the document.
I used gVim as the text editor, latexdaemon as the compilation engine,
and Sumatra as the PDF viewer.

In Vim, issue the command :au! CursorHoldI,CursorHold <buffer> silent!
:update to make it auto-save the document every time you stop typing.
Also :set updatetime=800 to set the timeout after which saving happens
to a low value.

latexdaemon will auto-compile the document in an efficient way every
time it's changed. Use the following at the beginning of the file to
make it produce PDF:

%Daemon> ini=pdflatex
Or just start it with latexdaemon -ini=pdflatex.

Sumatra will automatically re-load the file every time it is changed,
and it will not lock the PDF (so it can be recompiled without closing
Sumatra first).

This recipe will give you an almost real-time preview, but it takes
some effort to set up, and is not without issues. For example, you
might not want to continuously auto-save, in case you'd want to revert
to an earlier version.

There's a lot to improve on this, but I've been using it for some time
(after reading your question), and thought putting the recipe out here
might be useful for others too.

Since I was lazy, I just put everything to set this up into a .bat file:

@start C:\Path\To\Sumatra\SumatraPDF.exe %1.pdf
@start latexdaemon -ini=pdflatex %1.tex
@gvim -c ":au! CursorHoldI,CursorHold <buffer> silent! :update" -c
":set updatetime=800" %1.tex

also the sync issue, refer to
http://william.famille-blum.org/blog/static.php?page=static081010-000413

Friday, July 27, 2012

object oriented programming

so, object oriented programming is an important concept 
but only when you need it, you define a class

a class should be defined when containing data is important to an abstract object and is not important to outside. 
define a class means when you initiate an instance/object, the object can handle and should handle some thing by itself..!!!

Tuesday, July 24, 2012

python ctype resize issues

    

Let me summarize this issue myself. but please credit to @ecatmur and others The resize() function can be used to resize the memory buffer of an existing ctypes object. The function takes the object as first argument, and the requested size in bytes as the second argument. However, the resized object still has limited accessibility to the memory buffer based on its original size. to solve the problem. 3 different functions are defined:

    def customresize1(array, new_size):
    resize
(array, sizeof(array._type_)*new_size)
   
return (array._type_*new_size).from_address(addressof(array))
def customresize2(array, new_size):
   
return (array._type_*new_size).from_address(addressof(array))
def customresize3(array, new_size):
   
base = getattr(array, 'base', array)
    resize
(base, sizeof(array._type_)*new_size)
    new_array
= (array._type_*new_size).from_address(addressof(base))
    new_array
.base = base

all functions return an object that shares the memory of the original owner, which does not own the memory and can not be resized (e.g., gives error in customresize1)

customresize2 does return a resized array, but keey in mind that from_address does not allocate memory for resizing..

customresize3 keeps a record of the base object that owns the memory, but the returned object is not the owner of memory

As python is dynamically allocating its memory and garbage collecting, so, if you want to resize something, just redo the size will work. eg.:

    list = (c_int * NEW_SIZE)()

or you may want to keep the original values then:

    list = (c_int * NEW_SIZE)(*list)

Tuesday, July 17, 2012

a review on OCT optimization algorithms

the topic includes:
K-linearization
1. adding a prsim
2. NUDFT
3. NFFT (a very smart way, quick and almost simliar performance as NUDFFT)
4. zero crossing
5. zero crossing to initialize Auto Spectral Calibration (an iterative way to fit the curvature of the non-linear unwrapped phase)
6. Total Variance for NUDFT (this one shows the best results till now)

Doppler methods:
1. conventional
2. filtering in lateral
3. speckle
4. zero crossing (like STFFT for time domain)

lateral flow esitimation:
1. lateral correlation (Ruikang Wang)
2. speckle analysis 

Wednesday, July 11, 2012

修行心得2012-07-11

1.如果打坐过程中有恐惧担忧,记着慈悲没有敌人,智慧没有烦恼
2.心中要有正念的力量,应该是一种清净而又向上的。可以默念六字大明咒来来增强这种感觉
3.感觉是次要的,在数息静下来以后,要放下,止住,观照。

Tuesday, July 10, 2012

deep copy vs shallow copy vs weakref

look at the following example:

import copy
list = [ ['a'] ]
list_copy = copy.copy(list)
list_copy[0].append('b')
print list, list_copy

output is: 

[['a', 'b']] [['a', 'b']]

the lets try:

import copy
list = [ ['a'] ]
list_copy = copy.copy(list)
list_copy.append('b')
print list, list_copy

output is: 

[['a']] [['a'], 'b']


the above shows shallow copy, which share the element, but not the obj of list itself
a deep copy will not share anything as a brand new separate obj.

so what is the weakref used for?

class LeakTest(object):
   def __init__(self):
     print 'Object with id %d born here.' % id(self)
   def __del__(self):
     print 'Object with id %d dead here.' % id(self)
def foo():
   A = LeakTest()
   B = LeakTest()
   A.b = B
   B.a = A
foo()


output is: 

Object with id 71183792 born here.
Object with id 71182608 born here.

the object of A and B are not deleted, why? cus they refer to each other, cause a dead lock that can not delete the objs, that is why we need weakref:

import weakref
class LeakTest(object):
   def __init__(self):
     print 'Object with id %d born here.' % id(self)
   def __del__(self):
     print 'Object with id %d dead here.' % id(self)
def foo():
   A = LeakTest()
   B = LeakTest()
   A.b = weakref. proxy (B)
   B.a = weakref. proxy (A)
foo()


output is: 

Object with id 71180816 born here.
Object with id 71181008 born here.
Object with id 71180816 dead here.
Object with id 71181008 dead here.

Monday, July 2, 2012

so python is dynamic

basically, the value of the python objects does not change if you dont modify it, but the memory address changes. the reason is that the value, or shall we call it the Attributes, is constructed every time you call it, and wrapped, and send to python interpreter. it spends some time, but saves memory troubles.

python immutable and mutable values

In python, immutable variable types are int, bool, string and so on, all of them are considered as a single value variable, thus making them immutable insures the function calls behavior like other languages , c for example.

But for list and dict, usually it is considered as *args and  **kwdargs, which are passed as pointers,  thus making them mutabe again insures the function call behaviors like other languages.

 

--

Zhijia

 


Confidentiality Notice: This message (including attachments) is a private communication solely for use of the intended recipient(s). If you are not the intended recipient(s) or believe you received this message in error, notify the sender immediately and then delete this message. Any other use, retention, dissemination or copying is prohibited and may be a violation of law, including the Electronic Communication Privacy Act of 1986."   ­­  

Friday, June 29, 2012

python, numpy, c and ctypes

so, it is very easy for combining c and python together. 
and it is also very confusing because there are alot of ways to do such same task

for instance, there are boost, swig, sip and shiboken
i think it would better to standarize the interface and integrate it into new python 3000
anyway, here are some collections of how to do such 

1. memory address -> numpy array: 

ctypes_array = (ctypes.c_char * MEM_SIZE).from_address(pointer) 
numpy_array = numpy.frombuffer(ctypes_array, dtype=numpy.float64)
numpy_array

2. numpy array -> memory address
pointer = ndarray.__array_interface__['data'][0]

3. numpy array -> ctype pointer, which is already wrapped, not a simple address 

data = numpy.array([[0.1, 0.1], [0.2, 0.2], [0.3, 0.3]])
data = data.astype(numpy.float32)
c_float_p = ctypes.POINTER(ctypes.c_float)
data_p = data.ctypes.data_as(c_float_p)
then if we want to access the data at this address, use the function contents()

actually all these can be done in a standard numpy way, pls refer to :
C-Types Foreign Function Interface (numpy.ctypeslib)

Sunday, June 17, 2012

python tricks

1.      String to dict
eval(string)
or
import ast
ast.literal_eval(string)

the later one is considered to be safer

2.      The config parser module use cap letter for section name, and uncap for options , no matter what is the input.



Tuesday, June 12, 2012

Python packaging and installation

in setup.py file
for instance ::
    from distutils.core import setup
    setup(
      name = 'MyTools',
      version = '0.1.0',
      author = 'zhijia yuan',
      packages = ['oct'],
      author_email = 'zyuan@topcon.com',
      install_requires = ['NumPy >= 1.0.4'],
      )

after installation, the available import is related to the packages name::
    import oct #works
    import MyTools.oct #doesnot work
which means that the name MyTools just a top tag for your package, and oct is the real package name that you can import
if you have multiple packages, it would be more reasonable to keep the name and package name organized. 

Monday, April 23, 2012

PyQt - QLabel and QGraphicsView

These two classes are different
For a quick display of images , QLabel is nicer with low system cost
But QGraphicsView is more flexible with functionls such as transform, multiItem display


Wednesday, April 11, 2012

Extend python with c -2

when using py2exe and pyinstaller 
several issues are found and listed here:
  1. py2exe supports relative directory to find the ini files in the ./conf folder, but pyinstaller use absolute path, and can only be run under the folder
  2. for the c extend module of python, the loading dll error is due to that the computer does not have NI imaq installed, it seems that when the module is load, it already starts to load the dll file, and the dll file starts to load the driver of the imaq hardware, as such, the error of dll initialization is due to the lack of the driver/hardware
  3. the c extend module (.pyd) relies on the OS version, e.g., build from 32 bit system won't work on build from 64 bit system. the error msg is sth like:

    %1 Is Not a Valid Win32 Application


Tuesday, April 10, 2012

Extending Python with C - 1

The idea of linking these two languages is that:
python args -> Parser -> c args
c output  -> Parser ->python objects

the  Parser is written in C. and a Wrapper C program is needed to call the Parser and link python with C