Example #1
0
// Compute element-wise product C[i,j] = A[i,j] * B[i,j]. Returns new matrix.
func Mul(A, B *matrix.ComplexMatrix) *matrix.ComplexMatrix {
	if !A.SizeMatch(B.Size()) {
		return nil
	}
	C := A.Copy()
	return C.Mul(B)
}
Example #2
0
// Makes a copy of A and for all elements pointed by the element of the indexes array
// calculates fn(A[k], values[i]) where k is the i'th value in the indexes array.
func ApplyConstValues(A *matrix.ComplexMatrix, values []complex128, fn func(complex128, complex128) complex128, indexes []int) *matrix.ComplexMatrix {
	if A == nil {
		return A
	}
	C := A.Copy()
	return C.ApplyConstValues(values, fn, indexes)
}
Example #3
0
// Make a copy C of A and apply function fn element wise to C.
// For indexes is not empty then  C[indexes[i]] = fn(C[indexes[i]], x).
// Returns a new matrix.
func ApplyConst(A *matrix.ComplexMatrix, x complex128, fn func(complex128, complex128) complex128, indexes ...int) *matrix.ComplexMatrix {
	if A == nil {
		return nil
	}
	C := A.Copy()
	return C.ApplyConst(x, fn, indexes...)
}
Example #4
0
// Make copy C of A and compute  C[indexes[i]] +=  values[i]. Indexes are in column-major order.
// Returns a new matrix.
func AddAt(A *matrix.ComplexMatrix, values []complex128, indexes []int) *matrix.ComplexMatrix {
	C := A.Copy()
	if len(indexes) == 0 {
		return C
	}
	Cr := C.ComplexArray()
	N := A.NumElements()
	for i, k := range indexes {
		if i >= len(values) {
			return C
		}
		if k < 0 {
			k = N + k
		}
		Cr[k] += values[i]
	}
	return C
}
Example #5
0
// Make a copy C of A and compute C += alpha for all elements in the matrix if list of indexes
// is empty. Otherwise compute C[i] += alpha for indexes in column-major order.
func Add(A *matrix.ComplexMatrix, alpha complex128, indexes ...int) *matrix.ComplexMatrix {
	C := A.Copy()
	return C.Add(alpha, indexes...)
}
Example #6
0
// Make a copy C of A and compute inverse C[i] = 1.0/C[i]. If indexes is empty calculates for
// all elements. Returns a new matrix.
func Inv(A *matrix.ComplexMatrix, indexes ...int) *matrix.ComplexMatrix {
	C := A.Copy()
	return C.Inv()
}