The document introduces the Generic Image Library (GIL), Boost libraries, and generic programming. It provides an overview of GIL for image processing and Boost for peer-reviewed C++ libraries. It describes how generic programming separates algorithms from data structures and allows algorithms to work with different types through templates and polymorphism. Accumulating a data set is used as an example to compare object-oriented and generic programming approaches.
The document discusses applying design patterns to compiler code. It begins with an overview of design principles and smells in code. It then discusses refactoring code using patterns like composite and factory method. The case study shows transforming procedural compiler code to use these patterns by treating expression trees as objects. This improves readability and maintains separation of concerns. Examples demonstrate generating code for expressions by traversing the tree rather than conditional logic.
This document discusses chapters and concepts from Liang's Introduction to Java Programming textbook. It covers defining and using methods in Java, including defining methods with parameters and return types, invoking methods by passing arguments, and how method calls are handled by the call stack. Key points covered include formal vs actual parameters, method signatures, return values, and reusing methods from other classes. Examples are provided to demonstrate calculating sums and finding maximum values using methods.
This document provides an agenda for an iOS development training that covers Objective-C knowledge, the MVC pattern, and building a view-based application in Xcode. The topics include an introduction to iOS, the Objective-C language syntax including classes, objects, properties, and memory management, the model-view-controller pattern, and building an app using views, view controllers, navigation controllers, and common controls. The training aims to equip attendees with the skills needed to develop native iOS applications using Apple's SDK frameworks and development tools.
The document provides an introduction to a Java programming course. It outlines the course objectives which include understanding core Java concepts like primitive data types, control flow, methods, arrays, object-oriented programming, and core Java classes. It also discusses how upon completing the course students will be able to develop programs using Eclipse IDE and write simple programs using various Java features. The document then covers specific topics that will be taught like methods, object-oriented programming concepts like classes, constructors, and polymorphism.
Objective-C for iOS Application DevelopmentDhaval Kaneria
The document provides an introduction to Objective-C and iPhone development. It discusses key aspects of Objective-C including its syntax which extends C with object-oriented capabilities. Objective-C uses class definitions with interfaces and implementations. Programs create class instances that can receive messages to call methods. Classes can inherit from superclasses and support polymorphism. The document also outlines core concepts like memory management, frameworks for iOS development and examples of Hello World programs.
This document summarizes Chapter 13 of Liang's Introduction to Java Programming textbook. It discusses graphics and drawing in Java, including:
- Java's coordinate system and how each GUI component has its own coordinate space
- Using the Graphics class to draw strings, lines, rectangles, ovals, arcs and polygons
- Overriding the paintComponent method to draw on a component
- Examples of drawing different shapes and using classes like FigurePanel and MessagePanel
The document provides an overview of the Python programming language. It discusses that Python is an interpreted, interactive, object-oriented, and high-level programming language. It can be used to develop desktop and web applications. Popular applications built using Python include Instagram, Google, Dropbox, Yahoo Maps, Spotify, and Reddit. The document also covers Python variables, data types, operators, and basic control structures like if/else statements and while loops. It provides examples of how to write, run, and execute Python code in both interactive and script modes.
The document discusses applying design patterns to compiler code. It begins with an overview of design principles and smells in code. It then discusses refactoring code using patterns like composite and factory method. The case study shows transforming procedural compiler code to use these patterns by treating expression trees as objects. This improves readability and maintains separation of concerns. Examples demonstrate generating code for expressions by traversing the tree rather than conditional logic.
This document discusses chapters and concepts from Liang's Introduction to Java Programming textbook. It covers defining and using methods in Java, including defining methods with parameters and return types, invoking methods by passing arguments, and how method calls are handled by the call stack. Key points covered include formal vs actual parameters, method signatures, return values, and reusing methods from other classes. Examples are provided to demonstrate calculating sums and finding maximum values using methods.
This document provides an agenda for an iOS development training that covers Objective-C knowledge, the MVC pattern, and building a view-based application in Xcode. The topics include an introduction to iOS, the Objective-C language syntax including classes, objects, properties, and memory management, the model-view-controller pattern, and building an app using views, view controllers, navigation controllers, and common controls. The training aims to equip attendees with the skills needed to develop native iOS applications using Apple's SDK frameworks and development tools.
The document provides an introduction to a Java programming course. It outlines the course objectives which include understanding core Java concepts like primitive data types, control flow, methods, arrays, object-oriented programming, and core Java classes. It also discusses how upon completing the course students will be able to develop programs using Eclipse IDE and write simple programs using various Java features. The document then covers specific topics that will be taught like methods, object-oriented programming concepts like classes, constructors, and polymorphism.
Objective-C for iOS Application DevelopmentDhaval Kaneria
The document provides an introduction to Objective-C and iPhone development. It discusses key aspects of Objective-C including its syntax which extends C with object-oriented capabilities. Objective-C uses class definitions with interfaces and implementations. Programs create class instances that can receive messages to call methods. Classes can inherit from superclasses and support polymorphism. The document also outlines core concepts like memory management, frameworks for iOS development and examples of Hello World programs.
This document summarizes Chapter 13 of Liang's Introduction to Java Programming textbook. It discusses graphics and drawing in Java, including:
- Java's coordinate system and how each GUI component has its own coordinate space
- Using the Graphics class to draw strings, lines, rectangles, ovals, arcs and polygons
- Overriding the paintComponent method to draw on a component
- Examples of drawing different shapes and using classes like FigurePanel and MessagePanel
The document provides an overview of the Python programming language. It discusses that Python is an interpreted, interactive, object-oriented, and high-level programming language. It can be used to develop desktop and web applications. Popular applications built using Python include Instagram, Google, Dropbox, Yahoo Maps, Spotify, and Reddit. The document also covers Python variables, data types, operators, and basic control structures like if/else statements and while loops. It provides examples of how to write, run, and execute Python code in both interactive and script modes.
19. Data Structures and Algorithm ComplexityIntro C# Book
In this chapter we will compare the data structures we have learned so far by the performance (execution speed) of the basic operations (addition, search, deletion, etc.). We will give specific tips in what situations what data structures to use. We will explain how to choose between data structures like hash-tables, arrays, dynamic arrays and sets implemented by hash-tables or balanced trees. Almost all of these structures are implemented as part of NET Framework, so to be able to write efficient and reliable code we have to learn to apply the most appropriate structures for each situation.
This document provides an overview of pointers and arrays in C++. It begins by explaining what pointers are, how they store memory addresses, and how to declare and assign values to pointer variables. It then covers arrays, including how they allow storing multiple values in contiguous memory locations that can be indexed. The document also discusses different types of arrays, such as one-dimensional, two-dimensional, and arrays of objects. Finally, it briefly introduces dynamic memory allocation using new operator at runtime.
The document discusses Python modules and classes. It explains that a module is a .py file that can contain functions, classes, and variables. A module can be imported and its elements used in another file. A class defines the structure of an object with attributes like name and methods like setName(). Inheritance allows a child class to inherit attributes and methods from a parent class, with the ability to override methods. The document provides examples of defining classes like Shape and inheriting from it to create child classes like Circle.
In this chapter we will get familiar with primitive types and variables in Java – what they are and how to work with them. First we will consider the data types – integer types, real types with floating-point, Boolean, character, string and object type. We will continue with the variables, with their characteristics, how to declare them, how they are assigned a value and what is variable initialization.
This document provides an overview of several Java generics features including: generics allow compile-time type safety for collections without casting; the enhanced for loop automates use of iterators to avoid errors; autoboxing/unboxing avoids manual conversion between primitive types and wrapper types; typesafe enums provide benefits of the typesafe enum pattern; and examples of using generics with classes, methods, and collections.
The Goal and The Journey - Turning back on one year of C++14 MigrationJoel Falcou
C++14 has been announced as the next best thing since sliced bread in terms of simplicity, performance and overall elegance of c++ code. This talk is the story of why and how we decided to migrate one of our old 'modern C++' software library -- BSP++, a C++ implementation of the BSP parallel programming model -- to C++14.
More than just a recollection of 'use this' or 'do that' mottos, this talk will try to ponder on :
why one should consider migrating to C++14 now
which features actually helped and which one did not
the traps and pitfalls compilers tried to pull on us
The document provides an overview of functions in C++. It defines what a function is, its typical components like name, parameters, return type and statements. It gives examples of calling functions by value and by reference. It also discusses the differences between global and local scope, and how variables declared inside and outside functions are accessed. The objective is to teach how to define, prototype and call functions as well as understand their scope.
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.
Contents :
Language Concepts
How Objective C works- Basics
Data Types
NSInteger
NSNumber
Operators
Loop
Inheritance
Method Overloading
Mutable and Immutable Strings
Mutable and Immutable Arrays
File Management
The slides shown here have been used for talks given to scientists in informal contexts.
Python is introduced as a valuable tool for both producing and evaluating data.
The talk is essentially a guided tour of the author's favourite parts of the Python ecosystem. Besides the Python language itself, NumPy and SciPy as well as Matplotlib are mentioned.
A last part of the talk concerns itself with code execution speed. With this problem in sight, Cython and f2py are introduced as means of glueing different languages together and speeding Python up.
The source code for the slides, code snippets and further links are available in a git repository at
https://github.com/aeberspaecher/PythonForScientists
Python: Object oriented programming, RTS Tech. Indore
This is a presentation to take your skills to next level. Hope you will like our work to make programming easier for you.
Feel free to contact for the online/offline batches.
Syntax Comparison of Golang with C and Java - MindbowserMindbowser Inc
The document compares the syntax and features of C, Java, and Go programming languages. It discusses their file extensions, compilers, variable declaration, data types, operators, control flow statements, functions, arrays, maps, structs, classes, interfaces, pointers, error handling and concurrency models. The key differences summarized are that C uses .c extension and header files while Java uses .java extension and bytecode. Go can compile and run code directly without a virtual machine. Both Java and Go support OOPs concepts like classes while C uses structs. Go supports concurrency using goroutines and channels.
03 and 04 .Operators, Expressions, working with the console and conditional s...Intro C# Book
The document discusses Java syntax and concepts including:
1. It introduces primitive data types in Java like int, float, boolean and String.
2. It covers variables, operators, and expressions - how they are used to store and manipulate data in Java.
3. It explains console input and output using Scanner and System.out methods for reading user input and printing output.
4. It provides examples of using conditional statements like if and if-else to control program flow based on conditions.
This document provides an overview of object-oriented programming concepts in C++, including objects, classes, data abstraction, encapsulation, inheritance, and polymorphism. It defines each concept, provides examples in C++ code, and explains how they are implemented and relate to each other. The document is presented as part of a mentoring program to teach OOP concepts.
The Arduino reference document provides information about:
- The structure of Arduino programs including setup() and loop() functions
- Digital and analog input/output functions like pinMode(), digitalWrite(), and analogRead()
- Time functions like millis() and delay()
- Math functions like min(), max(), and map()
- Control structures like if/else statements and for loops
- Variables, data types, and libraries
The document discusses function overloading in C++ and provides an example program to calculate the area of different shapes using function overloading. It then discusses constructors and destructors with examples and explains polymorphism with an example. Next, it discusses different types of inheritance in C++ and provides an example program to implement operator overloading for a distance class. It also discusses virtual functions with an example and access specifiers in classes. Finally, it provides examples to define a student class, implement quicksort using templates and overloading relational operators.
The document discusses NumPy and SciPy, two popular Python packages for scientific computing. NumPy adds support for large, multi-dimensional arrays and matrices to Python. It also introduces data types and affords operations like linear algebra on array objects. SciPy builds on NumPy and contains modules for optimization, integration, interpolation and other tasks. Together, NumPy and SciPy provide a powerful yet easy to use environment for numerical computing in Python.
Designing Architecture-aware Library using Boost.ProtoJoel Falcou
This document discusses designing architecture-aware libraries using Boost.Proto. It describes how the NT2 scientific computing library was redesigned using Boost.Proto to make it more extensible and able to better support new hardware architectures. The redesign segmented the evaluation of expressions into phases. Boost.Proto transforms are used in each phase to advance code generation. Hardware specifications influence function overloads through generalized tag dispatching, allowing the best function implementation to be selected for a given hardware architecture. This makes it possible to more easily add support for new optimization schemes and hardware targets to the library.
This document provides an introduction to generic programming. It discusses the motivation for generic programming, which includes providing better abstraction and reusability in programming languages. It describes two main models for generic programming - parametric polymorphism in statically typed languages and dynamic typing in dynamically typed languages. The document also discusses implementation issues around generic programming such as efficiency, code generation, and language details.
Roche is recruiting for Senior Technical Programmers and Senior Programmers to join their site based in Welwyn Garden City in Hertfordshire. To find out more and apply please read this brochure.
19. Data Structures and Algorithm ComplexityIntro C# Book
In this chapter we will compare the data structures we have learned so far by the performance (execution speed) of the basic operations (addition, search, deletion, etc.). We will give specific tips in what situations what data structures to use. We will explain how to choose between data structures like hash-tables, arrays, dynamic arrays and sets implemented by hash-tables or balanced trees. Almost all of these structures are implemented as part of NET Framework, so to be able to write efficient and reliable code we have to learn to apply the most appropriate structures for each situation.
This document provides an overview of pointers and arrays in C++. It begins by explaining what pointers are, how they store memory addresses, and how to declare and assign values to pointer variables. It then covers arrays, including how they allow storing multiple values in contiguous memory locations that can be indexed. The document also discusses different types of arrays, such as one-dimensional, two-dimensional, and arrays of objects. Finally, it briefly introduces dynamic memory allocation using new operator at runtime.
The document discusses Python modules and classes. It explains that a module is a .py file that can contain functions, classes, and variables. A module can be imported and its elements used in another file. A class defines the structure of an object with attributes like name and methods like setName(). Inheritance allows a child class to inherit attributes and methods from a parent class, with the ability to override methods. The document provides examples of defining classes like Shape and inheriting from it to create child classes like Circle.
In this chapter we will get familiar with primitive types and variables in Java – what they are and how to work with them. First we will consider the data types – integer types, real types with floating-point, Boolean, character, string and object type. We will continue with the variables, with their characteristics, how to declare them, how they are assigned a value and what is variable initialization.
This document provides an overview of several Java generics features including: generics allow compile-time type safety for collections without casting; the enhanced for loop automates use of iterators to avoid errors; autoboxing/unboxing avoids manual conversion between primitive types and wrapper types; typesafe enums provide benefits of the typesafe enum pattern; and examples of using generics with classes, methods, and collections.
The Goal and The Journey - Turning back on one year of C++14 MigrationJoel Falcou
C++14 has been announced as the next best thing since sliced bread in terms of simplicity, performance and overall elegance of c++ code. This talk is the story of why and how we decided to migrate one of our old 'modern C++' software library -- BSP++, a C++ implementation of the BSP parallel programming model -- to C++14.
More than just a recollection of 'use this' or 'do that' mottos, this talk will try to ponder on :
why one should consider migrating to C++14 now
which features actually helped and which one did not
the traps and pitfalls compilers tried to pull on us
The document provides an overview of functions in C++. It defines what a function is, its typical components like name, parameters, return type and statements. It gives examples of calling functions by value and by reference. It also discusses the differences between global and local scope, and how variables declared inside and outside functions are accessed. The objective is to teach how to define, prototype and call functions as well as understand their scope.
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.
Contents :
Language Concepts
How Objective C works- Basics
Data Types
NSInteger
NSNumber
Operators
Loop
Inheritance
Method Overloading
Mutable and Immutable Strings
Mutable and Immutable Arrays
File Management
The slides shown here have been used for talks given to scientists in informal contexts.
Python is introduced as a valuable tool for both producing and evaluating data.
The talk is essentially a guided tour of the author's favourite parts of the Python ecosystem. Besides the Python language itself, NumPy and SciPy as well as Matplotlib are mentioned.
A last part of the talk concerns itself with code execution speed. With this problem in sight, Cython and f2py are introduced as means of glueing different languages together and speeding Python up.
The source code for the slides, code snippets and further links are available in a git repository at
https://github.com/aeberspaecher/PythonForScientists
Python: Object oriented programming, RTS Tech. Indore
This is a presentation to take your skills to next level. Hope you will like our work to make programming easier for you.
Feel free to contact for the online/offline batches.
Syntax Comparison of Golang with C and Java - MindbowserMindbowser Inc
The document compares the syntax and features of C, Java, and Go programming languages. It discusses their file extensions, compilers, variable declaration, data types, operators, control flow statements, functions, arrays, maps, structs, classes, interfaces, pointers, error handling and concurrency models. The key differences summarized are that C uses .c extension and header files while Java uses .java extension and bytecode. Go can compile and run code directly without a virtual machine. Both Java and Go support OOPs concepts like classes while C uses structs. Go supports concurrency using goroutines and channels.
03 and 04 .Operators, Expressions, working with the console and conditional s...Intro C# Book
The document discusses Java syntax and concepts including:
1. It introduces primitive data types in Java like int, float, boolean and String.
2. It covers variables, operators, and expressions - how they are used to store and manipulate data in Java.
3. It explains console input and output using Scanner and System.out methods for reading user input and printing output.
4. It provides examples of using conditional statements like if and if-else to control program flow based on conditions.
This document provides an overview of object-oriented programming concepts in C++, including objects, classes, data abstraction, encapsulation, inheritance, and polymorphism. It defines each concept, provides examples in C++ code, and explains how they are implemented and relate to each other. The document is presented as part of a mentoring program to teach OOP concepts.
The Arduino reference document provides information about:
- The structure of Arduino programs including setup() and loop() functions
- Digital and analog input/output functions like pinMode(), digitalWrite(), and analogRead()
- Time functions like millis() and delay()
- Math functions like min(), max(), and map()
- Control structures like if/else statements and for loops
- Variables, data types, and libraries
The document discusses function overloading in C++ and provides an example program to calculate the area of different shapes using function overloading. It then discusses constructors and destructors with examples and explains polymorphism with an example. Next, it discusses different types of inheritance in C++ and provides an example program to implement operator overloading for a distance class. It also discusses virtual functions with an example and access specifiers in classes. Finally, it provides examples to define a student class, implement quicksort using templates and overloading relational operators.
The document discusses NumPy and SciPy, two popular Python packages for scientific computing. NumPy adds support for large, multi-dimensional arrays and matrices to Python. It also introduces data types and affords operations like linear algebra on array objects. SciPy builds on NumPy and contains modules for optimization, integration, interpolation and other tasks. Together, NumPy and SciPy provide a powerful yet easy to use environment for numerical computing in Python.
Designing Architecture-aware Library using Boost.ProtoJoel Falcou
This document discusses designing architecture-aware libraries using Boost.Proto. It describes how the NT2 scientific computing library was redesigned using Boost.Proto to make it more extensible and able to better support new hardware architectures. The redesign segmented the evaluation of expressions into phases. Boost.Proto transforms are used in each phase to advance code generation. Hardware specifications influence function overloads through generalized tag dispatching, allowing the best function implementation to be selected for a given hardware architecture. This makes it possible to more easily add support for new optimization schemes and hardware targets to the library.
This document provides an introduction to generic programming. It discusses the motivation for generic programming, which includes providing better abstraction and reusability in programming languages. It describes two main models for generic programming - parametric polymorphism in statically typed languages and dynamic typing in dynamically typed languages. The document also discusses implementation issues around generic programming such as efficiency, code generation, and language details.
Roche is recruiting for Senior Technical Programmers and Senior Programmers to join their site based in Welwyn Garden City in Hertfordshire. To find out more and apply please read this brochure.
Case Study on the role of radio based extension and advisory services: Lesson...Andrea Bohn
This document summarizes a case study on the role of radio-based extension services in Malawi. It outlines the history of radio use in agricultural extension in Malawi since 1958. Key lessons learned from projects run by Farm Radio Trust focusing on participatory radio campaigns include: (1) radio can increase farmers' knowledge and improve agricultural practices, (2) radio is most effective when programs are developed with farmer input, and (3) radio can trigger demand for improved face-to-face extension and other support services. The case study highlights the importance of partnerships between farmers, researchers, extension workers, policymakers, and broadcasters in designing effective radio programming.
This document provides information about the Computer Vision Laboratory 2012 course at the Institute of Visual Computing. The course focuses on computer vision on mobile devices and will involve 180 hours of project work per person. Students will work in groups of 1-2 people on topics like 3D reconstruction from silhouettes or stereo images on mobile devices. Key dates are provided for submitting a work plan, mid-term presentation, and final report. Contact information is given for the lecturers and teaching assistant.
Apple has a new programming language? It looks like ruby and I don't have to learn Objective C? Well, not quite...
Based on a true life story, VanSwift present a thrilling story of trial and tribulation. Many restless nights cursing at XCode, staring at the stars and wishing this was ruby -- a gem of a language. We will cover what you need to know to be an effective Swift programmer if you are coming from Ruby, Python or Javascript.
This document provides an overview of OpenCV, an open source computer vision and machine learning software library. It discusses OpenCV's core functionality for representing images as matrices and directly accessing pixel data. It also covers topics like camera calibration, feature point extraction and matching, and estimating camera pose through techniques like structure from motion and planar homography. Hints are provided for Android developers on required permissions and for planar homography estimation using additional constraints rather than OpenCV's general homography function.
Similar to Cvpr2010 open source vision software, intro and training part-iii introduction to gil , boost and generic programming - jin - unknown - 2010
Prince Vishwakarma presented on the basics of C++. He began with an acknowledgement of the guidance he received from his professors. The presentation covered key C++ concepts like comments, variables, data types, control statements, operators, strings, arrays, functions, pointers, and classes. It provided examples and definitions of each concept to explain the fundamentals of the C++ programming language.
This document provides an overview of C++ programming concepts including:
- Procedure-oriented programming focuses on tasks like reading, calculating and printing using functions, while object-oriented programming emphasizes data through objects and classes.
- C++ was developed to include object-oriented features while retaining C's simplicity, with classes, inheritance, and other features enabling abstract data types.
- Key concepts covered include classes, objects, member functions, inline functions, passing objects as parameters, returning objects, arrays of objects, and function overloading. Examples are provided to illustrate each concept.
This document provides an overview of C++ programming concepts including:
- Procedure-oriented programming focuses on tasks like reading, calculating and printing using functions, while object-oriented programming emphasizes data through objects and classes.
- Some problems with C include lack of consideration for data elements and lack of security for networks.
- C++ classes contain variables and functions to characterize objects. Data and functions are tied together and data is hidden.
- Key concepts explained include objects, member functions, constructors, destructors, inheritance and polymorphism.
- Examples demonstrate basic C++ programs, classes, objects, arrays of objects, function overloading and the this pointer.
The document provides an overview of key C++ concepts including:
- C++ is an extension of C that adds object-oriented features like inheritance, polymorphism, encapsulation and abstraction.
- It discusses the differences between C and C++, data types, variables, arrays, strings, functions, and conditionals.
- The document concludes with examples of C++ programs and practice questions.
C++ is a general-purpose programming language used to create computer programs like art applications, music players, and video games. It was derived from C and is largely based on it. C++ is an open, compiled language that is standardized and allows for control, though it is unsafe. A basic C++ program structure includes main(), curly brackets to indicate functions, and statements ending with semicolons. Variables are declared with a data type and identifier before use, and can be assigned values and used in operations.
The document provides an overview of a hands-on workshop on the Python programming language conducted by Abdul Haseeb for a faculty development program. The workshop covers the basics of Python including its history, design philosophy, why it is popular, how to get started with the Python IDE, basic data types, variables, operators, input/output functions, and differences between Python versions 2 and 3. Examples are provided to demonstrate various Python concepts like strings, integers, floats, lists, tuples, dictionaries, functions to convert between types, and string operations. Comparisons between Python and C/C++ highlight differences in syntax, commenting, error handling and code readability.
The document describes an introduction to C++ lab covering:
- Assessment will include projects, reports, quizzes and a final exam.
- The lab outline covers a brief history of C++, object-oriented programming concepts, writing a first program, C++ syntax, function calls, and creating a C++ class.
- The lab will use the Code::Blocks IDE for writing and compiling C++ programs.
With Ateji PX, no need to be specialized in Java threads, parallel programming on multicore, GPU, cloud and grid can be as simple as inserting a || operator in the source code.
The document discusses compiler optimizations performed by Java just-in-time (JIT) compilers and the potential for deoptimization. It provides examples of compiler optimizations like reordering, dead code removal, value propagation, and inlining. It also discusses speculative optimizations the JIT compiler can perform like assuming branch behavior or object types. However, deoptimization may occur later if the compiler's assumptions prove incorrect, such as if a new class is loaded that conflicts with earlier class hierarchy analysis. An example program demonstrates deoptimization occurring when a method is compiled without realizing it calls two different classes.
C++ is an object-oriented programming language that was created as an extension of C programming language. It was created by Bjarne Stroustrup in 1979 at Bell Labs. Some key differences between C and C++ include C++ supporting object-oriented programming concepts like classes, inheritance and polymorphism, while C is a procedural language. Pointers and references are commonly used in C++ to pass arguments to functions by reference rather than by value. Arrays and functions are also important elements of C++ programs.
C++ is an object-oriented programming language that was created as an extension of C by Bjarne Stroustrup in 1979 at Bell Labs. It supports concepts like inheritance, polymorphism, and encapsulation. C++ is a systems programming language that is commonly used to develop applications that require high performance or require low-level access to hardware. Some key features of C++ include object-oriented programming, functions, arrays, pointers, strings, file handling, and inheritance. C++ allows programmers to write code that is very close to the underlying hardware and has performance advantages over other languages.
Functions allow programmers to organize code into reusable blocks to perform related actions. There are three types of functions: built-in functions, modules, and user-defined functions. Built-in functions like int(), float(), str(), and abs() are predefined to perform common tasks. Modules like the math module provide additional mathematical functions like ceil(), floor(), pow(), sqrt(), and trigonometric functions. User-defined functions are created by programmers to customize functionality.
U-SQL Killer Scenarios: Custom Processing, Big Cognition, Image and JSON Proc...Michael Rys
When analyzing big data, you often have to process data at scale that is not rectangular in nature and you would like to scale out your existing programs and cognitive algorithms to analyze your data. To address this need and make it easy for the programmer to add her domain specific code, U-SQL includes a rich extensibility model that allows you to process any kind of data, ranging from CSV files over JSON and XML to image files and add your own custom operators. In this presentation, we will provide some examples on how to use U-SQL to process interesting data formats with custom extractors and functions, including JSON, images, use U-SQL’s cognitive library and finally show how U-SQL allows you to invoke custom code written in Python and R.
Slides for SQL Saturday 635, Vancouver BC presentation, Vancouver BC. Aug 2017.
EMF is a modeling framework and code generation toolkit for building tools and other applications based on a structured data model. It allows defining a model and mapping it to Java code, providing basic functionality such as loading/saving data and change notification. Models can be defined using Java, UML or XML and EMF provides an API to work with the model programmatically. EMF is used in many Eclipse projects and provides a foundation for model-driven development.
This document provides an overview of the C++ Data Structures lab manual. It covers topics like C++ review, implementation of various data structures like stack, queue, linked list, binary tree, graph. It also discusses sorting and searching techniques, file input/output, functions, classes, templates and exercises for students to practice implementing different data structures and algorithms. The instructor's contact details are provided at the beginning.
This document introduces Python and provides an overview of its key features. It discusses Python's history and design philosophy, covers basic syntax like variables, expressions, conditionals and loops. It also summarizes Python's core datatypes like strings, lists, dictionaries and files. The document is intended to give readers a high-level understanding of Python for the purposes of an introductory talk or seminar on the language.
This document provides an overview of an intermediate computer programming course at the University of Gondar in Ethiopia. The course code is CoEng2111 and it is taught by instructor Wondimu B. Topics that will be covered in the course include C++ basics, arrays, strings, functions, and recursion. The course materials are presented over several pages that define concepts, provide code examples, and explain key ideas like variables, data types, operators, and array implementation in C++.
Implementation details and performance traits of generics in .NET, Java and C++. Presentation for the Jerusalem .NET/C++ User Group by Sasha Goldshtein.
The document discusses generics in Java. It explains that generics provide compile-time type safety and eliminate the risk of ClassCastExceptions. It provides examples to demonstrate how to define generic classes with single and multiple type parameters, bounded type parameters, and wildcards. The key benefits of generics are that they allow for type-safe operations on objects of unknown types.
The document provides an overview of the C++ programming language. It discusses the history and development of C++, with key points being that C++ was created by Bjarne Stroustrup in 1983 as an extension of C to support object-oriented programming. It then covers some of the main differences between C and C++, uses of C++, advantages and disadvantages, standard libraries, basic C++ structures like data types, variables, operators, functions, arrays, and pointers.
Similar to Cvpr2010 open source vision software, intro and training part-iii introduction to gil , boost and generic programming - jin - unknown - 2010 (20)
Mylyn helps address information overload and context loss when multi-tasking. It integrates tasks into the IDE workflow and uses a degree-of-interest model to monitor user interaction and provide a task-focused UI with features like view filtering, element decoration, automatic folding and content assist ranking. This creates a single view of all tasks that are centrally managed within the IDE.
This document summarizes a presentation on natural image statistics given by Siwei Lyu at the 2009 CIFAR NCAP Summer School. The presentation covered several key topics:
1) It discussed the motivation for studying natural image statistics, which is to understand representations in the visual system and develop computer vision applications like denoising.
2) It reviewed common statistical properties found in natural images like 1/f power spectra and non-Gaussian distributions.
3) Maximum entropy and Bayesian models were presented as approaches to model these statistics, with Gaussian and independent component analysis discussed as specific examples.
4) Efficient coding principles from information theory were introduced as a framework for understanding neural representations that aim to decorrelate and
Camera calibration involves determining the internal camera parameters like focal length, image center, distortion, and scaling factors that affect the imaging process. These parameters are important for applications like 3D reconstruction and robotics that require understanding the relationship between 3D world points and their 2D projections in an image. The document describes estimating internal parameters by taking images of a calibration target with known geometry and solving the equations that relate the 3D target points to their 2D image locations. Homogeneous coordinates and projection matrices are used to represent the calibration transformations mathematically.
Brunelli 2008: template matching techniques in computer visionzukun
The document discusses template matching techniques in computer vision. It begins with an overview that defines template matching and discusses some common computer vision tasks it can be used for, like object detection. It then covers topics like detection as hypothesis testing, training and testing techniques, and provides a bibliography.
The HARVEST Programme evaluates feature detectors and descriptors through indirect and direct benchmarks. Indirect benchmarks measure repeatability and matching scores on the affine covariant testbed to evaluate how features persist across transformations. Direct benchmarks evaluate features on image retrieval tasks using the Oxford 5k dataset to measure real-world performance. VLBenchmarks provides software for easily running these benchmarks and reproducing published results. It allows comparing features and selecting the best for a given application.
This document summarizes VLFeat, an open source computer vision library. It provides concise summaries of VLFeat's features, including SIFT, MSER, and other covariant detectors. It also compares VLFeat's performance to other libraries like OpenCV. The document highlights how VLFeat achieves state-of-the-art results in tasks like feature detection, description and matching while maintaining a simple MATLAB interface.
This document summarizes and compares local image descriptors. It begins with an introduction to modern descriptors like SIFT, SURF and DAISY. It then discusses efficient descriptors such as binary descriptors like BRIEF, ORB and BRISK which use comparisons of intensity value pairs. The document concludes with an overview section.
This document discusses various feature detectors used in computer vision. It begins by describing classic detectors such as the Harris detector and Hessian detector that search scale space to find distinguished locations. It then discusses detecting features at multiple scales using the Laplacian of Gaussian and determinant of Hessian. The document also covers affine covariant detectors such as maximally stable extremal regions and affine shape adaptation. It discusses approaches for speeding up detection using approximations like those in SURF and learning to emulate detectors. Finally, it outlines new developments in feature detection.
The document discusses modern feature detection techniques. It provides an introduction and agenda for a talk on advances in feature detectors and descriptors, including improvements since a 2005 paper. It also discusses software suites and benchmarks for feature detection. Several application domains are described, such as wide baseline matching, panoramic image stitching, 3D reconstruction, image search, location recognition, and object tracking.
System 1 and System 2 were basic early systems for image matching that used color and texture matching. Descriptor-based approaches like SIFT provided more invariance but not perfect invariance. Patch descriptors like SIFT were improved by making them more invariant to lighting changes like color and illumination shifts. The best performance came from combining descriptors with color invariance. Representing images as histograms of visual word occurrences captured patterns in local image patches and allowed measuring similarity between images. Large vocabularies of visual words provided more discriminative power but were costly to compute and store.
This document summarizes a research paper on internet video search. It discusses several key challenges: [1] the large variation in how the same thing can appear in images/videos due to lighting, viewpoint etc., [2] defining what defines different objects, and [3] the huge number of different things that exist. It also notes gaps in narrative understanding, shared concepts between humans and machines, and addressing diverse query contexts. The document advocates developing powerful yet simple visual features that capture uniqueness with invariance to irrelevant changes.
The document discusses computer vision techniques for object detection and localization. It describes methods like selective search that group image regions hierarchically to propose object locations. Large datasets like ImageNet and LabelMe that provide training examples are also discussed. Performance on object detection benchmarks like PASCAL VOC is shown to improve significantly over time. Evaluation standards for concept detection like those used in TRECVID are presented. The document concludes that results are impressively improving each year but that the number of detectable concepts remains limited. It also discusses making feature extraction more efficient using techniques like SURF that take advantage of integral images.
This document provides an outline and overview of Yoshua Bengio's 2012 tutorial on representation learning. The key points covered include:
1) The tutorial will cover motivations for representation learning, algorithms such as probabilistic models and auto-encoders, and analysis and practical issues.
2) Representation learning aims to automatically learn good representations of data rather than relying on handcrafted features. Learning representations can help address challenges like exploiting unlabeled data and the curse of dimensionality.
3) Deep learning algorithms attempt to learn multiple levels of increasingly complex representations, with the goal of developing more abstract, disentangled representations that generalize beyond local patterns in the data.
Advances in discrete energy minimisation for computer visionzukun
This document discusses string algorithms and data structures. It introduces the Knuth-Morris-Pratt algorithm for finding patterns in strings in O(n+m) time where n is the length of the text and m is the length of the pattern. It also discusses common string data structures like tries, suffix trees, and suffix arrays. Suffix trees and suffix arrays store all suffixes of a string and support efficient pattern matching and other string operations in linear time or O(m+logn) time where m is the pattern length and n is the text length.
This document provides a tutorial on how to use Gephi software to analyze and visualize network graphs. It outlines the basic steps of importing a sample graph file, applying layout algorithms to organize the nodes, calculating metrics, detecting communities, filtering the graph, and exporting/saving the results. The tutorial demonstrates features of Gephi including node ranking, partitioning, and interactive visualization of the graph.
EM algorithm and its application in probabilistic latent semantic analysiszukun
The document discusses the EM algorithm and its application in Probabilistic Latent Semantic Analysis (pLSA). It begins by introducing the parameter estimation problem and comparing frequentist and Bayesian approaches. It then describes the EM algorithm, which iteratively computes lower bounds to the log-likelihood function. Finally, it applies the EM algorithm to pLSA by modeling documents and words as arising from a mixture of latent topics.
This document describes an efficient framework for part-based object recognition using pictorial structures. The framework represents objects as graphs of parts with spatial relationships. It finds the optimal configuration of parts through global minimization using distance transforms, allowing fast computation despite modeling complex spatial relationships between parts. This enables soft detection to handle partial occlusion without early decisions about part locations.
Iccv2011 learning spatiotemporal graphs of human activities zukun
The document presents a new approach for learning spatiotemporal graphs of human activities from weakly supervised video data. The approach uses 2D+t tubes as mid-level features to represent activities as segmentation graphs, with nodes describing tubes and edges describing various relations. A probabilistic graph mixture model is used to model activities, and learning estimates the model parameters and permutation matrices using a structural EM algorithm. The learned models allow recognizing and segmenting activities in new videos through robust least squares inference. Evaluation on benchmark datasets demonstrates the ability to learn characteristic parts of activities and recognize them under weak supervision.
Icml2012 learning hierarchies of invariant featureszukun
This document discusses learning hierarchies of invariant features using convolutional neural networks. It describes how convolutional networks build hierarchical representations through multiple stacked layers that each apply normalization, filtering, non-linearity, and pooling operations to learn increasingly complex features. This architecture is inspired by the hierarchical organization of the mammalian visual cortex. The document outlines applications of convolutional networks in areas like computer vision, speech recognition, and natural language processing where they have achieved state-of-the-art performance by learning hierarchical representations from data.
ECCV2010: Modeling Temporal Structure of Decomposable Motion Segments for Act...zukun
The document describes a model for recognizing complex human activities by decomposing them into simpler motion segments. The model represents an activity as an ordered sequence of motion segments, each with an anchor location in time and possible temporal uncertainty. Recognition works by matching motion segments in a query video to those in a learned activity model. The model is learned from weakly labeled videos using a max-margin framework that optimizes for appearance and temporal arrangement of segments. Experiments show the approach can recognize both simple and complex activities.
ECCV2010: Modeling Temporal Structure of Decomposable Motion Segments for Act...
Cvpr2010 open source vision software, intro and training part-iii introduction to gil , boost and generic programming - jin - unknown - 2010
1. Introduction to GIL,
Boost and Generic
Programming
Hailin Jin
Advanced Technology Labs
Adobe Systems Incorporated
http://www.adobe.com/technology/people/sanjose/jin.html
1
2010 Adobe Systems Incorporated. All Rights Reserved.
2. Outline
GIL
Boost
Generic programming
STL
Summary
2010 Adobe Systems Incorporated. All Rights Reserved.
3. What is GIL?
Generic Image Library
C++ image library
Open-source
http://opensource.adobe.com/gil
Well documented
The core library only contains header files; No need to link anything
Thread-safe
Compatible with most C++ compilers (Visual Studio, gcc, etc)
2010 Adobe Systems Incorporated. All Rights Reserved.
4. GIL overview
Image containers
1-D iterators for traversing rows and columns
2-D iterators (locator) for arbitrary 2D traversal
Image views
Image processing algorithms
Extensions
io extension for reading and writing images of popular formats (PNG, JPEG, TIFF, …)
rgb8_image_t im;
read_png_image("test.png", im);
numeric extension for convolutions against fixed and variable-size kernels
kernel_1d_fixed<float, 7> kernel;
gray8_image_t im_in, im_out;
convolve_rows_fixed<gray32f_pixel_t>(const_view(im_in),
kernel,
view(im_out));
2010 Adobe Systems Incorporated. All Rights Reserved.
5. People
Lubomir Bourdev Hailin Jin Christian Henning
Adobe Adobe Independent
2010 Adobe Systems Incorporated. All Rights Reserved.
6. GIL history
Started as an Adobe internal project in 2005
Version 1.0 in June 2006
Accepted into Boost in November 2006
Version 2.0 in March 2007
Constantly updated and patched with Boost releases
2010 Adobe Systems Incorporated. All Rights Reserved.
7. License
Initially: MIT license
Currently: Boost Software License (similar to the MIT license)
Free to use, reproduce, display, distribute, execute, and transmit, including
derivative works
We retain the copyright
2010 Adobe Systems Incorporated. All Rights Reserved.
8. Image processing libraries
Your own image libraries
OpenCV
CImg
Vigra
GIL works third-party algorithms, libraries, etc
2010 Adobe Systems Incorporated. All Rights Reserved.
9. http://www.boost.org
High-quality C++ libraries
Open-source
Started in 1998
Latest version: 1.43.0 on May 6, 2010
Strict review system
10 of the Boost libraries are included in the C++ Standard Library TR
“It is usually a really dumb idea to go and reinvent a wheel that Boost already
offers. ”
— Bjarne Stroustrup, inventor of C++
2010 Adobe Systems Incorporated. All Rights Reserved.
10. Boost usage
http://www.boost.org/users/uses.html
Adobe
Google
SAP
McAFee
Real Networks
…
2010 Adobe Systems Incorporated. All Rights Reserved.
11. Boost components for computer vision
Image (GIL)
Graph (BGL)
Thread
Filesystem
uBLAS
Program options
Math related libraries
2010 Adobe Systems Incorporated. All Rights Reserved.
12. Boost Graph Library
Shortest paths
Dijkstra's shortest paths
Bellman-Ford shortest paths
Johnson's all-Pairs shortest paths
Minimum spanning trees
Kruskal's minimum spanning tree
Prim's minimum spanning tree
Connected components
Connected components
Strongly connected components
Maximum flow
Edmonds Karp
Push-relabel
Kolmogorov
Topological sort, sparse matrix ordering, and many more
2010 Adobe Systems Incorporated. All Rights Reserved.
13. Outline
GIL
Boost
Generic programming
STL
Summary
2010 Adobe Systems Incorporated. All Rights Reserved.
14. GIL design principles
Followed the paradigm of generic programming
Clean separation between algorithms and containers
Work with third-party algorithms, data structures, and libraries
Toward optimal performance
2010 Adobe Systems Incorporated. All Rights Reserved.
15. Generic programming
Programming paradigm for developing efficient, reusable software code
Pioneered by Alexander Stepanov and David Musser
First successful example is the Standard Template Library (STL) which is now
part of the C++ standard
Programming based on parameterization
Parameterize a data structure with different types (example: a std::vector<> with its
element types)
Parameterize an algorithm with different types and algorithms (example: std::sort()
function for int* and float* and with a comparison function)
Generalize an algorithm or data structure to its most general and useful form
Better code
Fewer bugs
2010 Adobe Systems Incorporated. All Rights Reserved.
16. Polymorphism
Allows values of different data types to be handled using a uniform interface
Object-oriented programming (OOP)
Ad-hoc polymorphism
Class hierarchies: specified inheritance
Function/method overloading: different and potentially heterogeneous implementations
depending on a limited range of individually specified types and combinations
Dynamic dispatch
Generic programming
Parametric polymorphism (data structure and algorithms)
Code is written without mention of any specific type and thus can be used transparently
with any number of new types
Static (compile-time) dispatch
2010 Adobe Systems Incorporated. All Rights Reserved.
17. Generic programming: a case study
Compute the sum of a set of data
17
2010 Adobe Systems Incorporated. All Rights Reserved.
18. Object-oriented style
class int_vector {
private:
int* array;
int n;
...
public:
...
int accumulate() {
int result = 0;
for (int i = 0; i < n; ++i)
result = result + array[i];
return result;
}
...
};
2010 Adobe Systems Incorporated. All Rights Reserved.
19. Separate the algorithm from the container
int accumulate(int* array, int n) {
int result = 0;
for (int i = 0; i < n; ++i)
result = result + array[i];
return result;
}
class int_vector {
private:
int* array;
int n;
...
public:
...
int size() {return n;}
int* begin() {return array;}
...
};
int_vector a_vec;
int result = accumulate(a_vec.begin(), a_vec.size());
2010 Adobe Systems Incorporated. All Rights Reserved.
20. Same algorithm with different types
int accumulate(int* array, int n) {
int result = 0;
for (int i = 0; i < n; ++i)
result = result + array[i];
return result;
}
float accumulate(float* array, int n) {
float result = 0;
for (int i = 0; i < n; ++i)
result = result + array[i];
return result;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
21. C++ templates
template <typename T>
T accumulate(T* array, int n) {
T result = 0;
for (int i = 0; i < n; ++i)
result = result + array[i];
return result;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
22. String concatenation
template <typename T>
T accumulate(T* array, int n) {
T result = 0;
for (int i = 0; i < n; ++i)
result = result + array[i];
return result;
}
std::string concatenate(std::string* array, int n) {
std::string result = ””;
for (int i = 0; i < n; ++i)
result = result + array[i];
return result;
}
template <typename T>
T accumulate(T* array, int n) {
T result = T(); T result;
for (int i = 0; i < n; ++i)
result = result + array[i];
return result;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
23. Generalize the interface and type requirements
template <typename T>
T accumulate(T* array, int n, T init) {
for (int i = 0; i < n; ++i)
init = init + array[i];
return init;
}
Type requirements on T
• T must have a copy constructor T(const T&)
• T must have an assignment operator=()
• T must have a binary operator+(,)
2010 Adobe Systems Incorporated. All Rights Reserved.
24. Linked list
template <typename T>
struct list_node {
list_node<T>* next;
T value;
};
template <typename T>
T accumulate(list_node<T>* first,
T init) {
while (first!=0) {
init = init + first->value;
first = first->next;
}
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
25. Unifying linked lists and arrays
template <typename T> template <typename T>
struct list_node { T accumulate(T* array, int n, T init) {
list_node<T>* next; for (int i = 0; i < n; ++i)
T value; init = init + array[i];
}; return init;
}
template <typename T>
T accumulate(list_node<T>* first,
T init) {
while (first!=0) {
init = init + first->value;
first = first->next;
}
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
26. Unifying linked lists and arrays
template <typename T> template <typename T>
struct list_node { T accumulate(T* first, int n, T init) {
list_node<T>* next; T* last = first + n;
T value; for (;first!=last;++first) {
}; init = init + *first;
}
template <typename T> return init;
T accumulate(list_node<T>* first, }
T init) {
while (first!=0) {
init = init + first->value;
first = first->next;
}
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
27. Unifying linked lists and arrays
template <typename T> template <typename T>
struct list_node { T accumulate(T* first, int n, T init) {
list_node<T>* next; T* last = first + n;
T value; while (first!=last) {
}; init = init + *first;
++first;
template <typename T> }
T accumulate(list_node<T>* first, return init;
T init) { }
while (first!=0) {
init = init + first->value;
first = first->next;
}
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
28. Unifying linked lists and arrays
template <typename T> template <typename T>
struct list_node { T accumulate(T* first, T* last, T init) {
list_node<T>* next; while (first!=last) {
T value; init = init + *first;
}; ++first;
}
template <typename T> return init;
T accumulate(list_node<T>* first, }
T init) {
while (first!=0) {
init = init + first->value;
first = first->next;
}
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
29. Unifying linked lists and arrays
template <typename T> template <typename T>
struct list_node { T accumulate(T* first, T* last, T init) {
list_node<T>* next; while (first!=last) {
T value; init = init + *first;
}; ++first;
}
template <typename T> return init;
struct list_iterator { }
list_node<T>* node;
};
template <typename T>
T accumulate(list_iterator<T> first,
T init) {
while (first.node!=0) {
init = init + first.node->value;
first.node = first.node->next;
}
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
30. Unifying linked lists and arrays
template <typename T> template <typename T>
struct list_node { T accumulate(T* first, T* last, T init) {
list_node<T>* next; while (first!=last) {
T value; init = init + *first;
}; ++first;
}
template <typename T> return init;
struct list_iterator { }
list_node<T>* node;
};
template <typename T>
T accumulate(list_iterator<T> first,
list_iterator<T> last,
T init) {
while (first!=last) {
init = init + first.node->value;
first.node = first.node->next;
}
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
31. Unifying linked lists and arrays
template <typename T> template <typename T>
struct list_node { T accumulate(T* first, T* last, T init) {
list_node<T>* next; while (first!=last) {
T value; init = init + *first;
}; ++first;
}
template <typename T> return init;
struct list_iterator { }
list_node<T>* node; template <typename T>
}; bool operator!=(list_iterator<T> x,
list_iterator<T> y) {
template <typename T> return x.node!=y.node;
T accumulate(list_iterator<T> first, }
list_iterator<T> last,
T init) {
while (first!=last) {
init = init + first.node->value;
first.node = first.node->next;
}
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
32. Unifying linked lists and arrays
template <typename T> template <typename T>
struct list_node { T accumulate(T* first, T* last, T init) {
list_node<T>* next; while (first!=last) {
T value; init = init + *first;
}; ++first;
}
template <typename T> return init;
struct list_iterator { }
list_node<T>* node; template <typename T>
}; bool operator!=(list_iterator<T> x,
list_iterator<T> y) {
template <typename T> return x.node!=y.node;
T accumulate(list_iterator<T> first, }
list_iterator<T> last,
T init) { template <typename T>
while (first!=last) { T operator*(list_iterator<T> x) {
init = init + first.node->value; return x.node->value;
first.node = first.node->next; }
}
return init; template <typename T>
} list_iterator<T>&
operator++(list_iterator<T>& x) {
x.node = x.node->next;
return x;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
33. Unifying linked lists and arrays
template <typename T> template <typename T>
struct list_node { T accumulate(T* first, T* last, T init) {
list_node<T>* next; while (first!=last) {
T value; init = init + *first;
}; ++first;
}
template <typename T> return init;
struct list_iterator { }
list_node<T>* node; template <typename T>
}; bool operator!=(list_iterator<T> x,
list_iterator<T> y) {
template <typename T> return x.node!=y.node;
T accumulate(list_iterator<T> first, }
list_iterator<T> last,
T init) { template <typename T>
while (first!=last) { T operator*(list_iterator<T> x) {
init = init + *first; return x.node->value;
++first; }
}
return init; template <typename T>
} list_iterator<T>&
operator++(list_iterator<T>& x) {
x.node = x.node->next;
return x;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
34. Unified version
template <typename I,
typename T>
T accumulate(I first, I last, T init) {
while (first!=last) {
init = init + *first;
++first;
}
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
35. Type requirements
template <typename I,
typename T>
T accumulate(I first, I last, T init) {
while (first!=last) {
init = init + *first;
++first;
}
return init;
}
• I must have a copy constructor I(const I&)
• I must have a binary operator!=(,)
• I must have an operator*()
• I must have an operator++()
• T must have a copy constructor T(const T&)
• T must have an assignment operator=()
• T must have a binary operator+(,)
2010 Adobe Systems Incorporated. All Rights Reserved.
36. Further generalization with function objects
template <typename I,
typename T>
T accumulate(I first, I last, T init) {
while (first!=last) {
init = init + *first;
++first;
}
return init;
}
template <typename I,
typename T,
typename B>
T accumulate(I first, I last, T init, B op) {
while (first!=last) {
init = op(init, *first);
++first;
}
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
37. Type requirements
template <typename I,
typename T,
typename B>
T accumulate(I first, I last, T init, B op) {
while (first!=last) {
init = op(init, *first);
++first;
} • I must have a copy constructor I(const I&)
return init;
} • I must have a binary operator!=(,)
• I must have an operator*()
• I must have an operator++()
• T must have a copy constructor T(const T&)
• T must have an assignment operator=()
• B must have a copy constructor B(const B&)
• B must have a binary application operator()(,)
2010 Adobe Systems Incorporated. All Rights Reserved.
38. Function object example
template <typename T>
struct moment_2 {
T m1, m2;
moment_2(T m1_, T m2_) : m1(m1_), m2(m2_) {}
};
template <typename T>
moment_2<T>
compute_moment_2(T* first, T* last, moment_2<T> init) {
while (first!=last) {
init.m1 += *first;
init.m2 += *first**first;
++first;
}
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
39. Function object example
template <typename T>
struct compute_moment_2_s {
moment_2<T> operator()(moment_2<T> m, T x) const {
m.m1 += x; m.m2 += x*x;
return m;
}
};
template <typename T>
moment_2<T>
compute_moment_2(T* first, T* last, moment_2<T> init) {
return accumulate(first, last, init,
compute_moment_2_s<T>());
}
template <typename T>
struct max_s {
T operator()(T x, T y) const {return x>y?x:y;}
};
template <typename T>
T range_max(T* first, T* last, T init) {
return accumulate(first, last, init, max_s());
}
2010 Adobe Systems Incorporated. All Rights Reserved.
40. Lessons learned: #1
Separate between an algorithms and a data structure
int accumulate(int* array, int n) {
int result = 0;
for (int i = 0; i < n; ++i)
result = result + array[i];
class int_vector {
return result;
private:
}
int* array;
int n;
class int_vector {
...
private:
public:
int* array;
...
int n;
int accumulate() {
...
int result = 0;
public:
for (int i = 0; i < n; ++i)
...
result = result + array[i];
int size() {return n;}
int* begin() {return array;}
return result;
...
}
};
...
};
int_vector a_vec;
int result = accumulate(a_vec.begin()
2010 Adobe Systems Incorporated. All Rights Reserved.
41. Lessons learned: #2
Generalize an algorithm to a general form
int accumulate(int* array, int n) {
int result = 0;
for (int i = 0; i < n; ++i)
result = result + array[i];
template <typename T>
return result; T accumulate(T* array, int n) {
} T result = T();
for (int i = 0; i < n; ++i)
float accumulate(float* array, int n) { result = result + array[i];
float result = 0; return result;
for (int i = 0; i < n; ++i) }
result = result + array[i];
return result;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
42. Lessons learned: #3
Generalize the interface of an algorithm
template <typename T>
T accumulate(T* array, int n) {
T result = T();
for (int i = 0; i < n; ++i)
result = result + array[i];
return result;
}
template <typename T>
T accumulate(T* array, int n, T init) {
for (int i = 0; i < n; ++i)
init = init + array[i];
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
43. Lessons learned: #4
Generalize through iterators
template <typename T>
T accumulate(list_iterator<T> first,
T init) {
while (first!=0) {
init = init + first.node->value;
template <typename I,
first.node = first.node->next;
typename T>
}
T accumulate(I first, I last, T init) {
return init;
while (first!=last) {
}
init = init + *first;
++first;
template <typename T> }
T accumulate(T* array, int n, T init) { return init;
for (int i = 0; i < n; ++i) }
init = init + array[i];
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
44. Lessons learned: #5
Generalize through function objects
template <typename I,
typename T>
T accumulate(I first, I last, T init) {
while (first!=last) {
init = init + *first;
++first;
}
return init;
}
template <typename I,
typename T,
typename B>
T accumulate(I first, I last, T init, B op) {
while (first!=last) {
init = op(init, *first);
++first;
}
return init;
}
2010 Adobe Systems Incorporated. All Rights Reserved.
45. Concepts/Models
Type requirements
Concept: description of requirements on one or more types stated in terms
of the existence and properties of procedures, type attributes, and type
functions defined on the types
Model: satisfies all the requirements of a concept
Example Concept
• T must have a copy constructor T(const T&)
template <typename T>
T accumulate(T* array, int n, T init) { • T must have an assignment operator=()
for (int i = 0; i < n; ++i) • T must have a binary operator+(,)
init = init + array[i];
return init; Model
}
• int, float, std::string, …
Concepts are not designed or invented. Instead they are discovered
2010 Adobe Systems Incorporated. All Rights Reserved.
46. Iterators
An interface between sequential data structures and algorithms
Separates containers from algorithms
Models: raw points and linked list iterators
template <typename I,
typename T>
T accumulate(I first, I last, T init) {
while (first!=last) {
init = init + *first;
++first;
}
return init;
}
• I must have a copy constructor I(const I&)
• I must have a binary operator!=(,)
• I must have operator*()
• I must have operator++()
2010 Adobe Systems Incorporated. All Rights Reserved.
47. More models of iterators
template <typename T> template <typename T>
class step_pointer { class indirect_pointer {
privte: privte:
T* x; T* x;
int step; int* y;
public: public:
... ...
T operator*() {return *x;} T operator*() {return x[*y];}
step_pointer& operator++() { step_pointer& operator++() {
x += step; return *this; ++y; return *this;
} }
... ...
}; };
template <typename T>
class value_iterator {
privte:
T x;
public:
...
T operator*() {return x;}
step_pointer& operator++() {
++x; return *this;
}
...
};
47
2010 Adobe Systems Incorporated. All Rights Reserved.
48. Compilers are working hard for us
C++ compilers resolves all templates at compile time
No dynamic (run-time) dispatch
Function objects can be inlined; No function calls overhead
2010 Adobe Systems Incorporated. All Rights Reserved.
49. STL
Standard Template Library
http://www.sgi.com/tech/stl
First widespread application of generic programming
Part of the C++ standard
Containers Iterators Algorithms
2010 Adobe Systems Incorporated. All Rights Reserved.