def dot(one, two): ''' implements one dotprod two. params: - one,two: splunkarrays to dot product returns: - a new splunk array that correctly represents the dot product of the two passed in arrays notes: - the strategy is to iterate through and set the new array with elements using vector dot products (vector_dot_string). i.e each element of the new array is the vector dot product of rows/columns of the old arrays ''' # check shapes if one.shape[1] != two.shape[0]: raise Exception( "Those shapes don't dot with each other! shapes were %s, %s" % (one.shape, two.shape)) # initialize the output array output_sa = SplunkArray(one.name + '_dot_' + two.name, (one.shape[0], two.shape[1])) # set the output array's string output_sa.string = splunk_concat(one.string, two.string) # now calculate the dot product for i in range(output_sa.shape[0]): for j in range(output_sa.shape[1]): # A_i,j = the i'th row of "one" dotted with the j'th column of "two": output_sa.set_element( i, j, vector_dot_string(one.elems[i], two.elems[:, j])) # output_sa.string += 'eval %s_%s_%s = %s | ' % (output_sa.name, i, j, vector_dot_string(one.elems[i], two.elems[:,j])) # output_sa.string = output_sa.string[:-2] output_sa.find_elements() return output_sa
def dot(one, two): ''' implements one dotprod two. params: - one,two: splunkarrays to dot product returns: - a new splunk array that correctly represents the dot product of the two passed in arrays notes: - the strategy is to iterate through and set the new array with elements using vector dot products (vector_dot_string). i.e each element of the new array is the vector dot product of rows/columns of the old arrays ''' # check shapes if one.shape[1] != two.shape[0]: raise Exception ("Those shapes don't dot with each other! shapes were %s, %s" % (one.shape, two.shape)) # initialize the output array output_sa = SplunkArray(one.name + '_dot_' + two.name, (one.shape[0], two.shape[1])) # set the output array's string output_sa.string = splunk_concat(one.string, two.string) # now calculate the dot product for i in range(output_sa.shape[0]): for j in range(output_sa.shape[1]): # A_i,j = the i'th row of "one" dotted with the j'th column of "two": output_sa.set_element(i, j, vector_dot_string(one.elems[i], two.elems[:,j])) # output_sa.string += 'eval %s_%s_%s = %s | ' % (output_sa.name, i, j, vector_dot_string(one.elems[i], two.elems[:,j])) # output_sa.string = output_sa.string[:-2] output_sa.find_elements() return output_sa
def elementwise_func(sa, func): ''' elementwise func "func" on the elements of sa. func expected to be the name of a func in splunk i.e "ln" ''' output = SplunkArray(func + '_d' + sa.name, sa.shape) output.string = sa.string output.find_elements() for i, j in sa.iterable(): output.set_element(i, j, func + '(%s)' % sa.elems[i][j]) return output
def elementwise_func(sa, func): ''' elementwise func "func" on the elements of sa. func expected to be the name of a func in splunk i.e "ln" ''' output = SplunkArray(func+'_d'+sa.name, sa.shape) output.string = sa.string output.find_elements() for i,j in sa.iterable(): output.set_element(i,j, func+'(%s)' % sa.elems[i][j]) return output
def elementwise_func_withargs(sa, func, arg): ''' elementwise func "func" on the elements of sa, with passed in arg 'arg'. func expected to be the name of a func in splunk i.e "pow" pow(field, exponent) ''' output = SplunkArray(func + '_d' + sa.name, sa.shape) output.string = sa.string output.find_elements() for i, j in sa.iterable(): output.set_element(i, j, func + '(%s,%s)' % (sa.elems[i][j], arg)) return output
def elementwise_func_withargs(sa, func, arg): ''' elementwise func "func" on the elements of sa, with passed in arg 'arg'. func expected to be the name of a func in splunk i.e "pow" pow(field, exponent) ''' output = SplunkArray(func+'_d'+sa.name, sa.shape) output.string = sa.string output.find_elements() for i,j in sa.iterable(): output.set_element(i,j, func+'(%s,%s)' % (sa.elems[i][j], arg)) return output