小编jmi*_*rez的帖子

如何检查Python中是否存在方法?

在函数中__getattr__(),如果找不到引用的变量,则它会给出错误.如何检查变量或方法是否作为对象的一部分存在?

import string
import logging

class Dynamo:
 def __init__(self,x):
  print "In Init def"
  self.x=x
 def __repr__(self):
  print self.x
 def __str__(self):
  print self.x
 def __int__(self):
  print "In Init def"
 def __getattr__(self, key):
    print "In getattr"
    if key == 'color':
        return 'PapayaWhip'
    else:
        raise AttributeError


dyn = Dynamo('1')
print dyn.color
dyn.color = 'LemonChiffon'
print dyn.color
dyn.__int__()
dyn.mymethod() //How to check whether this exist or not
Run Code Online (Sandbox Code Playgroud)

python methods

65
推荐指数
5
解决办法
8万
查看次数

Java中的HashMap实现.桶指数计算如何工作?

我正在研究HashMapJava 中的实现,并且一度陷入困境.功能
是如何indexFor计算的?

static int indexFor(int h, int length) {
   return h & (length-1);
}
Run Code Online (Sandbox Code Playgroud)

谢谢

java hashmap

46
推荐指数
2
解决办法
2万
查看次数

Math.pow根据java版本产生不同的结果

我在JDK版本1.7.0_60上运行以下代码:

System.out.println(Math.pow(1.5476348320352065, (0.3333333333333333)));
Run Code Online (Sandbox Code Playgroud)

其结果是:1.1567055833133086

我在JDK版本1.7.0上运行完全相同的代码.

其结果是:1.1567055833133089

我知道double并不是无限精确,但java规范中是否有变化会导致差异?

PS:因为我们使用遗留系统,所以Big Decimal不是一个选项.

编辑:我能够追踪更改的时间:它是在JDK版本1.7.0_40中引入的(与版本1.7.0_25相比).

java math floating-point pow

37
推荐指数
4
解决办法
2059
查看次数

git在windows和linux之间切换后强制刷新索引

我有一个由 windows 和 linux 共享的磁盘分区(格式:NTFS)。它包含一个 git 存储库(大约 6.7G)。
如果我只使用 windows只使用 linux来操作 git 存储库,一切都很好。
但是每次我切换系统。该git status命令将刷新索引,大约需要 1 分钟。在我运行之后git status,如果我git status再次在同一个系统中运行。只需不到 1 秒。这是结果

# Just after switch from windows
[#5#wangx@manjaro:duishang_design] git status  # this command takes more than 60s
Refresh index: 100% (2751/2751), done.
On branch master
nothing to commit, working tree clean

[#10#wangx@manjaro:duishang_design] git status  # this time the command takes less than 1s
On branch master
nothing to commit, working …
Run Code Online (Sandbox Code Playgroud)

linux windows git git-index

19
推荐指数
3
解决办法
5411
查看次数

解决WCF AddressFilter不匹配中的配置错误

我收到以下错误,可以使用一些帮助解决它.有人有主意吗?

由于EndpointDispatcher上的AddressFilter不匹配,因此无法在接收方处理带有" http:// localhost:60078/BidService.svc/Query " 的消息.检查发送方和接收方的EndpointAddresses是否一致.

客户端配置文件是:

<system.serviceModel>
    <bindings>
        <customBinding>
            <binding name="WebHttpBinding_IBidService">
                <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                    messageVersion="None" writeEncoding="utf-8">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" 
                                  maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                </textMessageEncoding>
                    <httpTransport manualAddressing="True" />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint binding="customBinding" bindingConfiguration="WebHttpBinding_IBidService" 
                  behaviorConfiguration="IBidServiceBehavior"
            contract="myService.IBidService" name="WebHttpBinding_IBidService" />
    </client>
        <behaviors>
            <endpointBehaviors>
                <behavior name="IBidServiceBehavior">
                    <webHttp/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

我的服务合同是:

[ServiceContract(Namespace = "http://xxxx.com/services/bids")]
public interface IBidService
{
    [OperationContract(Action = "*")]
    [WebGet(RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped)]
    List<BidSummary> Query();
}
Run Code Online (Sandbox Code Playgroud)

我的服务配置如下:

<service name="xxx.Web.Services.Bids.BidService" 
          behaviorConfiguration="Cutter.Web.Services.Bids.BidServiceBehavior">
   <endpoint address="" binding="basicHttpBinding" 
             contract="xxx.Web.Services.Bids.IBidService" …
Run Code Online (Sandbox Code Playgroud)

.net xml wcf

18
推荐指数
1
解决办法
6万
查看次数

bash:nano:在Windows git bash中找不到命令

我在Windows PC上使用git版本2.7.0.windows.1,我使用以下命令:

$ nano README
Run Code Online (Sandbox Code Playgroud)

这导致我:

bash: nano: command not found
Run Code Online (Sandbox Code Playgroud)

现在我如何安装纳米文本编辑器到git bash?

windows git nano git-bash

14
推荐指数
2
解决办法
1万
查看次数

切片`a`(例如`a [1:] == a [: - 1]`)是否创建了`a`的副本?

我的一个朋友向我展示了以下Python代码:

a[1:] == a[:-1]
Run Code Online (Sandbox Code Playgroud)

如果所有项目a都相同,则返回True .

我认为代码很难从一见钟情中理解,而且 - 它在内存使用方面效率低下,因为a将为比较创建两个副本.

我用Python dis来看看幕后发生了什么a[1:]==a[:-1]:

>>> def stanga_compare(a):
...     return a[1:]==a[:-1]
...
>>> a=range(10)
>>> stanga_compare(a)
False
>>> a=[0 for i in range(10)]
>>> stanga_compare(a)
True

>>> dis.dis(stanga_compare)
  2           0 LOAD_FAST                0 (a)
              3 LOAD_CONST               1 (1)
              6 SLICE+1
              7 LOAD_FAST                0 (a)
             10 LOAD_CONST               2 (-1)
             13 SLICE+2
             14 COMPARE_OP               2 (==)
             17 RETURN_VALUE
Run Code Online (Sandbox Code Playgroud)

归结为两个切片命令 - SLICE+1SLICE+2.文档不清楚这些操作码是否实际创建了一个新副本a,或仅仅是对它的引用.

  • SLICE命令是否复制a …

python cpython memory-efficient python-internals

11
推荐指数
1
解决办法
320
查看次数

如何在没有IIS的情况下部署WCF服务?

我正在做一些快速的Java-.NET互操作,并决定使用WCF进行POX.但是,我不希望 - 也无权访问 - 部署到IIS.

只是将它作为.NET服务包装起来就可以了吗?(在我这些年里,我已经建立了相当多的Windows服务.)

这周围有什么好的样品吗?

如果我不使用IIS,会处理HTTP的是什么?

我愿意接受任何可以创建简单的基于http的xml合约的建议.

此外,重要的是要注意,这只会暴露给内部服务器场,因此安全性和所有这一切都很少.

(由于所有的博客垃圾邮件,搜索Google并未提供非常好的结果.)

xml deployment wcf

10
推荐指数
2
解决办法
2万
查看次数

WCF Rest涉及复杂类型的参数

设置使用webHttpBinding的WCF服务...我可以从XML方法返回复杂类型.如何将复杂类型作为参数?

[ServiceContract(Name = "TestService", Namespace = "http://www.test.com/2009/11")]
public interface ITestService
{
    [OperationContract]
    [WebInvoke(Method = "POST", 
               BodyStyle = WebMessageBodyStyle.Bare, 
               UriTemplate = "/Person/{customerAccountNumber}, {userName}, {password}, {PersonCriteria}")]
    Person SubmitPersonCriteria(string customerAccountNumber, 
                                string userName, 
                                string password, 
                                PersonCriteria details);
}
Run Code Online (Sandbox Code Playgroud)

由于UriTemplate只允许字符串,最佳做法是什么?这个想法是客户端应用程序将向服务发布请求,例如一个人的搜索条件.该服务将使用包含XML数据的相应对象进行响应.

xml rest wcf

7
推荐指数
1
解决办法
2万
查看次数

Java Generics:通用映射(深层副本)的方法签名

我有几个Map自己再次可能包含Maps(任何类型).我用签名写了一个方法:

public static <K,V> HashMap<K,V> deepCopyHashMap(HashMap<K,V> s);
Run Code Online (Sandbox Code Playgroud)

但是,我现在想概括一下这个代码来支持Maps,但仍然返回与参数类型相同的对象.所以代替:

public static <K,V> HashMap<K,V> deepCopyHashMap(HashMap<K,V> s);
public static <K,V> CheckedMap<K,V> deepCopyCheckedMap(CheckedMap<K,V> s);
public static <K,V> TreeMap<K,V> deepCopyTreeMap(TreeMap<K,V> s);
...
etc.
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西:

public static <K,V, M extends Map<K,V>> M<K,V> deepCopyMap(M<K,V> s);
Run Code Online (Sandbox Code Playgroud)

但是,这给了我:

Multiple markers at this line
- The type M is not generic; it cannot be parameterized with arguments <K, 
 V>
- The type M is not generic; it cannot be parameterized with arguments <K, 
 V> …
Run Code Online (Sandbox Code Playgroud)

java generics map deep-copy

6
推荐指数
1
解决办法
1168
查看次数

当一个边缘权重减少50%时,两个顶点之间的最短路径?

这是我遇到的面试问题:

您将获得一个国家城市之间的飞机地图,基本上有一个有向图,其中权重是城市之间飞机的成本.您还获得了一张优惠券,可以在任何一个航班上获得50%的优惠券.查找您可以在两个城市之间旅行的最低费用?

algorithm graph-algorithm

3
推荐指数
1
解决办法
527
查看次数

设置 ICMP 与 POX 控制器匹配


我正在尝试使用 POX 控制器向交换机添加流条目,我的代码是:

    fm = of.ofp_flow_mod()
    fm.match.in_port = 1
    fm.priority = 33001
    fm.match.dl_type = 0x800
    fm.match.nw_src = IPAddr("10.0.0.1")
    fm.match.nw_dst = IPAddr("10.0.0.5")

    fm.actions.append(of.ofp_action_output( port = 2 ) )
    event.connection.send( fm )
Run Code Online (Sandbox Code Playgroud)

但是,当我从 10.0.0.1 ping 到 10.0.0.5 时,没有回复。可能是什么问题?(我还为 ICMP 回复添加了对称流)

谢谢

arp icmp pox openflow mininet

3
推荐指数
1
解决办法
3564
查看次数

具有潜在性能优化的浮点算法

对于大学讲座,我正在寻找具有已知渐近运行时的浮点算法,但是可以进行低级(微)优化.这意味着优化,例如最小化缓存未命中和寄存器溢出,最大化指令级并行性以及利用新CPU上的SIMD(向量)指令.优化将特定于CPU,并将使用适用的指令集扩展.

经典的教科书示例是矩阵乘法,通过简单地重新排序存储器访问序列(以及其他技巧)可以实现极大的加速.另一个例子是FFT.不幸的是,我不允许选择其中任何一个.

任何人有任何想法,或可以使用提升的算法/方法?

我只对可以想象每线程加速的算法感兴趣.通过多线程并行解决问题很好,但不是本讲座的范围.

编辑1:我的过程中,没有教它.在过去几年中,有不少项目在性能方面成功超越了当前最佳实施.

编辑2:本文列出了(从第11页开始)七类重要的数值方法和一些使用它们的相关算法.至少一些提到的算法是候选者,但是很难看出哪个算法.


编辑3:谢谢大家的好建议!我们建议实施曝光融合算法(2007年的论文),我们的提案被接受了.该算法创建类似HDR的图像,主要包括小核卷积,然后是源图像的加权多分辨率混合(在拉普拉斯金字塔上).我们感兴趣的是,该算法已经在广泛使用的Enfuse工具中实现,该工具现在的版本为4.1.因此,我们将能够验证和比较我们的结果与原始结果,也可能有助于工具本身的开发.如果可以的话,我将在未来更新这篇文章.

algorithm floating-point optimization performance micro-optimization

2
推荐指数
1
解决办法
186
查看次数