The document describes solving a programming problem involving creating a collection of sample objects with random values, sorting the collection, inserting new random values while maintaining the sorted order, and returning the average value of all samples. It involves implementing a test function that takes integers n and k as parameters. The function will create a collection of n sample objects, sort the collection, insert new random samples k times keeping the collection sorted, and return the average value of all samples.
Session in Python Bcn Meetup, Beginners session
>> Contents:
- Python execution model
- Everything is an object
- Everything is a pointer (or a reference)
- Mutable vs. immutable objects
- Common errors
>> Code examples:
https://github.com/pablito56/pybcn-beginners
Session in Python Bcn Meetup, Beginners session
>> Contents:
- Python execution model
- Everything is an object
- Everything is a pointer (or a reference)
- Mutable vs. immutable objects
- Common errors
>> Code examples:
https://github.com/pablito56/pybcn-beginners
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...GeeksLab Odessa
SubScript - это расширение языка Scala, добавляющее поддержку конструкций и синтаксиса аглебры общающихся процессов (Algebra of Communicating Processes, ACP). SubScript является перспективным расширением, применимым как для разработки высоконагруженных параллельных систем, так и для простых персональных приложений.
(3) cpp abstractions more_on_user_defined_typesNico Ludwig
- Advanced Creation of Instances on the Heap and the Freestore
-- The Operators new/delete, new[]/delete[] and Placement
- Controlling the Lifetime of an Object
-- Destructors and Resource Acquisition is Initialization (RAII)
-- Copies of Objects and Avoiding Copying Objects
- Instance- vs. Class Members
PVS-Studio for Linux Went on a Tour Around DisneyPVS-Studio
Recently we released a Linux version of PVS-Studio analyzer, which we had used before to check a number of open-source projects such as Chromium, GCC, LLVM (Clang), and others. Now this list includes several projects developed by Walt Disney Animation Studios for the community of virtual-reality developers. Let's see what bugs and defects the analyzer found in these projects.
Source Code Clone Search and Detection (SeClone is a Real-time and Internet-scale Clone Search and Detection).
*There are some animations in the presentation, to see them download and run it locally.
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)Sylvain Hallé
This talk reviews the basic principles behind the BeepBeep 3 event stream processing engine, and the facilities it provides to help you design you own, domain-specific query language.
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdfarihantmum
Write the code above and the ones below in netbeans IDE 8.1
3. (Eliminate duplicates) Write a method that returns a new array by eliminating the duplicate
values in the array using the following method header: public static int[]
eliminateDuplicates(int[] list) Write a test program that reads in ten integers, invokes the method,
and displays the result. Here is the sample run of the program:
Enter ten numbers: 1 2 3 2 1 6 3 4 5 2 [Enter]
The distinct numbers are: 1 2 3 6 4 5
4. (Sort students) Write a program that prompts the user to enter the number of students, the
students’ names, and their scores, and prints student names in decreasing order of their scores.
Solution
Please follow the code and comments for description :
a)
CODE :
import java.util.Scanner;
public class MeanSD {
public static double deviation (double[] x) { // method to return the deviation
double sum = 0, mean = 0, deviation = 0; // required initialisations
double[] temp = new double[10]; // temporary array
for (int i = 0; i < 10; i++) //calculate the standard deviation
{
temp[i] = Math.pow((x[i] - mean), 2); // assigning the value to the array
sum += temp[i]; // adding up the values
}
mean = sum / 10; // getting the mean
deviation = Math.sqrt(mean); // calculating the deviation
return deviation; // returning the deviation
}
public static double mean (double[] x) { // method to return themean of the values entered
double sum = 0, mean; // required initialisations
for (int i = 0; i < 10; i++) //Take input in the array
{
sum += x[i]; //sum of all elements
}
mean = sum / 10; // calculating the mean
return mean; // returning the mean value
}
public static void main(String[] args) { // driver method
System.out.println(\"Enter the 10 numbers.\"); // prompt to enter the data
Scanner in = new Scanner(System.in); // scanner class to get the data from the user
double[] arr = new double[10]; // array that saves the data
double sum = 0, mean = 0, deviation = 0; // required initialisations
for (int i = 0; i < 10; i++) //Take input in the array
{
System.out.print(\"Enter a number : \"); // prompt to enter the number
arr[i] = in.nextDouble(); // getting the data from the console
}
mean = mean(arr); // calling the method to return the mean value
System.out.println(\"Mean : \" + mean); //Display mean of all elements
deviation = deviation(arr); // calling the method to return teh deviation value
System.out.println(\"Deviation : \" + deviation); // display the result
}
}
OUPTPUT :
Enter the 10 numbers.
Enter a number : 1
Enter a number : 2
Enter a number : 3
Enter a number : 4
Enter a number : 5
Enter a number : 6
Enter a number : 7
Enter a number : 8
Enter a number : 9
Enter a number : 10
Mean : 5.5
Deviation : 6.2048368229954285
b)
CODE :
import java.util.Scanner;
public class MyDuplicateElements {
public static int[] eliminateDuplicates(int[] input) { // method to remove the duplicates
int j = 0; // required initialisations
int i = 1;
//return if the array length is less than 2
if (input..
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...GeeksLab Odessa
SubScript - это расширение языка Scala, добавляющее поддержку конструкций и синтаксиса аглебры общающихся процессов (Algebra of Communicating Processes, ACP). SubScript является перспективным расширением, применимым как для разработки высоконагруженных параллельных систем, так и для простых персональных приложений.
(3) cpp abstractions more_on_user_defined_typesNico Ludwig
- Advanced Creation of Instances on the Heap and the Freestore
-- The Operators new/delete, new[]/delete[] and Placement
- Controlling the Lifetime of an Object
-- Destructors and Resource Acquisition is Initialization (RAII)
-- Copies of Objects and Avoiding Copying Objects
- Instance- vs. Class Members
PVS-Studio for Linux Went on a Tour Around DisneyPVS-Studio
Recently we released a Linux version of PVS-Studio analyzer, which we had used before to check a number of open-source projects such as Chromium, GCC, LLVM (Clang), and others. Now this list includes several projects developed by Walt Disney Animation Studios for the community of virtual-reality developers. Let's see what bugs and defects the analyzer found in these projects.
Source Code Clone Search and Detection (SeClone is a Real-time and Internet-scale Clone Search and Detection).
*There are some animations in the presentation, to see them download and run it locally.
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)Sylvain Hallé
This talk reviews the basic principles behind the BeepBeep 3 event stream processing engine, and the facilities it provides to help you design you own, domain-specific query language.
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdfarihantmum
Write the code above and the ones below in netbeans IDE 8.1
3. (Eliminate duplicates) Write a method that returns a new array by eliminating the duplicate
values in the array using the following method header: public static int[]
eliminateDuplicates(int[] list) Write a test program that reads in ten integers, invokes the method,
and displays the result. Here is the sample run of the program:
Enter ten numbers: 1 2 3 2 1 6 3 4 5 2 [Enter]
The distinct numbers are: 1 2 3 6 4 5
4. (Sort students) Write a program that prompts the user to enter the number of students, the
students’ names, and their scores, and prints student names in decreasing order of their scores.
Solution
Please follow the code and comments for description :
a)
CODE :
import java.util.Scanner;
public class MeanSD {
public static double deviation (double[] x) { // method to return the deviation
double sum = 0, mean = 0, deviation = 0; // required initialisations
double[] temp = new double[10]; // temporary array
for (int i = 0; i < 10; i++) //calculate the standard deviation
{
temp[i] = Math.pow((x[i] - mean), 2); // assigning the value to the array
sum += temp[i]; // adding up the values
}
mean = sum / 10; // getting the mean
deviation = Math.sqrt(mean); // calculating the deviation
return deviation; // returning the deviation
}
public static double mean (double[] x) { // method to return themean of the values entered
double sum = 0, mean; // required initialisations
for (int i = 0; i < 10; i++) //Take input in the array
{
sum += x[i]; //sum of all elements
}
mean = sum / 10; // calculating the mean
return mean; // returning the mean value
}
public static void main(String[] args) { // driver method
System.out.println(\"Enter the 10 numbers.\"); // prompt to enter the data
Scanner in = new Scanner(System.in); // scanner class to get the data from the user
double[] arr = new double[10]; // array that saves the data
double sum = 0, mean = 0, deviation = 0; // required initialisations
for (int i = 0; i < 10; i++) //Take input in the array
{
System.out.print(\"Enter a number : \"); // prompt to enter the number
arr[i] = in.nextDouble(); // getting the data from the console
}
mean = mean(arr); // calling the method to return the mean value
System.out.println(\"Mean : \" + mean); //Display mean of all elements
deviation = deviation(arr); // calling the method to return teh deviation value
System.out.println(\"Deviation : \" + deviation); // display the result
}
}
OUPTPUT :
Enter the 10 numbers.
Enter a number : 1
Enter a number : 2
Enter a number : 3
Enter a number : 4
Enter a number : 5
Enter a number : 6
Enter a number : 7
Enter a number : 8
Enter a number : 9
Enter a number : 10
Mean : 5.5
Deviation : 6.2048368229954285
b)
CODE :
import java.util.Scanner;
public class MyDuplicateElements {
public static int[] eliminateDuplicates(int[] input) { // method to remove the duplicates
int j = 0; // required initialisations
int i = 1;
//return if the array length is less than 2
if (input..
This tutor introduces the basic idea of machine learning with a very simple example. Machine learning teaches machines (and me too) to learn to carry out tasks and concepts by themselves. It is that simple, so here is an overview:
http://www.softwareschule.ch/examples/machinelearning.jpg
This presentation considers certain specific features of C++11 and additions to STL library (uniform initialization, new containers and methods, move semantics).
Presentation by Taras Protsiv (Software Engineer, GlobalLogic), Kyiv, delivered at GlobalLogic C++ TechTalk in Lviv, September 18, 2014.
More details -
http://www.globallogic.com.ua/press-releases/lviv-cpp-techtalk-coverage
Here we are going to take a look how to use for loop, foreach loop and while loop. Also we are going to learn how to use and invoke methods and how to define classes in Java programming language.
The slide introduce some of the Rust concept that are necessary to write a kernel. Including wrapping an CSRs operation, locking mutable static variable, memory allocator, and pointer in Rust.
Please visit the project github to see the source code of the rrxv6 projects:
https://github.com/yodalee/rrxv6
CountPositiveNumbersInArray.java
package org.students;
import java.util.Scanner;
public class CountPositiveNumbersInArray {
public static void main(String[] args) throws Exception {
int array[] = null;
//Declaring variables
int count_positive_nos;
//Scanner object is used to Get the values entered by the user.
Scanner sc = new Scanner(System.in);
//Getting the Array Size from the user.
System.out.print(\"\ Enter no of elements you want to store in Array :\");
int number = sc.nextInt();
//Creating an array with that size
array = new int[number];
//Populating the array with user enterd values.
for (int i = 0; i < number; i++) {
System.out.print(\"\ Enter the element \" + (i + 1) + \" :\");
array[i] = sc.nextInt();
}
//Calling the method by passing the array as argument.
count_positive_nos = countPositive(array);
//Displaying the no of positive numbers in the array
System.out.println(\"The number of Positive Numbers in the array :\"+ count_positive_nos);
}
/*
* This method checks and count number of positive numbers in the array
* @Params, array of integer type
* @return array
*/
private static int countPositive(int[] array)
{
//Declaring local variable
int count = 0;
try
{
if (array == null)
{
throw new NullPointerException();
}
else
{
for (int i = 0; i < array.length; i++)
{
if (array[i] > 0)
{
count++;
}
}
}
}
catch (Exception e)
{
System.out.println(\"Exception :\"+e);
}
return count;
}
}
_______________________________________________________________
Output:
Enter no of elements you want to store in Array :4
Enter the element 1 :-4
Enter the element 2 :0
Enter the element 3 :2
Enter the element 4 :2
The number of Positive Numbers in the array :2
____________________________________________________________________
Solution
CountPositiveNumbersInArray.java
package org.students;
import java.util.Scanner;
public class CountPositiveNumbersInArray {
public static void main(String[] args) throws Exception {
int array[] = null;
//Declaring variables
int count_positive_nos;
//Scanner object is used to Get the values entered by the user.
Scanner sc = new Scanner(System.in);
//Getting the Array Size from the user.
System.out.print(\"\ Enter no of elements you want to store in Array :\");
int number = sc.nextInt();
//Creating an array with that size
array = new int[number];
//Populating the array with user enterd values.
for (int i = 0; i < number; i++) {
System.out.print(\"\ Enter the element \" + (i + 1) + \" :\");
array[i] = sc.nextInt();
}
//Calling the method by passing the array as argument.
count_positive_nos = countPositive(array);
//Displaying the no of positive numbers in the array
System.out.println(\"The number of Positive Numbers in the array :\"+ count_positive_nos);
}
/*
* This method checks and count number of positive numbers in the array
* @Params, array of integer type
* @return array
*/
private static int countPositive(int[] array)
{
//Declaring local variable
int count = 0;
try
{
if (array == null)
{
throw new NullPointerException(.
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfankkitextailes
SumNumbers.java
import java.util.Scanner;
public class SumNumbers {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int sum = 0;
while(true){
System.out.println(\"Enter integer:\");
int n = scan.nextInt();
if(n == -1){
break;
}
sum = sum + n;
}
System.out.println(\"The sum is \"+sum);
}
}
Output:
Enter integer:
1
Enter integer:
2
Enter integer:
3
Enter integer:
4
Enter integer:
5
Enter integer:
6
Enter integer:
7
Enter integer:
8
Enter integer:
9
Enter integer:
-1
The sum is 45
Solution
SumNumbers.java
import java.util.Scanner;
public class SumNumbers {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int sum = 0;
while(true){
System.out.println(\"Enter integer:\");
int n = scan.nextInt();
if(n == -1){
break;
}
sum = sum + n;
}
System.out.println(\"The sum is \"+sum);
}
}
Output:
Enter integer:
1
Enter integer:
2
Enter integer:
3
Enter integer:
4
Enter integer:
5
Enter integer:
6
Enter integer:
7
Enter integer:
8
Enter integer:
9
Enter integer:
-1
The sum is 45.
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source CodePVS-Studio
Debates on whether or not we are alone in the Universe have been exciting our minds for many decades. This question is approached seriously by the SETI program whose mission is to search for extraterrestrial civilizations and ways to contact them. It is the analysis of one of this program's projects, SETI@home, that we are going to talk about in this article.
Free Lunch is Over: Why is C++ so Important in the Modern World?Mateusz Pusz
"Don’t pay for what you don’t use" and "Don't leave room for a language below C++ (except assembler)" are the C++ design and evolution priorities that have stuck with us since the beginning of the programming language. CPU clock frequencies stopped growing more than 10 years ago, and since that time, our processor cores are no longer accelerating. Moreover, the demand for power savings is higher than ever for both small factor devices, like mobile phones, and for huge factor server farms. In the domains where each CPU cycle counts, C++ is the fastest and the most robust solution on the market. C++ programming language is evolving faster now than ever before — and EPAM is an active contributor to this transformation. This talk will briefly summarize the history of C++, describe the benefits of the programming language, highlight the business domains where its usage is essential, and provide some insights on the future of the language and its standardization process.
A Physical Units Library for the Next C++Mateusz Pusz
These are the slides from my CppCon 2020 talk. You can find the recording here: https://www.youtube.com/watch?v=7dExYGSOJzo. All my other talks can be found here: https://train-it.eu/resources.
---
During CppCon 2019 Mateusz provided an overview of current solutions on the market as well as challenges of implementing a modern C++ physical units library. This year's talk will focus on 'mp-units', the library that was developed by Mateusz and contributors, and which is proposed for C++ standardization. During the tutorial, we will get familiar with the building blocks of the library's framework and its most important concepts. Numerous code examples will present how to use and solve real-life problems with the library. The audience will learn how easy it is to extend it with new units, dimensions, or even whole new systems of quantities. Last but not least Mateusz will provide a fair comparison of how well this library performs in comparison to other products on the market.
These are the slides from my keynote talk on C++ on CoreHard Autumn 2019. You can find the recording here: https://www.youtube.com/watch?v=nqf53MlnMpo. All my other talks can be found here: https://train-it.eu/resources.
---
That talk will present the C++ world seen from Low Latency domain. The world where no dynamic allocations are welcomed, C++ exceptions are nearly not used, where STL containers are often not enough, and where developers often need to go deep down to assembly level to verify if the code really does its best.
Rethinking the Way We do Templates in C++Mateusz Pusz
These are the slides from my CppCon 2019 talk. You can find the recording here: https://www.youtube.com/watch?v=oNBnYhLxlTU. All my other talks can be found here: https://train-it.eu/resources.
---
Template metaprogramming is hard. In case it is hard only for the library implementer then it is not that bad. The problem arises when it also affects the users of this library.
This talk is summarizing my experience and thoughts gathered during the implementation of the Physical Units Library for C++. The way we do template metaprogramming now results with inscrutable compile-time errors and really long type names observed while debugging our code. That is mostly caused by aliasing class template specializations of non-trivial metaprogramming interface designs. Compilation times of such code also leave a lot of room for improvement, and the practices we chose to use in the Standard Library are often suboptimal. Taking into account the Rule of Chiel while designing templated code makes a huge difference in the compile times. This talk presents a few simple examples (including the practices from the C++ Standard Library) of achieving the same goal in different ways and provides benchmark results of time needed to compile such source code.
These are the slides from my talk on C++ London meetup. You can find the recording here: https://www.youtube.com/watch?v=HsC1EoFjf8U. All my other talks can be found here: https://train-it.eu/resources.
---
C++ is the fastest programming language in the world, and it leaves no room for other languages below it (except assembler). That is why it gets more attention now than ever before. As a result, we observe an increasing speed of C++ language evolution. C++11 was a game changer, but is now considered an "old" language already. C++14 & 17 provided many improvements that allow us to write portable, safer, and faster code in a shorter time. The resulting source code is easier to reason about and maintain. Moreover, C++20 is coming soon, and it is going to be a game changer again.
In my talk, I provide a few typical legacy code examples that most of us write every day. I describe how those samples evolve with the changes introduced in the each C++ language release from C++11 up to the major groundbreaking features of the upcoming C++20. During the talk, the audience will learn how much easier, more robust, and safer is the code written using modern tools that we get with every new C++ release.
Implementing a Physical Units Library for C++Mateusz Pusz
These are the slides from my keynote talk on C++ on CoreHard Spring 2019. You can find the recording here: https://www.youtube.com/watch?v=hcgL8QBmh2I. All my other talks can be found here: https://train-it.eu/resources.
---
This talk will present the current state of my work on designing and implementing Physical Units Library for C++. I will present all the challenges, design tradeoffs, and potential solutions to those problems. During the lecture, we will also see how new C++20 features help to make the library interface easier to use, maintain, and extend. Among others, we will see how we can benefit from class types provided as non-type template parameters, how new class template argument deduction rules simplify the interfaces and the full power of using concepts to constrain template types.
Effective replacement of dynamic polymorphism with std::variantMateusz Pusz
These are the slides from my ACCU 2019 talk. You can find the recording here: https://www.youtube.com/watch?v=JGYxOieiZnY. All my other talks can be found here: https://train-it.eu/resources.
---
This short talk presents how easy it is to replace some cases of dynamic polymorphism with std::variant. During the lecture, we will analyze and compare a few implementations of the same simple Finite State Machine. It turns up that variant-based code is not only much faster but also it gives us the opportunity to define our interfaces and program flow much better. The talk will end up with the discussion of pros and cons of each approach and will try to give guidelines on when to use them.
Implementing Physical Units Library for C++Mateusz Pusz
These are the slides from my 4Developers 2019 talk. You can find the recording here: https://www.youtube.com/watch?v=O1vlFZcaMKo. All my other talks can be found here: https://train-it.eu/resources.
---
This talk will present the current state of my work on designing and implementing Physical Units Library for C++. I will present all the challenges, design tradeoffs, and potential solutions to those problems. During the lecture, we will also see how new C++20 features help to make the library interface easier to use, maintain, and extend. Among others, we will see how we can benefit from class types provided as non-type template parameters, how new class template argument deduction rules simplify the interfaces, and a full power of using concepts to constrain template types.
C++ Concepts and Ranges - How to use them?Mateusz Pusz
These are the slides from my Meeting C++ 2018 talk. You can find the recording here: https://www.youtube.com/watch?v=pe05ZWdh0N0. All my other talks can be found here: https://train-it.eu/resources.
---
The most of the Concepts TS and Ranges TS is merged into the C++20 standard draft document. The talk will present a current design of those features and will provide suggestions on how to use them in our source code. That presentation is meant to inspire discussion on how should we use those long-awaited features while building tools and the C++ Standard Library.
Effective replacement of dynamic polymorphism with std::variantMateusz Pusz
These are the slides from my CppCon 2018 talk. You can find the recording here: https://www.youtube.com/watch?v=gKbORJtnVu8. All my other talks can be found here: https://train-it.eu/resources.
---
This short talk presents how easy it is to replace some cases of dynamic polymorphism with std::variant. During the lecture, we will analyze and compare 2 implementations of the same simple Finite State Machine. It turns up that variant-based code is not only much faster but also it gives us the opportunity to define our interfaces and program flow much better. The talk will end up with the discussion of pros and cons of each approach and will try to give guidelines on when to use them.
Git, CMake, Conan - How to ship and reuse our C++ projects?Mateusz Pusz
These are the slides from my CppCon 2018 talk. You can find the recording here: https://www.youtube.com/watch?v=S4QSKLXdTtA. All my other talks can be found here: https://train-it.eu/resources.
---
Git and CMake are already established standards in our community. However, it is uncommon to see them being used in an efficient way. As a result, many C++ projects have big problems with either importing other dependencies or making themselves easy to import by others. It gets even worse when we need to build many different configurations of our package on one machine.
That presentation lists and addresses the problems of build system and packaging that we have with large, multi-platform, C++ projects that often have many external and internal dependencies. The talk will present how proper use of CMake and Conan package manager can address those use cases. It will also describe current issues with the cooperation of those tools.
If you've attended or seen my talk at C++Now 2018, that time you can expect much more information on Conan and package creation using that tool. I will also describe how the integration of CMake and Conan changed over the last few months.
These are the slides from my C++Now 2018 talk. You can find the recording here: https://www.youtube.com/watch?v=y7PBciQp0B8. All my other talks can be found here: https://train-it.eu/resources.
---
Presentation of features already voted into C++20 Standard Draft in Toronto, Albuquerque, and Jacksonville ISO C++ Committee Meetings as well as the overview of other really promising proposals that have high chances to arrive in C++20.
Pointless Pointers - How to make our interfaces efficient?Mateusz Pusz
These are the slides from my code::dive 2017 talk. You can find the recording here: https://www.youtube.com/watch?v=qrifyjQW9gA. All my other talks can be found here: https://train-it.eu/resources.
---
C++ is not C. C++ developers too often forget about that. The effects are often disastrous. nullptr dereferences, buffer overflows, resource leaks are the problems often seen in C++ applications bug trackers. Does it have to be like that? The talk presents a few simple rules tested in production that will make most of those issues go away and never appear again in the C++ software. Interested? Come and see :-)
These are the slides from my 4Developers 2017 talk. You can find the recording here: https://www.youtube.com/watch?v=pU0VRMqM5vs. All my other talks can be found here: https://train-it.eu/resources.
---
That talk will present the C++ world seen from Low Latency domain. The world where no dynamic allocations are welcomed, C++ exceptions are nearly not used, where STL containers are often not enough, and where developers often need to go deep down to assembly level to verify if the code really does its best.
std::shared_ptr<T> - (not so) Smart hammer for every pointy nailMateusz Pusz
These are the slides from my code::dive 2016 talk. You can find the recording here: https://www.youtube.com/watch?v=hHQS-Q7aMzg. All my other talks can be found here: https://train-it.eu/resources.
---
C++ rule of thumb is “you do not pay for what you do not use”. However, it turns out that this is not the case for some of the utilities from the C++ Standard Library. The key example here is the favorite tool of many developers – std::shared_ptr. The talk will describe the problems related to it in detail. It will also try to answer the question how it was possible to avoid them.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
How world-class product teams are winning in the AI era by CEO and Founder, P...
Small Lie in Big O
1. Small Lie in Big O
Mateusz Pusz
November 15, 2016
2. 2code::dive 2016 Mateusz Pusz
‘sample’ is a simple class containing 8-bit unsigned integral member
and a few user defined methods. Integral member inside ‘sample’
class should be initialized during class construction.
Implement function ‘test’ that:
• takes 2 integral arguments ‘n’ and ‘k’
• creates a collection of ‘n’ ‘sample’ objects with random values
assigned
• sorts created collection
• inserts a new random value keeping the collection sorted
(repeat ‘k’ times)
• returns average value from all the samples in the collection
SIMPLE PROGRAMMING PROBLEM
3. 3code::dive 2016 Mateusz Pusz
class sample {
std::uint8_t value_;
public:
// more interface...
};
‘sample’ is a simple class containing 8-bit unsigned integral member and a few user defined
methods
4. 4code::dive 2016 Mateusz Pusz
class sample {
std::uint8_t value_;
public:
explicit constexpr sample(std::uint8_t value) noexcept : value_{value} {}
// more interface...
};
Integral member inside ‘sample’ class should be initialized during class construction
5. 5code::dive 2016 Mateusz Pusz
class sample {
std::uint8_t value_;
public:
explicit constexpr sample(std::uint8_t value) noexcept : value_{value} {}
// more interface...
};
std::uint8_t test(int n, int k)
{
}
implement a function ‘test’ that takes 2 integral arguments ‘n’ and ‘k’
6. 6code::dive 2016 Mateusz Pusz
class sample {
std::uint8_t value_;
public:
explicit constexpr sample(std::uint8_t value) noexcept : value_{value} {}
// more interface...
};
std::uint8_t test(int n, int k)
{
// create collection of 'n' random samples
// sort the collection
// k times insert a new random sample keeping the collection sorted
// return average value from samples in the collection
}
implement a function ‘test’ that …
7. 7code::dive 2016 Mateusz Pusz
class sample {
std::uint8_t value_;
public:
explicit constexpr sample(std::uint8_t value) noexcept : value_{value} {}
// more interface...
// returns stored value
constexpr operator std::uint8_t() const noexcept { return value_; }
};
“sorting”, “comparing values”, … –> need to extend ‘sample’ interface
8. 8code::dive 2016 Mateusz Pusz
using elem_type = sample*;
using collection = std::list<elem_type>;
“class”, not a fundamental type –> dynamic memory allocation
“inserting in the middle”, “sorting”, … –> std::list
9. 9code::dive 2016 Mateusz Pusz
std::uint8_t generate()
{
... // probably not enough time today to describe the implementation
}
“random values” –> provide random numbers generator
… or use C++11 <random>
XKCD way …
10. 10code::dive 2016 Mateusz Pusz
collection init_random(int n)
{
collection samples;
for(int i=0; i<num; ++i)
samples.emplace_back(new sample{generate()});
return samples;
}
std::uint8_t test(int n, int k)
{
// create collection of 'n' random samples
auto samples = init_random(n);
// ...
}
creates a collection of ‘n’ ‘sample’ objects with random values assigned
O(n)
11. 11code::dive 2016 Mateusz Pusz
std::uint8_t test(int n, int k)
{
// create collection of 'n' random samples
auto samples = init_random(n);
// sort the collection
values.sort([](const auto& l, const auto& r) { return *l < *r; });
// ...
}
sorts created collection
O(nlogn)
12. 12code::dive 2016 Mateusz Pusz
std::uint8_t test(int n, int k)
{
// ...
// k times insert a new random sample keeping the collection sorted
for(int i=0; i<k; ++i) {
const sample new_sample{generate()};
samples.emplace(
),
new sample{new_sample});
}
// ...
}
std::uint8_t test(int n, int k)
{
// ...
// k times insert a new random sample keeping the collection sorted
for(int i=0; i<k; ++i) {
const sample new_sample{generate()};
samples.emplace(find_if(begin(samples), end(samples),
),
new sample{new_sample});
}
// ...
}
std::uint8_t test(int n, int k)
{
// ...
// k times insert a new random sample keeping the collection sorted
for(int i=0; i<k; ++i) {
const sample new_sample{generate()};
samples.emplace(find_if(begin(samples), end(samples),
[&](const auto& s) { return new_sample < *s; }),
new sample{new_sample});
}
// ...
}
inserts a new random value keeping the collection sorted (repeat ‘k’ times)
O(k * (n+k))
13. 13code::dive 2016 Mateusz Pusz
std::uint8_t test(int n, int k)
{
// ...
// return average value from samples in the collection
return std::accumulate(begin(samples), end(samples), std::uint64_t{},
[](const auto& sum, const auto& s){ return sum + *s; }) / samples.size();
}
returns average value from all the samples in the collection
O(n)
14. 14code::dive 2016 Mateusz Pusz
std::uint8_t test(int n, int k)
{
// create collection of 'n' random samples
auto samples = init_random(n);
// sort the collection
samples.sort([](const auto& l, const auto& r) { return *l < *r; });
// k times insert a new random sample keeping the collection sorted
for(int i = 0; i < k; ++i) {
const sample new_sample{generate()};
samples.emplace(find_if(begin(samples), end(samples),
[&](const auto& s) { return new_sample < *s; }),
new sample{new_sample});
}
// return average value from samples in the collection
return std::accumulate(begin(samples), end(samples), std::uint64_t{},
[](const auto& sum, const auto& s){ return sum + *s; }) / samples.size();
}
Whole code
Do you see a problem?
15. 15code::dive 2016 Mateusz Pusz
std::uint8_t test(int n, int k)
{
// create collection of 'n' random samples
auto samples = init_random(n);
// sort the collection
samples.sort([](const auto& l, const auto& r) { return *l < *r; });
// k times insert a new random sample keeping the collection sorted
for(int i = 0; i < k; ++i) {
const sample new_sample{generate()};
samples.emplace(find_if(begin(samples), end(samples),
[&](const auto& s) { return new_sample < *s; }),
new sample{new_sample});
}
// return average value from samples in the collection
return std::accumulate(begin(samples), end(samples), std::uint64_t{},
[](const auto& sum, const auto& s){ return sum + *s; }) / samples.size();
}
Whole code
Do you see a problem?
17. 17code::dive 2016 Mateusz Pusz
std::uint8_t test(int n, int k)
{
// ...
// cleanup the collection
for(auto& s : samples)
delete s;
}
Adding cleanup is simple, right?
18. 18code::dive 2016 Mateusz Pusz
std::uint8_t test(int n, int k)
{
// create collection of 'n' random samples
auto samples = init_random(n);
// sort the collection
samples.sort([](const auto& l, const auto& r) { return *l < *r; });
// k times insert a new random sample keeping the collection sorted
for(int i = 0; i < k; ++i) {
const sample new_sample{generate()};
samples.emplace(find_if(begin(samples), end(samples),
[&](const auto& s) { return new_sample < *s; }),
new sample{new_sample});
}
// return average value from samples in the collection
auto avg = std::accumulate(begin(samples), end(samples), std::uint64_t{},
[](const auto& sum, const auto& s){ return sum + *s; }) / samples.size();
// cleanup the collection
for(auto& s : samples)
delete s;
return avg;
}
Whole code
Do you see a problem?
19. 19code::dive 2016 Mateusz Pusz
std::uint8_t test(int n, int k)
{
// create collection of 'n' random samples
auto samples = init_random(n);
// sort the collection
samples.sort([](const auto& l, const auto& r) { return *l < *r; });
// k times insert a new random sample keeping the collection sorted
for(int i = 0; i < k; ++i) {
const sample new_sample{generate()};
samples.emplace(find_if(begin(samples), end(samples),
[&](const auto& s) { return new_sample < *s; }),
new sample{new_sample});
}
// return average value from samples in the collection
auto avg = std::accumulate(begin(samples), end(samples), std::uint64_t{},
[](const auto& sum, const auto& s){ return sum + *s; }) / samples.size();
// cleanup the collection
for(auto& s : samples)
delete s;
return avg;
}
Whole code
Do you see a problem?
21. 21code::dive 2016 Mateusz Pusz
class resource {
// resource handle
public:
resource(/* args */)
{ /* obtain ownership of a resource and store the handle */ }
~resource()
{ /* reclaim the resource */ }
};
If you dissect the words of the RAII acronym (Resource Acquisition Is
Initialization), you will think RAII is about acquiring resources during
initialization. However the power of RAII comes not from tying acquisition to
initialization, but from tying reclamation to destruction.
-- Bjarne Stroustrup
RESOURCE ACQUISITION IS INITIALIZATION (RAII)
22. 22code::dive 2016 Mateusz Pusz
• Smart Pointers
– std::unique_ptr<T, Deleter = std::default_delete<T>>
– std::shared_ptr<T>
– std::weak_ptr<T>
– std::auto_ptr<T>
• Containers
– all STL containers manage ownership of their data
• File streams
• Mutex locks
– std::lock_guard<Mutex>
– std::unique_lock<Mutex>
• More…
RAII USAGE IN C++ STANDARD LIBRARY
23. 23code::dive 2016 Mateusz Pusz
using elem_type = std::unique_ptr<sample>;
// ...
// replace all
new sample{...}
// with
std::make_unique<sample>(...)
std::uint8_t test(int n, int k)
{
// ...
// cleanup the collection
for(auto& s : samples)
delete s;
}
Let’s fix our code to be C++ exception safe
Writing exception safe code
is not that hard at all!!!
24. 24code::dive 2016 Mateusz Pusz
Solution test(10 000 000, 0) test(0, 100 000) test(100 000, 10 000)
Original 10,7s 104,5s 32,6s
Change 1 9,3s 57,1s 16,4s
Change 2 0,75s 1,7s 0,37s
Change 3 0,75s 0,98s 0,21s
Speedup 14x 106x 155x
Can we make our code faster?
TWEAKING ‘N’ IN ‘F(N)’
25. 25code::dive 2016 Mateusz Pusz
Solution test(10 000 000, 0) test(0, 100 000) test(100 000, 10 000)
Original 10,7s 104,5s 32,6s
Change #1 9,3s 57,1s 16,4s
Change #2 0,75s 1,7s 0,37s
Change #3 0,75s 0,98s 0,21s
Speedup 14x 106x 155x
Can we make our code faster?
Yes, A LOT faster
TWEAKING ‘N’ IN ‘F(N)’
26. 26code::dive 2016 Mateusz Pusz
using elem_type = sample*;
using collection = std::list<elem_type>;
“class”, not a fundamental type –> dynamic memory allocation
“inserting in the middle”, “sorting”, … –> std::list
WRONG!!!
27. 27code::dive 2016 Mateusz Pusz
• Heap usage should be avoided if possible
– allocation and deallocation of heap memory is slow
– obtaining data from non-cached memory is slow
– heap allocation can fail
– allocation of many small objects causes huge memory fragmentation
• C++ loves value semantics
– using pointers changes semantics of copy, assignment and equality
– pointer dereferencing takes time
– much easier to write thread-safe code
– reference/pointer semantics causes aliasing problems
• compiler optimizer cannot do its best -> slower code
– Copy Elision (RVO) and Move Semantics improve things a lot
C++ IS NOT C# OR JAVA
32. 32code::dive 2016 Mateusz Pusz
• easy to insert new elements
• easy to erase existing elements
• easy to reorder elements
• bidirectional iteration
• memory ineffective
– for small T large memory overhead
– a lot of dynamic memory allocations and deallocations
– a lot of pointer dereferences during iteration
– not cache friendly
std::list<T>
T
prev
next
T
prev
nextT
prev
next
T
prev
next
34. 34code::dive 2016 Mateusz Pusz
{ reserved }
• inserting new elements
– end – easy (unless buffer reallocation is needed)
– begin, middle – hard
• erasing existing elements
– end – easy
– begin, middle – hard
• swapping values needed to reorder elements
• random access iteration
• memory effective
– small memory overhead (reserved space)
– nearly no dynamic memory allocations and deallocations
– no pointer dereferences during iteration
– cache friendly!!!
std::vector<T>
T T T T T T T T T T T T
35. 35code::dive 2016 Mateusz Pusz
int
CPU cache
Writing cache
friendly code makes a
huge difference!
std::vector<int> ITERATION
M
E
M
O
R
Y
36. 36code::dive 2016 Mateusz Pusz
Performance counter stats for './test_list':
83991,294231 task-clock (msec) # 0,999 CPUs utilized
213901565783 cycles # 2,547 GHz
27748493084 instructions # 0,13 insn per cycle
8472128537 branches # 100,869 M/sec
61763769 branch-misses # 0,73% of all branches
8822212776 L1-dcache-loads # 105,037 M/sec
4799991469 L1-dcache-load-misses # 54,41% of all L1-dcache hits
4177763046 LLC-loads # 49,740 M/sec
550506468 LLC-load-misses # 13,18% of all LL-cache hits
78237 page-faults # 0,931 K/sec
Performance counter stats for './test_vector':
2826,385943 task-clock (msec) # 0,999 CPUs utilized
7462656329 cycles # 2,640 GHz
27117855932 instructions # 3,63 insn per cycle
7396349132 branches # 2616,893 M/sec
39248559 branch-misses # 0,53% of all branches
6466518567 L1-dcache-loads # 2287,911 M/sec
77800147 L1-dcache-load-misses # 1,20% of all L1-dcache hits
89304 LLC-loads # 0,032 M/sec
36469 LLC-load-misses # 40,84% of all LL-cache hits
1050 page-faults # 0,371 K/sec
LISTVECTOR
37. 37code::dive 2016 Mateusz Pusz
L1 cache reference 0.5 ns
Branch misprediction 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns
Read 4K randomly from SSD 150,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Read 1 MB sequentially from SSD 1,000,000 ns 4X memory
Disk seek 10,000,000 ns 20x datacenter roundtrip
Read 1 MB sequentially from disk 20,000,000 ns 80x memory, 20X SSD
Send packet CA->Netherlands->CA 150,000,000 ns
Latency Numbers Every Programmer Should Know
-- Jeff Dean
38. 38code::dive 2016 Mateusz Pusz
std::uint8_t test(int n, int k)
{
// create collection of 'n' random samples
// sort the collection
// k times insert a new random sample keeping the collection sorted
// return average value from samples in the collection
}
§25.4.3.1
template<class ForwardIterator, class T>
ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
1 Requires: The elements e of [first,last) shall be partitioned with respect to the expression e < value
2 Returns: The furthermost iterator i in the range [first,last] such that for every iterator j in the range
[first,i) the following corresponding conditions hold: *j < value.
3 Complexity: At most log2(last − first) + O(1) comparisons.
A NEW POSSIBILITY FOR ALGORITHMIC OPTIMIZATION
39. 39code::dive 2016 Mateusz Pusz
Know and use C++ algorithms
std::uint8_t test(int n, int k)
{
// ...
// k times insert a new random sample keeping the collection sorted
for(int i=0; i<k; ++i) {
const sample new_sample{generate()};
samples.emplace(lower_bound(begin(samples), end(samples), new_sample), new_sample);
}
// ...
}
1x-1.7x speedup
CHANGE #3
40. 40code::dive 2016 Mateusz Pusz
collection init_random(int n, int k)
{
collection samples;
samples.reserve(n + k);
for(int i=0; i<n; ++i)
samples.emplace_back(generate());
return samples;
}
std::uint8_t test(int n, int k)
{
auto samples = init_random(n, k);
sort(begin(samples), end(samples));
// k times insert a new random sample keeping the collection sorted
for(int i=0; i<k; ++i) {
const sample new_sample{generate()};
samples.emplace(lower_bound(begin(samples), end(samples), new_sample), new_sample);
}
return std::accumulate(begin(samples), end(samples), std::uint64_t{}) / samples.size();
}
Isn’t it a great
example of efficient
programming?
Whole code
41. 41code::dive 2016 Mateusz Pusz
QUOTES FROM THE C++ COMMUNITY
Using std::map is an exercise in slowing down code.
If you think link list is bad... maps are worse.
51. Learn C++ to be a more
efficient programmer
• containers,
• algorithms,
• new C++11/C++14/C++17
features
52. Use RAII design pattern as
your first resort tool for
management of all
resources
53. Use tools provided by the
C++ standard or C++
community
Do not reinvent the wheel!!!
54. Remember that memory
access is the bottleneck of
many today’s applications!
Limit pointers usage
Write cache friendly code
Photograph by Mauro Sartori
55. Always meassure your code
if you care for performance!
Do not do premature
optimizations based only on
your assumptions
(algorithms, CPU cache
friendliness or others)