performance

Tensorflow operations are unsusably slow

你离开我真会死。 提交于 2021-02-19 03:48:46
问题 I'm trying to get started with tensorflow using the python interface. My problem is that executing even the most basic operations, they take a long time (> 5 minutes) This problem occurs when using python3.6, installed from macports and tensorflow-1.13, the tf-nightly, and tensorflow2.0 alpha, all installed using pip. This simple example takes more than 5 minutes to execute. > ipython Python 3.6.8 (default, Dec 30 2018, 13:01:27) In [1]: import numpy as np In [2]: import tensorflow as tf In

Recursion, memoization and mutable default arguments in Python

人走茶凉 提交于 2021-02-19 02:48:52
问题 "Base" meaning without just using lru_cache. All of these are "fast enough" -- I'm not looking for the fastest algorithm -- but the timings surprised me so I was hoping I could learn something about how Python "works". Simple loop (/tail recursion): def fibonacci(n): a, b = 0, 1 if n in (a, b): return n for _ in range(n - 1): a, b = b, a + b return b Simple memoized: def fibonacci(n, memo={0:0, 1:1}): if len(memo) <= n: memo[n] = fibonacci(n - 1) + fibonacci(n - 2) return memo[n] Using a

How can I improve this square root method?

£可爱£侵袭症+ 提交于 2021-02-19 02:09:25
问题 I know this sounds like a homework assignment, but it isn't. Lately I've been interested in algorithms used to perform certain mathematical operations, such as sine, square root, etc. At the moment, I'm trying to write the Babylonian method of computing square roots in C#. So far, I have this: public static double SquareRoot(double x) { if (x == 0) return 0; double r = x / 2; // this is inefficient, but I can't find a better way // to get a close estimate for the starting value of r double

Why is using structure Vector3I instead of three ints much slower in C#?

主宰稳场 提交于 2021-02-18 21:43:34
问题 I'm processing lots of data in a 3D grid so I wanted to implement a simple iterator instead of three nested loops. However, I encountered a performance problem: first, I implemented a simple loop using only int x, y and z variables. Then I implemented a Vector3I structure and used that - and the calculation time doubled. Now I'm struggling with the question - why is that? What did I do wrong? Example for reproduction: using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; using

Why is using structure Vector3I instead of three ints much slower in C#?

十年热恋 提交于 2021-02-18 21:42:26
问题 I'm processing lots of data in a 3D grid so I wanted to implement a simple iterator instead of three nested loops. However, I encountered a performance problem: first, I implemented a simple loop using only int x, y and z variables. Then I implemented a Vector3I structure and used that - and the calculation time doubled. Now I'm struggling with the question - why is that? What did I do wrong? Example for reproduction: using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; using

Ant Junit tests are running much slower via ant than via IDE - what to look at?

岁酱吖の 提交于 2021-02-18 21:17:06
问题 I am running my junit tests via ant and they are running substantially slower than via the IDE. My ant call is: <junit fork="yes" forkmode="once" printsummary="off"> <classpath refid="test.classpath"/> <formatter type="brief" usefile="false"/> <batchtest todir="${test.results.dir}/xml"> <formatter type="xml"/> <fileset dir="src" includes="**/*Test.java" /> </batchtest> </junit> The same test that runs in near instantaneously in my IDE (0.067s) takes 4.632s when run through Ant. In the past, I

Parallel.For partitioning

会有一股神秘感。 提交于 2021-02-18 19:42:56
问题 How is partitioning done for something like Parallel.For(0, buffer.Length, (i)=> buffer[i] = 0); My assumption was that for an n core machine, work would be partitioned n way and n threads will carry out the work payload. Which means for example buffer.Length = 100 and n = 4, each thread will get 0-24, 25-49, 50-74, 75-99 blocks. (100 element array is an example to illustrate partitioning, but please consider an array of millions of items.) Is this a fair assumption? Please discuss. I noticed

How to count matches between a vector and dataframe of sequence coordinates?

梦想与她 提交于 2021-02-18 18:55:42
问题 Given a data table with start and end coordinates for sequences of integers: set.seed(1) df1 <- data.table( START = c(seq(1, 10000000, 10), seq(1, 10000000, 10), seq(1, 10000000, 10)), END = c(seq(10, 10000000, 10), seq(10, 10000000, 10), seq(10, 10000000, 10)) And a vector of integers: vec1 <- sample(1:100000, 10000) How can I count the number of integers in vec1 that are within the start and end coordinates of each sequence in df1? I am currently using a for loop: COUNT <- rep(NA, nrow(df1)

Optimisation tips to find in which triangle a point belongs

和自甴很熟 提交于 2021-02-18 17:49:03
问题 I'm actually having some troubles optimising my algorithm: I have a disk (centered in 0, with radius 1) filled with triangles (not necessarily of same area/length). There could be a HUGE amount of triangle (let's say from 1k to 300k triangles) My goal is to find as quick as possible in which triangle a point belongs. The operation has to be repeated a large amount of time (around 10k times ). For now the algorithm I'm using is: I'm computing the barycentric coordinates of the point in each

Android webview loading fail in API 21 and above

微笑、不失礼 提交于 2021-02-18 17:11:15
问题 I have an Android application that uses WebView and load a page. This application works on Android devices running API 16 or above . Android WebView Code: String URL = "https://sandbox.napas.com.vn/gateway/message"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web_view); webview = (WebView) findViewById(R.id.webview); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setAllowFileAccess