## list – C: Vectorization of vectors

Hello so I have the instructions:

``````// Create a new vector.
// The initial capacity is 1.
// The initial size is 0.
// there is not enough memory, the
print program
// "Not enough memory!" and go out with the
error code 1.
// (uses the errx () function of the standard
library.)
// Warning, you must allocate two
memory spaces.
// - The memory space that contains the
variable & # 39; vector struct & # 39;
// - The memory space containing the data.
``````

I did it:

``````vector struct * vector_new ();
{
capacity = 1;
size = 0;
if (// not enough memory)
{
errx (1, "Not enough memory!")
}
malloc (// vector allocation & # 39;);
malloc (// data allocation);
}
``````

I wrote pseudo-code if anyone could help me write it in C language, thank you

## Minimum number of support vectors?

I'm learning SVM and it's written everywhere that the minimum number of support vectors is 2? But I could not find any formal proof of that. Why can not there be less than 2 support vectors? Can any one give an intuitive way to understand this and a formal explanation?

## details of implementation – Listable built-in functions – Why are they so fast on digital vectors?

Consider the following small example, where I calculate `Exp` on a big vector using the listability many of which have built-in mathematical functions:

``````data = RandomReal[1, 10^7];
RepeatedTiming[Exp[data];](* {0.0115, Null} *)
``````

The list is packed, but even when decompressing, the performance is good (it is probably repacked)

``````data2 = Developer`FromPackedArray[data];
RepeatedTiming[Exp[data2];](* {0.0705, Null} *)
``````

As soon as we add a non-numeric element or a number of a different type, the performance drops dramatically

``````data3 = Append[data, 1];
RepeatedTiming[Exp[data3];](* {3.11, Null} *)
``````

Now, I wonder if I have forgotten anything in the documentation or where there is a place where it is explained how exactly these calls are made so performantly. Specifically, I want to know

1. Does such a call use vectorization, is it parallelized, or does it simply call a fast but sequential code?
2. How does this compare to `Compile` with `Parallelization` alight?
Posted on

## c ++ – Class for storing and manipulating Cartesian coordinates and vectors

I created a C ++ class to manipulate 3D vectors in Cartesian coordinates.

However, the performance of my class is much slower (about 2.5x) than the use of something like: `double p ` and then running `for` loops for additions, subtractions, etc.

My specific concerns are:

• Is there anything fundamentally wrong that I do that causes this slowdown?
• Is there a way to achieve what I try, but without slowing down as much?
• Is it just a fundamental limitation of classes and operator overload that I have to live in return for convenience?

Here is the class:

``````#ifndef COORD_H
#define COORD_H

#understand
#understand
#understand
#understand
#understand
#understand
#understand
#understand
#include "math.h"

// Useful reference: http://courses.cms.caltech.edu/cs11/material/cpp/donnie/cpp-ops.html

/ *!  brief Class to store and manipulate points or position vectors in 3D, in Cartesian coordinates. * /
vect3D class
{
public:

double x = 0.0, y = 0.0, z = 0.0;
double tol = 1.0e-15;

// builders
vect3D () {};
vect3D (std :: initializer_list RHS) {x = * RHS.begin (); y = * (RHS.begin () + 1); z = * (RHS.begin () + 2); };
vect3D (std :: vector & RHS) {x = RHS; y = RHS; z = RHS; };
vect3D (double * RHS) {x = RHS; y = RHS; z = RHS; };

// assignment
vect3D & operator = (const vect3D & RHS) {x = RHS.x; y = RHS.y; z = RHS.z; return * this; };

vect3D & operator + = (const vect3D & RHS) {x + = RHS.x; y + = RHS.y; z + = RHS.z; return * this; };
vect3D & operator - = (const vect3D & RHS) {x - = RHS.x; y - = RHS.y; z - = RHS.z; return * this; };

vect3D & operator + = (double const and RHS) {x + = RHS; y + = RHS; z + = RHS; return * this; };
vect3D & operator - = (double const and RHS) {x - = RHS; y - = RHS; z - = RHS; return * this; };

operator vect3D + (const vect3D & RHS) {returns vect3D (* this) + = RHS; };
operator vect3D - (const vect3D & RHS) {returns vect3D (* this) - = RHS; };

Operator vect3D + (double const & RHS) {returns vect3D (* this) + = RHS; };
Operator vect3D - (double const & RHS) {returns vect3D (* this) - = RHS; };

// Product and scalar division
vect3D & operator * = (double const and RHS) {x * = RHS; y * = RHS; z * = RHS; return * this; };
vect3D & operator / = (double const and RHS) {x / = RHS; y / = RHS; z / = RHS; return * this; };

Operator vect3D * (double const & RHS) {returns vect3D (* this) * = RHS; };
Operator vect3D / (double const & RHS) {return vect3D (* this) / = RHS; };

friend vect3D operator * (double c, vect3D & vec) {return vec * c; };
friend operator vect3D / (double c, vect3D & vec) {return vec / c; };

// Comparisons
operator bool == (const vect3D & RHS) {return ((x - RHS.x <x * tol) && (y - RHS.y <y * tol) && (z - RHS.z < z*tol)); };
bool operator!=(const vect3D &RHS) { return !(*this == RHS); };

bool operator>= (const vect3D & RHS) {return ((x> = RHS.x) && (y> = RHS.y) && (z> = RHS.z)); };
Boolean operator <= (const vect3D & RHS) {return ((x <= RHS.x) && (y <= RHS.y) && (z <= RHS.z)); };
bool operator>(const vect3D & RHS) {return! (* this <= RHS); };
bool operator<(const vect3D &RHS) { return !(*this >= RHS); };

// Euclidean norm
double norm2 () {return std :: sqrt (std :: pow (x, 2) + std :: pow (y, 2) + std :: pow (z, 2)); };
friend double standard2 (const and vect3D) {return std :: sqrt (std :: pow (a.x, 2) + std :: pow (a.y, 2) + std :: pow (a.z, 2)); };

// Scalar product
double point friend (vect3D const & a, vect3D const & b) {return a.x * b.x + a.y * b.y + a.z * b.z; };

// Cross product
friend vect3D traverse (vect3D const & a, vect3D const & b) {return {(a.y * b.z-a.z * b.y), (a.z * b.x-a.x * b.z), (a.x * b.y-a.y * b.x)}; };

friend std :: ostream & operator << (std :: ostream & stream, vect3D const & p) {return flow << "(" << px << "," << py << "," << pz << ")" << std :: flush; };

// Function to explicitly return coordinates as an array of duplicates, if necessary
cancel DoubleArray (double * v) {v = x; v = y; v = z; return; };

// To access the coordinates using the notation in square brackets, for convenience
std :: vector p = std :: vector {& X Y Z};
double operator [] (int ii) const {return * (p[ii])};

};

#end if
``````

Thank you!

Posted on

## graph theory – Potential flow and impact vectors

Let $$f$$ to be a function on the arc game $$A$$ of an acyclic network $$N (x, y)$$ (right here $$x$$ is the source and $$y$$ l & # 39; sink). assume $$0 leq f (a) leq c (a)$$ for everyone $$a in A$$ ($$c$$ is the capacity function). CA watch $$f$$ is a flow if and only if it is a non-negative linear combination of vectors of incidence of $$(x, y)$$paths.

Posted on

## How to correctly access the vectors of objects in a coherent data structure?

This is my greatly reduced code to the parts concerning my problem:

Node.hpp:

``````Solarsystem knot, sun, mercury, venus, earth, moon, mars, jupiter, saturn, uranus, neptune, pluto;
Node class {
public:
Node getChild (std :: string aName);
std :: vector getChildrenList ();
std :: string getName ();
private:
std :: vector children;
std :: string name;
float size;
};
``````

Now I have tried adding the planets of our solar system to the solarsystem node system. Except for the moon. This one is supposed to be added as a child to the earth.

Main interior:

``````        solarsystem.addChildren (mercury);
...

std :: cout << "Solarsystem child vector size:" << solarsystem.getChildrenList (). size () << std :: endl;
std :: cout << "node name at (2):" << solarsystem.getChildrenList (). at (2) .getName () << std :: endl;
std :: cout << << size of the earth (1): << solarsystem.getChildrenList (). at (2) .getChildrenList (). size () << std :: endl;
std :: cout << << size of the earth (2): << << earth.getChildrenList (). size () << std :: endl;
``````

ouput:

``````Vector children's size of solarsystem: 9
name: earth
size of the earth (1): 0
size of the earth (2): 1
``````

My problem is: why are there two different results? What should I change so that the 0 also changes to 1? And why can I get all the other members like floating size using both methods, but the vector just will not?

Every help is highly appreciated. Thank you

Posted on

## Linear algebra – What is the best way to calculate the set of normal vectors to a given?

For 2D vectors, calculate the vector orthogonal to a given $$v$$ is downright done using `cross`, as for example shown here.

however, `cross` does not seem to work for more than two dimensions, and I have found no function giving a complete set of normal vectors to a given datum. $$v$$.

For example, I'm looking for a function that, given `v = {1,0,0}`, will give me back `{{0,1,0}, {0,0,1}}`, or some other equivalent set of vectors (that is, I want a base for the orthogonal space $$v ^ perp$$).

An easy way to do this in 3D is with something like:

``````normalVecs[v_] : = Cross[v, #] & / @ IdentityMatrix @ 3 // Orthogonalize // DeleteCases @ {0, 0, 0};
normalVecs @ {1, 0, 0}
``````

but using `cross` do not generalize to more than 3 dimensions.

What is the best way to proceed?

Posted on