in-place

CUDA In-place Transpose Error

那年仲夏 提交于 2019-12-05 18:03:11
I'm implementing a CUDA program for transposing an image. I created 2 kernels. The first kernel does out of place transposition and works perfectly for any image size. Then I created a kernel for in-place transposition of square images. However, the output is incorrect. The lower triangle of the image is transposed but the upper triangle remains the same. The resulting image has a stairs like pattern in the diagonal and the size of each step of the stairs is equal to the 2D block size which I used for my kernel. Out-of-Place Kernel: Works perfectly for any image size if src and dst are

Numpy passing input array as `out` argument to ufunc

馋奶兔 提交于 2019-12-05 12:05:42
问题 Is it generally safe to provide the input array as the optional out argument to a ufunc in numpy, provided the type is correct? For example, I have verified that the following works: >>> import numpy as np >>> arr = np.array([1.2, 3.4, 4.5]) >>> np.floor(arr, arr) array([ 1., 3., 4.]) The array type must be either compatible or identical with the output (which is a float for numpy.floor() ), or this happens: >>> arr2 = np.array([1, 3, 4], dtype = np.uint8) >>> np.floor(arr2, arr2) Traceback

How do you append an element to a list in place in Prolog?

ぃ、小莉子 提交于 2019-12-05 11:18:51
问题 If I have a list in Prolog such as X = [1, 2, 3, 4], how do I add the element 5 to the end of the list to have X = [1, 2, 3, 4, 5]? The append function needs two lists, ie append(A,B,C) to get A and B concatenated to the list C. I can do this with a temporary list Y = [1, 2, 3, 4] and Z = [5], to then do an append(Y, Z, X), but I don't like having a temporary list. The usual disclaimers apply here - this is not homework and I am just learning Prolog. 回答1: Variables in Prolog can only be

Have the `__rdiv__()` and `__idiv__` operators changed in Python 3.x?

ⅰ亾dé卋堺 提交于 2019-12-05 04:16:00
In Python 3.x the __div__() operator was deprecated in favor of __floordiv__() and __truediv__() . Are the __rdiv__() and __idiv__() operators still used to refer to the reversed and in-place versions of __truediv__() ? If so, what are the operator names for the reversed and in-place versions of __floordiv__() ? __rdiv__ and __idiv__ no longer exist. The new names are the obvious choices of __rtruediv__ , __itruediv__ , __rfloordiv__ , and __ifloordiv__ , following the standard format. This is visible in the link in the second answer on the question you linked, or by doing dir(int) in a Python

In-Place String Reverse in C

爱⌒轻易说出口 提交于 2019-12-04 06:31:04
问题 I am trying to learn the fundamentals of C, but I cannot figure out why this code doesn't work. The while loop in reverse() causes a bus error. I found almost identical code in a programming interview book as a valid solution, but neither this nor other similar methods I have seen posted here work for me without a bus error. #include <stdio.h> void reverse(char* str) { char* end = str; char tmp = 0; if(str) { while(*end) { end++; } --end; while(end>str) { tmp = *end; *end-- = *str; *str++ =

How to remove duplicates from a file and write to the same file?

六月ゝ 毕业季﹏ 提交于 2019-12-04 03:20:19
I know my title is not much self-explanatory but let me try to explain it here. I have a file name test.txt which has some duplicate lines. Now, what I want to do is remove those duplicate lines and at the same time update test.txt with the new content. test.txt AAAA BBBB AAAA CCCC I know I can use sort -u test.txt to remove the duplicates but to update the file with new content how do I redirect it's output to the same file. The below command doesn't work. sort -u test.txt > test.txt So, why the above command is not working and whats the correct way? Also is there any other way like sort_and

Replacing words in text file using a dictionary

孤者浪人 提交于 2019-12-04 01:23:59
问题 I'm trying to open a text file and then read through it replacing certain strings with strings stored in a dictionary. Based on answers to How do I edit a text file in Python? I could pull out the dictionary values before doing the replacing, but looping through the dictionary seems more efficient. The code doesn't produce any errors, but also doesn't do any replacing. import fileinput text = "sample file.txt" fields = {"pattern 1": "replacement text 1", "pattern 2": "replacement text 2"} for

How do you append an element to a list in place in Prolog?

心不动则不痛 提交于 2019-12-04 00:50:27
If I have a list in Prolog such as X = [1, 2, 3, 4], how do I add the element 5 to the end of the list to have X = [1, 2, 3, 4, 5]? The append function needs two lists, ie append(A,B,C) to get A and B concatenated to the list C. I can do this with a temporary list Y = [1, 2, 3, 4] and Z = [5], to then do an append(Y, Z, X), but I don't like having a temporary list. The usual disclaimers apply here - this is not homework and I am just learning Prolog. Variables in Prolog can only be assigned once. As soon as X has the value [1,2,3,4] it can never have another value. A temporary variable and

Sort multiple arrays simultaneously “in place”

大兔子大兔子 提交于 2019-12-03 22:31:06
I have the following 3 arrays: int[] indexes = new int[]{0,2,8,5}; String[] sources = new String[]{"how", "are", "today", "you"}; String[] targets = new String[]{"I", "am", "thanks", "fine"}; I want to sort the three arrays based on the indexes: indexes -> {0,2,5,8} sources -> {"how", "are", "you", "today"} targets -> {"I", "am", "fine", "thanks"} I can create a new class myClass with all three elements: class myClass { int x; String source; String target; } Reassign everything to myClass, then sort myClass using x . However, this would required additional spaces. I am wondering if it is

In-place processing with grep

前提是你 提交于 2019-12-03 08:26:16
问题 I've got a script that calls grep to process a text file. Currently I am doing something like this. $ grep 'SomeRegEx' myfile.txt > myfile.txt.temp $ mv myfile.txt.temp myfile.txt I'm wondering if there is any way to do in-place processing, as in store the results to the same original file without having to create a temporary file and then replace the original with the temp file when processing is done. Of course I welcome comments as to why this should or should not be done, but I'm mainly