Tutorial by Examples: c

Lets build a kernel to generate a grayscale image. We will use image data which is defined using uints for each component and with order RGBA. __constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | C...
Each fundamental opencl type has a vector version. You can use the vector type by appending the number of desired components after the type. Supported number of components are 2,3,4,8 and 16. OpenCL 1.0 does not offer three components. You can initialize any vector using two ways: Provide a sing...
Lets look at a gamma correction kernel __constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; __kernel void Gamma(__read_only image2d_t input, __write_only image2d_t output, __c...
Recent versions of Delphi ships with the TStopwatch record which is for time interval measurement. Example usage: uses System.Diagnostics; var StopWatch: TStopwatch; ElapsedMillseconds: Int64; begin StopWatch := TStopwatch.StartNew; // do something that requires measurement El...
trait Show[T] { def show(t: T): String } object Show extends ProductTypeClassCompanion[Show] { def apply[T](implicit T: Show[T]) = T def from[T](f: T => String): Show[T] = new Show[T] { def show(t: T): String = f(t) } implicit val string = from[String](_.reverse) ...
DRF offers the chance to further customize the behavior of the generic views/viewsets by allowing the creation of custom mixins. How to: To define a custom mixin we just need to create a class inheriting from object. Let's assume that we want to define two separate views for a model named MyM...
To make your APK file as small as possible, you should enable shrinking to remove unused code and resources in your release build. This page describes how to do that and how to specify what code and resources to keep or discard during the build. Code shrinking is available with ProGuard, which dete...
An inner class which is visible to any outside class can be created from this class as well. The inner class depends on the outside class and requires a reference to an instance of it. To create an instance of the inner class, the new operator only needs to be called on an instance of the outer cla...
1. Enable Flat Categories and Products One of the top reasons of Magento speed issues with database read speed. To fasten the read speed of the database you should enable Flat Catalog. This will minify the number of database joins done when showing products and due to that the MySQL query complexit...
To discovery all the available print services, we can use the PrintServiceLookup class. Let's see how: import javax.print.PrintService; import javax.print.PrintServiceLookup; public class DiscoveringAvailablePrintServices { public static void main(String[] args) { discoverPrintS...
To discovery the default print service, we can use the PrintServiceLookup class. Let's see how:: import javax.print.PrintService; import javax.print.PrintServiceLookup; public class DiscoveringDefaultPrintService { public static void main(String[] args) { discoverDefaultPrintSer...
A print job is a request of printing something in a specific print service. It consists, basically, by: the data that will be printed (see Building the Doc that will be printed) a set of attributes After picking-up the right print service instance, we can request the creation of a print job...
Doc is an interface and the Java Print Service API provide a simple implementation called SimpleDoc. Every Doc instance is basically made of two aspects: the print data content itself (an E-mail, an image, a document etc) the print data format, called DocFlavor (MIME type + Representation class...

C#

internal sealed class TextToTextCryptography : IDisposable { // This type is not thread-safe because it repeatedly mutates the IV property. private SymmetricAlgorithm _cipher; // The input to Encrypt and the output from Decrypt need to use the same Encoding // so text -> by...
The problem statement is like if we are given two string str1 and str2 then how many minimum number of operations can be performed on the str1 that it gets converted to str2. Implementation in Java public class EditDistance { public static void main(String[] args) { // TODO Auto-generated ...
If we are given with the two strings we have to find the longest common sub-sequence present in both of them. Example LCS for input Sequences “ABCDGH” and “AEDFHR” is “ADH” of length 3. LCS for input Sequences “AGGTAB” and “GXTXAYB” is “GTAB” of length 4. Implementation in Java public class LC...
Bottom up approach for printing the nth Fibonacci number using Dynamic Programming. Recursive Tree fib(5) / \ fib(4) fib(3) / \ / \ fib(3) fib(2...
Given 2 string str1 and str2 we have to find the length of the longest common substring between them. Examples Input : X = "abcdxyz", y = "xyzabcd" Output : 4 The longest common substring is "abcd" and is of length 4. Input : X = "zxabcdezy", y = "y...
For example, we can create a ring-shaped cursor fixed to the center of the screen. To fix the cursor to the screen so the cursor is always present no matter where we look, we place it as a child of the active camera entity. We pull it in front of the camera by placing it on the negative Z axis. When...

Page 789 of 826