Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
def make_temp_splunk_array(argument):
    '''
	usage: a = make_temp_splunk_array(1) or make_temp_splunk_array([1,2,3]) or make_temp_splunk_array(np.array([[1,2,3],[4,5,6]]))

	makes a temp splunk array with no string and with elems being the actual numbers given
	'''
    # try a bunch of different types:
    if type(argument) == float or type(argument) == int:
        shape = (1, 1)
        elems = np.array([[argument]])
    elif type(argument) == list:
        if type(argument[0]) == list:
            shape = (len(argument), len(argument[0]))
            elems = np.array(argument)
        else:
            shape = (1, len(argument))
            elems = np.array([argument])
    elif type(argument) == np.ndarray:
        # numpy uses the (n,) convention for n length arrays - so far, splunkmath uses (1,n). so we need to check for htat.
        if len(argument.shape) == 1:
            shape = (1, argument.shape[0])
            elems = np.array([argument])
        else:
            shape = argument.shape
            elems = argument

    else:
        raise Exception(
            "You didn't pass in a float, int, list, or numpy array. You passed in a %s"
            % type(argument))

    # now initialize an empty SplunkArray, name doesn't matter
    sa = SplunkArray('temp_UNIQUEHASHTOCHANGE', shape)
    # set the elements to the argument itself
    sa.elems = elems
    # make sure the string is the empty string
    sa.string = ''
    return sa
Beispiel #5
0
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
Beispiel #6
0
def make_temp_splunk_array(argument):
	'''
	usage: a = make_temp_splunk_array(1) or make_temp_splunk_array([1,2,3]) or make_temp_splunk_array(np.array([[1,2,3],[4,5,6]]))

	makes a temp splunk array with no string and with elems being the actual numbers given
	'''
	# try a bunch of different types:
	if type(argument) == float or type(argument) == int:
		shape = (1,1)
		elems = np.array([[argument]])
	elif type(argument) == list:
		if type(argument[0]) == list:
			shape = (len(argument), len(argument[0]))
			elems = np.array(argument)
		else:
			shape = (1, len(argument))
			elems = np.array([argument])
	elif type(argument) == np.ndarray:
		# numpy uses the (n,) convention for n length arrays - so far, splunkmath uses (1,n). so we need to check for htat.
		if len(argument.shape) == 1:
			shape = (1, argument.shape[0])
			elems = np.array([argument])
		else:
			shape = argument.shape
			elems = argument

	else:
		raise Exception("You didn't pass in a float, int, list, or numpy array. You passed in a %s" % type(argument))

	# now initialize an empty SplunkArray, name doesn't matter
	sa = SplunkArray('temp_UNIQUEHASHTOCHANGE', shape)
	# set the elements to the argument itself
	sa.elems = elems
	# make sure the string is the empty string
	sa.string = ''
	return sa
Beispiel #7
0
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
Beispiel #8
0
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