Cartesian product of A and B, denoted A × B, is the set whose members are
all possible ordered pairs (a, b) where a is a member of A and b is a
member of B.
@param <A>
@param <B>
@param a
@param b
@return
337564
public static final <A,B> Set<OrderedPair<A,B>> cartesianProduct(Set<A> a, Set<B> b)
    {
        Set<OrderedPair<A,B>> set = new HashSet<>();
        for (A t : a)
        {
            for (B v : b)
            {
                set.add(new OrderedPair(t, v));
            }
        }
        return set;
    }
126521
public Vector2d fma(Vector2dc a, Vector2dc b) {
        return fma(a, b, thisOrNew());
    }
64194
public Vector3d fma(Vector3dc a, Vector3dc b) {
        return fma(a, b, thisOrNew());
    }
725487
function cartesian(list)
{
  var last, init, keys, product = [];

  if (Array.isArray(list))
  {
    init = [];
    last = list.length - 1;
  }
  else if (typeof list == 'object' && list !== null)
  {
    init = {};
    keys = Object.keys(list);
    last = keys.length - 1;
  }
  else
  {
    throw new TypeError('Expecting an Array or an Object, but `' + (list === null ? 'null' : typeof list) + '` provided.');
  }

  function add(row, i)
  {
    var j, k, r;

    k = keys ? keys[i] : i;

    // either array or not, not expecting objects here
    Array.isArray(list[k]) || (typeof list[k] == 'undefined' ? list[k] = [] : list[k] = [list[k]]);

    for (j=0; j < list[k].length; j++)
    {
      r = clone(row);
      store(r, list[k][j], k);

      if (i >= last)
      {
        product.push(r);
      }
      else
      {
        add(r, i + 1);
      }
    }
  }

  add(init, 0);

  return product;
}
977126
public static <E> Iterable<E> concat(Iterable<E> a, Iterable<E> b) {
    List<E> result = new ArrayList<>();
    for (E e : a) {
      result.add(e);
    }
    for (E e : b) {
      result.add(e);
    }

    return result;
  }
578840
function(a, b) {
		if (a || !b) {
			var r = {};
			for (var x in a) {
				// Does the property not exist?
				if (!(x in b)) {
					r[x] = a[x];
				}
			}

			return r;
		}

		return a;
	}
357472
function keyUnion(a, b) {

    var k = {};
    for (var i in a) {
      k[i] = 1;
    }
    for (var i in b) {
      k[i] = 1;
    }
    return k;
  }
1153322
public static DoubleMatrix2D subdiagonalMultiply(final DoubleMatrix2D A, final DoubleMatrix2D B){
		final int r = A.rows();
		final int rc = A.columns();
		final int c = B.columns();

		if(r != c){
			throw new IllegalArgumentException("The result must be square");
		}

		boolean useSparsity = A instanceof SparseDoubleMatrix2D;
		DoubleFactory2D F2 = (useSparsity)? DoubleFactory2D.sparse : DoubleFactory2D.dense; 
		final DoubleMatrix2D ret = F2.make(r, c);

		if(useSparsity){
			IntIntDoubleFunction myFunct = new IntIntDoubleFunction() {
				@Override
				public double apply(int t, int s, double pts) {
					int i = t;
					for (int j = 0; j < i + 1; j++) {
						ret.setQuick(i, j, ret.getQuick(i, j) + pts * B.getQuick(s, j));
					}
					return pts;
				}
			};

			//view A row by row
			A.forEachNonZero(myFunct);
		}else{
			for (int i = 0; i < r; i++) {
				for (int j = 0; j < i + 1; j++) {
					double s = 0;
					for (int k = 0; k < rc; k++) {
						s += A.getQuick(i, k) * B.getQuick(k, j);
					}
					ret.setQuick(i, j, s);
				}
			}
		}

		return ret;
	}
309734
public static <E> Set<E> union(final Set<? extends E> set1, final Set<? extends E> set2) {
        checkArgumentNotNull(set1, "set1");
        checkArgumentNotNull(set2, "set2");

        // Set 2 minus set 1
        final Set<E> difference = new HashSet<>(set2);
        difference.removeAll(set1);
        // Following stream does not compile on some JDKs
        // See also https://bugs.openjdk.java.net/browse/JDK-8051443
        // set2.stream().filter((e) -> !set1.contains(e)).collect(Collectors.toSet());

        return new AbstractSet<E>() {

            @Override
            public Iterator<E> iterator() {
                final Iterator<E> iterator = Iterators.concat(ImmutableList.of(set1.iterator(), difference.iterator()).iterator());
                // Remove operation is not supported by default
                return new Iterator<E>() {
                    @Override
                    public boolean hasNext() {
                        return iterator.hasNext();
                    }

                    @Override
                    public E next() {
                        return iterator.next();
                    }
                };
            }

            @Override
            public int size() {
                return set1.size() + difference.size();
            }

            @Override
            public boolean isEmpty() {
                return set1.isEmpty() && difference.isEmpty();
            }

            @Override
            public boolean contains(Object o) {
                return set1.contains(o) || difference.contains(o);
            }
        };
    }
293877
public static double euclideanSq(TupleDesc_F64 a, TupleDesc_F64 b) {
		final int N = a.value.length;
		double total = 0;
		for( int i = 0; i < N; i++ ) {
			double d = a.value[i]-b.value[i];
			total += d*d;
		}

		return total;
	}
686076
public static <T> boolean equal(T a, T b) {
        return a != null ? a.equals(b) : b == null;
    }
1331224
public static double[] solve(double[][] A, double[] b) {
    final int rows = A.length, cols = A[0].length;
    return rows == cols //
        ? (new LUDecomposition(A, rows, cols)).solve(b) //
        : (new QRDecomposition(A, rows, cols)).solve(b);
  }
429455
public static <A> Set<A> intersection(Set<A> first, Set<A> second) {

        HashSet<A> result = new HashSet<A>(first);
        result.retainAll(second);
        return result;
    }
462065
def union(other)
      if other.is_a?(RelativeComplement)
        # A ∪ ¬B = ¬B ∪ A
        other.union(self)
      elsif other.is_a?(AbstractSet)
        unless other.is_a?(RelativeSet) and size < other.size
          hash = other.inject(@hash.clone){|h,o| h[o] = true; h }

          if hash.empty?
            NullSet.build
          else
            RelativeSet.new(hash)
          end
        else
          # For efficiency, iterate the smaller of the two sets: A ∪ B = B ∪ A
          if other.empty?
            self
          else
            other.union(self)
          end
        end
      else
        union(Cantor.build(other))
      end
    end
660530
public Vector2f fma(Vector2fc a, Vector2fc b, Vector2f dest) {
        dest.x = x + a.x() * b.x();
        dest.y = y + a.y() * b.y();
        return dest;
    }
852627
public function coprime($a, $b)
    {
        list($a, $b) = array($this->bcNormalize($a), $this->bcNormalize($b));

        try {

            while ($this->coCompare($a, $b)) {
                list($a, $b) = $this->coSwitch($a, $b);
            }

        } catch (\Exception $e) {
            throw $e;
        }

        return (bccomp($a, '1') == 0) ? true : false;
    }
1367612
public static void multAddTransAB(DMatrixSparseCSC A , DMatrixRMaj B , DMatrixRMaj C )
    {
        if( A.numCols != C.numRows || B.numRows != C.numCols )
            throw new IllegalArgumentException("Inconsistent matrix shapes. "+stringShapes(A,B,C));

        ImplSparseSparseMult_DSCC.multAddTransAB(A,B,C);
    }