由买买提看人间百态

topics

全部话题 - 话题: callable
首页 上页 1 2 3 (共3页)
s******e
发帖数: 493
1
来自主题: Java版 - 工作中遇到的并行处理问题
Executor framework allows you to specify your own thread factory for
creating the threads. If you have to associate one predicator class to each
thread, you can do it there. But since predicator class is expensive to
create, you'd better ask yourself if it is absolutely needed for each thread
having its own predicator instance.
After that, you can simply implement callable interface, pass the input to
the constructor of the implemented class and save the input as a class
variable for use later. ... 阅读全帖
g*****g
发帖数: 34805
2
来自主题: Java版 - 工作中遇到的并行处理问题
Put the predictors in a blocking queue. In your Callable do a queue.get and
queue.put before and after, the code is much cleaner. You don't need to
synchronize in the Predictor BTW.
r****t
发帖数: 10904
3
来自主题: Programming版 - python下的expect
use threading, make a loop that calls a callable every some minutes.
i*****f
发帖数: 578
4
来自主题: Programming版 - Static variables in function
【 以下文字转载自 Python 俱乐部 】
发信人: icewolf (好好活), 信区: Python
标 题: Static variables in function
发信站: BBS 未名空间站 (Fri Feb 12 16:50:57 2010, 美东)
# method 1: a callable instance
# pros: good encapsulation
# cons: too verbal
class _func_with_static_var:
def __init__(self):
self.static_var = 0
def __call__(self, *args):
self.static_var += 1
print self.static_var
func_with_static_var = _func_with_static_var()
# method 2: pass as a list with default value
# pros: less verbal
# cons: a
d****p
发帖数: 685
5
来自主题: Programming版 - java main的疑问
So your point is make EACH java method callable from command line?
This is not doable.
Suppose you have a method
void foo(Foo f) where Foo is an object.
How can you provide argument f for invoking the method in command line? And
since you could not
provide it, why expose this method to command line for unnecessary fuss?
And your concept is really bad for performance: it needs the java runtime to
inteprete string in argument
list to suitable types for function lookup and value conversion and this
l********f
发帖数: 149
6
来自主题: Programming版 - 问题一枚
Basically, ur runnable3 is blocked by Callable.Get(), and ur Callalbe thread
is not released by barrier until runnable3 is done. It's a deadlock
scenario.
"A CyclicBarrier supports an optional Runnable command that is run once per
barrier point, after the last thread in the party arrives, but BEFORE ANY
THREADS ARE RELEASED. This barrier action is useful for updating shared-
state before any of the parties continue. "
f*******n
发帖数: 12623
7
来自主题: Programming版 - 问一个函数指针的问题,c++
In C++, you might want to use function pointers or function objects. The
most general is to make a template function that can accept any callable
type:
template
double objectFunc(F func) {
return func(x);
}
o**2
发帖数: 168
8
来自主题: Programming版 - FMP vs ExecutorService/Future
再来比较输入参数。Runnable的run()和Callable的call(),都不接受输入参数。如果
你的程序要给一个task设置参数,那你的主程序和这个task class都要有额外的处理。
Task class必须要加上必要的setters,主程序则要调用这些setter来设置输入参数,
然后才是submit给ExecutorService。
FMP tutorial里有一个完整可运行的GUI example,可以看到调用一个active object里
的method,只要一句就可以了:messenger.sendMessage ("file.analyzer:countWord"
, file, "Good");
http://www.mitbbs.com/article_t/Programming/31258831.html
更不用说不同的参数会带来task object的可重用性问题。
在输入参数上,FMP胜。
c********l
发帖数: 8138
9
来自主题: Programming版 - Java 多线程 的架构如何改进?
目前有这么一个程序,共有如下三种线程:
1,GUI主线程, non-daemon
2,2个服务器线程,分别监听端口号为8000和8001的socket, non-daemon
3,每当服务器socket.accept()时,生成一个新的daemon线程,
然后在这些n个新生成的并发线程中处理具体业务。
所以,主线程,服务器线程,daemon线程,这三种线程目前是三个实现Runnable的类
上述设计比较过时,因为是用的非常传统的implements Runnable的教科书式方法
有没有更先进的,比如Future/Callable/ExecutorService?
如果是这样,那么具体应该如何改进?
p**o
发帖数: 3409
10
来自主题: Programming版 - Python做计算怎么只用一个核?
python3的concurrent.futures有一些便利,可以在一个with语句块里多进程。
python2可以自己摸索一下multiprocessing
偷懒的话可以参考我下面的代码(从我自己写函数库里扒出来的),
实现的是一个比较通用的进程池链(把几个进程池串联起来)。
后面附一个使用示例。
要睡觉没时间慢慢解释了,看得懂就用,看不懂就算了...
文件 parallel.py
# -*- coding: utf-8 -*-
#
#
""" Helper functions and templates for multiprocessing.
http://docs.python.org/2/library/multiprocessing.html#examples
http://hg.python.org/cpython/file/3.3/Lib/concurrent/futures/pr
http://www.ibm.com/developerworks/aix/library/au-threadingpytho
"""
__all__ = [
'ProcessPo... 阅读全帖
p***o
发帖数: 1252
11
就是比如这样的代码:
... executor ...
... searcher ...
... target ...
Future future = executor.submit(new Callable() {
public String call() { return searcher.search(target); }
});
懒得每次都写那个lambda函数,能不能有个asyncCall可以这样:
Future future = asyncCall(executor, searcher, methodSearch, target);
p***o
发帖数: 1252
12
哦,我是在说那个Callable的匿名类,->也许可以省点事。
k**********g
发帖数: 989
13

我认为最大贡献其实是 immutability 和 data-flow thinking (value-based
thinking)。
These have contributed changes to database architectures, as well as
application programming. They also make multicore programming easier.
These ideas can be brought back into imperative (procedural) or OO languages.
To bring them back into OO languages, there need to be a kind of immutable
classes: (similar to C++ const keyword)
(1) all class fields are marked "immutable" keyword
(2) if class fields contain references to anot... 阅读全帖
l*****t
发帖数: 2019
14
来自主题: Programming版 - java笑node的
future, callable, executor
z****e
发帖数: 54598
15
来自主题: Programming版 - java笑node的
看rxjava
去reactive就可以绕开callable了
当然本质是一样的
l**********n
发帖数: 8443
16
来自主题: Programming版 - Scala question
is a code block like { } a Callable?
h****1
发帖数: 9
17
来自主题: Programming版 - scala开发效率确实奇高
居然会有人把scala说成糙快猛.真心是在用scala么?
scala = oop + fp. 最后都是编译成java bytecode 的
如果scala糙快猛 那java(尤其java8)也同样糙快猛
讨论oop 和 fp 哪个更好没有任何意义 人家scala就是把两者都结合了 你可以封装
在o级别也可以封装在f级别 取决与你的不确定性是"什么东西"还是"什么行为"
这两个层面的封装即使oop的programmer也每天碰到. Google 的Predicate, 甚至java
core 里面自带的 ActionListener, Runnable, Callable 都带有浓重的functional的
味道
说白了scala就是把你封装的function 再套一层class/interface的壳子扔给jvm
s****y
发帖数: 503
18

估计是题目想增加些难度,所以加个Properties。
题中要求Each thread provided with its own private share of the work (the
list, individual to each thread),是不是要为每个线程传入一个新的对象(实现
Callable的),每个对象的list都是私有的?
c******f
发帖数: 243
19
只用过future + executor service + callable/runnable...
多线的traffic,netty用的比较多
k**********g
发帖数: 989
20

首先所有底层的第三方代码要进行代码审查,看看有没有要修补,要上锁或加倍留意的
地方,例如mutable singleton,thread local data。其中的「锁」会用两种方式确保
正确运作而不锁死∶数据依赖和任务依赖。巩固代码後,下面的工作可分为三方面∶任
务包装,数据包装,界面包装。这包装和encapsulation不同,本质是换汤不换药,不
过是把代码结构稍为修改了。任务包装是把可执行的耗时任务分割为单元,细分为CPU
intensive和IO intensive,再分装为Callable。要确保每一个单元提交到Executor後
,能在任意thread成功执行。数据包装是把数据分类为Write once read many(WORM)或
是mutable。WORM会变成Futures。Mutable按需要可能改写成immutable pattern(类似
copy on modify)或用上述的依赖链使其单线程化。(即使单线程化,不相关的任务仍
可并列执行。)界面包装是把上述的改写用最简洁易用的方式表达,确保接口的组合性
(composability)。
经常会用到 ... 阅读全帖
c********1
发帖数: 5269
21
来自主题: Programming版 - Ruby和Scala很像。
Is lambda just a piece of code that is callable?
Is a lambda kind of like a function? sample code
import sys
sum = lambda x, y: x + y # def sum(x,y): return x + y
out = lambda *x: sys.stdout.write(" ".join(map(str,x)))
a = sum(1,2)
out(a)
out("\n")
print(a)
c*****e
发帖数: 3226
22
很容易的。
class SortSolution extends RecursiveTask {
final File[] files;
final int size;
Solution (File[] files) {
this.files = files;
this.size = files.length;
}
File[] sort() {
if (size== 1)
return files[0].sort();
File[] f1 = new SortSolution (files[0:size/2];
f1.fork();
File[] f2 = new SortSolution (files[size/2:size];
return f2.compute() + f1.join();
}
}
其实这玩意用Guava ListenableFutureTask 也很爽, 因为可以串联。只是这里用不上
ListeningExecutorService servic... 阅读全帖
k**********g
发帖数: 989
23
来自主题: Programming版 - C++并发和Java并发有多大区别?

Start with Java Executors.
Learn how to use it just like the Runnable and Callable class.
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/E
For example, if your goal is to write Android programs, (1) Executors is
basically all you need - the only other things you need are (2) thread
safety on Android, and (3) understand when and why you need to call Activity
.runOnUiThread() in some situations
C++ didn't have anything in the standard library comparable to Java
Executors. Design-by... 阅读全帖
c*********e
发帖数: 16335
24
用Thread还是ThreadPoolExecutor?
g*****g
发帖数: 34805
25
这个纯粹是个legacy问题,Runnable 出现的时候连concurrency package都没有。
Runnable没啥不能被替代的。
c*****e
发帖数: 3226
26
建议用 future
n******n
发帖数: 12088
27
向下兼容?
z*******3
发帖数: 13709
28
api名称都不一样,兼容什么?
c*********e
发帖数: 16335
29
别动不动就是task,thread.
java里面都是用的callable,如果用executor的话。
c*********e
发帖数: 16335
30
来自主题: Programming版 - 如何快速处理大量网上xml文件?
这个。。。现在不是流行callable吗?
d******e
发帖数: 2265
31
sorted('a', 'aa', 'bba')
Traceback (most recent call last):
File "", line 1, in
TypeError: 'str' object is not callable
>>> sorted(['a', 'aa', 'bba'])
['a', 'aa', 'bba']
算法是tim sort.
实现是进一个iterable.然后sort by key呗。就知道这么多。
你要问那么深,我认为有点装了。python这种胶水语言,知道上面怎么粘就够了。
c******a
发帖数: 10623
32
来自主题: Unix版 - One question about DBX debuger
for example:
G is a TYPE variable having
T1 as an integer array,
T2 as an integer.
Want to see the values of them.
Try "print G%T1(1)"
--it says 'T1 not callable'
Try "print G%T2" or "print G%T1"
--it says 'can't read from process'
Is there any way I can get what I want?
thx
b****f
发帖数: 27
33
这道题是ACTEX中Bonds, Page M4-20 中的11题:
该题目如下
A 1000 par value bond pays annual coupons of 80. The bond is redeemable at
par in 30 years, but is callable any time from the end of the 10th year at
1050. Based on her desired yield rate, an investor calculates the following
potential purchase prices, P:
Assuming the bond is called at the end of the 10th year, P=957
Assuming the bond is held until maturity, P=897
The investor buys the bond at the highest price that guarantees she will
receive at le
h*********1
发帖数: 102
34
Here is just my little thought:
First, the investor's desired yield rate should be the same rather the bond
is callable or not in order for the investor to compare and calculate the
potential purchase prices. If the desired yield rate is not unique, there is
no point to seek guarantee. After some calculations, we can find that the
desired yield rate is 9.00281466%.
If you choose the PV of the bond which is called at the end of 10th year,
the investor's desired yield rate can be guaranteed if and
h*********1
发帖数: 102
35
A 1000 par value bond pays annual coupons of 80. The bond is redeemable at
par in 30 years, but is callable any time from the end of the 10th year at
1050. Based on her desired yield rate, an investor calculates the following
potential purchase prices, P:
1) Assuming the bond is called at the end of the 10th year, P=957
2) Assuming the bond is held until maturity, P=897
For 2) PV=897, n=30, PMT=-80, FV=-1000, CPT i and store i value in the
calculator.
For 1) then I tried, PV=957, PMT=-80, FV=-10
l**********1
发帖数: 5204
36
来自主题: Biology版 - NGS数据分析的流程
Plus
To LZ:
just check,
>http://bcbio.wordpress.com/tag/ngs/
cited:
>Access VCF variant information
>In addition to extending the GATK through walkers and annotations you can
also utilize the extensive API directly, taking advantage of parsers and
data structures to handle common file formats. Using Clojure’s Java
interoperability, the variantcontext module provides a high level API to
parse and extract information from VCF files. To loop through a VCF file and
print the location, reference alle... 阅读全帖
b*t
发帖数: 5
37
来自主题: EE版 - Re: MEX file help
generally MEX is codes in C or FORTRAN, which has an
interface to MATLAB .m files, i.e. the file would be
callable from .m files. the MEX file needs to be compiled
into machine codes, kind of executable.
you can use MCC to convert .m file into executable .exe
files, in C fashion.
n*****r
发帖数: 159
38
来自主题: Quant版 - Question on bond duration
Duration, by its name, is the averaged-time to get cash back.
for Bullet bonds, Modified duration can gauge the relation between bond
price change and yield change. and in this case ONLY, Duration is the first
term in Taylor expansion of P(y). the second term is convexity.
But for bonds with embedded options (callable corporate bond, mortgages, ABS
), the relation between Duration and bond price breaks down. And people
often use effective duration.

really
particular
w****j
发帖数: 6262
39
如果Z-spread大于OAS,应该是callable bond还是putable bond。
到底什么是OAS,还是很糊涂。我以为就是含option的bond的spot yield curve高于
Treasury spot rate curve 的部分。可好像又不对。
多谢。
J***e
发帖数: 283
40
callable
OAS is the spread after removing the option cost
J*****n
发帖数: 4859
41
来自主题: Quant版 - A question on agency callable bond

,
is
说的太泛了,请说说你的详细过程阿。
w*l
发帖数: 6
42
来自主题: Quant版 - A question on agency callable bond
"the strike on the payer swaption depends on both the coupon rate and the
spread over LIBOR" this is the part I can't understand. Is that like the
swaption strike should be expected 2yr forward rate 1yr from now? I guess I
don't know how to calculate the strike for the swaption. Can you explain a
little bit more?

more
b***k
发帖数: 2673
43
☆─────────────────────────────────────☆
anderg (anderg) 于 (Sat Jun 27 22:14:28 2009, 美东) 提到:
我不是搞金融的,但是有几个问题,在google上做了功课,但觉得不大对.请教一下大家:
1, interest rate rally是啥意思? (google上有文章说,rally了,callable bond
issuer
就会call,好像觉得和我理解的不一样).
2, butterfly spread是什么意思?我明白butterfly的意思...
3, treasury curve 2y/5y是啥意思?
谢谢大家!
☆─────────────────────────────────────☆
helmertblock (fun) 于 (Mon Jun 29 10:24:00 2009, 美东) 提到:
u may have asked in the wrong place. few people here understand 金融.
☆──────────────────
t*****e
发帖数: 38
44
约好2点, 1点55找了个没人的位置(很难找),等到2点15分,还没来电话。回到工作
岗位,突然打来了。没有道歉,直接开始。
1.what is your strongest area? math,statistics,然后从统计开始
2. give me 3 important result of prob theory. This was OK.
3. what is the prob that A result after computation, any other way, I gave an intuitive way, any other
way, I said sorry, he said" I have a better way I thought you could have
used,I am a little bit disappointed"
4. How could you generate a normal from uniform? I said use sum... 阅读全帖
h*y
发帖数: 1289
45
Nice discussion. I also have a question. My understanding is that the gamma
is similar to the convexity in Fixed Income, which is positive for a non
callable bond. And positive convexity is always good because we benefit in
either direction of interest rate movements.
So as the gamma, if delta is hedged, we should benefit from positive gamma
no matter price goes up or down.
Am I right or not?
If I'm right, why we want to hedge gamma?
B*M
发帖数: 1340
46
来自主题: Quant版 - oas高好还是低好
多谢你的解释,
oas对其他bond也有,callable,putable,stochastic rate,都可以影响oas,
o******2
发帖数: 159
47
来自主题: Quant版 - phone interview遇到老印....
职位是risk analyst in a QA team. 任何background都没有问,直接上来他介绍说这
个工作干些什么。接着非常严重的说:你写的program出了任何问题的话,责任都是由
你来负责,问我明不明白。请问各位这样是正常的吗?你们面试时候有被这样警告过吗?
然后接下来就直接技术问题了,stochastic calculus,pde,duration,convexity,
callable bond, interest,call-put parity,etc.。其中几个问题故意说的不清楚,而
且见我没有明白也不再解释,结果导致我不会回答,其实问题很简单的,只是不知道他
要我回答啥。
A*****s
发帖数: 13748
48
来自主题: Quant版 - 关于bond valuation
这个前提还是提前跟买家商量的
如果不商量,直接发bond往市场上卖,怎么办?
你所说的optionality是structure么?put/call/sink?这就更是另一回事了,因为这
种bond的YTM根本就是另一回事。Putable的表征YTM肯定低,Callable的表征YTM肯定高
w******o
发帖数: 59
49
对于buy side,已经有了 market price,一般用什么方法算出OAS and duration,
convexity etc? 谢谢
d********t
发帖数: 9628
50
这些应什么方法算有差别吗
首页 上页 1 2 3 (共3页)