question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace Vec#of with VecFactory#ofObjectVec

See original GitHub issue

First of all: Thank you very much for addressing #546 as part of release 5.2.0.

My code previously looked like:

return Vec.of(fitnesses.stream().toArray(Fitness[]::new));

Now I would like to use the aforementioned new feature with something like:

private final VecFactory<Fitness[]> vecFactory = VecFactory.ofObjectVec(
		Comparator.naturalOrder(),
		(u, v, i) -> u[i].compareTo(v[i]),
		Optimize.MAXIMUM, Optimize.MAXIMUM, Optimize.MINIMUM);

// ...

return vecFactory.newVec(fitnesses.stream().toArray(Fitness[]::new));

However, I’m unsure about the ElementDistance. I was looking into Vec#of in order to replace it with VecFactory#ofObjectVec, where I saw the following code:

static <C extends Comparable<? super C>>
Vec<C[]> of(final C[] array) {
	return of(
		array,
		(u, v, i) -> clamp(u[i].compareTo(v[i]), -1, 1)
	);
}

Naturally I would try to do the same, but Basics#clamp is internal and I wonder what is the proper way to reproduce the Vec#of behavior while providing the new optimization directions.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jeneticscommented, Feb 24, 2020

Makes sense, but I would name it

VecFactory.ofObjectVec(List<Optimize>)
VecFactory.ofObjectVec(Optimize...)

and probably adding also

VecFactory.ofObjectVec(ElementDistance, List<Optimize>)
VecFactory.ofObjectVec(ElementDistance, Optimize...)

I’m not sure about the VecFactory.ofComparableVec(). In this case, you don’t need a factory, you can create a Vec instance with Vec.of directly.

0reactions
beatngu13commented, Apr 27, 2020

Wanted to submit a PR, but haven’t found time for it … so thanks a lot for doing it! 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Replacing element of a vector of objects - c++ - Stack Overflow
I have an std::vector of objects. How do I replace the element at index i, while ensuring the destructor of the object that...
Read more >
Replace value from vector array of object - Microsoft Q&A
Replace value from vector array of object. Hi folks,. here is my sample code as below: #include <iostream>; #include <fstream> ...
Read more >
Replace the Elements of a Vector in R Programming
replace () function in R Language is used to replace the values in the specified string vector x with indices given in list...
Read more >
Replacing Element in Java Vector - GeeksforGeeks
To replace an element in Java Vector, set() method of java.util.Vector class can be used. The set() method takes two parameters-the indexes ...
Read more >
Conditionally replace values in a vector in C++ - Techie Delight
The best option to conditionally replace values in a vector in C++ is using the std::replace_if function. It assigns a new value to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found