Questions tagged [in-place]

Use this tag on questions about algorithms that modify the data in-place, as opposed to making a copy. For example, in-place sorting, in-place merge, etc.

Use this tag on questions about algorithms that modify the data in-place, as opposed to making a copy. For example, in-place , in-place , etc.

379 questions
0
votes
1 answer

Eigen LDLT Cholesky decomposition in-place

I am trying to get Eigen3 to solve a linear system A * X = B with an in-place Cholesky decomposition. I cannot afford to have any temporaries of the size of A pushed on the stack, but I am free to destroy A in the…
Stefan
  • 4,380
  • 2
  • 30
  • 33
0
votes
2 answers

Merge two sorted arrays in place in O(1) space

Can someone please help me understand the algorithm / code for this problem given two integer arrays, sort them such that, initial numbers are placed in first array and remaining numbers in second array. For example: Input: ar1[ ] = {1, 5, 9, 10,…
Ajinkya Kale
  • 127
  • 1
  • 12
0
votes
1 answer

Python in-place operator (as "+="), numpy array and identity function not working properly?

The arrays yn and zn are equals numericaly speaking, but there is an odd difference: the line yn += 7, as expected, does not change tn array, but the second last line zn += 7 changes tn array! This is the code: import numpy as np def f(x): return…
Dawnx
  • 1
0
votes
2 answers

python3/numpy: in place addition inconsistency when adding a complex number

I was testing a piece of code and encountered the following behaviour. Although I have found an explanation and a solution myself (this looks related although not same), I'd like to ask here if anybody of you has more to add. a) I cannot…
lurix66
  • 502
  • 1
  • 5
  • 14
0
votes
1 answer

Compute difference and update value in place in javascript

The following snippet does it job, but it looks clumsy to me: var lastFrame = performance.now(); function elapsedMillis(){ var now = performance.now(); var elapsedTime = lastFrame - now; lastFrame = now; return elapsedTime; } Every time…
estani
  • 24,254
  • 2
  • 93
  • 76
0
votes
1 answer

Why doesn't pandas drop_duplicates() seem to work for me?

I have a dataframe with one text column. It has duplicate elements in different rows. I want to eliminate the duplicates. I use df.drop_duplicates(..., inplace=True) but it doesn't seem to work. How do I solve this?
eclairs
  • 1,515
  • 6
  • 21
  • 26
0
votes
2 answers

Return statement in method that modifies in-place

Say I wanted a simple method that takes a list and modifies it in-place by appending 5 to it. Below are two methods that do this, but ret(l) returns while no_ret(l) does not. def ret(l): l.append(5) return l def no_ret(l): …
onepiece
  • 3,279
  • 8
  • 44
  • 63
0
votes
4 answers

Perl in-place editing produces garbage

I am having trouble with in-place file editing, having browsed the web for a couple of hours without results. I really don't want to use the general temporary file scheme, i.e. writing everything to a new file and replace the old one. I need…
tachylatus
  • 113
  • 1
  • 4
0
votes
2 answers

How do I configure the Maven WAR plugin to execute the "inplace" goal by default?

I’m using Maven 3.2.3 and the Maven War 2.6 plugin. I would like the “inlace” goal of the Maven WAR plugin to execute by default (without my having to explicitly specify “war:inlace” on the command line). So I created a profile to include the…
Dave
  • 15,639
  • 133
  • 442
  • 830
0
votes
2 answers

How to sort List made of Lists in C#?

I have a class that looks like this: public class HistoryViewModel { [Display(Name="Name")] public string ItemName { get; set; } [Display(Name="Original Path")] public string ItemPath { get; set; } …
Antun Tun
  • 1,507
  • 5
  • 20
  • 38
0
votes
3 answers

How to use Perl one-liner to add line based on first line pattern match?

My boss needs to change a particular routing file on some dozens (hundreds) of hosts by adding a line like: 10.11.0.0/16 via 172.16.2.XX dev tun0 ... where XX is based on the octet preceding the "dev" keyword on the first line of the same…
Jim Dennis
  • 17,054
  • 13
  • 68
  • 116
0
votes
2 answers

Mapcar in-place: destructively modify a list of lists

I have a list of lists: (setq xs (list (list 1 2 3) (list 4 5 6) (list 7 8 9))). I want to remove a first element from each list to get ((2 3) (5 6) (8 9)). It's easy to do it non-destructively: (mapcar 'cdr xs). But I want mutate the original list.…
Mirzhan Irkegulov
  • 17,660
  • 12
  • 105
  • 166
0
votes
2 answers

Selection sort in Swift

I'm creating a simple selection sort in Swift. In my sort method I'm getting an error when calling method for exchanging values within the array. class func sort(a:[String]) { var N = a.count for(var i = 0; i < N; i++) { …
oyvindhauge
  • 3,496
  • 2
  • 29
  • 45
0
votes
1 answer

Algorithm to uniformize a directory path with constant space

I was going through some coding exercises, and had some trouble with a question to implement a function to uniformize a directory path. Example: Input: /dir1/dir2/../dir3/file.txt Output: /dir1/dir3/file.txt We could use a stack to solve this…
yohm
  • 452
  • 7
  • 14
0
votes
1 answer

In-place "pop" operation for array-based binary heap?

I have an array-based binary heap used for graph searching (though the purpose is irrelevant). (The item at index 0 is the top of the heap.) Every once in a while, the item at the top of the heap satisfies the criterion that I'm seeking, and thus I…
user541686
  • 205,094
  • 128
  • 528
  • 886