repo
stringlengths 7
55
| path
stringlengths 4
127
| func_name
stringlengths 1
88
| original_string
stringlengths 75
19.8k
| language
stringclasses 1
value | code
stringlengths 75
19.8k
| code_tokens
sequence | docstring
stringlengths 3
17.3k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 87
242
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | tpictr | def tpictr(sample, lenout=_default_len_out, lenerr=_default_len_out):
"""
Given a sample time string, create a time format picture
suitable for use by the routine timout.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/tpictr_c.html
:param sample: A sample time string.
:type sample: str
:param lenout: The length for the output picture string.
:type lenout: int
:param lenerr: The length for the output error string.
:type lenerr: int
:return:
A format picture that describes sample,
Flag indicating whether sample parsed successfully,
Diagnostic returned if sample cannot be parsed
:rtype: tuple
"""
sample = stypes.stringToCharP(sample)
pictur = stypes.stringToCharP(lenout)
errmsg = stypes.stringToCharP(lenerr)
lenout = ctypes.c_int(lenout)
lenerr = ctypes.c_int(lenerr)
ok = ctypes.c_int()
libspice.tpictr_c(sample, lenout, lenerr, pictur, ctypes.byref(ok), errmsg)
return stypes.toPythonString(pictur), ok.value, stypes.toPythonString(
errmsg) | python | def tpictr(sample, lenout=_default_len_out, lenerr=_default_len_out):
"""
Given a sample time string, create a time format picture
suitable for use by the routine timout.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/tpictr_c.html
:param sample: A sample time string.
:type sample: str
:param lenout: The length for the output picture string.
:type lenout: int
:param lenerr: The length for the output error string.
:type lenerr: int
:return:
A format picture that describes sample,
Flag indicating whether sample parsed successfully,
Diagnostic returned if sample cannot be parsed
:rtype: tuple
"""
sample = stypes.stringToCharP(sample)
pictur = stypes.stringToCharP(lenout)
errmsg = stypes.stringToCharP(lenerr)
lenout = ctypes.c_int(lenout)
lenerr = ctypes.c_int(lenerr)
ok = ctypes.c_int()
libspice.tpictr_c(sample, lenout, lenerr, pictur, ctypes.byref(ok), errmsg)
return stypes.toPythonString(pictur), ok.value, stypes.toPythonString(
errmsg) | [
"def",
"tpictr",
"(",
"sample",
",",
"lenout",
"=",
"_default_len_out",
",",
"lenerr",
"=",
"_default_len_out",
")",
":",
"sample",
"=",
"stypes",
".",
"stringToCharP",
"(",
"sample",
")",
"pictur",
"=",
"stypes",
".",
"stringToCharP",
"(",
"lenout",
")",
"errmsg",
"=",
"stypes",
".",
"stringToCharP",
"(",
"lenerr",
")",
"lenout",
"=",
"ctypes",
".",
"c_int",
"(",
"lenout",
")",
"lenerr",
"=",
"ctypes",
".",
"c_int",
"(",
"lenerr",
")",
"ok",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"libspice",
".",
"tpictr_c",
"(",
"sample",
",",
"lenout",
",",
"lenerr",
",",
"pictur",
",",
"ctypes",
".",
"byref",
"(",
"ok",
")",
",",
"errmsg",
")",
"return",
"stypes",
".",
"toPythonString",
"(",
"pictur",
")",
",",
"ok",
".",
"value",
",",
"stypes",
".",
"toPythonString",
"(",
"errmsg",
")"
] | Given a sample time string, create a time format picture
suitable for use by the routine timout.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/tpictr_c.html
:param sample: A sample time string.
:type sample: str
:param lenout: The length for the output picture string.
:type lenout: int
:param lenerr: The length for the output error string.
:type lenerr: int
:return:
A format picture that describes sample,
Flag indicating whether sample parsed successfully,
Diagnostic returned if sample cannot be parsed
:rtype: tuple | [
"Given",
"a",
"sample",
"time",
"string",
"create",
"a",
"time",
"format",
"picture",
"suitable",
"for",
"use",
"by",
"the",
"routine",
"timout",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L13986-L14013 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | trcdep | def trcdep():
"""
Return the number of modules in the traceback representation.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/trcdep_c.html
:return: The number of modules in the traceback.
:rtype: int
"""
depth = ctypes.c_int()
libspice.trcdep_c(ctypes.byref(depth))
return depth.value | python | def trcdep():
"""
Return the number of modules in the traceback representation.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/trcdep_c.html
:return: The number of modules in the traceback.
:rtype: int
"""
depth = ctypes.c_int()
libspice.trcdep_c(ctypes.byref(depth))
return depth.value | [
"def",
"trcdep",
"(",
")",
":",
"depth",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"libspice",
".",
"trcdep_c",
"(",
"ctypes",
".",
"byref",
"(",
"depth",
")",
")",
"return",
"depth",
".",
"value"
] | Return the number of modules in the traceback representation.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/trcdep_c.html
:return: The number of modules in the traceback.
:rtype: int | [
"Return",
"the",
"number",
"of",
"modules",
"in",
"the",
"traceback",
"representation",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14033-L14044 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | trcnam | def trcnam(index, namlen=_default_len_out):
"""
Return the name of the module having the specified position in
the trace representation. The first module to check in is at
index 0.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/trcnam_c.html
:param index: The position of the requested module name.
:type index: int
:param namlen: Available space in output name string.
:type namlen: int
:return: The name at position index in the traceback.
:rtype: str
"""
index = ctypes.c_int(index)
name = stypes.stringToCharP(namlen)
namlen = ctypes.c_int(namlen)
libspice.trcnam_c(index, namlen, name)
return stypes.toPythonString(name) | python | def trcnam(index, namlen=_default_len_out):
"""
Return the name of the module having the specified position in
the trace representation. The first module to check in is at
index 0.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/trcnam_c.html
:param index: The position of the requested module name.
:type index: int
:param namlen: Available space in output name string.
:type namlen: int
:return: The name at position index in the traceback.
:rtype: str
"""
index = ctypes.c_int(index)
name = stypes.stringToCharP(namlen)
namlen = ctypes.c_int(namlen)
libspice.trcnam_c(index, namlen, name)
return stypes.toPythonString(name) | [
"def",
"trcnam",
"(",
"index",
",",
"namlen",
"=",
"_default_len_out",
")",
":",
"index",
"=",
"ctypes",
".",
"c_int",
"(",
"index",
")",
"name",
"=",
"stypes",
".",
"stringToCharP",
"(",
"namlen",
")",
"namlen",
"=",
"ctypes",
".",
"c_int",
"(",
"namlen",
")",
"libspice",
".",
"trcnam_c",
"(",
"index",
",",
"namlen",
",",
"name",
")",
"return",
"stypes",
".",
"toPythonString",
"(",
"name",
")"
] | Return the name of the module having the specified position in
the trace representation. The first module to check in is at
index 0.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/trcnam_c.html
:param index: The position of the requested module name.
:type index: int
:param namlen: Available space in output name string.
:type namlen: int
:return: The name at position index in the traceback.
:rtype: str | [
"Return",
"the",
"name",
"of",
"the",
"module",
"having",
"the",
"specified",
"position",
"in",
"the",
"trace",
"representation",
".",
"The",
"first",
"module",
"to",
"check",
"in",
"is",
"at",
"index",
"0",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14048-L14067 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | twovec | def twovec(axdef, indexa, plndef, indexp):
"""
Find the transformation to the right-handed frame having a
given vector as a specified axis and having a second given
vector lying in a specified coordinate plane.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/twovec_c.html
:param axdef: Vector defining a principal axis.
:type axdef: 3-Element Array of floats
:param indexa: Principal axis number of axdef (X=1, Y=2, Z=3).
:type indexa: int
:param plndef: Vector defining (with axdef) a principal plane.
:type plndef: 3-Element Array of floats
:param indexp: Second axis number (with indexa) of principal plane.
:type indexp: int
:return: Output rotation matrix.
:rtype: 3x3-Element Array of floats
"""
axdef = stypes.toDoubleVector(axdef)
indexa = ctypes.c_int(indexa)
plndef = stypes.toDoubleVector(plndef)
indexp = ctypes.c_int(indexp)
mout = stypes.emptyDoubleMatrix()
libspice.twovec_c(axdef, indexa, plndef, indexp, mout)
return stypes.cMatrixToNumpy(mout) | python | def twovec(axdef, indexa, plndef, indexp):
"""
Find the transformation to the right-handed frame having a
given vector as a specified axis and having a second given
vector lying in a specified coordinate plane.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/twovec_c.html
:param axdef: Vector defining a principal axis.
:type axdef: 3-Element Array of floats
:param indexa: Principal axis number of axdef (X=1, Y=2, Z=3).
:type indexa: int
:param plndef: Vector defining (with axdef) a principal plane.
:type plndef: 3-Element Array of floats
:param indexp: Second axis number (with indexa) of principal plane.
:type indexp: int
:return: Output rotation matrix.
:rtype: 3x3-Element Array of floats
"""
axdef = stypes.toDoubleVector(axdef)
indexa = ctypes.c_int(indexa)
plndef = stypes.toDoubleVector(plndef)
indexp = ctypes.c_int(indexp)
mout = stypes.emptyDoubleMatrix()
libspice.twovec_c(axdef, indexa, plndef, indexp, mout)
return stypes.cMatrixToNumpy(mout) | [
"def",
"twovec",
"(",
"axdef",
",",
"indexa",
",",
"plndef",
",",
"indexp",
")",
":",
"axdef",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"axdef",
")",
"indexa",
"=",
"ctypes",
".",
"c_int",
"(",
"indexa",
")",
"plndef",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"plndef",
")",
"indexp",
"=",
"ctypes",
".",
"c_int",
"(",
"indexp",
")",
"mout",
"=",
"stypes",
".",
"emptyDoubleMatrix",
"(",
")",
"libspice",
".",
"twovec_c",
"(",
"axdef",
",",
"indexa",
",",
"plndef",
",",
"indexp",
",",
"mout",
")",
"return",
"stypes",
".",
"cMatrixToNumpy",
"(",
"mout",
")"
] | Find the transformation to the right-handed frame having a
given vector as a specified axis and having a second given
vector lying in a specified coordinate plane.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/twovec_c.html
:param axdef: Vector defining a principal axis.
:type axdef: 3-Element Array of floats
:param indexa: Principal axis number of axdef (X=1, Y=2, Z=3).
:type indexa: int
:param plndef: Vector defining (with axdef) a principal plane.
:type plndef: 3-Element Array of floats
:param indexp: Second axis number (with indexa) of principal plane.
:type indexp: int
:return: Output rotation matrix.
:rtype: 3x3-Element Array of floats | [
"Find",
"the",
"transformation",
"to",
"the",
"right",
"-",
"handed",
"frame",
"having",
"a",
"given",
"vector",
"as",
"a",
"specified",
"axis",
"and",
"having",
"a",
"second",
"given",
"vector",
"lying",
"in",
"a",
"specified",
"coordinate",
"plane",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14112-L14137 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | txtopn | def txtopn(fname):
"""
Internal undocumented command for opening a new text file for
subsequent write access.
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ftncls_c.html#Files
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ftncls_c.html#Examples
:param fname: name of the new text file to be opened.
:type fname: str
:return: FORTRAN logical unit of opened file
:rtype: int
"""
fnameP = stypes.stringToCharP(fname)
unit_out = ctypes.c_int()
fname_len = ctypes.c_int(len(fname))
libspice.txtopn_(fnameP, ctypes.byref(unit_out), fname_len)
return unit_out.value | python | def txtopn(fname):
"""
Internal undocumented command for opening a new text file for
subsequent write access.
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ftncls_c.html#Files
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ftncls_c.html#Examples
:param fname: name of the new text file to be opened.
:type fname: str
:return: FORTRAN logical unit of opened file
:rtype: int
"""
fnameP = stypes.stringToCharP(fname)
unit_out = ctypes.c_int()
fname_len = ctypes.c_int(len(fname))
libspice.txtopn_(fnameP, ctypes.byref(unit_out), fname_len)
return unit_out.value | [
"def",
"txtopn",
"(",
"fname",
")",
":",
"fnameP",
"=",
"stypes",
".",
"stringToCharP",
"(",
"fname",
")",
"unit_out",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"fname_len",
"=",
"ctypes",
".",
"c_int",
"(",
"len",
"(",
"fname",
")",
")",
"libspice",
".",
"txtopn_",
"(",
"fnameP",
",",
"ctypes",
".",
"byref",
"(",
"unit_out",
")",
",",
"fname_len",
")",
"return",
"unit_out",
".",
"value"
] | Internal undocumented command for opening a new text file for
subsequent write access.
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ftncls_c.html#Files
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ftncls_c.html#Examples
:param fname: name of the new text file to be opened.
:type fname: str
:return: FORTRAN logical unit of opened file
:rtype: int | [
"Internal",
"undocumented",
"command",
"for",
"opening",
"a",
"new",
"text",
"file",
"for",
"subsequent",
"write",
"access",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14141-L14158 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | ucase | def ucase(inchar, lenout=None):
"""
Convert the characters in a string to uppercase.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ucase_c.html
:param inchar: Input string.
:type inchar: str
:param lenout: Optional Maximum length of output string.
:type lenout: int
:return: Output string, all uppercase.
:rtype: str
"""
if lenout is None:
lenout = len(inchar) + 1
inchar = stypes.stringToCharP(inchar)
outchar = stypes.stringToCharP(" " * lenout)
lenout = ctypes.c_int(lenout)
libspice.ucase_c(inchar, lenout, outchar)
return stypes.toPythonString(outchar) | python | def ucase(inchar, lenout=None):
"""
Convert the characters in a string to uppercase.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ucase_c.html
:param inchar: Input string.
:type inchar: str
:param lenout: Optional Maximum length of output string.
:type lenout: int
:return: Output string, all uppercase.
:rtype: str
"""
if lenout is None:
lenout = len(inchar) + 1
inchar = stypes.stringToCharP(inchar)
outchar = stypes.stringToCharP(" " * lenout)
lenout = ctypes.c_int(lenout)
libspice.ucase_c(inchar, lenout, outchar)
return stypes.toPythonString(outchar) | [
"def",
"ucase",
"(",
"inchar",
",",
"lenout",
"=",
"None",
")",
":",
"if",
"lenout",
"is",
"None",
":",
"lenout",
"=",
"len",
"(",
"inchar",
")",
"+",
"1",
"inchar",
"=",
"stypes",
".",
"stringToCharP",
"(",
"inchar",
")",
"outchar",
"=",
"stypes",
".",
"stringToCharP",
"(",
"\" \"",
"*",
"lenout",
")",
"lenout",
"=",
"ctypes",
".",
"c_int",
"(",
"lenout",
")",
"libspice",
".",
"ucase_c",
"(",
"inchar",
",",
"lenout",
",",
"outchar",
")",
"return",
"stypes",
".",
"toPythonString",
"(",
"outchar",
")"
] | Convert the characters in a string to uppercase.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ucase_c.html
:param inchar: Input string.
:type inchar: str
:param lenout: Optional Maximum length of output string.
:type lenout: int
:return: Output string, all uppercase.
:rtype: str | [
"Convert",
"the",
"characters",
"in",
"a",
"string",
"to",
"uppercase",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14178-L14197 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | ucrss | def ucrss(v1, v2):
"""
Compute the normalized cross product of two 3-vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ucrss_c.html
:param v1: Left vector for cross product.
:type v1: 3-Element Array of floats
:param v2: Right vector for cross product.
:type v2: 3-Element Array of floats
:return: Normalized cross product v1xv2 / abs(v1xv2).
:rtype: Array of floats
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
vout = stypes.emptyDoubleVector(3)
libspice.ucrss_c(v1, v2, vout)
return stypes.cVectorToPython(vout) | python | def ucrss(v1, v2):
"""
Compute the normalized cross product of two 3-vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ucrss_c.html
:param v1: Left vector for cross product.
:type v1: 3-Element Array of floats
:param v2: Right vector for cross product.
:type v2: 3-Element Array of floats
:return: Normalized cross product v1xv2 / abs(v1xv2).
:rtype: Array of floats
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
vout = stypes.emptyDoubleVector(3)
libspice.ucrss_c(v1, v2, vout)
return stypes.cVectorToPython(vout) | [
"def",
"ucrss",
"(",
"v1",
",",
"v2",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"libspice",
".",
"ucrss_c",
"(",
"v1",
",",
"v2",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Compute the normalized cross product of two 3-vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ucrss_c.html
:param v1: Left vector for cross product.
:type v1: 3-Element Array of floats
:param v2: Right vector for cross product.
:type v2: 3-Element Array of floats
:return: Normalized cross product v1xv2 / abs(v1xv2).
:rtype: Array of floats | [
"Compute",
"the",
"normalized",
"cross",
"product",
"of",
"two",
"3",
"-",
"vectors",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14201-L14218 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | uddc | def uddc(udfunc, x, dx):
"""
SPICE private routine intended solely for the support of SPICE
routines. Users should not call this routine directly due to the
volatile nature of this routine.
This routine calculates the derivative of 'udfunc' with respect
to time for 'et', then determines if the derivative has a
negative value.
Use the @spiceypy.utils.callbacks.SpiceUDFUNS dectorator to wrap
a given python function that takes one parameter (float) and
returns a float. For example::
@spiceypy.utils.callbacks.SpiceUDFUNS
def udfunc(et_in):
pos, new_et = spice.spkpos("MERCURY", et_in, "J2000", "LT+S", "MOON")
return new_et
deriv = spice.uddf(udfunc, et, 1.0)
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/uddc_c.html
:param udfunc: Name of the routine that computes the scalar value of interest.
:type udfunc: ctypes.CFunctionType
:param x: Independent variable of 'udfunc'.
:type x: float
:param dx: Interval from 'x' for derivative calculation.
:type dx: float
:return: Boolean indicating if the derivative is negative.
:rtype: bool
"""
x = ctypes.c_double(x)
dx = ctypes.c_double(dx)
isdescr = ctypes.c_int()
libspice.uddc_c(udfunc, x, dx, ctypes.byref(isdescr))
return bool(isdescr.value) | python | def uddc(udfunc, x, dx):
"""
SPICE private routine intended solely for the support of SPICE
routines. Users should not call this routine directly due to the
volatile nature of this routine.
This routine calculates the derivative of 'udfunc' with respect
to time for 'et', then determines if the derivative has a
negative value.
Use the @spiceypy.utils.callbacks.SpiceUDFUNS dectorator to wrap
a given python function that takes one parameter (float) and
returns a float. For example::
@spiceypy.utils.callbacks.SpiceUDFUNS
def udfunc(et_in):
pos, new_et = spice.spkpos("MERCURY", et_in, "J2000", "LT+S", "MOON")
return new_et
deriv = spice.uddf(udfunc, et, 1.0)
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/uddc_c.html
:param udfunc: Name of the routine that computes the scalar value of interest.
:type udfunc: ctypes.CFunctionType
:param x: Independent variable of 'udfunc'.
:type x: float
:param dx: Interval from 'x' for derivative calculation.
:type dx: float
:return: Boolean indicating if the derivative is negative.
:rtype: bool
"""
x = ctypes.c_double(x)
dx = ctypes.c_double(dx)
isdescr = ctypes.c_int()
libspice.uddc_c(udfunc, x, dx, ctypes.byref(isdescr))
return bool(isdescr.value) | [
"def",
"uddc",
"(",
"udfunc",
",",
"x",
",",
"dx",
")",
":",
"x",
"=",
"ctypes",
".",
"c_double",
"(",
"x",
")",
"dx",
"=",
"ctypes",
".",
"c_double",
"(",
"dx",
")",
"isdescr",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"libspice",
".",
"uddc_c",
"(",
"udfunc",
",",
"x",
",",
"dx",
",",
"ctypes",
".",
"byref",
"(",
"isdescr",
")",
")",
"return",
"bool",
"(",
"isdescr",
".",
"value",
")"
] | SPICE private routine intended solely for the support of SPICE
routines. Users should not call this routine directly due to the
volatile nature of this routine.
This routine calculates the derivative of 'udfunc' with respect
to time for 'et', then determines if the derivative has a
negative value.
Use the @spiceypy.utils.callbacks.SpiceUDFUNS dectorator to wrap
a given python function that takes one parameter (float) and
returns a float. For example::
@spiceypy.utils.callbacks.SpiceUDFUNS
def udfunc(et_in):
pos, new_et = spice.spkpos("MERCURY", et_in, "J2000", "LT+S", "MOON")
return new_et
deriv = spice.uddf(udfunc, et, 1.0)
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/uddc_c.html
:param udfunc: Name of the routine that computes the scalar value of interest.
:type udfunc: ctypes.CFunctionType
:param x: Independent variable of 'udfunc'.
:type x: float
:param dx: Interval from 'x' for derivative calculation.
:type dx: float
:return: Boolean indicating if the derivative is negative.
:rtype: bool | [
"SPICE",
"private",
"routine",
"intended",
"solely",
"for",
"the",
"support",
"of",
"SPICE",
"routines",
".",
"Users",
"should",
"not",
"call",
"this",
"routine",
"directly",
"due",
"to",
"the",
"volatile",
"nature",
"of",
"this",
"routine",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14221-L14257 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | uddf | def uddf(udfunc, x, dx):
"""
Routine to calculate the first derivative of a caller-specified
function using a three-point estimation.
Use the @spiceypy.utils.callbacks.SpiceUDFUNS dectorator to wrap
a given python function that takes one parameter (float) and
returns a float. For example::
@spiceypy.utils.callbacks.SpiceUDFUNS
def udfunc(et_in):
pos, new_et = spice.spkpos("MERCURY", et_in, "J2000", "LT+S", "MOON")
return new_et
deriv = spice.uddf(udfunc, et, 1.0)
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/uddf_c.html
:param udfunc: Name of the routine that computes the scalar value of interest.
:type udfunc: ctypes.CFunctionType
:param x: Independent variable of 'udfunc'.
:type x: float
:param dx: Interval from 'x' for derivative calculation.
:type dx: float
:return: Approximate derivative of 'udfunc' at 'x'
:rtype: float
"""
x = ctypes.c_double(x)
dx = ctypes.c_double(dx)
deriv = ctypes.c_double()
libspice.uddf_c(udfunc, x, dx, ctypes.byref(deriv))
return deriv.value | python | def uddf(udfunc, x, dx):
"""
Routine to calculate the first derivative of a caller-specified
function using a three-point estimation.
Use the @spiceypy.utils.callbacks.SpiceUDFUNS dectorator to wrap
a given python function that takes one parameter (float) and
returns a float. For example::
@spiceypy.utils.callbacks.SpiceUDFUNS
def udfunc(et_in):
pos, new_et = spice.spkpos("MERCURY", et_in, "J2000", "LT+S", "MOON")
return new_et
deriv = spice.uddf(udfunc, et, 1.0)
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/uddf_c.html
:param udfunc: Name of the routine that computes the scalar value of interest.
:type udfunc: ctypes.CFunctionType
:param x: Independent variable of 'udfunc'.
:type x: float
:param dx: Interval from 'x' for derivative calculation.
:type dx: float
:return: Approximate derivative of 'udfunc' at 'x'
:rtype: float
"""
x = ctypes.c_double(x)
dx = ctypes.c_double(dx)
deriv = ctypes.c_double()
libspice.uddf_c(udfunc, x, dx, ctypes.byref(deriv))
return deriv.value | [
"def",
"uddf",
"(",
"udfunc",
",",
"x",
",",
"dx",
")",
":",
"x",
"=",
"ctypes",
".",
"c_double",
"(",
"x",
")",
"dx",
"=",
"ctypes",
".",
"c_double",
"(",
"dx",
")",
"deriv",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"libspice",
".",
"uddf_c",
"(",
"udfunc",
",",
"x",
",",
"dx",
",",
"ctypes",
".",
"byref",
"(",
"deriv",
")",
")",
"return",
"deriv",
".",
"value"
] | Routine to calculate the first derivative of a caller-specified
function using a three-point estimation.
Use the @spiceypy.utils.callbacks.SpiceUDFUNS dectorator to wrap
a given python function that takes one parameter (float) and
returns a float. For example::
@spiceypy.utils.callbacks.SpiceUDFUNS
def udfunc(et_in):
pos, new_et = spice.spkpos("MERCURY", et_in, "J2000", "LT+S", "MOON")
return new_et
deriv = spice.uddf(udfunc, et, 1.0)
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/uddf_c.html
:param udfunc: Name of the routine that computes the scalar value of interest.
:type udfunc: ctypes.CFunctionType
:param x: Independent variable of 'udfunc'.
:type x: float
:param dx: Interval from 'x' for derivative calculation.
:type dx: float
:return: Approximate derivative of 'udfunc' at 'x'
:rtype: float | [
"Routine",
"to",
"calculate",
"the",
"first",
"derivative",
"of",
"a",
"caller",
"-",
"specified",
"function",
"using",
"a",
"three",
"-",
"point",
"estimation",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14261-L14292 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | udf | def udf(x):
"""
No-op routine for with an argument signature matching udfuns.
Allways returns 0.0 .
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/udf_c.html
:param x: Double precision value, unused.
:type x: float
:return: Double precision value, unused.
:rtype: float
"""
x = ctypes.c_double(x)
value = ctypes.c_double()
libspice.udf_c(x, ctypes.byref(value))
return value.value | python | def udf(x):
"""
No-op routine for with an argument signature matching udfuns.
Allways returns 0.0 .
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/udf_c.html
:param x: Double precision value, unused.
:type x: float
:return: Double precision value, unused.
:rtype: float
"""
x = ctypes.c_double(x)
value = ctypes.c_double()
libspice.udf_c(x, ctypes.byref(value))
return value.value | [
"def",
"udf",
"(",
"x",
")",
":",
"x",
"=",
"ctypes",
".",
"c_double",
"(",
"x",
")",
"value",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"libspice",
".",
"udf_c",
"(",
"x",
",",
"ctypes",
".",
"byref",
"(",
"value",
")",
")",
"return",
"value",
".",
"value"
] | No-op routine for with an argument signature matching udfuns.
Allways returns 0.0 .
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/udf_c.html
:param x: Double precision value, unused.
:type x: float
:return: Double precision value, unused.
:rtype: float | [
"No",
"-",
"op",
"routine",
"for",
"with",
"an",
"argument",
"signature",
"matching",
"udfuns",
".",
"Allways",
"returns",
"0",
".",
"0",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14295-L14310 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | unitim | def unitim(epoch, insys, outsys):
"""
Transform time from one uniform scale to another. The uniform
time scales are TAI, TDT, TDB, ET, JED, JDTDB, JDTDT.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unitim_c.html
:param epoch: An epoch to be converted.
:type epoch: float
:param insys: The time scale associated with the input epoch.
:type insys: str
:param outsys: The time scale associated with the function value.
:type outsys: str
:return:
The float in outsys that is equivalent
to the epoch on the insys time scale.
:rtype: float
"""
epoch = ctypes.c_double(epoch)
insys = stypes.stringToCharP(insys)
outsys = stypes.stringToCharP(outsys)
return libspice.unitim_c(epoch, insys, outsys) | python | def unitim(epoch, insys, outsys):
"""
Transform time from one uniform scale to another. The uniform
time scales are TAI, TDT, TDB, ET, JED, JDTDB, JDTDT.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unitim_c.html
:param epoch: An epoch to be converted.
:type epoch: float
:param insys: The time scale associated with the input epoch.
:type insys: str
:param outsys: The time scale associated with the function value.
:type outsys: str
:return:
The float in outsys that is equivalent
to the epoch on the insys time scale.
:rtype: float
"""
epoch = ctypes.c_double(epoch)
insys = stypes.stringToCharP(insys)
outsys = stypes.stringToCharP(outsys)
return libspice.unitim_c(epoch, insys, outsys) | [
"def",
"unitim",
"(",
"epoch",
",",
"insys",
",",
"outsys",
")",
":",
"epoch",
"=",
"ctypes",
".",
"c_double",
"(",
"epoch",
")",
"insys",
"=",
"stypes",
".",
"stringToCharP",
"(",
"insys",
")",
"outsys",
"=",
"stypes",
".",
"stringToCharP",
"(",
"outsys",
")",
"return",
"libspice",
".",
"unitim_c",
"(",
"epoch",
",",
"insys",
",",
"outsys",
")"
] | Transform time from one uniform scale to another. The uniform
time scales are TAI, TDT, TDB, ET, JED, JDTDB, JDTDT.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unitim_c.html
:param epoch: An epoch to be converted.
:type epoch: float
:param insys: The time scale associated with the input epoch.
:type insys: str
:param outsys: The time scale associated with the function value.
:type outsys: str
:return:
The float in outsys that is equivalent
to the epoch on the insys time scale.
:rtype: float | [
"Transform",
"time",
"from",
"one",
"uniform",
"scale",
"to",
"another",
".",
"The",
"uniform",
"time",
"scales",
"are",
"TAI",
"TDT",
"TDB",
"ET",
"JED",
"JDTDB",
"JDTDT",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14345-L14366 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | unload | def unload(filename):
"""
Unload a SPICE kernel.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unload_c.html
:param filename: The name of a kernel to unload.
:type filename: str
"""
if isinstance(filename, list):
for f in filename:
libspice.unload_c(stypes.stringToCharP(f))
return
filename = stypes.stringToCharP(filename)
libspice.unload_c(filename) | python | def unload(filename):
"""
Unload a SPICE kernel.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unload_c.html
:param filename: The name of a kernel to unload.
:type filename: str
"""
if isinstance(filename, list):
for f in filename:
libspice.unload_c(stypes.stringToCharP(f))
return
filename = stypes.stringToCharP(filename)
libspice.unload_c(filename) | [
"def",
"unload",
"(",
"filename",
")",
":",
"if",
"isinstance",
"(",
"filename",
",",
"list",
")",
":",
"for",
"f",
"in",
"filename",
":",
"libspice",
".",
"unload_c",
"(",
"stypes",
".",
"stringToCharP",
"(",
"f",
")",
")",
"return",
"filename",
"=",
"stypes",
".",
"stringToCharP",
"(",
"filename",
")",
"libspice",
".",
"unload_c",
"(",
"filename",
")"
] | Unload a SPICE kernel.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unload_c.html
:param filename: The name of a kernel to unload.
:type filename: str | [
"Unload",
"a",
"SPICE",
"kernel",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14370-L14384 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | unorm | def unorm(v1):
"""
Normalize a double precision 3-vector and return its magnitude.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unorm_c.html
:param v1: Vector to be normalized.
:type v1: 3-Element Array of floats
:return: Unit vector of v1, Magnitude of v1.
:rtype: tuple
"""
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(3)
vmag = ctypes.c_double()
libspice.unorm_c(v1, vout, ctypes.byref(vmag))
return stypes.cVectorToPython(vout), vmag.value | python | def unorm(v1):
"""
Normalize a double precision 3-vector and return its magnitude.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unorm_c.html
:param v1: Vector to be normalized.
:type v1: 3-Element Array of floats
:return: Unit vector of v1, Magnitude of v1.
:rtype: tuple
"""
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(3)
vmag = ctypes.c_double()
libspice.unorm_c(v1, vout, ctypes.byref(vmag))
return stypes.cVectorToPython(vout), vmag.value | [
"def",
"unorm",
"(",
"v1",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"vmag",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"libspice",
".",
"unorm_c",
"(",
"v1",
",",
"vout",
",",
"ctypes",
".",
"byref",
"(",
"vmag",
")",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")",
",",
"vmag",
".",
"value"
] | Normalize a double precision 3-vector and return its magnitude.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unorm_c.html
:param v1: Vector to be normalized.
:type v1: 3-Element Array of floats
:return: Unit vector of v1, Magnitude of v1.
:rtype: tuple | [
"Normalize",
"a",
"double",
"precision",
"3",
"-",
"vector",
"and",
"return",
"its",
"magnitude",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14388-L14403 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | unormg | def unormg(v1, ndim):
"""
Normalize a double precision vector of arbitrary dimension and
return its magnitude.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unormg_c.html
:param v1: Vector to be normalized.
:type v1: Array of floats
:param ndim: This is the dimension of v1 and vout.
:type ndim: int
:return: Unit vector of v1, Magnitude of v1.
:rtype: tuple
"""
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(ndim)
vmag = ctypes.c_double()
ndim = ctypes.c_int(ndim)
libspice.unormg_c(v1, ndim, vout, ctypes.byref(vmag))
return stypes.cVectorToPython(vout), vmag.value | python | def unormg(v1, ndim):
"""
Normalize a double precision vector of arbitrary dimension and
return its magnitude.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unormg_c.html
:param v1: Vector to be normalized.
:type v1: Array of floats
:param ndim: This is the dimension of v1 and vout.
:type ndim: int
:return: Unit vector of v1, Magnitude of v1.
:rtype: tuple
"""
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(ndim)
vmag = ctypes.c_double()
ndim = ctypes.c_int(ndim)
libspice.unormg_c(v1, ndim, vout, ctypes.byref(vmag))
return stypes.cVectorToPython(vout), vmag.value | [
"def",
"unormg",
"(",
"v1",
",",
"ndim",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"ndim",
")",
"vmag",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"ndim",
"=",
"ctypes",
".",
"c_int",
"(",
"ndim",
")",
"libspice",
".",
"unormg_c",
"(",
"v1",
",",
"ndim",
",",
"vout",
",",
"ctypes",
".",
"byref",
"(",
"vmag",
")",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")",
",",
"vmag",
".",
"value"
] | Normalize a double precision vector of arbitrary dimension and
return its magnitude.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/unormg_c.html
:param v1: Vector to be normalized.
:type v1: Array of floats
:param ndim: This is the dimension of v1 and vout.
:type ndim: int
:return: Unit vector of v1, Magnitude of v1.
:rtype: tuple | [
"Normalize",
"a",
"double",
"precision",
"vector",
"of",
"arbitrary",
"dimension",
"and",
"return",
"its",
"magnitude",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14407-L14426 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | utc2et | def utc2et(utcstr):
"""
Convert an input time from Calendar or Julian Date format, UTC,
to ephemeris seconds past J2000.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/utc2et_c.html
:param utcstr: Input time string, UTC.
:type utcstr: str
:return: Output epoch, ephemeris seconds past J2000.
:rtype: float
"""
utcstr = stypes.stringToCharP(utcstr)
et = ctypes.c_double()
libspice.utc2et_c(utcstr, ctypes.byref(et))
return et.value | python | def utc2et(utcstr):
"""
Convert an input time from Calendar or Julian Date format, UTC,
to ephemeris seconds past J2000.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/utc2et_c.html
:param utcstr: Input time string, UTC.
:type utcstr: str
:return: Output epoch, ephemeris seconds past J2000.
:rtype: float
"""
utcstr = stypes.stringToCharP(utcstr)
et = ctypes.c_double()
libspice.utc2et_c(utcstr, ctypes.byref(et))
return et.value | [
"def",
"utc2et",
"(",
"utcstr",
")",
":",
"utcstr",
"=",
"stypes",
".",
"stringToCharP",
"(",
"utcstr",
")",
"et",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"libspice",
".",
"utc2et_c",
"(",
"utcstr",
",",
"ctypes",
".",
"byref",
"(",
"et",
")",
")",
"return",
"et",
".",
"value"
] | Convert an input time from Calendar or Julian Date format, UTC,
to ephemeris seconds past J2000.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/utc2et_c.html
:param utcstr: Input time string, UTC.
:type utcstr: str
:return: Output epoch, ephemeris seconds past J2000.
:rtype: float | [
"Convert",
"an",
"input",
"time",
"from",
"Calendar",
"or",
"Julian",
"Date",
"format",
"UTC",
"to",
"ephemeris",
"seconds",
"past",
"J2000",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14430-L14445 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | valid | def valid(insize, n, inset):
"""
Create a valid CSPICE set from a CSPICE Cell of any data type.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/valid_c.html
:param insize: Size (maximum cardinality) of the set.
:type insize: int
:param n: Initial no. of (possibly non-distinct) elements.
:type n: int
:param inset: Set to be validated.
:return: validated set
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(inset, stypes.SpiceCell)
insize = ctypes.c_int(insize)
n = ctypes.c_int(n)
libspice.valid_c(insize, n, inset)
return inset | python | def valid(insize, n, inset):
"""
Create a valid CSPICE set from a CSPICE Cell of any data type.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/valid_c.html
:param insize: Size (maximum cardinality) of the set.
:type insize: int
:param n: Initial no. of (possibly non-distinct) elements.
:type n: int
:param inset: Set to be validated.
:return: validated set
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(inset, stypes.SpiceCell)
insize = ctypes.c_int(insize)
n = ctypes.c_int(n)
libspice.valid_c(insize, n, inset)
return inset | [
"def",
"valid",
"(",
"insize",
",",
"n",
",",
"inset",
")",
":",
"assert",
"isinstance",
"(",
"inset",
",",
"stypes",
".",
"SpiceCell",
")",
"insize",
"=",
"ctypes",
".",
"c_int",
"(",
"insize",
")",
"n",
"=",
"ctypes",
".",
"c_int",
"(",
"n",
")",
"libspice",
".",
"valid_c",
"(",
"insize",
",",
"n",
",",
"inset",
")",
"return",
"inset"
] | Create a valid CSPICE set from a CSPICE Cell of any data type.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/valid_c.html
:param insize: Size (maximum cardinality) of the set.
:type insize: int
:param n: Initial no. of (possibly non-distinct) elements.
:type n: int
:param inset: Set to be validated.
:return: validated set
:rtype: spiceypy.utils.support_types.SpiceCell | [
"Create",
"a",
"valid",
"CSPICE",
"set",
"from",
"a",
"CSPICE",
"Cell",
"of",
"any",
"data",
"type",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14494-L14512 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vcrss | def vcrss(v1, v2):
"""
Compute the cross product of two 3-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vcrss_c.html
:param v1: Left hand vector for cross product.
:type v1: 3-Element Array of floats
:param v2: Right hand vector for cross product.
:type v2: 3-Element Array of floats
:return: Cross product v1 x v2.
:rtype: 3-Element Array of floats
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
vout = stypes.emptyDoubleVector(3)
libspice.vcrss_c(v1, v2, vout)
return stypes.cVectorToPython(vout) | python | def vcrss(v1, v2):
"""
Compute the cross product of two 3-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vcrss_c.html
:param v1: Left hand vector for cross product.
:type v1: 3-Element Array of floats
:param v2: Right hand vector for cross product.
:type v2: 3-Element Array of floats
:return: Cross product v1 x v2.
:rtype: 3-Element Array of floats
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
vout = stypes.emptyDoubleVector(3)
libspice.vcrss_c(v1, v2, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vcrss",
"(",
"v1",
",",
"v2",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"libspice",
".",
"vcrss_c",
"(",
"v1",
",",
"v2",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Compute the cross product of two 3-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vcrss_c.html
:param v1: Left hand vector for cross product.
:type v1: 3-Element Array of floats
:param v2: Right hand vector for cross product.
:type v2: 3-Element Array of floats
:return: Cross product v1 x v2.
:rtype: 3-Element Array of floats | [
"Compute",
"the",
"cross",
"product",
"of",
"two",
"3",
"-",
"dimensional",
"vectors",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14516-L14533 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vdist | def vdist(v1, v2):
"""
Return the distance between two three-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdist_c.html
:param v1: First vector in the dot product.
:type v1: 3-Element Array of floats
:param v2: Second vector in the dot product.
:type v2: 3-Element Array of floats
:return: the distance between v1 and v2
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
return libspice.vdist_c(v1, v2) | python | def vdist(v1, v2):
"""
Return the distance between two three-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdist_c.html
:param v1: First vector in the dot product.
:type v1: 3-Element Array of floats
:param v2: Second vector in the dot product.
:type v2: 3-Element Array of floats
:return: the distance between v1 and v2
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
return libspice.vdist_c(v1, v2) | [
"def",
"vdist",
"(",
"v1",
",",
"v2",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"return",
"libspice",
".",
"vdist_c",
"(",
"v1",
",",
"v2",
")"
] | Return the distance between two three-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdist_c.html
:param v1: First vector in the dot product.
:type v1: 3-Element Array of floats
:param v2: Second vector in the dot product.
:type v2: 3-Element Array of floats
:return: the distance between v1 and v2
:rtype: float | [
"Return",
"the",
"distance",
"between",
"two",
"three",
"-",
"dimensional",
"vectors",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14537-L14552 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vdistg | def vdistg(v1, v2, ndim):
"""
Return the distance between two vectors of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdistg_c.html
:param v1: ndim-dimensional double precision vector.
:type v1: list[ndim]
:param v2: ndim-dimensional double precision vector.
:type v2: list[ndim]
:param ndim: Dimension of v1 and v2.
:type ndim: int
:return: the distance between v1 and v2
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
ndim = ctypes.c_int(ndim)
return libspice.vdistg_c(v1, v2, ndim) | python | def vdistg(v1, v2, ndim):
"""
Return the distance between two vectors of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdistg_c.html
:param v1: ndim-dimensional double precision vector.
:type v1: list[ndim]
:param v2: ndim-dimensional double precision vector.
:type v2: list[ndim]
:param ndim: Dimension of v1 and v2.
:type ndim: int
:return: the distance between v1 and v2
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
ndim = ctypes.c_int(ndim)
return libspice.vdistg_c(v1, v2, ndim) | [
"def",
"vdistg",
"(",
"v1",
",",
"v2",
",",
"ndim",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"ndim",
"=",
"ctypes",
".",
"c_int",
"(",
"ndim",
")",
"return",
"libspice",
".",
"vdistg_c",
"(",
"v1",
",",
"v2",
",",
"ndim",
")"
] | Return the distance between two vectors of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdistg_c.html
:param v1: ndim-dimensional double precision vector.
:type v1: list[ndim]
:param v2: ndim-dimensional double precision vector.
:type v2: list[ndim]
:param ndim: Dimension of v1 and v2.
:type ndim: int
:return: the distance between v1 and v2
:rtype: float | [
"Return",
"the",
"distance",
"between",
"two",
"vectors",
"of",
"arbitrary",
"dimension",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14556-L14574 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vdot | def vdot(v1, v2):
"""
Compute the dot product of two double precision, 3-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdot_c.html
:param v1: First vector in the dot product.
:type v1: 3-Element Array of floats
:param v2: Second vector in the dot product.
:type v2: 3-Element Array of floats
:return: dot product of v1 and v2.
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
return libspice.vdot_c(v1, v2) | python | def vdot(v1, v2):
"""
Compute the dot product of two double precision, 3-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdot_c.html
:param v1: First vector in the dot product.
:type v1: 3-Element Array of floats
:param v2: Second vector in the dot product.
:type v2: 3-Element Array of floats
:return: dot product of v1 and v2.
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
return libspice.vdot_c(v1, v2) | [
"def",
"vdot",
"(",
"v1",
",",
"v2",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"return",
"libspice",
".",
"vdot_c",
"(",
"v1",
",",
"v2",
")"
] | Compute the dot product of two double precision, 3-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdot_c.html
:param v1: First vector in the dot product.
:type v1: 3-Element Array of floats
:param v2: Second vector in the dot product.
:type v2: 3-Element Array of floats
:return: dot product of v1 and v2.
:rtype: float | [
"Compute",
"the",
"dot",
"product",
"of",
"two",
"double",
"precision",
"3",
"-",
"dimensional",
"vectors",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14578-L14593 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vdotg | def vdotg(v1, v2, ndim):
"""
Compute the dot product of two double precision vectors of
arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdotg_c.html
:param v1: First vector in the dot product.
:type v1: list[ndim]
:param v2: Second vector in the dot product.
:type v2: list[ndim]
:param ndim: Dimension of v1 and v2.
:type ndim: int
:return: dot product of v1 and v2.
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
ndim = ctypes.c_int(ndim)
return libspice.vdotg_c(v1, v2, ndim) | python | def vdotg(v1, v2, ndim):
"""
Compute the dot product of two double precision vectors of
arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdotg_c.html
:param v1: First vector in the dot product.
:type v1: list[ndim]
:param v2: Second vector in the dot product.
:type v2: list[ndim]
:param ndim: Dimension of v1 and v2.
:type ndim: int
:return: dot product of v1 and v2.
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
ndim = ctypes.c_int(ndim)
return libspice.vdotg_c(v1, v2, ndim) | [
"def",
"vdotg",
"(",
"v1",
",",
"v2",
",",
"ndim",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"ndim",
"=",
"ctypes",
".",
"c_int",
"(",
"ndim",
")",
"return",
"libspice",
".",
"vdotg_c",
"(",
"v1",
",",
"v2",
",",
"ndim",
")"
] | Compute the dot product of two double precision vectors of
arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vdotg_c.html
:param v1: First vector in the dot product.
:type v1: list[ndim]
:param v2: Second vector in the dot product.
:type v2: list[ndim]
:param ndim: Dimension of v1 and v2.
:type ndim: int
:return: dot product of v1 and v2.
:rtype: float | [
"Compute",
"the",
"dot",
"product",
"of",
"two",
"double",
"precision",
"vectors",
"of",
"arbitrary",
"dimension",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14597-L14616 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vequ | def vequ(v1):
"""
Make one double precision 3-dimensional vector equal to another.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vequ_c.html
:param v1: 3-dimensional double precision vector.
:type v1: 3-Element Array of floats
:return: 3-dimensional double precision vector set equal to vin.
:rtype: 3-Element Array of floats
"""
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(3)
libspice.vequ_c(v1, vout)
return stypes.cVectorToPython(vout) | python | def vequ(v1):
"""
Make one double precision 3-dimensional vector equal to another.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vequ_c.html
:param v1: 3-dimensional double precision vector.
:type v1: 3-Element Array of floats
:return: 3-dimensional double precision vector set equal to vin.
:rtype: 3-Element Array of floats
"""
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(3)
libspice.vequ_c(v1, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vequ",
"(",
"v1",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"libspice",
".",
"vequ_c",
"(",
"v1",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Make one double precision 3-dimensional vector equal to another.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vequ_c.html
:param v1: 3-dimensional double precision vector.
:type v1: 3-Element Array of floats
:return: 3-dimensional double precision vector set equal to vin.
:rtype: 3-Element Array of floats | [
"Make",
"one",
"double",
"precision",
"3",
"-",
"dimensional",
"vector",
"equal",
"to",
"another",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14620-L14634 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vequg | def vequg(v1, ndim):
"""
Make one double precision vector of arbitrary dimension equal to another.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vequg_c.html
:param v1: ndim-dimensional double precision vector.
:type v1: list[ndim]
:param ndim: Dimension of vin (and also vout).
:type ndim: int
:return: ndim-dimensional double precision vector set equal to vin.
:rtype: list[ndim]
"""
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(ndim)
ndim = ctypes.c_int(ndim)
libspice.vequg_c(v1, ndim, vout)
return stypes.cVectorToPython(vout) | python | def vequg(v1, ndim):
"""
Make one double precision vector of arbitrary dimension equal to another.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vequg_c.html
:param v1: ndim-dimensional double precision vector.
:type v1: list[ndim]
:param ndim: Dimension of vin (and also vout).
:type ndim: int
:return: ndim-dimensional double precision vector set equal to vin.
:rtype: list[ndim]
"""
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(ndim)
ndim = ctypes.c_int(ndim)
libspice.vequg_c(v1, ndim, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vequg",
"(",
"v1",
",",
"ndim",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"ndim",
")",
"ndim",
"=",
"ctypes",
".",
"c_int",
"(",
"ndim",
")",
"libspice",
".",
"vequg_c",
"(",
"v1",
",",
"ndim",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Make one double precision vector of arbitrary dimension equal to another.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vequg_c.html
:param v1: ndim-dimensional double precision vector.
:type v1: list[ndim]
:param ndim: Dimension of vin (and also vout).
:type ndim: int
:return: ndim-dimensional double precision vector set equal to vin.
:rtype: list[ndim] | [
"Make",
"one",
"double",
"precision",
"vector",
"of",
"arbitrary",
"dimension",
"equal",
"to",
"another",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14638-L14655 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vhat | def vhat(v1):
"""
Find the unit vector along a double precision 3-dimensional vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vhat_c.html
:param v1: Vector to be unitized.
:type v1: 3-Element Array of floats
:return: Unit vector v / abs(v).
:rtype: 3-Element Array of floats
"""
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(3)
libspice.vhat_c(v1, vout)
return stypes.cVectorToPython(vout) | python | def vhat(v1):
"""
Find the unit vector along a double precision 3-dimensional vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vhat_c.html
:param v1: Vector to be unitized.
:type v1: 3-Element Array of floats
:return: Unit vector v / abs(v).
:rtype: 3-Element Array of floats
"""
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(3)
libspice.vhat_c(v1, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vhat",
"(",
"v1",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"libspice",
".",
"vhat_c",
"(",
"v1",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Find the unit vector along a double precision 3-dimensional vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vhat_c.html
:param v1: Vector to be unitized.
:type v1: 3-Element Array of floats
:return: Unit vector v / abs(v).
:rtype: 3-Element Array of floats | [
"Find",
"the",
"unit",
"vector",
"along",
"a",
"double",
"precision",
"3",
"-",
"dimensional",
"vector",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14659-L14673 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vhatg | def vhatg(v1, ndim):
"""
Find the unit vector along a double precision vector of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vhatg_c.html
:param v1: Vector to be normalized.
:type v1: list[ndim]
:param ndim: Dimension of v1 (and also vout).
:type ndim: int
:return: Unit vector v / abs(v).
:rtype: list[ndim]
"""
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(ndim)
ndim = ctypes.c_int(ndim)
libspice.vhatg_c(v1, ndim, vout)
return stypes.cVectorToPython(vout) | python | def vhatg(v1, ndim):
"""
Find the unit vector along a double precision vector of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vhatg_c.html
:param v1: Vector to be normalized.
:type v1: list[ndim]
:param ndim: Dimension of v1 (and also vout).
:type ndim: int
:return: Unit vector v / abs(v).
:rtype: list[ndim]
"""
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(ndim)
ndim = ctypes.c_int(ndim)
libspice.vhatg_c(v1, ndim, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vhatg",
"(",
"v1",
",",
"ndim",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"ndim",
")",
"ndim",
"=",
"ctypes",
".",
"c_int",
"(",
"ndim",
")",
"libspice",
".",
"vhatg_c",
"(",
"v1",
",",
"ndim",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Find the unit vector along a double precision vector of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vhatg_c.html
:param v1: Vector to be normalized.
:type v1: list[ndim]
:param ndim: Dimension of v1 (and also vout).
:type ndim: int
:return: Unit vector v / abs(v).
:rtype: list[ndim] | [
"Find",
"the",
"unit",
"vector",
"along",
"a",
"double",
"precision",
"vector",
"of",
"arbitrary",
"dimension",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14677-L14694 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vlcom | def vlcom(a, v1, b, v2):
"""
Compute a vector linear combination of two double precision,
3-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vlcom_c.html
:param a: Coefficient of v1
:type a: float
:param v1: Vector in 3-space
:type v1: 3-Element Array of floats
:param b: Coefficient of v2
:type b: float
:param v2: Vector in 3-space
:type v2: 3-Element Array of floats
:return: Linear Vector Combination a*v1 + b*v2.
:rtype: 3-Element Array of floats
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
sumv = stypes.emptyDoubleVector(3)
a = ctypes.c_double(a)
b = ctypes.c_double(b)
libspice.vlcom_c(a, v1, b, v2, sumv)
return stypes.cVectorToPython(sumv) | python | def vlcom(a, v1, b, v2):
"""
Compute a vector linear combination of two double precision,
3-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vlcom_c.html
:param a: Coefficient of v1
:type a: float
:param v1: Vector in 3-space
:type v1: 3-Element Array of floats
:param b: Coefficient of v2
:type b: float
:param v2: Vector in 3-space
:type v2: 3-Element Array of floats
:return: Linear Vector Combination a*v1 + b*v2.
:rtype: 3-Element Array of floats
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
sumv = stypes.emptyDoubleVector(3)
a = ctypes.c_double(a)
b = ctypes.c_double(b)
libspice.vlcom_c(a, v1, b, v2, sumv)
return stypes.cVectorToPython(sumv) | [
"def",
"vlcom",
"(",
"a",
",",
"v1",
",",
"b",
",",
"v2",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"sumv",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"a",
"=",
"ctypes",
".",
"c_double",
"(",
"a",
")",
"b",
"=",
"ctypes",
".",
"c_double",
"(",
"b",
")",
"libspice",
".",
"vlcom_c",
"(",
"a",
",",
"v1",
",",
"b",
",",
"v2",
",",
"sumv",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"sumv",
")"
] | Compute a vector linear combination of two double precision,
3-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vlcom_c.html
:param a: Coefficient of v1
:type a: float
:param v1: Vector in 3-space
:type v1: 3-Element Array of floats
:param b: Coefficient of v2
:type b: float
:param v2: Vector in 3-space
:type v2: 3-Element Array of floats
:return: Linear Vector Combination a*v1 + b*v2.
:rtype: 3-Element Array of floats | [
"Compute",
"a",
"vector",
"linear",
"combination",
"of",
"two",
"double",
"precision",
"3",
"-",
"dimensional",
"vectors",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14698-L14722 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vlcomg | def vlcomg(n, a, v1, b, v2):
"""
Compute a vector linear combination of two double precision
vectors of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vlcomg_c.html
:param n: Dimension of vector space
:type n: int
:param a: Coefficient of v1
:type a: float
:param v1: Vector in n-space
:type v1: list[n]
:param b: Coefficient of v2
:type b: float
:param v2: Vector in n-space
:type v2: list[n]
:return: Linear Vector Combination a*v1 + b*v2
:rtype: list[n]
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
sumv = stypes.emptyDoubleVector(n)
a = ctypes.c_double(a)
b = ctypes.c_double(b)
n = ctypes.c_int(n)
libspice.vlcomg_c(n, a, v1, b, v2, sumv)
return stypes.cVectorToPython(sumv) | python | def vlcomg(n, a, v1, b, v2):
"""
Compute a vector linear combination of two double precision
vectors of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vlcomg_c.html
:param n: Dimension of vector space
:type n: int
:param a: Coefficient of v1
:type a: float
:param v1: Vector in n-space
:type v1: list[n]
:param b: Coefficient of v2
:type b: float
:param v2: Vector in n-space
:type v2: list[n]
:return: Linear Vector Combination a*v1 + b*v2
:rtype: list[n]
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
sumv = stypes.emptyDoubleVector(n)
a = ctypes.c_double(a)
b = ctypes.c_double(b)
n = ctypes.c_int(n)
libspice.vlcomg_c(n, a, v1, b, v2, sumv)
return stypes.cVectorToPython(sumv) | [
"def",
"vlcomg",
"(",
"n",
",",
"a",
",",
"v1",
",",
"b",
",",
"v2",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"sumv",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"n",
")",
"a",
"=",
"ctypes",
".",
"c_double",
"(",
"a",
")",
"b",
"=",
"ctypes",
".",
"c_double",
"(",
"b",
")",
"n",
"=",
"ctypes",
".",
"c_int",
"(",
"n",
")",
"libspice",
".",
"vlcomg_c",
"(",
"n",
",",
"a",
",",
"v1",
",",
"b",
",",
"v2",
",",
"sumv",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"sumv",
")"
] | Compute a vector linear combination of two double precision
vectors of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vlcomg_c.html
:param n: Dimension of vector space
:type n: int
:param a: Coefficient of v1
:type a: float
:param v1: Vector in n-space
:type v1: list[n]
:param b: Coefficient of v2
:type b: float
:param v2: Vector in n-space
:type v2: list[n]
:return: Linear Vector Combination a*v1 + b*v2
:rtype: list[n] | [
"Compute",
"a",
"vector",
"linear",
"combination",
"of",
"two",
"double",
"precision",
"vectors",
"of",
"arbitrary",
"dimension",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14760-L14787 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vminug | def vminug(vin, ndim):
"""
Negate a double precision vector of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vminug_c.html
:param vin: ndim-dimensional double precision vector to be negated.
:type vin: Array of floats
:param ndim: Dimension of vin.
:type ndim: int
:return: ndim-dimensional double precision vector equal to -vin.
:rtype: list[ndim]
"""
vin = stypes.toDoubleVector(vin)
vout = stypes.emptyDoubleVector(ndim)
ndim = ctypes.c_int(ndim)
libspice.vminug_c(vin, ndim, vout)
return stypes.cVectorToPython(vout) | python | def vminug(vin, ndim):
"""
Negate a double precision vector of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vminug_c.html
:param vin: ndim-dimensional double precision vector to be negated.
:type vin: Array of floats
:param ndim: Dimension of vin.
:type ndim: int
:return: ndim-dimensional double precision vector equal to -vin.
:rtype: list[ndim]
"""
vin = stypes.toDoubleVector(vin)
vout = stypes.emptyDoubleVector(ndim)
ndim = ctypes.c_int(ndim)
libspice.vminug_c(vin, ndim, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vminug",
"(",
"vin",
",",
"ndim",
")",
":",
"vin",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"vin",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"ndim",
")",
"ndim",
"=",
"ctypes",
".",
"c_int",
"(",
"ndim",
")",
"libspice",
".",
"vminug_c",
"(",
"vin",
",",
"ndim",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Negate a double precision vector of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vminug_c.html
:param vin: ndim-dimensional double precision vector to be negated.
:type vin: Array of floats
:param ndim: Dimension of vin.
:type ndim: int
:return: ndim-dimensional double precision vector equal to -vin.
:rtype: list[ndim] | [
"Negate",
"a",
"double",
"precision",
"vector",
"of",
"arbitrary",
"dimension",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14791-L14808 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vminus | def vminus(vin):
"""
Negate a double precision 3-dimensional vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vminus_c.html
:param vin: Vector to be negated.
:type vin: 3-Element Array of floats
:return: Negated vector -v1.
:rtype: 3-Element Array of floats
"""
vin = stypes.toDoubleVector(vin)
vout = stypes.emptyDoubleVector(3)
libspice.vminus_c(vin, vout)
return stypes.cVectorToPython(vout) | python | def vminus(vin):
"""
Negate a double precision 3-dimensional vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vminus_c.html
:param vin: Vector to be negated.
:type vin: 3-Element Array of floats
:return: Negated vector -v1.
:rtype: 3-Element Array of floats
"""
vin = stypes.toDoubleVector(vin)
vout = stypes.emptyDoubleVector(3)
libspice.vminus_c(vin, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vminus",
"(",
"vin",
")",
":",
"vin",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"vin",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"libspice",
".",
"vminus_c",
"(",
"vin",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Negate a double precision 3-dimensional vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vminus_c.html
:param vin: Vector to be negated.
:type vin: 3-Element Array of floats
:return: Negated vector -v1.
:rtype: 3-Element Array of floats | [
"Negate",
"a",
"double",
"precision",
"3",
"-",
"dimensional",
"vector",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14812-L14826 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vnormg | def vnormg(v, ndim):
"""
Compute the magnitude of a double precision vector of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vnormg_c.html
:param v: Vector whose magnitude is to be found.
:type v: Array of floats
:param ndim: Dimension of v
:type ndim: int
:return: magnitude of v calculated in a numerically stable way
:rtype: float
"""
v = stypes.toDoubleVector(v)
ndim = ctypes.c_int(ndim)
return libspice.vnormg_c(v, ndim) | python | def vnormg(v, ndim):
"""
Compute the magnitude of a double precision vector of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vnormg_c.html
:param v: Vector whose magnitude is to be found.
:type v: Array of floats
:param ndim: Dimension of v
:type ndim: int
:return: magnitude of v calculated in a numerically stable way
:rtype: float
"""
v = stypes.toDoubleVector(v)
ndim = ctypes.c_int(ndim)
return libspice.vnormg_c(v, ndim) | [
"def",
"vnormg",
"(",
"v",
",",
"ndim",
")",
":",
"v",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v",
")",
"ndim",
"=",
"ctypes",
".",
"c_int",
"(",
"ndim",
")",
"return",
"libspice",
".",
"vnormg_c",
"(",
"v",
",",
"ndim",
")"
] | Compute the magnitude of a double precision vector of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vnormg_c.html
:param v: Vector whose magnitude is to be found.
:type v: Array of floats
:param ndim: Dimension of v
:type ndim: int
:return: magnitude of v calculated in a numerically stable way
:rtype: float | [
"Compute",
"the",
"magnitude",
"of",
"a",
"double",
"precision",
"vector",
"of",
"arbitrary",
"dimension",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14846-L14861 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vpack | def vpack(x, y, z):
"""
Pack three scalar components into a vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vpack_c.html
:param x: first scalar component
:type x: float
:param y: second scalar component
:type y: float
:param z: third scalar component
:type z: float
:return: Equivalent 3-vector.
:rtype: 3-Element Array of floats
"""
x = ctypes.c_double(x)
y = ctypes.c_double(y)
z = ctypes.c_double(z)
vout = stypes.emptyDoubleVector(3)
libspice.vpack_c(x, y, z, vout)
return stypes.cVectorToPython(vout) | python | def vpack(x, y, z):
"""
Pack three scalar components into a vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vpack_c.html
:param x: first scalar component
:type x: float
:param y: second scalar component
:type y: float
:param z: third scalar component
:type z: float
:return: Equivalent 3-vector.
:rtype: 3-Element Array of floats
"""
x = ctypes.c_double(x)
y = ctypes.c_double(y)
z = ctypes.c_double(z)
vout = stypes.emptyDoubleVector(3)
libspice.vpack_c(x, y, z, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vpack",
"(",
"x",
",",
"y",
",",
"z",
")",
":",
"x",
"=",
"ctypes",
".",
"c_double",
"(",
"x",
")",
"y",
"=",
"ctypes",
".",
"c_double",
"(",
"y",
")",
"z",
"=",
"ctypes",
".",
"c_double",
"(",
"z",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"libspice",
".",
"vpack_c",
"(",
"x",
",",
"y",
",",
"z",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Pack three scalar components into a vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vpack_c.html
:param x: first scalar component
:type x: float
:param y: second scalar component
:type y: float
:param z: third scalar component
:type z: float
:return: Equivalent 3-vector.
:rtype: 3-Element Array of floats | [
"Pack",
"three",
"scalar",
"components",
"into",
"a",
"vector",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14865-L14885 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vperp | def vperp(a, b):
"""
Find the component of a vector that is perpendicular to a second
vector. All vectors are 3-dimensional.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vperp_c.html
:param a: The vector whose orthogonal component is sought.
:type a: 3-Element Array of floats
:param b: The vector used as the orthogonal reference.
:type b: 3-Element Array of floats
:return: The component of a orthogonal to b.
:rtype: 3-Element Array of floats
"""
a = stypes.toDoubleVector(a)
b = stypes.toDoubleVector(b)
vout = stypes.emptyDoubleVector(3)
libspice.vperp_c(a, b, vout)
return stypes.cVectorToPython(vout) | python | def vperp(a, b):
"""
Find the component of a vector that is perpendicular to a second
vector. All vectors are 3-dimensional.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vperp_c.html
:param a: The vector whose orthogonal component is sought.
:type a: 3-Element Array of floats
:param b: The vector used as the orthogonal reference.
:type b: 3-Element Array of floats
:return: The component of a orthogonal to b.
:rtype: 3-Element Array of floats
"""
a = stypes.toDoubleVector(a)
b = stypes.toDoubleVector(b)
vout = stypes.emptyDoubleVector(3)
libspice.vperp_c(a, b, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vperp",
"(",
"a",
",",
"b",
")",
":",
"a",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"a",
")",
"b",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"b",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"libspice",
".",
"vperp_c",
"(",
"a",
",",
"b",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Find the component of a vector that is perpendicular to a second
vector. All vectors are 3-dimensional.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vperp_c.html
:param a: The vector whose orthogonal component is sought.
:type a: 3-Element Array of floats
:param b: The vector used as the orthogonal reference.
:type b: 3-Element Array of floats
:return: The component of a orthogonal to b.
:rtype: 3-Element Array of floats | [
"Find",
"the",
"component",
"of",
"a",
"vector",
"that",
"is",
"perpendicular",
"to",
"a",
"second",
"vector",
".",
"All",
"vectors",
"are",
"3",
"-",
"dimensional",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14889-L14907 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vprjp | def vprjp(vin, plane):
"""
Project a vector onto a specified plane, orthogonally.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vprjp_c.html
:param vin: The projected vector.
:type vin: 3-Element Array of floats
:param plane: Plane containing vin.
:type plane: spiceypy.utils.support_types.Plane
:return: Vector resulting from projection.
:rtype: 3-Element Array of floats
"""
vin = stypes.toDoubleVector(vin)
vout = stypes.emptyDoubleVector(3)
libspice.vprjp_c(vin, ctypes.byref(plane), vout)
return stypes.cVectorToPython(vout) | python | def vprjp(vin, plane):
"""
Project a vector onto a specified plane, orthogonally.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vprjp_c.html
:param vin: The projected vector.
:type vin: 3-Element Array of floats
:param plane: Plane containing vin.
:type plane: spiceypy.utils.support_types.Plane
:return: Vector resulting from projection.
:rtype: 3-Element Array of floats
"""
vin = stypes.toDoubleVector(vin)
vout = stypes.emptyDoubleVector(3)
libspice.vprjp_c(vin, ctypes.byref(plane), vout)
return stypes.cVectorToPython(vout) | [
"def",
"vprjp",
"(",
"vin",
",",
"plane",
")",
":",
"vin",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"vin",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"libspice",
".",
"vprjp_c",
"(",
"vin",
",",
"ctypes",
".",
"byref",
"(",
"plane",
")",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Project a vector onto a specified plane, orthogonally.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vprjp_c.html
:param vin: The projected vector.
:type vin: 3-Element Array of floats
:param plane: Plane containing vin.
:type plane: spiceypy.utils.support_types.Plane
:return: Vector resulting from projection.
:rtype: 3-Element Array of floats | [
"Project",
"a",
"vector",
"onto",
"a",
"specified",
"plane",
"orthogonally",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14911-L14927 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vprjpi | def vprjpi(vin, projpl, invpl):
"""
Find the vector in a specified plane that maps to a specified
vector in another plane under orthogonal projection.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vprjpi_c.html
:param vin: The projected vector.
:type vin: 3-Element Array of floats
:param projpl: Plane containing vin.
:type projpl: spiceypy.utils.support_types.Plane
:param invpl: Plane containing inverse image of vin.
:type invpl: spiceypy.utils.support_types.Plane
:return: Inverse projection of vin.
:rtype: list
"""
vin = stypes.toDoubleVector(vin)
vout = stypes.emptyDoubleVector(3)
found = ctypes.c_int()
libspice.vprjpi_c(vin, ctypes.byref(projpl), ctypes.byref(invpl), vout,
ctypes.byref(found))
return stypes.cVectorToPython(vout), bool(found.value) | python | def vprjpi(vin, projpl, invpl):
"""
Find the vector in a specified plane that maps to a specified
vector in another plane under orthogonal projection.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vprjpi_c.html
:param vin: The projected vector.
:type vin: 3-Element Array of floats
:param projpl: Plane containing vin.
:type projpl: spiceypy.utils.support_types.Plane
:param invpl: Plane containing inverse image of vin.
:type invpl: spiceypy.utils.support_types.Plane
:return: Inverse projection of vin.
:rtype: list
"""
vin = stypes.toDoubleVector(vin)
vout = stypes.emptyDoubleVector(3)
found = ctypes.c_int()
libspice.vprjpi_c(vin, ctypes.byref(projpl), ctypes.byref(invpl), vout,
ctypes.byref(found))
return stypes.cVectorToPython(vout), bool(found.value) | [
"def",
"vprjpi",
"(",
"vin",
",",
"projpl",
",",
"invpl",
")",
":",
"vin",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"vin",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"found",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"libspice",
".",
"vprjpi_c",
"(",
"vin",
",",
"ctypes",
".",
"byref",
"(",
"projpl",
")",
",",
"ctypes",
".",
"byref",
"(",
"invpl",
")",
",",
"vout",
",",
"ctypes",
".",
"byref",
"(",
"found",
")",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")",
",",
"bool",
"(",
"found",
".",
"value",
")"
] | Find the vector in a specified plane that maps to a specified
vector in another plane under orthogonal projection.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vprjpi_c.html
:param vin: The projected vector.
:type vin: 3-Element Array of floats
:param projpl: Plane containing vin.
:type projpl: spiceypy.utils.support_types.Plane
:param invpl: Plane containing inverse image of vin.
:type invpl: spiceypy.utils.support_types.Plane
:return: Inverse projection of vin.
:rtype: list | [
"Find",
"the",
"vector",
"in",
"a",
"specified",
"plane",
"that",
"maps",
"to",
"a",
"specified",
"vector",
"in",
"another",
"plane",
"under",
"orthogonal",
"projection",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14932-L14953 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vproj | def vproj(a, b):
"""
Find the projection of one vector onto another vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vproj_c.html
:param a: The vector to be projected.
:type a: 3-Element Array of floats
:param b: The vector onto which a is to be projected.
:type b: 3-Element Array of floats
:return: The projection of a onto b.
:rtype: 3-Element Array of floats
"""
a = stypes.toDoubleVector(a)
b = stypes.toDoubleVector(b)
vout = stypes.emptyDoubleVector(3)
libspice.vproj_c(a, b, vout)
return stypes.cVectorToPython(vout) | python | def vproj(a, b):
"""
Find the projection of one vector onto another vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vproj_c.html
:param a: The vector to be projected.
:type a: 3-Element Array of floats
:param b: The vector onto which a is to be projected.
:type b: 3-Element Array of floats
:return: The projection of a onto b.
:rtype: 3-Element Array of floats
"""
a = stypes.toDoubleVector(a)
b = stypes.toDoubleVector(b)
vout = stypes.emptyDoubleVector(3)
libspice.vproj_c(a, b, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vproj",
"(",
"a",
",",
"b",
")",
":",
"a",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"a",
")",
"b",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"b",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"libspice",
".",
"vproj_c",
"(",
"a",
",",
"b",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Find the projection of one vector onto another vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vproj_c.html
:param a: The vector to be projected.
:type a: 3-Element Array of floats
:param b: The vector onto which a is to be projected.
:type b: 3-Element Array of floats
:return: The projection of a onto b.
:rtype: 3-Element Array of floats | [
"Find",
"the",
"projection",
"of",
"one",
"vector",
"onto",
"another",
"vector",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14957-L14974 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vrel | def vrel(v1, v2):
"""
Return the relative difference between two 3-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vrel_c.html
:param v1: First vector
:type v1: 3-Element Array of floats
:param v2: Second vector
:type v2: 3-Element Array of floats
:return: the relative difference between v1 and v2.
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
return libspice.vrel_c(v1, v2) | python | def vrel(v1, v2):
"""
Return the relative difference between two 3-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vrel_c.html
:param v1: First vector
:type v1: 3-Element Array of floats
:param v2: Second vector
:type v2: 3-Element Array of floats
:return: the relative difference between v1 and v2.
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
return libspice.vrel_c(v1, v2) | [
"def",
"vrel",
"(",
"v1",
",",
"v2",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"return",
"libspice",
".",
"vrel_c",
"(",
"v1",
",",
"v2",
")"
] | Return the relative difference between two 3-dimensional vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vrel_c.html
:param v1: First vector
:type v1: 3-Element Array of floats
:param v2: Second vector
:type v2: 3-Element Array of floats
:return: the relative difference between v1 and v2.
:rtype: float | [
"Return",
"the",
"relative",
"difference",
"between",
"two",
"3",
"-",
"dimensional",
"vectors",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14978-L14993 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vrelg | def vrelg(v1, v2, ndim):
"""
Return the relative difference between two vectors of general dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vrelg_c.html
:param v1: First vector
:type v1: Array of floats
:param v2: Second vector
:type v2: Array of floats
:param ndim: Dimension of v1 and v2.
:type ndim: int
:return: the relative difference between v1 and v2.
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
ndim = ctypes.c_int(ndim)
return libspice.vrelg_c(v1, v2, ndim) | python | def vrelg(v1, v2, ndim):
"""
Return the relative difference between two vectors of general dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vrelg_c.html
:param v1: First vector
:type v1: Array of floats
:param v2: Second vector
:type v2: Array of floats
:param ndim: Dimension of v1 and v2.
:type ndim: int
:return: the relative difference between v1 and v2.
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
ndim = ctypes.c_int(ndim)
return libspice.vrelg_c(v1, v2, ndim) | [
"def",
"vrelg",
"(",
"v1",
",",
"v2",
",",
"ndim",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"ndim",
"=",
"ctypes",
".",
"c_int",
"(",
"ndim",
")",
"return",
"libspice",
".",
"vrelg_c",
"(",
"v1",
",",
"v2",
",",
"ndim",
")"
] | Return the relative difference between two vectors of general dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vrelg_c.html
:param v1: First vector
:type v1: Array of floats
:param v2: Second vector
:type v2: Array of floats
:param ndim: Dimension of v1 and v2.
:type ndim: int
:return: the relative difference between v1 and v2.
:rtype: float | [
"Return",
"the",
"relative",
"difference",
"between",
"two",
"vectors",
"of",
"general",
"dimension",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L14997-L15015 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vrotv | def vrotv(v, axis, theta):
"""
Rotate a vector about a specified axis vector by a
specified angle and return the rotated vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vrotv_c.html
:param v: Vector to be rotated.
:type v: 3-Element Array of floats
:param axis: Axis of the rotation.
:type axis: 3-Element Array of floats
:param theta: Angle of rotation (radians).
:type theta: float
:return: Result of rotating v about axis by theta
:rtype: 3-Element Array of floats
"""
v = stypes.toDoubleVector(v)
axis = stypes.toDoubleVector(axis)
theta = ctypes.c_double(theta)
r = stypes.emptyDoubleVector(3)
libspice.vrotv_c(v, axis, theta, r)
return stypes.cVectorToPython(r) | python | def vrotv(v, axis, theta):
"""
Rotate a vector about a specified axis vector by a
specified angle and return the rotated vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vrotv_c.html
:param v: Vector to be rotated.
:type v: 3-Element Array of floats
:param axis: Axis of the rotation.
:type axis: 3-Element Array of floats
:param theta: Angle of rotation (radians).
:type theta: float
:return: Result of rotating v about axis by theta
:rtype: 3-Element Array of floats
"""
v = stypes.toDoubleVector(v)
axis = stypes.toDoubleVector(axis)
theta = ctypes.c_double(theta)
r = stypes.emptyDoubleVector(3)
libspice.vrotv_c(v, axis, theta, r)
return stypes.cVectorToPython(r) | [
"def",
"vrotv",
"(",
"v",
",",
"axis",
",",
"theta",
")",
":",
"v",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v",
")",
"axis",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"axis",
")",
"theta",
"=",
"ctypes",
".",
"c_double",
"(",
"theta",
")",
"r",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"libspice",
".",
"vrotv_c",
"(",
"v",
",",
"axis",
",",
"theta",
",",
"r",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"r",
")"
] | Rotate a vector about a specified axis vector by a
specified angle and return the rotated vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vrotv_c.html
:param v: Vector to be rotated.
:type v: 3-Element Array of floats
:param axis: Axis of the rotation.
:type axis: 3-Element Array of floats
:param theta: Angle of rotation (radians).
:type theta: float
:return: Result of rotating v about axis by theta
:rtype: 3-Element Array of floats | [
"Rotate",
"a",
"vector",
"about",
"a",
"specified",
"axis",
"vector",
"by",
"a",
"specified",
"angle",
"and",
"return",
"the",
"rotated",
"vector",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15019-L15040 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vscl | def vscl(s, v1):
"""
Multiply a scalar and a 3-dimensional double precision vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vscl_c.html
:param s: Scalar to multiply a vector
:type s: float
:param v1: Vector to be multiplied
:type v1: 3-Element Array of floats
:return: Product vector, s*v1.
:rtype: 3-Element Array of floats
"""
s = ctypes.c_double(s)
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(3)
libspice.vscl_c(s, v1, vout)
return stypes.cVectorToPython(vout) | python | def vscl(s, v1):
"""
Multiply a scalar and a 3-dimensional double precision vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vscl_c.html
:param s: Scalar to multiply a vector
:type s: float
:param v1: Vector to be multiplied
:type v1: 3-Element Array of floats
:return: Product vector, s*v1.
:rtype: 3-Element Array of floats
"""
s = ctypes.c_double(s)
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(3)
libspice.vscl_c(s, v1, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vscl",
"(",
"s",
",",
"v1",
")",
":",
"s",
"=",
"ctypes",
".",
"c_double",
"(",
"s",
")",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"libspice",
".",
"vscl_c",
"(",
"s",
",",
"v1",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Multiply a scalar and a 3-dimensional double precision vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vscl_c.html
:param s: Scalar to multiply a vector
:type s: float
:param v1: Vector to be multiplied
:type v1: 3-Element Array of floats
:return: Product vector, s*v1.
:rtype: 3-Element Array of floats | [
"Multiply",
"a",
"scalar",
"and",
"a",
"3",
"-",
"dimensional",
"double",
"precision",
"vector",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15044-L15061 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vsclg | def vsclg(s, v1, ndim):
"""
Multiply a scalar and a double precision vector of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsclg_c.html
:param s: Scalar to multiply a vector
:type s: float
:param v1: Vector to be multiplied
:type v1: Array of floats
:param ndim: Dimension of v1
:type ndim: int
:return: Product vector, s*v1.
:rtype: Array of floats
"""
s = ctypes.c_double(s)
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(ndim)
ndim = ctypes.c_int(ndim)
libspice.vsclg_c(s, v1, ndim, vout)
return stypes.cVectorToPython(vout) | python | def vsclg(s, v1, ndim):
"""
Multiply a scalar and a double precision vector of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsclg_c.html
:param s: Scalar to multiply a vector
:type s: float
:param v1: Vector to be multiplied
:type v1: Array of floats
:param ndim: Dimension of v1
:type ndim: int
:return: Product vector, s*v1.
:rtype: Array of floats
"""
s = ctypes.c_double(s)
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(ndim)
ndim = ctypes.c_int(ndim)
libspice.vsclg_c(s, v1, ndim, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vsclg",
"(",
"s",
",",
"v1",
",",
"ndim",
")",
":",
"s",
"=",
"ctypes",
".",
"c_double",
"(",
"s",
")",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"ndim",
")",
"ndim",
"=",
"ctypes",
".",
"c_int",
"(",
"ndim",
")",
"libspice",
".",
"vsclg_c",
"(",
"s",
",",
"v1",
",",
"ndim",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Multiply a scalar and a double precision vector of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsclg_c.html
:param s: Scalar to multiply a vector
:type s: float
:param v1: Vector to be multiplied
:type v1: Array of floats
:param ndim: Dimension of v1
:type ndim: int
:return: Product vector, s*v1.
:rtype: Array of floats | [
"Multiply",
"a",
"scalar",
"and",
"a",
"double",
"precision",
"vector",
"of",
"arbitrary",
"dimension",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15065-L15085 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vsep | def vsep(v1, v2):
"""
Find the separation angle in radians between two double
precision, 3-dimensional vectors. This angle is defined as zero
if either vector is zero.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsep_c.html
:param v1: First vector
:type v1: 3-Element Array of floats
:param v2: Second vector
:type v2: 3-Element Array of floats
:return: separation angle in radians
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
return libspice.vsep_c(v1, v2) | python | def vsep(v1, v2):
"""
Find the separation angle in radians between two double
precision, 3-dimensional vectors. This angle is defined as zero
if either vector is zero.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsep_c.html
:param v1: First vector
:type v1: 3-Element Array of floats
:param v2: Second vector
:type v2: 3-Element Array of floats
:return: separation angle in radians
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
return libspice.vsep_c(v1, v2) | [
"def",
"vsep",
"(",
"v1",
",",
"v2",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"return",
"libspice",
".",
"vsep_c",
"(",
"v1",
",",
"v2",
")"
] | Find the separation angle in radians between two double
precision, 3-dimensional vectors. This angle is defined as zero
if either vector is zero.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsep_c.html
:param v1: First vector
:type v1: 3-Element Array of floats
:param v2: Second vector
:type v2: 3-Element Array of floats
:return: separation angle in radians
:rtype: float | [
"Find",
"the",
"separation",
"angle",
"in",
"radians",
"between",
"two",
"double",
"precision",
"3",
"-",
"dimensional",
"vectors",
".",
"This",
"angle",
"is",
"defined",
"as",
"zero",
"if",
"either",
"vector",
"is",
"zero",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15089-L15106 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vsepg | def vsepg(v1, v2, ndim):
"""
Find the separation angle in radians between two double
precision vectors of arbitrary dimension. This angle is defined
as zero if either vector is zero.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsepg_c.html
:param v1: First vector
:type v1: Array of floats
:param v2: Second vector
:type v2: Array of floats
:param ndim: The number of elements in v1 and v2.
:type ndim: int
:return: separation angle in radians
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
ndim = ctypes.c_int(ndim)
return libspice.vsepg_c(v1, v2, ndim) | python | def vsepg(v1, v2, ndim):
"""
Find the separation angle in radians between two double
precision vectors of arbitrary dimension. This angle is defined
as zero if either vector is zero.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsepg_c.html
:param v1: First vector
:type v1: Array of floats
:param v2: Second vector
:type v2: Array of floats
:param ndim: The number of elements in v1 and v2.
:type ndim: int
:return: separation angle in radians
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
ndim = ctypes.c_int(ndim)
return libspice.vsepg_c(v1, v2, ndim) | [
"def",
"vsepg",
"(",
"v1",
",",
"v2",
",",
"ndim",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"ndim",
"=",
"ctypes",
".",
"c_int",
"(",
"ndim",
")",
"return",
"libspice",
".",
"vsepg_c",
"(",
"v1",
",",
"v2",
",",
"ndim",
")"
] | Find the separation angle in radians between two double
precision vectors of arbitrary dimension. This angle is defined
as zero if either vector is zero.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsepg_c.html
:param v1: First vector
:type v1: Array of floats
:param v2: Second vector
:type v2: Array of floats
:param ndim: The number of elements in v1 and v2.
:type ndim: int
:return: separation angle in radians
:rtype: float | [
"Find",
"the",
"separation",
"angle",
"in",
"radians",
"between",
"two",
"double",
"precision",
"vectors",
"of",
"arbitrary",
"dimension",
".",
"This",
"angle",
"is",
"defined",
"as",
"zero",
"if",
"either",
"vector",
"is",
"zero",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15110-L15130 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vsub | def vsub(v1, v2):
"""
Compute the difference between two 3-dimensional,
double precision vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsub_c.html
:param v1: First vector (minuend).
:type v1: 3-Element Array of floats
:param v2: Second vector (subtrahend).
:type v2: 3-Element Array of floats
:return: Difference vector, v1 - v2.
:rtype: 3-Element Array of floats
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
vout = stypes.emptyDoubleVector(3)
libspice.vsub_c(v1, v2, vout)
return stypes.cVectorToPython(vout) | python | def vsub(v1, v2):
"""
Compute the difference between two 3-dimensional,
double precision vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsub_c.html
:param v1: First vector (minuend).
:type v1: 3-Element Array of floats
:param v2: Second vector (subtrahend).
:type v2: 3-Element Array of floats
:return: Difference vector, v1 - v2.
:rtype: 3-Element Array of floats
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
vout = stypes.emptyDoubleVector(3)
libspice.vsub_c(v1, v2, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vsub",
"(",
"v1",
",",
"v2",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"3",
")",
"libspice",
".",
"vsub_c",
"(",
"v1",
",",
"v2",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Compute the difference between two 3-dimensional,
double precision vectors.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsub_c.html
:param v1: First vector (minuend).
:type v1: 3-Element Array of floats
:param v2: Second vector (subtrahend).
:type v2: 3-Element Array of floats
:return: Difference vector, v1 - v2.
:rtype: 3-Element Array of floats | [
"Compute",
"the",
"difference",
"between",
"two",
"3",
"-",
"dimensional",
"double",
"precision",
"vectors",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15134-L15152 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vsubg | def vsubg(v1, v2, ndim):
"""
Compute the difference between two double precision
vectors of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsubg_c.html
:param v1: First vector (minuend).
:type v1: Array of floats
:param v2: Second vector (subtrahend).
:type v2: Array of floats
:param ndim: Dimension of v1, v2, and vout.
:type ndim: int
:return: Difference vector, v1 - v2.
:rtype: Array of floats
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
vout = stypes.emptyDoubleVector(ndim)
ndim = ctypes.c_int(ndim)
libspice.vsubg_c(v1, v2, ndim, vout)
return stypes.cVectorToPython(vout) | python | def vsubg(v1, v2, ndim):
"""
Compute the difference between two double precision
vectors of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsubg_c.html
:param v1: First vector (minuend).
:type v1: Array of floats
:param v2: Second vector (subtrahend).
:type v2: Array of floats
:param ndim: Dimension of v1, v2, and vout.
:type ndim: int
:return: Difference vector, v1 - v2.
:rtype: Array of floats
"""
v1 = stypes.toDoubleVector(v1)
v2 = stypes.toDoubleVector(v2)
vout = stypes.emptyDoubleVector(ndim)
ndim = ctypes.c_int(ndim)
libspice.vsubg_c(v1, v2, ndim, vout)
return stypes.cVectorToPython(vout) | [
"def",
"vsubg",
"(",
"v1",
",",
"v2",
",",
"ndim",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"vout",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"ndim",
")",
"ndim",
"=",
"ctypes",
".",
"c_int",
"(",
"ndim",
")",
"libspice",
".",
"vsubg_c",
"(",
"v1",
",",
"v2",
",",
"ndim",
",",
"vout",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"vout",
")"
] | Compute the difference between two double precision
vectors of arbitrary dimension.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsubg_c.html
:param v1: First vector (minuend).
:type v1: Array of floats
:param v2: Second vector (subtrahend).
:type v2: Array of floats
:param ndim: Dimension of v1, v2, and vout.
:type ndim: int
:return: Difference vector, v1 - v2.
:rtype: Array of floats | [
"Compute",
"the",
"difference",
"between",
"two",
"double",
"precision",
"vectors",
"of",
"arbitrary",
"dimension",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15156-L15177 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vtmv | def vtmv(v1, matrix, v2):
"""
Multiply the transpose of a 3-dimensional column vector
a 3x3 matrix, and a 3-dimensional column vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vtmv_c.html
:param v1: 3 dimensional double precision column vector.
:type v1: 3-Element Array of floats
:param matrix: 3x3 double precision matrix.
:type matrix: 3x3-Element Array of floats
:param v2: 3 dimensional double precision column vector.
:type v2: 3-Element Array of floats
:return: the result of (v1**t * matrix * v2 ).
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
matrix = stypes.toDoubleMatrix(matrix)
v2 = stypes.toDoubleVector(v2)
return libspice.vtmv_c(v1, matrix, v2) | python | def vtmv(v1, matrix, v2):
"""
Multiply the transpose of a 3-dimensional column vector
a 3x3 matrix, and a 3-dimensional column vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vtmv_c.html
:param v1: 3 dimensional double precision column vector.
:type v1: 3-Element Array of floats
:param matrix: 3x3 double precision matrix.
:type matrix: 3x3-Element Array of floats
:param v2: 3 dimensional double precision column vector.
:type v2: 3-Element Array of floats
:return: the result of (v1**t * matrix * v2 ).
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
matrix = stypes.toDoubleMatrix(matrix)
v2 = stypes.toDoubleVector(v2)
return libspice.vtmv_c(v1, matrix, v2) | [
"def",
"vtmv",
"(",
"v1",
",",
"matrix",
",",
"v2",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"matrix",
"=",
"stypes",
".",
"toDoubleMatrix",
"(",
"matrix",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"return",
"libspice",
".",
"vtmv_c",
"(",
"v1",
",",
"matrix",
",",
"v2",
")"
] | Multiply the transpose of a 3-dimensional column vector
a 3x3 matrix, and a 3-dimensional column vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vtmv_c.html
:param v1: 3 dimensional double precision column vector.
:type v1: 3-Element Array of floats
:param matrix: 3x3 double precision matrix.
:type matrix: 3x3-Element Array of floats
:param v2: 3 dimensional double precision column vector.
:type v2: 3-Element Array of floats
:return: the result of (v1**t * matrix * v2 ).
:rtype: float | [
"Multiply",
"the",
"transpose",
"of",
"a",
"3",
"-",
"dimensional",
"column",
"vector",
"a",
"3x3",
"matrix",
"and",
"a",
"3",
"-",
"dimensional",
"column",
"vector",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15181-L15200 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vtmvg | def vtmvg(v1, matrix, v2, nrow, ncol):
"""
Multiply the transpose of a n-dimensional
column vector a nxm matrix,
and a m-dimensional column vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vtmvg_c.html
:param v1: n-dimensional double precision column vector.
:type v1: Array of floats
:param matrix: nxm double precision matrix.
:type matrix: NxM-Element Array of floats
:param v2: m-dimensional double porecision column vector.
:type v2: Array of floats
:param nrow: Number of rows in matrix (number of rows in v1.)
:type nrow: int
:param ncol: Number of columns in matrix (number of rows in v2.)
:type ncol: int
:return: the result of (v1**t * matrix * v2 )
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
matrix = stypes.toDoubleMatrix(matrix)
v2 = stypes.toDoubleVector(v2)
nrow = ctypes.c_int(nrow)
ncol = ctypes.c_int(ncol)
return libspice.vtmvg_c(v1, matrix, v2, nrow, ncol) | python | def vtmvg(v1, matrix, v2, nrow, ncol):
"""
Multiply the transpose of a n-dimensional
column vector a nxm matrix,
and a m-dimensional column vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vtmvg_c.html
:param v1: n-dimensional double precision column vector.
:type v1: Array of floats
:param matrix: nxm double precision matrix.
:type matrix: NxM-Element Array of floats
:param v2: m-dimensional double porecision column vector.
:type v2: Array of floats
:param nrow: Number of rows in matrix (number of rows in v1.)
:type nrow: int
:param ncol: Number of columns in matrix (number of rows in v2.)
:type ncol: int
:return: the result of (v1**t * matrix * v2 )
:rtype: float
"""
v1 = stypes.toDoubleVector(v1)
matrix = stypes.toDoubleMatrix(matrix)
v2 = stypes.toDoubleVector(v2)
nrow = ctypes.c_int(nrow)
ncol = ctypes.c_int(ncol)
return libspice.vtmvg_c(v1, matrix, v2, nrow, ncol) | [
"def",
"vtmvg",
"(",
"v1",
",",
"matrix",
",",
"v2",
",",
"nrow",
",",
"ncol",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v1",
")",
"matrix",
"=",
"stypes",
".",
"toDoubleMatrix",
"(",
"matrix",
")",
"v2",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v2",
")",
"nrow",
"=",
"ctypes",
".",
"c_int",
"(",
"nrow",
")",
"ncol",
"=",
"ctypes",
".",
"c_int",
"(",
"ncol",
")",
"return",
"libspice",
".",
"vtmvg_c",
"(",
"v1",
",",
"matrix",
",",
"v2",
",",
"nrow",
",",
"ncol",
")"
] | Multiply the transpose of a n-dimensional
column vector a nxm matrix,
and a m-dimensional column vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vtmvg_c.html
:param v1: n-dimensional double precision column vector.
:type v1: Array of floats
:param matrix: nxm double precision matrix.
:type matrix: NxM-Element Array of floats
:param v2: m-dimensional double porecision column vector.
:type v2: Array of floats
:param nrow: Number of rows in matrix (number of rows in v1.)
:type nrow: int
:param ncol: Number of columns in matrix (number of rows in v2.)
:type ncol: int
:return: the result of (v1**t * matrix * v2 )
:rtype: float | [
"Multiply",
"the",
"transpose",
"of",
"a",
"n",
"-",
"dimensional",
"column",
"vector",
"a",
"nxm",
"matrix",
"and",
"a",
"m",
"-",
"dimensional",
"column",
"vector",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15204-L15230 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vupack | def vupack(v):
"""
Unpack three scalar components from a vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vupack_c.html
:param v: Vector
:type v: 3-Element Array of floats
:return: (x, y, z)
:rtype: tuple
"""
v1 = stypes.toDoubleVector(v)
x = ctypes.c_double()
y = ctypes.c_double()
z = ctypes.c_double()
libspice.vupack_c(v1, ctypes.byref(x), ctypes.byref(y), ctypes.byref(z))
return x.value, y.value, z.value | python | def vupack(v):
"""
Unpack three scalar components from a vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vupack_c.html
:param v: Vector
:type v: 3-Element Array of floats
:return: (x, y, z)
:rtype: tuple
"""
v1 = stypes.toDoubleVector(v)
x = ctypes.c_double()
y = ctypes.c_double()
z = ctypes.c_double()
libspice.vupack_c(v1, ctypes.byref(x), ctypes.byref(y), ctypes.byref(z))
return x.value, y.value, z.value | [
"def",
"vupack",
"(",
"v",
")",
":",
"v1",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v",
")",
"x",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"y",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"z",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"libspice",
".",
"vupack_c",
"(",
"v1",
",",
"ctypes",
".",
"byref",
"(",
"x",
")",
",",
"ctypes",
".",
"byref",
"(",
"y",
")",
",",
"ctypes",
".",
"byref",
"(",
"z",
")",
")",
"return",
"x",
".",
"value",
",",
"y",
".",
"value",
",",
"z",
".",
"value"
] | Unpack three scalar components from a vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vupack_c.html
:param v: Vector
:type v: 3-Element Array of floats
:return: (x, y, z)
:rtype: tuple | [
"Unpack",
"three",
"scalar",
"components",
"from",
"a",
"vector",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15234-L15250 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vzero | def vzero(v):
"""
Indicate whether a 3-vector is the zero vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vzero_c.html
:param v: Vector to be tested
:type v: 3-Element Array of floats
:return: true if and only if v is the zero vector
:rtype: bool
"""
v = stypes.toDoubleVector(v)
return bool(libspice.vzero_c(v)) | python | def vzero(v):
"""
Indicate whether a 3-vector is the zero vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vzero_c.html
:param v: Vector to be tested
:type v: 3-Element Array of floats
:return: true if and only if v is the zero vector
:rtype: bool
"""
v = stypes.toDoubleVector(v)
return bool(libspice.vzero_c(v)) | [
"def",
"vzero",
"(",
"v",
")",
":",
"v",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v",
")",
"return",
"bool",
"(",
"libspice",
".",
"vzero_c",
"(",
"v",
")",
")"
] | Indicate whether a 3-vector is the zero vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vzero_c.html
:param v: Vector to be tested
:type v: 3-Element Array of floats
:return: true if and only if v is the zero vector
:rtype: bool | [
"Indicate",
"whether",
"a",
"3",
"-",
"vector",
"is",
"the",
"zero",
"vector",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15254-L15266 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | vzerog | def vzerog(v, ndim):
"""
Indicate whether a general-dimensional vector is the zero vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vzerog_c.html
:param v: Vector to be tested
:type v: Array of floats
:param ndim: Dimension of v
:type ndim: int
:return: true if and only if v is the zero vector
:rtype: bool
"""
v = stypes.toDoubleVector(v)
ndim = ctypes.c_int(ndim)
return bool(libspice.vzerog_c(v, ndim)) | python | def vzerog(v, ndim):
"""
Indicate whether a general-dimensional vector is the zero vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vzerog_c.html
:param v: Vector to be tested
:type v: Array of floats
:param ndim: Dimension of v
:type ndim: int
:return: true if and only if v is the zero vector
:rtype: bool
"""
v = stypes.toDoubleVector(v)
ndim = ctypes.c_int(ndim)
return bool(libspice.vzerog_c(v, ndim)) | [
"def",
"vzerog",
"(",
"v",
",",
"ndim",
")",
":",
"v",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"v",
")",
"ndim",
"=",
"ctypes",
".",
"c_int",
"(",
"ndim",
")",
"return",
"bool",
"(",
"libspice",
".",
"vzerog_c",
"(",
"v",
",",
"ndim",
")",
")"
] | Indicate whether a general-dimensional vector is the zero vector.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vzerog_c.html
:param v: Vector to be tested
:type v: Array of floats
:param ndim: Dimension of v
:type ndim: int
:return: true if and only if v is the zero vector
:rtype: bool | [
"Indicate",
"whether",
"a",
"general",
"-",
"dimensional",
"vector",
"is",
"the",
"zero",
"vector",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15270-L15285 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wncomd | def wncomd(left, right, window):
"""
Determine the complement of a double precision window with
respect to a specified interval.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wncomd_c.html
:param left: left endpoints of complement interval.
:type left: float
:param right: right endpoints of complement interval.
:type right: float
:param window: Input window
:type window: spiceypy.utils.support_types.SpiceCell
:return: Complement of window with respect to left and right.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
left = ctypes.c_double(left)
right = ctypes.c_double(right)
result = stypes.SpiceCell.double(window.size)
libspice.wncomd_c(left, right, ctypes.byref(window), result)
return result | python | def wncomd(left, right, window):
"""
Determine the complement of a double precision window with
respect to a specified interval.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wncomd_c.html
:param left: left endpoints of complement interval.
:type left: float
:param right: right endpoints of complement interval.
:type right: float
:param window: Input window
:type window: spiceypy.utils.support_types.SpiceCell
:return: Complement of window with respect to left and right.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
left = ctypes.c_double(left)
right = ctypes.c_double(right)
result = stypes.SpiceCell.double(window.size)
libspice.wncomd_c(left, right, ctypes.byref(window), result)
return result | [
"def",
"wncomd",
"(",
"left",
",",
"right",
",",
"window",
")",
":",
"assert",
"isinstance",
"(",
"window",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"window",
".",
"dtype",
"==",
"1",
"left",
"=",
"ctypes",
".",
"c_double",
"(",
"left",
")",
"right",
"=",
"ctypes",
".",
"c_double",
"(",
"right",
")",
"result",
"=",
"stypes",
".",
"SpiceCell",
".",
"double",
"(",
"window",
".",
"size",
")",
"libspice",
".",
"wncomd_c",
"(",
"left",
",",
"right",
",",
"ctypes",
".",
"byref",
"(",
"window",
")",
",",
"result",
")",
"return",
"result"
] | Determine the complement of a double precision window with
respect to a specified interval.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wncomd_c.html
:param left: left endpoints of complement interval.
:type left: float
:param right: right endpoints of complement interval.
:type right: float
:param window: Input window
:type window: spiceypy.utils.support_types.SpiceCell
:return: Complement of window with respect to left and right.
:rtype: spiceypy.utils.support_types.SpiceCell | [
"Determine",
"the",
"complement",
"of",
"a",
"double",
"precision",
"window",
"with",
"respect",
"to",
"a",
"specified",
"interval",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15310-L15332 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wncond | def wncond(left, right, window):
"""
Contract each of the intervals of a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wncond_c.html
:param left: Amount added to each left endpoint.
:type left: float
:param right: Amount subtracted from each right endpoint.
:type right: float
:param window: Window to be contracted
:type window: spiceypy.utils.support_types.SpiceCell
:return: Contracted Window.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
left = ctypes.c_double(left)
right = ctypes.c_double(right)
libspice.wncond_c(left, right, ctypes.byref(window))
return window | python | def wncond(left, right, window):
"""
Contract each of the intervals of a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wncond_c.html
:param left: Amount added to each left endpoint.
:type left: float
:param right: Amount subtracted from each right endpoint.
:type right: float
:param window: Window to be contracted
:type window: spiceypy.utils.support_types.SpiceCell
:return: Contracted Window.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
left = ctypes.c_double(left)
right = ctypes.c_double(right)
libspice.wncond_c(left, right, ctypes.byref(window))
return window | [
"def",
"wncond",
"(",
"left",
",",
"right",
",",
"window",
")",
":",
"assert",
"isinstance",
"(",
"window",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"window",
".",
"dtype",
"==",
"1",
"left",
"=",
"ctypes",
".",
"c_double",
"(",
"left",
")",
"right",
"=",
"ctypes",
".",
"c_double",
"(",
"right",
")",
"libspice",
".",
"wncond_c",
"(",
"left",
",",
"right",
",",
"ctypes",
".",
"byref",
"(",
"window",
")",
")",
"return",
"window"
] | Contract each of the intervals of a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wncond_c.html
:param left: Amount added to each left endpoint.
:type left: float
:param right: Amount subtracted from each right endpoint.
:type right: float
:param window: Window to be contracted
:type window: spiceypy.utils.support_types.SpiceCell
:return: Contracted Window.
:rtype: spiceypy.utils.support_types.SpiceCell | [
"Contract",
"each",
"of",
"the",
"intervals",
"of",
"a",
"double",
"precision",
"window",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15336-L15356 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wndifd | def wndifd(a, b):
"""
Place the difference of two double precision windows into
a third window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wndifd_c.html
:param a: Input window A.
:type a: spiceypy.utils.support_types.SpiceCell
:param b: Input window B.
:type b: spiceypy.utils.support_types.SpiceCell
:return: Difference of a and b.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(a, stypes.SpiceCell)
assert isinstance(b, stypes.SpiceCell)
assert a.dtype == 1
assert b.dtype == 1
c = stypes.SpiceCell.double(a.size + b.size)
libspice.wndifd_c(ctypes.byref(a), ctypes.byref(b), ctypes.byref(c))
return c | python | def wndifd(a, b):
"""
Place the difference of two double precision windows into
a third window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wndifd_c.html
:param a: Input window A.
:type a: spiceypy.utils.support_types.SpiceCell
:param b: Input window B.
:type b: spiceypy.utils.support_types.SpiceCell
:return: Difference of a and b.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(a, stypes.SpiceCell)
assert isinstance(b, stypes.SpiceCell)
assert a.dtype == 1
assert b.dtype == 1
c = stypes.SpiceCell.double(a.size + b.size)
libspice.wndifd_c(ctypes.byref(a), ctypes.byref(b), ctypes.byref(c))
return c | [
"def",
"wndifd",
"(",
"a",
",",
"b",
")",
":",
"assert",
"isinstance",
"(",
"a",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"isinstance",
"(",
"b",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"a",
".",
"dtype",
"==",
"1",
"assert",
"b",
".",
"dtype",
"==",
"1",
"c",
"=",
"stypes",
".",
"SpiceCell",
".",
"double",
"(",
"a",
".",
"size",
"+",
"b",
".",
"size",
")",
"libspice",
".",
"wndifd_c",
"(",
"ctypes",
".",
"byref",
"(",
"a",
")",
",",
"ctypes",
".",
"byref",
"(",
"b",
")",
",",
"ctypes",
".",
"byref",
"(",
"c",
")",
")",
"return",
"c"
] | Place the difference of two double precision windows into
a third window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wndifd_c.html
:param a: Input window A.
:type a: spiceypy.utils.support_types.SpiceCell
:param b: Input window B.
:type b: spiceypy.utils.support_types.SpiceCell
:return: Difference of a and b.
:rtype: spiceypy.utils.support_types.SpiceCell | [
"Place",
"the",
"difference",
"of",
"two",
"double",
"precision",
"windows",
"into",
"a",
"third",
"window",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15360-L15380 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wnelmd | def wnelmd(point, window):
"""
Determine whether a point is an element of a double precision
window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnelmd_c.html
:param point: Input point.
:type point: float
:param window: Input window
:type window: spiceypy.utils.support_types.SpiceCell
:return: returns True if point is an element of window.
:rtype: bool
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
point = ctypes.c_double(point)
return bool(libspice.wnelmd_c(point, ctypes.byref(window))) | python | def wnelmd(point, window):
"""
Determine whether a point is an element of a double precision
window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnelmd_c.html
:param point: Input point.
:type point: float
:param window: Input window
:type window: spiceypy.utils.support_types.SpiceCell
:return: returns True if point is an element of window.
:rtype: bool
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
point = ctypes.c_double(point)
return bool(libspice.wnelmd_c(point, ctypes.byref(window))) | [
"def",
"wnelmd",
"(",
"point",
",",
"window",
")",
":",
"assert",
"isinstance",
"(",
"window",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"window",
".",
"dtype",
"==",
"1",
"point",
"=",
"ctypes",
".",
"c_double",
"(",
"point",
")",
"return",
"bool",
"(",
"libspice",
".",
"wnelmd_c",
"(",
"point",
",",
"ctypes",
".",
"byref",
"(",
"window",
")",
")",
")"
] | Determine whether a point is an element of a double precision
window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnelmd_c.html
:param point: Input point.
:type point: float
:param window: Input window
:type window: spiceypy.utils.support_types.SpiceCell
:return: returns True if point is an element of window.
:rtype: bool | [
"Determine",
"whether",
"a",
"point",
"is",
"an",
"element",
"of",
"a",
"double",
"precision",
"window",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15384-L15401 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wnexpd | def wnexpd(left, right, window):
"""
Expand each of the intervals of a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnexpd_c.html
:param left: Amount subtracted from each left endpoint.
:type left: float
:param right: Amount added to each right endpoint.
:type right: float
:param window: Window to be expanded.
:type window: spiceypy.utils.support_types.SpiceCell
:return: Expanded Window.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
left = ctypes.c_double(left)
right = ctypes.c_double(right)
libspice.wnexpd_c(left, right, ctypes.byref(window))
return window | python | def wnexpd(left, right, window):
"""
Expand each of the intervals of a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnexpd_c.html
:param left: Amount subtracted from each left endpoint.
:type left: float
:param right: Amount added to each right endpoint.
:type right: float
:param window: Window to be expanded.
:type window: spiceypy.utils.support_types.SpiceCell
:return: Expanded Window.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
left = ctypes.c_double(left)
right = ctypes.c_double(right)
libspice.wnexpd_c(left, right, ctypes.byref(window))
return window | [
"def",
"wnexpd",
"(",
"left",
",",
"right",
",",
"window",
")",
":",
"assert",
"isinstance",
"(",
"window",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"window",
".",
"dtype",
"==",
"1",
"left",
"=",
"ctypes",
".",
"c_double",
"(",
"left",
")",
"right",
"=",
"ctypes",
".",
"c_double",
"(",
"right",
")",
"libspice",
".",
"wnexpd_c",
"(",
"left",
",",
"right",
",",
"ctypes",
".",
"byref",
"(",
"window",
")",
")",
"return",
"window"
] | Expand each of the intervals of a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnexpd_c.html
:param left: Amount subtracted from each left endpoint.
:type left: float
:param right: Amount added to each right endpoint.
:type right: float
:param window: Window to be expanded.
:type window: spiceypy.utils.support_types.SpiceCell
:return: Expanded Window.
:rtype: spiceypy.utils.support_types.SpiceCell | [
"Expand",
"each",
"of",
"the",
"intervals",
"of",
"a",
"double",
"precision",
"window",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15405-L15425 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wnextd | def wnextd(side, window):
"""
Extract the left or right endpoints from a double precision
window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnextd_c.html
:param side: Extract left "L" or right "R" endpoints.
:type side: str
:param window: Window to be extracted.
:type window: spiceypy.utils.support_types.SpiceCell
:return: Extracted Window.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
assert side == 'L' or side == 'R'
side = ctypes.c_char(side.encode(encoding='UTF-8'))
libspice.wnextd_c(side, ctypes.byref(window))
return window | python | def wnextd(side, window):
"""
Extract the left or right endpoints from a double precision
window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnextd_c.html
:param side: Extract left "L" or right "R" endpoints.
:type side: str
:param window: Window to be extracted.
:type window: spiceypy.utils.support_types.SpiceCell
:return: Extracted Window.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
assert side == 'L' or side == 'R'
side = ctypes.c_char(side.encode(encoding='UTF-8'))
libspice.wnextd_c(side, ctypes.byref(window))
return window | [
"def",
"wnextd",
"(",
"side",
",",
"window",
")",
":",
"assert",
"isinstance",
"(",
"window",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"window",
".",
"dtype",
"==",
"1",
"assert",
"side",
"==",
"'L'",
"or",
"side",
"==",
"'R'",
"side",
"=",
"ctypes",
".",
"c_char",
"(",
"side",
".",
"encode",
"(",
"encoding",
"=",
"'UTF-8'",
")",
")",
"libspice",
".",
"wnextd_c",
"(",
"side",
",",
"ctypes",
".",
"byref",
"(",
"window",
")",
")",
"return",
"window"
] | Extract the left or right endpoints from a double precision
window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnextd_c.html
:param side: Extract left "L" or right "R" endpoints.
:type side: str
:param window: Window to be extracted.
:type window: spiceypy.utils.support_types.SpiceCell
:return: Extracted Window.
:rtype: spiceypy.utils.support_types.SpiceCell | [
"Extract",
"the",
"left",
"or",
"right",
"endpoints",
"from",
"a",
"double",
"precision",
"window",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15429-L15448 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wnfetd | def wnfetd(window, n):
"""
Fetch a particular interval from a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnfetd_c.html
:param window: Input window
:type window: spiceypy.utils.support_types.SpiceCell
:param n: Index of interval to be fetched.
:type n: int
:return: Left, right endpoints of the nth interval.
:rtype: tuple
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
n = ctypes.c_int(n)
left = ctypes.c_double()
right = ctypes.c_double()
libspice.wnfetd_c(ctypes.byref(window), n, ctypes.byref(left),
ctypes.byref(right))
return left.value, right.value | python | def wnfetd(window, n):
"""
Fetch a particular interval from a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnfetd_c.html
:param window: Input window
:type window: spiceypy.utils.support_types.SpiceCell
:param n: Index of interval to be fetched.
:type n: int
:return: Left, right endpoints of the nth interval.
:rtype: tuple
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
n = ctypes.c_int(n)
left = ctypes.c_double()
right = ctypes.c_double()
libspice.wnfetd_c(ctypes.byref(window), n, ctypes.byref(left),
ctypes.byref(right))
return left.value, right.value | [
"def",
"wnfetd",
"(",
"window",
",",
"n",
")",
":",
"assert",
"isinstance",
"(",
"window",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"window",
".",
"dtype",
"==",
"1",
"n",
"=",
"ctypes",
".",
"c_int",
"(",
"n",
")",
"left",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"right",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"libspice",
".",
"wnfetd_c",
"(",
"ctypes",
".",
"byref",
"(",
"window",
")",
",",
"n",
",",
"ctypes",
".",
"byref",
"(",
"left",
")",
",",
"ctypes",
".",
"byref",
"(",
"right",
")",
")",
"return",
"left",
".",
"value",
",",
"right",
".",
"value"
] | Fetch a particular interval from a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnfetd_c.html
:param window: Input window
:type window: spiceypy.utils.support_types.SpiceCell
:param n: Index of interval to be fetched.
:type n: int
:return: Left, right endpoints of the nth interval.
:rtype: tuple | [
"Fetch",
"a",
"particular",
"interval",
"from",
"a",
"double",
"precision",
"window",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15452-L15472 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wnfild | def wnfild(small, window):
"""
Fill small gaps between adjacent intervals of a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnfild_c.html
:param small: Limiting measure of small gaps.
:type small: float
:param window: Window to be filled
:type window: spiceypy.utils.support_types.SpiceCell
:return: Filled Window.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
small = ctypes.c_double(small)
libspice.wnfild_c(small, ctypes.byref(window))
return window | python | def wnfild(small, window):
"""
Fill small gaps between adjacent intervals of a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnfild_c.html
:param small: Limiting measure of small gaps.
:type small: float
:param window: Window to be filled
:type window: spiceypy.utils.support_types.SpiceCell
:return: Filled Window.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
small = ctypes.c_double(small)
libspice.wnfild_c(small, ctypes.byref(window))
return window | [
"def",
"wnfild",
"(",
"small",
",",
"window",
")",
":",
"assert",
"isinstance",
"(",
"window",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"window",
".",
"dtype",
"==",
"1",
"small",
"=",
"ctypes",
".",
"c_double",
"(",
"small",
")",
"libspice",
".",
"wnfild_c",
"(",
"small",
",",
"ctypes",
".",
"byref",
"(",
"window",
")",
")",
"return",
"window"
] | Fill small gaps between adjacent intervals of a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnfild_c.html
:param small: Limiting measure of small gaps.
:type small: float
:param window: Window to be filled
:type window: spiceypy.utils.support_types.SpiceCell
:return: Filled Window.
:rtype: spiceypy.utils.support_types.SpiceCell | [
"Fill",
"small",
"gaps",
"between",
"adjacent",
"intervals",
"of",
"a",
"double",
"precision",
"window",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15476-L15493 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wnincd | def wnincd(left, right, window):
"""
Determine whether an interval is included in a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnincd_c.html
:param left: Left interval
:type left: float
:param right: Right interval
:type right: float
:param window: Input window
:type window: spiceypy.utils.support_types.SpiceCell
:return: Returns True if the input interval is included in window.
:rtype: bool
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
left = ctypes.c_double(left)
right = ctypes.c_double(right)
return bool(libspice.wnincd_c(left, right, ctypes.byref(window))) | python | def wnincd(left, right, window):
"""
Determine whether an interval is included in a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnincd_c.html
:param left: Left interval
:type left: float
:param right: Right interval
:type right: float
:param window: Input window
:type window: spiceypy.utils.support_types.SpiceCell
:return: Returns True if the input interval is included in window.
:rtype: bool
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
left = ctypes.c_double(left)
right = ctypes.c_double(right)
return bool(libspice.wnincd_c(left, right, ctypes.byref(window))) | [
"def",
"wnincd",
"(",
"left",
",",
"right",
",",
"window",
")",
":",
"assert",
"isinstance",
"(",
"window",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"window",
".",
"dtype",
"==",
"1",
"left",
"=",
"ctypes",
".",
"c_double",
"(",
"left",
")",
"right",
"=",
"ctypes",
".",
"c_double",
"(",
"right",
")",
"return",
"bool",
"(",
"libspice",
".",
"wnincd_c",
"(",
"left",
",",
"right",
",",
"ctypes",
".",
"byref",
"(",
"window",
")",
")",
")"
] | Determine whether an interval is included in a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnincd_c.html
:param left: Left interval
:type left: float
:param right: Right interval
:type right: float
:param window: Input window
:type window: spiceypy.utils.support_types.SpiceCell
:return: Returns True if the input interval is included in window.
:rtype: bool | [
"Determine",
"whether",
"an",
"interval",
"is",
"included",
"in",
"a",
"double",
"precision",
"window",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15518-L15537 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wninsd | def wninsd(left, right, window):
"""
Insert an interval into a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wninsd_c.html
:param left: Left endpoints of new interval.
:type left: float
:param right: Right endpoints of new interval.
:type right: float
:param window: Input window.
:type window: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
left = ctypes.c_double(left)
right = ctypes.c_double(right)
libspice.wninsd_c(left, right, ctypes.byref(window)) | python | def wninsd(left, right, window):
"""
Insert an interval into a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wninsd_c.html
:param left: Left endpoints of new interval.
:type left: float
:param right: Right endpoints of new interval.
:type right: float
:param window: Input window.
:type window: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
left = ctypes.c_double(left)
right = ctypes.c_double(right)
libspice.wninsd_c(left, right, ctypes.byref(window)) | [
"def",
"wninsd",
"(",
"left",
",",
"right",
",",
"window",
")",
":",
"assert",
"isinstance",
"(",
"window",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"window",
".",
"dtype",
"==",
"1",
"left",
"=",
"ctypes",
".",
"c_double",
"(",
"left",
")",
"right",
"=",
"ctypes",
".",
"c_double",
"(",
"right",
")",
"libspice",
".",
"wninsd_c",
"(",
"left",
",",
"right",
",",
"ctypes",
".",
"byref",
"(",
"window",
")",
")"
] | Insert an interval into a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wninsd_c.html
:param left: Left endpoints of new interval.
:type left: float
:param right: Right endpoints of new interval.
:type right: float
:param window: Input window.
:type window: spiceypy.utils.support_types.SpiceCell | [
"Insert",
"an",
"interval",
"into",
"a",
"double",
"precision",
"window",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15541-L15558 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wnintd | def wnintd(a, b):
"""
Place the intersection of two double precision windows into
a third window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnintd_c.html
:param a: Input window A.
:type a: spiceypy.utils.support_types.SpiceCell
:param b: Input window B.
:type b: spiceypy.utils.support_types.SpiceCell
:return: Intersection of a and b.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(a, stypes.SpiceCell)
assert b.dtype == 1
assert isinstance(b, stypes.SpiceCell)
assert a.dtype == 1
c = stypes.SpiceCell.double(b.size + a.size)
libspice.wnintd_c(ctypes.byref(a), ctypes.byref(b), ctypes.byref(c))
return c | python | def wnintd(a, b):
"""
Place the intersection of two double precision windows into
a third window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnintd_c.html
:param a: Input window A.
:type a: spiceypy.utils.support_types.SpiceCell
:param b: Input window B.
:type b: spiceypy.utils.support_types.SpiceCell
:return: Intersection of a and b.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(a, stypes.SpiceCell)
assert b.dtype == 1
assert isinstance(b, stypes.SpiceCell)
assert a.dtype == 1
c = stypes.SpiceCell.double(b.size + a.size)
libspice.wnintd_c(ctypes.byref(a), ctypes.byref(b), ctypes.byref(c))
return c | [
"def",
"wnintd",
"(",
"a",
",",
"b",
")",
":",
"assert",
"isinstance",
"(",
"a",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"b",
".",
"dtype",
"==",
"1",
"assert",
"isinstance",
"(",
"b",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"a",
".",
"dtype",
"==",
"1",
"c",
"=",
"stypes",
".",
"SpiceCell",
".",
"double",
"(",
"b",
".",
"size",
"+",
"a",
".",
"size",
")",
"libspice",
".",
"wnintd_c",
"(",
"ctypes",
".",
"byref",
"(",
"a",
")",
",",
"ctypes",
".",
"byref",
"(",
"b",
")",
",",
"ctypes",
".",
"byref",
"(",
"c",
")",
")",
"return",
"c"
] | Place the intersection of two double precision windows into
a third window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnintd_c.html
:param a: Input window A.
:type a: spiceypy.utils.support_types.SpiceCell
:param b: Input window B.
:type b: spiceypy.utils.support_types.SpiceCell
:return: Intersection of a and b.
:rtype: spiceypy.utils.support_types.SpiceCell | [
"Place",
"the",
"intersection",
"of",
"two",
"double",
"precision",
"windows",
"into",
"a",
"third",
"window",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15562-L15583 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wnreld | def wnreld(a, op, b):
"""
Compare two double precision windows.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnreld_c.html
:param a: First window.
:type a: spiceypy.utils.support_types.SpiceCell
:param op: Comparison operator.
:type op: str
:param b: Second window.
:type b: spiceypy.utils.support_types.SpiceCell
:return: The result of comparison: a (op) b.
:rtype: bool
"""
assert isinstance(a, stypes.SpiceCell)
assert b.dtype == 1
assert isinstance(b, stypes.SpiceCell)
assert a.dtype == 1
assert isinstance(op, str)
op = stypes.stringToCharP(op.encode(encoding='UTF-8'))
return bool(libspice.wnreld_c(ctypes.byref(a), op, ctypes.byref(b))) | python | def wnreld(a, op, b):
"""
Compare two double precision windows.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnreld_c.html
:param a: First window.
:type a: spiceypy.utils.support_types.SpiceCell
:param op: Comparison operator.
:type op: str
:param b: Second window.
:type b: spiceypy.utils.support_types.SpiceCell
:return: The result of comparison: a (op) b.
:rtype: bool
"""
assert isinstance(a, stypes.SpiceCell)
assert b.dtype == 1
assert isinstance(b, stypes.SpiceCell)
assert a.dtype == 1
assert isinstance(op, str)
op = stypes.stringToCharP(op.encode(encoding='UTF-8'))
return bool(libspice.wnreld_c(ctypes.byref(a), op, ctypes.byref(b))) | [
"def",
"wnreld",
"(",
"a",
",",
"op",
",",
"b",
")",
":",
"assert",
"isinstance",
"(",
"a",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"b",
".",
"dtype",
"==",
"1",
"assert",
"isinstance",
"(",
"b",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"a",
".",
"dtype",
"==",
"1",
"assert",
"isinstance",
"(",
"op",
",",
"str",
")",
"op",
"=",
"stypes",
".",
"stringToCharP",
"(",
"op",
".",
"encode",
"(",
"encoding",
"=",
"'UTF-8'",
")",
")",
"return",
"bool",
"(",
"libspice",
".",
"wnreld_c",
"(",
"ctypes",
".",
"byref",
"(",
"a",
")",
",",
"op",
",",
"ctypes",
".",
"byref",
"(",
"b",
")",
")",
")"
] | Compare two double precision windows.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnreld_c.html
:param a: First window.
:type a: spiceypy.utils.support_types.SpiceCell
:param op: Comparison operator.
:type op: str
:param b: Second window.
:type b: spiceypy.utils.support_types.SpiceCell
:return: The result of comparison: a (op) b.
:rtype: bool | [
"Compare",
"two",
"double",
"precision",
"windows",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15587-L15608 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wnsumd | def wnsumd(window):
"""
Summarize the contents of a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnsumd_c.html
:param window: Window to be summarized.
:type window: spiceypy.utils.support_types.SpiceCell
:return:
Total measure of intervals in window,
Average measure, Standard deviation,
Location of shortest interval,
Location of longest interval.
:rtype: tuple
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
meas = ctypes.c_double()
avg = ctypes.c_double()
stddev = ctypes.c_double()
shortest = ctypes.c_int()
longest = ctypes.c_int()
libspice.wnsumd_c(ctypes.byref(window), ctypes.byref(meas),
ctypes.byref(avg), ctypes.byref(stddev),
ctypes.byref(shortest), ctypes.byref(longest))
return meas.value, avg.value, stddev.value, shortest.value, longest.value | python | def wnsumd(window):
"""
Summarize the contents of a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnsumd_c.html
:param window: Window to be summarized.
:type window: spiceypy.utils.support_types.SpiceCell
:return:
Total measure of intervals in window,
Average measure, Standard deviation,
Location of shortest interval,
Location of longest interval.
:rtype: tuple
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
meas = ctypes.c_double()
avg = ctypes.c_double()
stddev = ctypes.c_double()
shortest = ctypes.c_int()
longest = ctypes.c_int()
libspice.wnsumd_c(ctypes.byref(window), ctypes.byref(meas),
ctypes.byref(avg), ctypes.byref(stddev),
ctypes.byref(shortest), ctypes.byref(longest))
return meas.value, avg.value, stddev.value, shortest.value, longest.value | [
"def",
"wnsumd",
"(",
"window",
")",
":",
"assert",
"isinstance",
"(",
"window",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"window",
".",
"dtype",
"==",
"1",
"meas",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"avg",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"stddev",
"=",
"ctypes",
".",
"c_double",
"(",
")",
"shortest",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"longest",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"libspice",
".",
"wnsumd_c",
"(",
"ctypes",
".",
"byref",
"(",
"window",
")",
",",
"ctypes",
".",
"byref",
"(",
"meas",
")",
",",
"ctypes",
".",
"byref",
"(",
"avg",
")",
",",
"ctypes",
".",
"byref",
"(",
"stddev",
")",
",",
"ctypes",
".",
"byref",
"(",
"shortest",
")",
",",
"ctypes",
".",
"byref",
"(",
"longest",
")",
")",
"return",
"meas",
".",
"value",
",",
"avg",
".",
"value",
",",
"stddev",
".",
"value",
",",
"shortest",
".",
"value",
",",
"longest",
".",
"value"
] | Summarize the contents of a double precision window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnsumd_c.html
:param window: Window to be summarized.
:type window: spiceypy.utils.support_types.SpiceCell
:return:
Total measure of intervals in window,
Average measure, Standard deviation,
Location of shortest interval,
Location of longest interval.
:rtype: tuple | [
"Summarize",
"the",
"contents",
"of",
"a",
"double",
"precision",
"window",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15612-L15637 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wnunid | def wnunid(a, b):
"""
Place the union of two double precision windows into a third window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnunid_c.html
:param a: Input window A.
:type a: spiceypy.utils.support_types.SpiceCell
:param b: Input window B.
:type b: spiceypy.utils.support_types.SpiceCell
:return: Union of a and b.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(a, stypes.SpiceCell)
assert b.dtype == 1
assert isinstance(b, stypes.SpiceCell)
assert a.dtype == 1
c = stypes.SpiceCell.double(b.size + a.size)
libspice.wnunid_c(ctypes.byref(a), ctypes.byref(b), ctypes.byref(c))
return c | python | def wnunid(a, b):
"""
Place the union of two double precision windows into a third window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnunid_c.html
:param a: Input window A.
:type a: spiceypy.utils.support_types.SpiceCell
:param b: Input window B.
:type b: spiceypy.utils.support_types.SpiceCell
:return: Union of a and b.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(a, stypes.SpiceCell)
assert b.dtype == 1
assert isinstance(b, stypes.SpiceCell)
assert a.dtype == 1
c = stypes.SpiceCell.double(b.size + a.size)
libspice.wnunid_c(ctypes.byref(a), ctypes.byref(b), ctypes.byref(c))
return c | [
"def",
"wnunid",
"(",
"a",
",",
"b",
")",
":",
"assert",
"isinstance",
"(",
"a",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"b",
".",
"dtype",
"==",
"1",
"assert",
"isinstance",
"(",
"b",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"a",
".",
"dtype",
"==",
"1",
"c",
"=",
"stypes",
".",
"SpiceCell",
".",
"double",
"(",
"b",
".",
"size",
"+",
"a",
".",
"size",
")",
"libspice",
".",
"wnunid_c",
"(",
"ctypes",
".",
"byref",
"(",
"a",
")",
",",
"ctypes",
".",
"byref",
"(",
"b",
")",
",",
"ctypes",
".",
"byref",
"(",
"c",
")",
")",
"return",
"c"
] | Place the union of two double precision windows into a third window.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnunid_c.html
:param a: Input window A.
:type a: spiceypy.utils.support_types.SpiceCell
:param b: Input window B.
:type b: spiceypy.utils.support_types.SpiceCell
:return: Union of a and b.
:rtype: spiceypy.utils.support_types.SpiceCell | [
"Place",
"the",
"union",
"of",
"two",
"double",
"precision",
"windows",
"into",
"a",
"third",
"window",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15641-L15660 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | wnvald | def wnvald(insize, n, window):
"""
Form a valid double precision window from the contents
of a window array.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnvald_c.html
:param insize: Size of window.
:type insize: int
:param n: Original number of endpoints.
:type n: int
:param window: Input window.
:type window: spiceypy.utils.support_types.SpiceCell
:return: The union of the intervals in the input cell.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
insize = ctypes.c_int(insize)
n = ctypes.c_int(n)
libspice.wnvald_c(insize, n, ctypes.byref(window))
return window | python | def wnvald(insize, n, window):
"""
Form a valid double precision window from the contents
of a window array.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnvald_c.html
:param insize: Size of window.
:type insize: int
:param n: Original number of endpoints.
:type n: int
:param window: Input window.
:type window: spiceypy.utils.support_types.SpiceCell
:return: The union of the intervals in the input cell.
:rtype: spiceypy.utils.support_types.SpiceCell
"""
assert isinstance(window, stypes.SpiceCell)
assert window.dtype == 1
insize = ctypes.c_int(insize)
n = ctypes.c_int(n)
libspice.wnvald_c(insize, n, ctypes.byref(window))
return window | [
"def",
"wnvald",
"(",
"insize",
",",
"n",
",",
"window",
")",
":",
"assert",
"isinstance",
"(",
"window",
",",
"stypes",
".",
"SpiceCell",
")",
"assert",
"window",
".",
"dtype",
"==",
"1",
"insize",
"=",
"ctypes",
".",
"c_int",
"(",
"insize",
")",
"n",
"=",
"ctypes",
".",
"c_int",
"(",
"n",
")",
"libspice",
".",
"wnvald_c",
"(",
"insize",
",",
"n",
",",
"ctypes",
".",
"byref",
"(",
"window",
")",
")",
"return",
"window"
] | Form a valid double precision window from the contents
of a window array.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/wnvald_c.html
:param insize: Size of window.
:type insize: int
:param n: Original number of endpoints.
:type n: int
:param window: Input window.
:type window: spiceypy.utils.support_types.SpiceCell
:return: The union of the intervals in the input cell.
:rtype: spiceypy.utils.support_types.SpiceCell | [
"Form",
"a",
"valid",
"double",
"precision",
"window",
"from",
"the",
"contents",
"of",
"a",
"window",
"array",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15664-L15685 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | writln | def writln(line, unit):
"""
Internal undocumented command for writing a text line to a logical unit
No URL available; relevant lines from SPICE source:
FORTRAN SPICE, writln.f::
C$Procedure WRITLN ( Write a text line to a logical unit )
SUBROUTINE WRITLN ( LINE, UNIT )
CHARACTER*(*) LINE
INTEGER UNIT
C Variable I/O Description
C -------- --- --------------------------------------------------
C LINE I The line which is to be written to UNIT.
C UNIT I The Fortran unit number to use for output.
CSPICE, writln.c::
/* $Procedure WRITLN ( Write a text line to a logical unit ) */
/* Subroutine */ int writln_(char *line, integer *unit, ftnlen line_len)
:param line: The line which is to be written to UNIT.
:type line: str
:param unit: The Fortran unit number to use for output.
:type unit: int
"""
lineP = stypes.stringToCharP(line)
unit = ctypes.c_int(unit)
line_len = ctypes.c_int(len(line))
libspice.writln_(lineP, ctypes.byref(unit), line_len) | python | def writln(line, unit):
"""
Internal undocumented command for writing a text line to a logical unit
No URL available; relevant lines from SPICE source:
FORTRAN SPICE, writln.f::
C$Procedure WRITLN ( Write a text line to a logical unit )
SUBROUTINE WRITLN ( LINE, UNIT )
CHARACTER*(*) LINE
INTEGER UNIT
C Variable I/O Description
C -------- --- --------------------------------------------------
C LINE I The line which is to be written to UNIT.
C UNIT I The Fortran unit number to use for output.
CSPICE, writln.c::
/* $Procedure WRITLN ( Write a text line to a logical unit ) */
/* Subroutine */ int writln_(char *line, integer *unit, ftnlen line_len)
:param line: The line which is to be written to UNIT.
:type line: str
:param unit: The Fortran unit number to use for output.
:type unit: int
"""
lineP = stypes.stringToCharP(line)
unit = ctypes.c_int(unit)
line_len = ctypes.c_int(len(line))
libspice.writln_(lineP, ctypes.byref(unit), line_len) | [
"def",
"writln",
"(",
"line",
",",
"unit",
")",
":",
"lineP",
"=",
"stypes",
".",
"stringToCharP",
"(",
"line",
")",
"unit",
"=",
"ctypes",
".",
"c_int",
"(",
"unit",
")",
"line_len",
"=",
"ctypes",
".",
"c_int",
"(",
"len",
"(",
"line",
")",
")",
"libspice",
".",
"writln_",
"(",
"lineP",
",",
"ctypes",
".",
"byref",
"(",
"unit",
")",
",",
"line_len",
")"
] | Internal undocumented command for writing a text line to a logical unit
No URL available; relevant lines from SPICE source:
FORTRAN SPICE, writln.f::
C$Procedure WRITLN ( Write a text line to a logical unit )
SUBROUTINE WRITLN ( LINE, UNIT )
CHARACTER*(*) LINE
INTEGER UNIT
C Variable I/O Description
C -------- --- --------------------------------------------------
C LINE I The line which is to be written to UNIT.
C UNIT I The Fortran unit number to use for output.
CSPICE, writln.c::
/* $Procedure WRITLN ( Write a text line to a logical unit ) */
/* Subroutine */ int writln_(char *line, integer *unit, ftnlen line_len)
:param line: The line which is to be written to UNIT.
:type line: str
:param unit: The Fortran unit number to use for output.
:type unit: int | [
"Internal",
"undocumented",
"command",
"for",
"writing",
"a",
"text",
"line",
"to",
"a",
"logical",
"unit"
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15689-L15720 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | xfmsta | def xfmsta(input_state, input_coord_sys, output_coord_sys, body):
"""
Transform a state between coordinate systems.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xfmsta_c.html
:param input_state: Input state.
:type input_state: 6-Element Array of floats
:param input_coord_sys: Current (input) coordinate system.
:type input_coord_sys: str
:param output_coord_sys: Desired (output) coordinate system.
:type output_coord_sys: str
:param body:
Name or NAIF ID of body with which coordinates
are associated (if applicable).
:type body: str
:return: Converted output state
:rtype: 6-Element Array of floats
"""
input_state = stypes.toDoubleVector(input_state)
input_coord_sys = stypes.stringToCharP(input_coord_sys)
output_coord_sys = stypes.stringToCharP(output_coord_sys)
body = stypes.stringToCharP(body)
output_state = stypes.emptyDoubleVector(6)
libspice.xfmsta_c(input_state, input_coord_sys, output_coord_sys, body,
output_state)
return stypes.cVectorToPython(output_state) | python | def xfmsta(input_state, input_coord_sys, output_coord_sys, body):
"""
Transform a state between coordinate systems.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xfmsta_c.html
:param input_state: Input state.
:type input_state: 6-Element Array of floats
:param input_coord_sys: Current (input) coordinate system.
:type input_coord_sys: str
:param output_coord_sys: Desired (output) coordinate system.
:type output_coord_sys: str
:param body:
Name or NAIF ID of body with which coordinates
are associated (if applicable).
:type body: str
:return: Converted output state
:rtype: 6-Element Array of floats
"""
input_state = stypes.toDoubleVector(input_state)
input_coord_sys = stypes.stringToCharP(input_coord_sys)
output_coord_sys = stypes.stringToCharP(output_coord_sys)
body = stypes.stringToCharP(body)
output_state = stypes.emptyDoubleVector(6)
libspice.xfmsta_c(input_state, input_coord_sys, output_coord_sys, body,
output_state)
return stypes.cVectorToPython(output_state) | [
"def",
"xfmsta",
"(",
"input_state",
",",
"input_coord_sys",
",",
"output_coord_sys",
",",
"body",
")",
":",
"input_state",
"=",
"stypes",
".",
"toDoubleVector",
"(",
"input_state",
")",
"input_coord_sys",
"=",
"stypes",
".",
"stringToCharP",
"(",
"input_coord_sys",
")",
"output_coord_sys",
"=",
"stypes",
".",
"stringToCharP",
"(",
"output_coord_sys",
")",
"body",
"=",
"stypes",
".",
"stringToCharP",
"(",
"body",
")",
"output_state",
"=",
"stypes",
".",
"emptyDoubleVector",
"(",
"6",
")",
"libspice",
".",
"xfmsta_c",
"(",
"input_state",
",",
"input_coord_sys",
",",
"output_coord_sys",
",",
"body",
",",
"output_state",
")",
"return",
"stypes",
".",
"cVectorToPython",
"(",
"output_state",
")"
] | Transform a state between coordinate systems.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xfmsta_c.html
:param input_state: Input state.
:type input_state: 6-Element Array of floats
:param input_coord_sys: Current (input) coordinate system.
:type input_coord_sys: str
:param output_coord_sys: Desired (output) coordinate system.
:type output_coord_sys: str
:param body:
Name or NAIF ID of body with which coordinates
are associated (if applicable).
:type body: str
:return: Converted output state
:rtype: 6-Element Array of floats | [
"Transform",
"a",
"state",
"between",
"coordinate",
"systems",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15774-L15800 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | xpose | def xpose(m):
"""
Transpose a 3x3 matrix
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xpose_c.html
:param m: Matrix to be transposed
:type m: 3x3-Element Array of floats
:return: Transposed matrix
:rtype: 3x3-Element Array of floats
"""
m = stypes.toDoubleMatrix(m)
mout = stypes.emptyDoubleMatrix(x=3, y=3)
libspice.xpose_c(m, mout)
return stypes.cMatrixToNumpy(mout) | python | def xpose(m):
"""
Transpose a 3x3 matrix
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xpose_c.html
:param m: Matrix to be transposed
:type m: 3x3-Element Array of floats
:return: Transposed matrix
:rtype: 3x3-Element Array of floats
"""
m = stypes.toDoubleMatrix(m)
mout = stypes.emptyDoubleMatrix(x=3, y=3)
libspice.xpose_c(m, mout)
return stypes.cMatrixToNumpy(mout) | [
"def",
"xpose",
"(",
"m",
")",
":",
"m",
"=",
"stypes",
".",
"toDoubleMatrix",
"(",
"m",
")",
"mout",
"=",
"stypes",
".",
"emptyDoubleMatrix",
"(",
"x",
"=",
"3",
",",
"y",
"=",
"3",
")",
"libspice",
".",
"xpose_c",
"(",
"m",
",",
"mout",
")",
"return",
"stypes",
".",
"cMatrixToNumpy",
"(",
"mout",
")"
] | Transpose a 3x3 matrix
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xpose_c.html
:param m: Matrix to be transposed
:type m: 3x3-Element Array of floats
:return: Transposed matrix
:rtype: 3x3-Element Array of floats | [
"Transpose",
"a",
"3x3",
"matrix"
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15804-L15818 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | xpose6 | def xpose6(m):
"""
Transpose a 6x6 matrix
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xpose6_c.html
:param m: Matrix to be transposed
:type m: list[6][6]
:return: Transposed matrix
:rtype: list[6][6]
"""
m = stypes.toDoubleMatrix(m)
mout = stypes.emptyDoubleMatrix(x=6, y=6)
libspice.xpose6_c(m, mout)
return stypes.cMatrixToNumpy(mout) | python | def xpose6(m):
"""
Transpose a 6x6 matrix
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xpose6_c.html
:param m: Matrix to be transposed
:type m: list[6][6]
:return: Transposed matrix
:rtype: list[6][6]
"""
m = stypes.toDoubleMatrix(m)
mout = stypes.emptyDoubleMatrix(x=6, y=6)
libspice.xpose6_c(m, mout)
return stypes.cMatrixToNumpy(mout) | [
"def",
"xpose6",
"(",
"m",
")",
":",
"m",
"=",
"stypes",
".",
"toDoubleMatrix",
"(",
"m",
")",
"mout",
"=",
"stypes",
".",
"emptyDoubleMatrix",
"(",
"x",
"=",
"6",
",",
"y",
"=",
"6",
")",
"libspice",
".",
"xpose6_c",
"(",
"m",
",",
"mout",
")",
"return",
"stypes",
".",
"cMatrixToNumpy",
"(",
"mout",
")"
] | Transpose a 6x6 matrix
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xpose6_c.html
:param m: Matrix to be transposed
:type m: list[6][6]
:return: Transposed matrix
:rtype: list[6][6] | [
"Transpose",
"a",
"6x6",
"matrix"
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15822-L15836 | train |
AndrewAnnex/SpiceyPy | spiceypy/spiceypy.py | xposeg | def xposeg(matrix, nrow, ncol):
"""
Transpose a matrix of arbitrary size
in place, the matrix need not be square.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xposeg_c.html
:param matrix: Matrix to be transposed
:type matrix: NxM-Element Array of floats
:param nrow: Number of rows of input matrix.
:type nrow: int
:param ncol: Number of columns of input matrix
:type ncol: int
:return: Transposed matrix
:rtype: NxM-Element Array of floats
"""
matrix = stypes.toDoubleMatrix(matrix)
mout = stypes.emptyDoubleMatrix(x=ncol, y=nrow)
ncol = ctypes.c_int(ncol)
nrow = ctypes.c_int(nrow)
libspice.xposeg_c(matrix, nrow, ncol, mout)
return stypes.cMatrixToNumpy(mout) | python | def xposeg(matrix, nrow, ncol):
"""
Transpose a matrix of arbitrary size
in place, the matrix need not be square.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xposeg_c.html
:param matrix: Matrix to be transposed
:type matrix: NxM-Element Array of floats
:param nrow: Number of rows of input matrix.
:type nrow: int
:param ncol: Number of columns of input matrix
:type ncol: int
:return: Transposed matrix
:rtype: NxM-Element Array of floats
"""
matrix = stypes.toDoubleMatrix(matrix)
mout = stypes.emptyDoubleMatrix(x=ncol, y=nrow)
ncol = ctypes.c_int(ncol)
nrow = ctypes.c_int(nrow)
libspice.xposeg_c(matrix, nrow, ncol, mout)
return stypes.cMatrixToNumpy(mout) | [
"def",
"xposeg",
"(",
"matrix",
",",
"nrow",
",",
"ncol",
")",
":",
"matrix",
"=",
"stypes",
".",
"toDoubleMatrix",
"(",
"matrix",
")",
"mout",
"=",
"stypes",
".",
"emptyDoubleMatrix",
"(",
"x",
"=",
"ncol",
",",
"y",
"=",
"nrow",
")",
"ncol",
"=",
"ctypes",
".",
"c_int",
"(",
"ncol",
")",
"nrow",
"=",
"ctypes",
".",
"c_int",
"(",
"nrow",
")",
"libspice",
".",
"xposeg_c",
"(",
"matrix",
",",
"nrow",
",",
"ncol",
",",
"mout",
")",
"return",
"stypes",
".",
"cMatrixToNumpy",
"(",
"mout",
")"
] | Transpose a matrix of arbitrary size
in place, the matrix need not be square.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xposeg_c.html
:param matrix: Matrix to be transposed
:type matrix: NxM-Element Array of floats
:param nrow: Number of rows of input matrix.
:type nrow: int
:param ncol: Number of columns of input matrix
:type ncol: int
:return: Transposed matrix
:rtype: NxM-Element Array of floats | [
"Transpose",
"a",
"matrix",
"of",
"arbitrary",
"size",
"in",
"place",
"the",
"matrix",
"need",
"not",
"be",
"square",
"."
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/spiceypy.py#L15840-L15861 | train |
AndrewAnnex/SpiceyPy | spiceypy/utils/callbacks.py | CallUDFUNS | def CallUDFUNS(f, x):
"""
We are given a UDF CFUNCTYPE and want to call it in python
:param f: SpiceUDFUNS
:type f: CFUNCTYPE
:param x: some scalar
:type x: float
:return: value
:rtype: float
"""
value = c_double()
f(x, byref(value))
return value.value | python | def CallUDFUNS(f, x):
"""
We are given a UDF CFUNCTYPE and want to call it in python
:param f: SpiceUDFUNS
:type f: CFUNCTYPE
:param x: some scalar
:type x: float
:return: value
:rtype: float
"""
value = c_double()
f(x, byref(value))
return value.value | [
"def",
"CallUDFUNS",
"(",
"f",
",",
"x",
")",
":",
"value",
"=",
"c_double",
"(",
")",
"f",
"(",
"x",
",",
"byref",
"(",
"value",
")",
")",
"return",
"value",
".",
"value"
] | We are given a UDF CFUNCTYPE and want to call it in python
:param f: SpiceUDFUNS
:type f: CFUNCTYPE
:param x: some scalar
:type x: float
:return: value
:rtype: float | [
"We",
"are",
"given",
"a",
"UDF",
"CFUNCTYPE",
"and",
"want",
"to",
"call",
"it",
"in",
"python"
] | fc20a9b9de68b58eed5b332f0c051fb343a6e335 | https://github.com/AndrewAnnex/SpiceyPy/blob/fc20a9b9de68b58eed5b332f0c051fb343a6e335/spiceypy/utils/callbacks.py#L158-L171 | train |
mnick/scikit-tensor | sktensor/dedicom.py | Updater.updateD_G | def updateD_G(self, x):
"""
Compute Gradient for update of D
See [2] for derivation of Gradient
"""
self.precompute(x)
g = zeros(len(x))
Ai = zeros(self.A.shape[0])
for i in range(len(g)):
Ai = self.A[:, i]
g[i] = (self.E * (dot(self.AD, outer(self.R[:, i], Ai)) +
dot(outer(Ai, self.R[i, :]), self.ADt))).sum()
return -2 * g | python | def updateD_G(self, x):
"""
Compute Gradient for update of D
See [2] for derivation of Gradient
"""
self.precompute(x)
g = zeros(len(x))
Ai = zeros(self.A.shape[0])
for i in range(len(g)):
Ai = self.A[:, i]
g[i] = (self.E * (dot(self.AD, outer(self.R[:, i], Ai)) +
dot(outer(Ai, self.R[i, :]), self.ADt))).sum()
return -2 * g | [
"def",
"updateD_G",
"(",
"self",
",",
"x",
")",
":",
"self",
".",
"precompute",
"(",
"x",
")",
"g",
"=",
"zeros",
"(",
"len",
"(",
"x",
")",
")",
"Ai",
"=",
"zeros",
"(",
"self",
".",
"A",
".",
"shape",
"[",
"0",
"]",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"g",
")",
")",
":",
"Ai",
"=",
"self",
".",
"A",
"[",
":",
",",
"i",
"]",
"g",
"[",
"i",
"]",
"=",
"(",
"self",
".",
"E",
"*",
"(",
"dot",
"(",
"self",
".",
"AD",
",",
"outer",
"(",
"self",
".",
"R",
"[",
":",
",",
"i",
"]",
",",
"Ai",
")",
")",
"+",
"dot",
"(",
"outer",
"(",
"Ai",
",",
"self",
".",
"R",
"[",
"i",
",",
":",
"]",
")",
",",
"self",
".",
"ADt",
")",
")",
")",
".",
"sum",
"(",
")",
"return",
"-",
"2",
"*",
"g"
] | Compute Gradient for update of D
See [2] for derivation of Gradient | [
"Compute",
"Gradient",
"for",
"update",
"of",
"D"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/dedicom.py#L226-L239 | train |
mnick/scikit-tensor | sktensor/dedicom.py | Updater.updateD_H | def updateD_H(self, x):
"""
Compute Hessian for update of D
See [2] for derivation of Hessian
"""
self.precompute(x)
H = zeros((len(x), len(x)))
Ai = zeros(self.A.shape[0])
Aj = zeros(Ai.shape)
for i in range(len(x)):
Ai = self.A[:, i]
ti = dot(self.AD, outer(self.R[:, i], Ai)) + dot(outer(Ai, self.R[i, :]), self.ADt)
for j in range(i, len(x)):
Aj = self.A[:, j]
tj = outer(Ai, Aj)
H[i, j] = (
self.E * (self.R[i, j] * tj + self.R[j, i] * tj.T) -
ti * (
dot(self.AD, outer(self.R[:, j], Aj)) +
dot(outer(Aj, self.R[j, :]), self.ADt)
)
).sum()
H[j, i] = H[i, j]
H *= -2
e = eigvals(H).min()
H = H + (eye(H.shape[0]) * e)
return H | python | def updateD_H(self, x):
"""
Compute Hessian for update of D
See [2] for derivation of Hessian
"""
self.precompute(x)
H = zeros((len(x), len(x)))
Ai = zeros(self.A.shape[0])
Aj = zeros(Ai.shape)
for i in range(len(x)):
Ai = self.A[:, i]
ti = dot(self.AD, outer(self.R[:, i], Ai)) + dot(outer(Ai, self.R[i, :]), self.ADt)
for j in range(i, len(x)):
Aj = self.A[:, j]
tj = outer(Ai, Aj)
H[i, j] = (
self.E * (self.R[i, j] * tj + self.R[j, i] * tj.T) -
ti * (
dot(self.AD, outer(self.R[:, j], Aj)) +
dot(outer(Aj, self.R[j, :]), self.ADt)
)
).sum()
H[j, i] = H[i, j]
H *= -2
e = eigvals(H).min()
H = H + (eye(H.shape[0]) * e)
return H | [
"def",
"updateD_H",
"(",
"self",
",",
"x",
")",
":",
"self",
".",
"precompute",
"(",
"x",
")",
"H",
"=",
"zeros",
"(",
"(",
"len",
"(",
"x",
")",
",",
"len",
"(",
"x",
")",
")",
")",
"Ai",
"=",
"zeros",
"(",
"self",
".",
"A",
".",
"shape",
"[",
"0",
"]",
")",
"Aj",
"=",
"zeros",
"(",
"Ai",
".",
"shape",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"x",
")",
")",
":",
"Ai",
"=",
"self",
".",
"A",
"[",
":",
",",
"i",
"]",
"ti",
"=",
"dot",
"(",
"self",
".",
"AD",
",",
"outer",
"(",
"self",
".",
"R",
"[",
":",
",",
"i",
"]",
",",
"Ai",
")",
")",
"+",
"dot",
"(",
"outer",
"(",
"Ai",
",",
"self",
".",
"R",
"[",
"i",
",",
":",
"]",
")",
",",
"self",
".",
"ADt",
")",
"for",
"j",
"in",
"range",
"(",
"i",
",",
"len",
"(",
"x",
")",
")",
":",
"Aj",
"=",
"self",
".",
"A",
"[",
":",
",",
"j",
"]",
"tj",
"=",
"outer",
"(",
"Ai",
",",
"Aj",
")",
"H",
"[",
"i",
",",
"j",
"]",
"=",
"(",
"self",
".",
"E",
"*",
"(",
"self",
".",
"R",
"[",
"i",
",",
"j",
"]",
"*",
"tj",
"+",
"self",
".",
"R",
"[",
"j",
",",
"i",
"]",
"*",
"tj",
".",
"T",
")",
"-",
"ti",
"*",
"(",
"dot",
"(",
"self",
".",
"AD",
",",
"outer",
"(",
"self",
".",
"R",
"[",
":",
",",
"j",
"]",
",",
"Aj",
")",
")",
"+",
"dot",
"(",
"outer",
"(",
"Aj",
",",
"self",
".",
"R",
"[",
"j",
",",
":",
"]",
")",
",",
"self",
".",
"ADt",
")",
")",
")",
".",
"sum",
"(",
")",
"H",
"[",
"j",
",",
"i",
"]",
"=",
"H",
"[",
"i",
",",
"j",
"]",
"H",
"*=",
"-",
"2",
"e",
"=",
"eigvals",
"(",
"H",
")",
".",
"min",
"(",
")",
"H",
"=",
"H",
"+",
"(",
"eye",
"(",
"H",
".",
"shape",
"[",
"0",
"]",
")",
"*",
"e",
")",
"return",
"H"
] | Compute Hessian for update of D
See [2] for derivation of Hessian | [
"Compute",
"Hessian",
"for",
"update",
"of",
"D"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/dedicom.py#L241-L269 | train |
mnick/scikit-tensor | sktensor/pyutils.py | is_sequence | def is_sequence(obj):
"""
Helper function to determine sequences
across Python 2.x and 3.x
"""
try:
from collections import Sequence
except ImportError:
from operator import isSequenceType
return isSequenceType(obj)
else:
return isinstance(obj, Sequence) | python | def is_sequence(obj):
"""
Helper function to determine sequences
across Python 2.x and 3.x
"""
try:
from collections import Sequence
except ImportError:
from operator import isSequenceType
return isSequenceType(obj)
else:
return isinstance(obj, Sequence) | [
"def",
"is_sequence",
"(",
"obj",
")",
":",
"try",
":",
"from",
"collections",
"import",
"Sequence",
"except",
"ImportError",
":",
"from",
"operator",
"import",
"isSequenceType",
"return",
"isSequenceType",
"(",
"obj",
")",
"else",
":",
"return",
"isinstance",
"(",
"obj",
",",
"Sequence",
")"
] | Helper function to determine sequences
across Python 2.x and 3.x | [
"Helper",
"function",
"to",
"determine",
"sequences",
"across",
"Python",
"2",
".",
"x",
"and",
"3",
".",
"x"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/pyutils.py#L8-L19 | train |
mnick/scikit-tensor | sktensor/pyutils.py | is_number | def is_number(obj):
"""
Helper function to determine numbers
across Python 2.x and 3.x
"""
try:
from numbers import Number
except ImportError:
from operator import isNumberType
return isNumberType(obj)
else:
return isinstance(obj, Number) | python | def is_number(obj):
"""
Helper function to determine numbers
across Python 2.x and 3.x
"""
try:
from numbers import Number
except ImportError:
from operator import isNumberType
return isNumberType(obj)
else:
return isinstance(obj, Number) | [
"def",
"is_number",
"(",
"obj",
")",
":",
"try",
":",
"from",
"numbers",
"import",
"Number",
"except",
"ImportError",
":",
"from",
"operator",
"import",
"isNumberType",
"return",
"isNumberType",
"(",
"obj",
")",
"else",
":",
"return",
"isinstance",
"(",
"obj",
",",
"Number",
")"
] | Helper function to determine numbers
across Python 2.x and 3.x | [
"Helper",
"function",
"to",
"determine",
"numbers",
"across",
"Python",
"2",
".",
"x",
"and",
"3",
".",
"x"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/pyutils.py#L22-L33 | train |
mnick/scikit-tensor | sktensor/pyutils.py | func_attr | def func_attr(f, attr):
"""
Helper function to get the attribute of a function
like, name, code, defaults across Python 2.x and 3.x
"""
if hasattr(f, 'func_%s' % attr):
return getattr(f, 'func_%s' % attr)
elif hasattr(f, '__%s__' % attr):
return getattr(f, '__%s__' % attr)
else:
raise ValueError('Object %s has no attr' % (str(f), attr)) | python | def func_attr(f, attr):
"""
Helper function to get the attribute of a function
like, name, code, defaults across Python 2.x and 3.x
"""
if hasattr(f, 'func_%s' % attr):
return getattr(f, 'func_%s' % attr)
elif hasattr(f, '__%s__' % attr):
return getattr(f, '__%s__' % attr)
else:
raise ValueError('Object %s has no attr' % (str(f), attr)) | [
"def",
"func_attr",
"(",
"f",
",",
"attr",
")",
":",
"if",
"hasattr",
"(",
"f",
",",
"'func_%s'",
"%",
"attr",
")",
":",
"return",
"getattr",
"(",
"f",
",",
"'func_%s'",
"%",
"attr",
")",
"elif",
"hasattr",
"(",
"f",
",",
"'__%s__'",
"%",
"attr",
")",
":",
"return",
"getattr",
"(",
"f",
",",
"'__%s__'",
"%",
"attr",
")",
"else",
":",
"raise",
"ValueError",
"(",
"'Object %s has no attr'",
"%",
"(",
"str",
"(",
"f",
")",
",",
"attr",
")",
")"
] | Helper function to get the attribute of a function
like, name, code, defaults across Python 2.x and 3.x | [
"Helper",
"function",
"to",
"get",
"the",
"attribute",
"of",
"a",
"function",
"like",
"name",
"code",
"defaults",
"across",
"Python",
"2",
".",
"x",
"and",
"3",
".",
"x"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/pyutils.py#L36-L46 | train |
mnick/scikit-tensor | sktensor/pyutils.py | from_to_without | def from_to_without(frm, to, without, step=1, skip=1, reverse=False, separate=False):
"""
Helper function to create ranges with missing entries
"""
if reverse:
frm, to = (to - 1), (frm - 1)
step *= -1
skip *= -1
a = list(range(frm, without, step))
b = list(range(without + skip, to, step))
if separate:
return a, b
else:
return a + b | python | def from_to_without(frm, to, without, step=1, skip=1, reverse=False, separate=False):
"""
Helper function to create ranges with missing entries
"""
if reverse:
frm, to = (to - 1), (frm - 1)
step *= -1
skip *= -1
a = list(range(frm, without, step))
b = list(range(without + skip, to, step))
if separate:
return a, b
else:
return a + b | [
"def",
"from_to_without",
"(",
"frm",
",",
"to",
",",
"without",
",",
"step",
"=",
"1",
",",
"skip",
"=",
"1",
",",
"reverse",
"=",
"False",
",",
"separate",
"=",
"False",
")",
":",
"if",
"reverse",
":",
"frm",
",",
"to",
"=",
"(",
"to",
"-",
"1",
")",
",",
"(",
"frm",
"-",
"1",
")",
"step",
"*=",
"-",
"1",
"skip",
"*=",
"-",
"1",
"a",
"=",
"list",
"(",
"range",
"(",
"frm",
",",
"without",
",",
"step",
")",
")",
"b",
"=",
"list",
"(",
"range",
"(",
"without",
"+",
"skip",
",",
"to",
",",
"step",
")",
")",
"if",
"separate",
":",
"return",
"a",
",",
"b",
"else",
":",
"return",
"a",
"+",
"b"
] | Helper function to create ranges with missing entries | [
"Helper",
"function",
"to",
"create",
"ranges",
"with",
"missing",
"entries"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/pyutils.py#L49-L62 | train |
mnick/scikit-tensor | sktensor/dtensor.py | dtensor.unfold | def unfold(self, mode):
"""
Unfolds a dense tensor in mode n.
Parameters
----------
mode : int
Mode in which tensor is unfolded
Returns
-------
unfolded_dtensor : unfolded_dtensor object
Tensor unfolded along mode
Examples
--------
Create dense tensor from numpy array
>>> T = np.zeros((3, 4, 2))
>>> T[:, :, 0] = [[ 1, 4, 7, 10], [ 2, 5, 8, 11], [3, 6, 9, 12]]
>>> T[:, :, 1] = [[13, 16, 19, 22], [14, 17, 20, 23], [15, 18, 21, 24]]
>>> T = dtensor(T)
Unfolding of dense tensors
>>> T.unfold(0)
array([[ 1., 4., 7., 10., 13., 16., 19., 22.],
[ 2., 5., 8., 11., 14., 17., 20., 23.],
[ 3., 6., 9., 12., 15., 18., 21., 24.]])
>>> T.unfold(1)
array([[ 1., 2., 3., 13., 14., 15.],
[ 4., 5., 6., 16., 17., 18.],
[ 7., 8., 9., 19., 20., 21.],
[ 10., 11., 12., 22., 23., 24.]])
>>> T.unfold(2)
array([[ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.,
12.],
[ 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23.,
24.]])
"""
sz = array(self.shape)
N = len(sz)
order = ([mode], from_to_without(N - 1, -1, mode, step=-1, skip=-1))
newsz = (sz[order[0]][0], prod(sz[order[1]]))
arr = self.transpose(axes=(order[0] + order[1]))
arr = arr.reshape(newsz)
return unfolded_dtensor(arr, mode, self.shape) | python | def unfold(self, mode):
"""
Unfolds a dense tensor in mode n.
Parameters
----------
mode : int
Mode in which tensor is unfolded
Returns
-------
unfolded_dtensor : unfolded_dtensor object
Tensor unfolded along mode
Examples
--------
Create dense tensor from numpy array
>>> T = np.zeros((3, 4, 2))
>>> T[:, :, 0] = [[ 1, 4, 7, 10], [ 2, 5, 8, 11], [3, 6, 9, 12]]
>>> T[:, :, 1] = [[13, 16, 19, 22], [14, 17, 20, 23], [15, 18, 21, 24]]
>>> T = dtensor(T)
Unfolding of dense tensors
>>> T.unfold(0)
array([[ 1., 4., 7., 10., 13., 16., 19., 22.],
[ 2., 5., 8., 11., 14., 17., 20., 23.],
[ 3., 6., 9., 12., 15., 18., 21., 24.]])
>>> T.unfold(1)
array([[ 1., 2., 3., 13., 14., 15.],
[ 4., 5., 6., 16., 17., 18.],
[ 7., 8., 9., 19., 20., 21.],
[ 10., 11., 12., 22., 23., 24.]])
>>> T.unfold(2)
array([[ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.,
12.],
[ 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23.,
24.]])
"""
sz = array(self.shape)
N = len(sz)
order = ([mode], from_to_without(N - 1, -1, mode, step=-1, skip=-1))
newsz = (sz[order[0]][0], prod(sz[order[1]]))
arr = self.transpose(axes=(order[0] + order[1]))
arr = arr.reshape(newsz)
return unfolded_dtensor(arr, mode, self.shape) | [
"def",
"unfold",
"(",
"self",
",",
"mode",
")",
":",
"sz",
"=",
"array",
"(",
"self",
".",
"shape",
")",
"N",
"=",
"len",
"(",
"sz",
")",
"order",
"=",
"(",
"[",
"mode",
"]",
",",
"from_to_without",
"(",
"N",
"-",
"1",
",",
"-",
"1",
",",
"mode",
",",
"step",
"=",
"-",
"1",
",",
"skip",
"=",
"-",
"1",
")",
")",
"newsz",
"=",
"(",
"sz",
"[",
"order",
"[",
"0",
"]",
"]",
"[",
"0",
"]",
",",
"prod",
"(",
"sz",
"[",
"order",
"[",
"1",
"]",
"]",
")",
")",
"arr",
"=",
"self",
".",
"transpose",
"(",
"axes",
"=",
"(",
"order",
"[",
"0",
"]",
"+",
"order",
"[",
"1",
"]",
")",
")",
"arr",
"=",
"arr",
".",
"reshape",
"(",
"newsz",
")",
"return",
"unfolded_dtensor",
"(",
"arr",
",",
"mode",
",",
"self",
".",
"shape",
")"
] | Unfolds a dense tensor in mode n.
Parameters
----------
mode : int
Mode in which tensor is unfolded
Returns
-------
unfolded_dtensor : unfolded_dtensor object
Tensor unfolded along mode
Examples
--------
Create dense tensor from numpy array
>>> T = np.zeros((3, 4, 2))
>>> T[:, :, 0] = [[ 1, 4, 7, 10], [ 2, 5, 8, 11], [3, 6, 9, 12]]
>>> T[:, :, 1] = [[13, 16, 19, 22], [14, 17, 20, 23], [15, 18, 21, 24]]
>>> T = dtensor(T)
Unfolding of dense tensors
>>> T.unfold(0)
array([[ 1., 4., 7., 10., 13., 16., 19., 22.],
[ 2., 5., 8., 11., 14., 17., 20., 23.],
[ 3., 6., 9., 12., 15., 18., 21., 24.]])
>>> T.unfold(1)
array([[ 1., 2., 3., 13., 14., 15.],
[ 4., 5., 6., 16., 17., 18.],
[ 7., 8., 9., 19., 20., 21.],
[ 10., 11., 12., 22., 23., 24.]])
>>> T.unfold(2)
array([[ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.,
12.],
[ 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23.,
24.]]) | [
"Unfolds",
"a",
"dense",
"tensor",
"in",
"mode",
"n",
"."
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/dtensor.py#L103-L150 | train |
mnick/scikit-tensor | sktensor/utils.py | accum | def accum(subs, vals, func=np.sum, issorted=False, with_subs=False):
"""
NumPy implementation for Matlab's accumarray
"""
# sort accmap for ediff if not sorted
if not issorted:
sidx = lexsort(subs, axis=0)
subs = [sub[sidx] for sub in subs]
vals = vals[sidx]
idx = np.where(np.diff(subs).any(axis=0))[0] + 1
idx = np.concatenate(([0], idx, [subs[0].shape[0]]))
# create values array
nvals = np.zeros(len(idx) - 1)
for i in range(len(idx) - 1):
nvals[i] = func(vals[idx[i]:idx[i + 1]])
# return results
if with_subs:
return nvals, tuple(sub[idx[:-1]] for sub in subs)
else:
return nvals | python | def accum(subs, vals, func=np.sum, issorted=False, with_subs=False):
"""
NumPy implementation for Matlab's accumarray
"""
# sort accmap for ediff if not sorted
if not issorted:
sidx = lexsort(subs, axis=0)
subs = [sub[sidx] for sub in subs]
vals = vals[sidx]
idx = np.where(np.diff(subs).any(axis=0))[0] + 1
idx = np.concatenate(([0], idx, [subs[0].shape[0]]))
# create values array
nvals = np.zeros(len(idx) - 1)
for i in range(len(idx) - 1):
nvals[i] = func(vals[idx[i]:idx[i + 1]])
# return results
if with_subs:
return nvals, tuple(sub[idx[:-1]] for sub in subs)
else:
return nvals | [
"def",
"accum",
"(",
"subs",
",",
"vals",
",",
"func",
"=",
"np",
".",
"sum",
",",
"issorted",
"=",
"False",
",",
"with_subs",
"=",
"False",
")",
":",
"# sort accmap for ediff if not sorted",
"if",
"not",
"issorted",
":",
"sidx",
"=",
"lexsort",
"(",
"subs",
",",
"axis",
"=",
"0",
")",
"subs",
"=",
"[",
"sub",
"[",
"sidx",
"]",
"for",
"sub",
"in",
"subs",
"]",
"vals",
"=",
"vals",
"[",
"sidx",
"]",
"idx",
"=",
"np",
".",
"where",
"(",
"np",
".",
"diff",
"(",
"subs",
")",
".",
"any",
"(",
"axis",
"=",
"0",
")",
")",
"[",
"0",
"]",
"+",
"1",
"idx",
"=",
"np",
".",
"concatenate",
"(",
"(",
"[",
"0",
"]",
",",
"idx",
",",
"[",
"subs",
"[",
"0",
"]",
".",
"shape",
"[",
"0",
"]",
"]",
")",
")",
"# create values array",
"nvals",
"=",
"np",
".",
"zeros",
"(",
"len",
"(",
"idx",
")",
"-",
"1",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"idx",
")",
"-",
"1",
")",
":",
"nvals",
"[",
"i",
"]",
"=",
"func",
"(",
"vals",
"[",
"idx",
"[",
"i",
"]",
":",
"idx",
"[",
"i",
"+",
"1",
"]",
"]",
")",
"# return results",
"if",
"with_subs",
":",
"return",
"nvals",
",",
"tuple",
"(",
"sub",
"[",
"idx",
"[",
":",
"-",
"1",
"]",
"]",
"for",
"sub",
"in",
"subs",
")",
"else",
":",
"return",
"nvals"
] | NumPy implementation for Matlab's accumarray | [
"NumPy",
"implementation",
"for",
"Matlab",
"s",
"accumarray"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/utils.py#L5-L26 | train |
mnick/scikit-tensor | sktensor/tucker.py | hooi | def hooi(X, rank, **kwargs):
"""
Compute Tucker decomposition of a tensor using Higher-Order Orthogonal
Iterations.
Parameters
----------
X : tensor_mixin
The tensor to be decomposed
rank : array_like
The rank of the decomposition for each mode of the tensor.
The length of ``rank`` must match the number of modes of ``X``.
init : {'random', 'nvecs'}, optional
The initialization method to use.
- random : Factor matrices are initialized randomly.
- nvecs : Factor matrices are initialzed via HOSVD.
default : 'nvecs'
Examples
--------
Create dense tensor
>>> T = np.zeros((3, 4, 2))
>>> T[:, :, 0] = [[ 1, 4, 7, 10], [ 2, 5, 8, 11], [3, 6, 9, 12]]
>>> T[:, :, 1] = [[13, 16, 19, 22], [14, 17, 20, 23], [15, 18, 21, 24]]
>>> T = dtensor(T)
Compute Tucker decomposition of ``T`` with n-rank [2, 3, 1] via higher-order
orthogonal iterations
>>> Y = hooi(T, [2, 3, 1], init='nvecs')
Shape of the core tensor matches n-rank of the decomposition.
>>> Y['core'].shape
(2, 3, 1)
>>> Y['U'][1].shape
(3, 2)
References
----------
.. [1] L. De Lathauwer, B. De Moor, J. Vandewalle: On the best rank-1 and
rank-(R_1, R_2, \ldots, R_N) approximation of higher order tensors;
IEEE Trans. Signal Process. 49 (2001), pp. 2262-2271
"""
# init options
ainit = kwargs.pop('init', __DEF_INIT)
maxIter = kwargs.pop('maxIter', __DEF_MAXITER)
conv = kwargs.pop('conv', __DEF_CONV)
dtype = kwargs.pop('dtype', X.dtype)
if not len(kwargs) == 0:
raise ValueError('Unknown keywords (%s)' % (kwargs.keys()))
ndims = X.ndim
if is_number(rank):
rank = rank * ones(ndims)
normX = norm(X)
U = __init(ainit, X, ndims, rank, dtype)
fit = 0
exectimes = []
for itr in range(maxIter):
tic = time.clock()
fitold = fit
for n in range(ndims):
Utilde = ttm(X, U, n, transp=True, without=True)
U[n] = nvecs(Utilde, n, rank[n])
# compute core tensor to get fit
core = ttm(Utilde, U, n, transp=True)
# since factors are orthonormal, compute fit on core tensor
normresidual = sqrt(normX ** 2 - norm(core) ** 2)
# fraction explained by model
fit = 1 - (normresidual / normX)
fitchange = abs(fitold - fit)
exectimes.append(time.clock() - tic)
_log.debug(
'[%3d] fit: %.5f | delta: %7.1e | secs: %.5f'
% (itr, fit, fitchange, exectimes[-1])
)
if itr > 1 and fitchange < conv:
break
return core, U | python | def hooi(X, rank, **kwargs):
"""
Compute Tucker decomposition of a tensor using Higher-Order Orthogonal
Iterations.
Parameters
----------
X : tensor_mixin
The tensor to be decomposed
rank : array_like
The rank of the decomposition for each mode of the tensor.
The length of ``rank`` must match the number of modes of ``X``.
init : {'random', 'nvecs'}, optional
The initialization method to use.
- random : Factor matrices are initialized randomly.
- nvecs : Factor matrices are initialzed via HOSVD.
default : 'nvecs'
Examples
--------
Create dense tensor
>>> T = np.zeros((3, 4, 2))
>>> T[:, :, 0] = [[ 1, 4, 7, 10], [ 2, 5, 8, 11], [3, 6, 9, 12]]
>>> T[:, :, 1] = [[13, 16, 19, 22], [14, 17, 20, 23], [15, 18, 21, 24]]
>>> T = dtensor(T)
Compute Tucker decomposition of ``T`` with n-rank [2, 3, 1] via higher-order
orthogonal iterations
>>> Y = hooi(T, [2, 3, 1], init='nvecs')
Shape of the core tensor matches n-rank of the decomposition.
>>> Y['core'].shape
(2, 3, 1)
>>> Y['U'][1].shape
(3, 2)
References
----------
.. [1] L. De Lathauwer, B. De Moor, J. Vandewalle: On the best rank-1 and
rank-(R_1, R_2, \ldots, R_N) approximation of higher order tensors;
IEEE Trans. Signal Process. 49 (2001), pp. 2262-2271
"""
# init options
ainit = kwargs.pop('init', __DEF_INIT)
maxIter = kwargs.pop('maxIter', __DEF_MAXITER)
conv = kwargs.pop('conv', __DEF_CONV)
dtype = kwargs.pop('dtype', X.dtype)
if not len(kwargs) == 0:
raise ValueError('Unknown keywords (%s)' % (kwargs.keys()))
ndims = X.ndim
if is_number(rank):
rank = rank * ones(ndims)
normX = norm(X)
U = __init(ainit, X, ndims, rank, dtype)
fit = 0
exectimes = []
for itr in range(maxIter):
tic = time.clock()
fitold = fit
for n in range(ndims):
Utilde = ttm(X, U, n, transp=True, without=True)
U[n] = nvecs(Utilde, n, rank[n])
# compute core tensor to get fit
core = ttm(Utilde, U, n, transp=True)
# since factors are orthonormal, compute fit on core tensor
normresidual = sqrt(normX ** 2 - norm(core) ** 2)
# fraction explained by model
fit = 1 - (normresidual / normX)
fitchange = abs(fitold - fit)
exectimes.append(time.clock() - tic)
_log.debug(
'[%3d] fit: %.5f | delta: %7.1e | secs: %.5f'
% (itr, fit, fitchange, exectimes[-1])
)
if itr > 1 and fitchange < conv:
break
return core, U | [
"def",
"hooi",
"(",
"X",
",",
"rank",
",",
"*",
"*",
"kwargs",
")",
":",
"# init options",
"ainit",
"=",
"kwargs",
".",
"pop",
"(",
"'init'",
",",
"__DEF_INIT",
")",
"maxIter",
"=",
"kwargs",
".",
"pop",
"(",
"'maxIter'",
",",
"__DEF_MAXITER",
")",
"conv",
"=",
"kwargs",
".",
"pop",
"(",
"'conv'",
",",
"__DEF_CONV",
")",
"dtype",
"=",
"kwargs",
".",
"pop",
"(",
"'dtype'",
",",
"X",
".",
"dtype",
")",
"if",
"not",
"len",
"(",
"kwargs",
")",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"'Unknown keywords (%s)'",
"%",
"(",
"kwargs",
".",
"keys",
"(",
")",
")",
")",
"ndims",
"=",
"X",
".",
"ndim",
"if",
"is_number",
"(",
"rank",
")",
":",
"rank",
"=",
"rank",
"*",
"ones",
"(",
"ndims",
")",
"normX",
"=",
"norm",
"(",
"X",
")",
"U",
"=",
"__init",
"(",
"ainit",
",",
"X",
",",
"ndims",
",",
"rank",
",",
"dtype",
")",
"fit",
"=",
"0",
"exectimes",
"=",
"[",
"]",
"for",
"itr",
"in",
"range",
"(",
"maxIter",
")",
":",
"tic",
"=",
"time",
".",
"clock",
"(",
")",
"fitold",
"=",
"fit",
"for",
"n",
"in",
"range",
"(",
"ndims",
")",
":",
"Utilde",
"=",
"ttm",
"(",
"X",
",",
"U",
",",
"n",
",",
"transp",
"=",
"True",
",",
"without",
"=",
"True",
")",
"U",
"[",
"n",
"]",
"=",
"nvecs",
"(",
"Utilde",
",",
"n",
",",
"rank",
"[",
"n",
"]",
")",
"# compute core tensor to get fit",
"core",
"=",
"ttm",
"(",
"Utilde",
",",
"U",
",",
"n",
",",
"transp",
"=",
"True",
")",
"# since factors are orthonormal, compute fit on core tensor",
"normresidual",
"=",
"sqrt",
"(",
"normX",
"**",
"2",
"-",
"norm",
"(",
"core",
")",
"**",
"2",
")",
"# fraction explained by model",
"fit",
"=",
"1",
"-",
"(",
"normresidual",
"/",
"normX",
")",
"fitchange",
"=",
"abs",
"(",
"fitold",
"-",
"fit",
")",
"exectimes",
".",
"append",
"(",
"time",
".",
"clock",
"(",
")",
"-",
"tic",
")",
"_log",
".",
"debug",
"(",
"'[%3d] fit: %.5f | delta: %7.1e | secs: %.5f'",
"%",
"(",
"itr",
",",
"fit",
",",
"fitchange",
",",
"exectimes",
"[",
"-",
"1",
"]",
")",
")",
"if",
"itr",
">",
"1",
"and",
"fitchange",
"<",
"conv",
":",
"break",
"return",
"core",
",",
"U"
] | Compute Tucker decomposition of a tensor using Higher-Order Orthogonal
Iterations.
Parameters
----------
X : tensor_mixin
The tensor to be decomposed
rank : array_like
The rank of the decomposition for each mode of the tensor.
The length of ``rank`` must match the number of modes of ``X``.
init : {'random', 'nvecs'}, optional
The initialization method to use.
- random : Factor matrices are initialized randomly.
- nvecs : Factor matrices are initialzed via HOSVD.
default : 'nvecs'
Examples
--------
Create dense tensor
>>> T = np.zeros((3, 4, 2))
>>> T[:, :, 0] = [[ 1, 4, 7, 10], [ 2, 5, 8, 11], [3, 6, 9, 12]]
>>> T[:, :, 1] = [[13, 16, 19, 22], [14, 17, 20, 23], [15, 18, 21, 24]]
>>> T = dtensor(T)
Compute Tucker decomposition of ``T`` with n-rank [2, 3, 1] via higher-order
orthogonal iterations
>>> Y = hooi(T, [2, 3, 1], init='nvecs')
Shape of the core tensor matches n-rank of the decomposition.
>>> Y['core'].shape
(2, 3, 1)
>>> Y['U'][1].shape
(3, 2)
References
----------
.. [1] L. De Lathauwer, B. De Moor, J. Vandewalle: On the best rank-1 and
rank-(R_1, R_2, \ldots, R_N) approximation of higher order tensors;
IEEE Trans. Signal Process. 49 (2001), pp. 2262-2271 | [
"Compute",
"Tucker",
"decomposition",
"of",
"a",
"tensor",
"using",
"Higher",
"-",
"Order",
"Orthogonal",
"Iterations",
"."
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/tucker.py#L36-L123 | train |
mnick/scikit-tensor | sktensor/ktensor.py | ktensor.uttkrp | def uttkrp(self, U, mode):
"""
Unfolded tensor times Khatri-Rao product for Kruskal tensors
Parameters
----------
X : tensor_mixin
Tensor whose unfolding should be multiplied.
U : list of array_like
Matrices whose Khatri-Rao product should be multiplied.
mode : int
Mode in which X should be unfolded.
See also
--------
sktensor.sptensor.uttkrp : Efficient computation of uttkrp for sparse tensors
ttensor.uttkrp : Efficient computation of uttkrp for Tucker operators
"""
N = self.ndim
if mode == 1:
R = U[1].shape[1]
else:
R = U[0].shape[1]
W = np.tile(self.lmbda, 1, R)
for i in range(mode) + range(mode + 1, N):
W = W * dot(self.U[i].T, U[i])
return dot(self.U[mode], W) | python | def uttkrp(self, U, mode):
"""
Unfolded tensor times Khatri-Rao product for Kruskal tensors
Parameters
----------
X : tensor_mixin
Tensor whose unfolding should be multiplied.
U : list of array_like
Matrices whose Khatri-Rao product should be multiplied.
mode : int
Mode in which X should be unfolded.
See also
--------
sktensor.sptensor.uttkrp : Efficient computation of uttkrp for sparse tensors
ttensor.uttkrp : Efficient computation of uttkrp for Tucker operators
"""
N = self.ndim
if mode == 1:
R = U[1].shape[1]
else:
R = U[0].shape[1]
W = np.tile(self.lmbda, 1, R)
for i in range(mode) + range(mode + 1, N):
W = W * dot(self.U[i].T, U[i])
return dot(self.U[mode], W) | [
"def",
"uttkrp",
"(",
"self",
",",
"U",
",",
"mode",
")",
":",
"N",
"=",
"self",
".",
"ndim",
"if",
"mode",
"==",
"1",
":",
"R",
"=",
"U",
"[",
"1",
"]",
".",
"shape",
"[",
"1",
"]",
"else",
":",
"R",
"=",
"U",
"[",
"0",
"]",
".",
"shape",
"[",
"1",
"]",
"W",
"=",
"np",
".",
"tile",
"(",
"self",
".",
"lmbda",
",",
"1",
",",
"R",
")",
"for",
"i",
"in",
"range",
"(",
"mode",
")",
"+",
"range",
"(",
"mode",
"+",
"1",
",",
"N",
")",
":",
"W",
"=",
"W",
"*",
"dot",
"(",
"self",
".",
"U",
"[",
"i",
"]",
".",
"T",
",",
"U",
"[",
"i",
"]",
")",
"return",
"dot",
"(",
"self",
".",
"U",
"[",
"mode",
"]",
",",
"W",
")"
] | Unfolded tensor times Khatri-Rao product for Kruskal tensors
Parameters
----------
X : tensor_mixin
Tensor whose unfolding should be multiplied.
U : list of array_like
Matrices whose Khatri-Rao product should be multiplied.
mode : int
Mode in which X should be unfolded.
See also
--------
sktensor.sptensor.uttkrp : Efficient computation of uttkrp for sparse tensors
ttensor.uttkrp : Efficient computation of uttkrp for Tucker operators | [
"Unfolded",
"tensor",
"times",
"Khatri",
"-",
"Rao",
"product",
"for",
"Kruskal",
"tensors"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/ktensor.py#L84-L111 | train |
mnick/scikit-tensor | sktensor/ktensor.py | ktensor.norm | def norm(self):
"""
Efficient computation of the Frobenius norm for ktensors
Returns
-------
norm : float
Frobenius norm of the ktensor
"""
N = len(self.shape)
coef = outer(self.lmbda, self.lmbda)
for i in range(N):
coef = coef * dot(self.U[i].T, self.U[i])
return np.sqrt(coef.sum()) | python | def norm(self):
"""
Efficient computation of the Frobenius norm for ktensors
Returns
-------
norm : float
Frobenius norm of the ktensor
"""
N = len(self.shape)
coef = outer(self.lmbda, self.lmbda)
for i in range(N):
coef = coef * dot(self.U[i].T, self.U[i])
return np.sqrt(coef.sum()) | [
"def",
"norm",
"(",
"self",
")",
":",
"N",
"=",
"len",
"(",
"self",
".",
"shape",
")",
"coef",
"=",
"outer",
"(",
"self",
".",
"lmbda",
",",
"self",
".",
"lmbda",
")",
"for",
"i",
"in",
"range",
"(",
"N",
")",
":",
"coef",
"=",
"coef",
"*",
"dot",
"(",
"self",
".",
"U",
"[",
"i",
"]",
".",
"T",
",",
"self",
".",
"U",
"[",
"i",
"]",
")",
"return",
"np",
".",
"sqrt",
"(",
"coef",
".",
"sum",
"(",
")",
")"
] | Efficient computation of the Frobenius norm for ktensors
Returns
-------
norm : float
Frobenius norm of the ktensor | [
"Efficient",
"computation",
"of",
"the",
"Frobenius",
"norm",
"for",
"ktensors"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/ktensor.py#L113-L126 | train |
mnick/scikit-tensor | sktensor/ktensor.py | ktensor.innerprod | def innerprod(self, X):
"""
Efficient computation of the inner product of a ktensor with another tensor
Parameters
----------
X : tensor_mixin
Tensor to compute the inner product with.
Returns
-------
p : float
Inner product between ktensor and X.
"""
N = len(self.shape)
R = len(self.lmbda)
res = 0
for r in range(R):
vecs = []
for n in range(N):
vecs.append(self.U[n][:, r])
res += self.lmbda[r] * X.ttv(tuple(vecs))
return res | python | def innerprod(self, X):
"""
Efficient computation of the inner product of a ktensor with another tensor
Parameters
----------
X : tensor_mixin
Tensor to compute the inner product with.
Returns
-------
p : float
Inner product between ktensor and X.
"""
N = len(self.shape)
R = len(self.lmbda)
res = 0
for r in range(R):
vecs = []
for n in range(N):
vecs.append(self.U[n][:, r])
res += self.lmbda[r] * X.ttv(tuple(vecs))
return res | [
"def",
"innerprod",
"(",
"self",
",",
"X",
")",
":",
"N",
"=",
"len",
"(",
"self",
".",
"shape",
")",
"R",
"=",
"len",
"(",
"self",
".",
"lmbda",
")",
"res",
"=",
"0",
"for",
"r",
"in",
"range",
"(",
"R",
")",
":",
"vecs",
"=",
"[",
"]",
"for",
"n",
"in",
"range",
"(",
"N",
")",
":",
"vecs",
".",
"append",
"(",
"self",
".",
"U",
"[",
"n",
"]",
"[",
":",
",",
"r",
"]",
")",
"res",
"+=",
"self",
".",
"lmbda",
"[",
"r",
"]",
"*",
"X",
".",
"ttv",
"(",
"tuple",
"(",
"vecs",
")",
")",
"return",
"res"
] | Efficient computation of the inner product of a ktensor with another tensor
Parameters
----------
X : tensor_mixin
Tensor to compute the inner product with.
Returns
-------
p : float
Inner product between ktensor and X. | [
"Efficient",
"computation",
"of",
"the",
"inner",
"product",
"of",
"a",
"ktensor",
"with",
"another",
"tensor"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/ktensor.py#L128-L150 | train |
mnick/scikit-tensor | sktensor/ktensor.py | ktensor.toarray | def toarray(self):
"""
Converts a ktensor into a dense multidimensional ndarray
Returns
-------
arr : np.ndarray
Fully computed multidimensional array whose shape matches
the original ktensor.
"""
A = dot(self.lmbda, khatrirao(tuple(self.U)).T)
return A.reshape(self.shape) | python | def toarray(self):
"""
Converts a ktensor into a dense multidimensional ndarray
Returns
-------
arr : np.ndarray
Fully computed multidimensional array whose shape matches
the original ktensor.
"""
A = dot(self.lmbda, khatrirao(tuple(self.U)).T)
return A.reshape(self.shape) | [
"def",
"toarray",
"(",
"self",
")",
":",
"A",
"=",
"dot",
"(",
"self",
".",
"lmbda",
",",
"khatrirao",
"(",
"tuple",
"(",
"self",
".",
"U",
")",
")",
".",
"T",
")",
"return",
"A",
".",
"reshape",
"(",
"self",
".",
"shape",
")"
] | Converts a ktensor into a dense multidimensional ndarray
Returns
-------
arr : np.ndarray
Fully computed multidimensional array whose shape matches
the original ktensor. | [
"Converts",
"a",
"ktensor",
"into",
"a",
"dense",
"multidimensional",
"ndarray"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/ktensor.py#L152-L163 | train |
mnick/scikit-tensor | sktensor/sptensor.py | fromarray | def fromarray(A):
"""Create a sptensor from a dense numpy array"""
subs = np.nonzero(A)
vals = A[subs]
return sptensor(subs, vals, shape=A.shape, dtype=A.dtype) | python | def fromarray(A):
"""Create a sptensor from a dense numpy array"""
subs = np.nonzero(A)
vals = A[subs]
return sptensor(subs, vals, shape=A.shape, dtype=A.dtype) | [
"def",
"fromarray",
"(",
"A",
")",
":",
"subs",
"=",
"np",
".",
"nonzero",
"(",
"A",
")",
"vals",
"=",
"A",
"[",
"subs",
"]",
"return",
"sptensor",
"(",
"subs",
",",
"vals",
",",
"shape",
"=",
"A",
".",
"shape",
",",
"dtype",
"=",
"A",
".",
"dtype",
")"
] | Create a sptensor from a dense numpy array | [
"Create",
"a",
"sptensor",
"from",
"a",
"dense",
"numpy",
"array"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/sptensor.py#L362-L366 | train |
mnick/scikit-tensor | sktensor/sptensor.py | sptensor._ttm_me_compute | def _ttm_me_compute(self, V, edims, sdims, transp):
"""
Assume Y = T x_i V_i for i = 1...n can fit into memory
"""
shapeY = np.copy(self.shape)
# Determine size of Y
for n in np.union1d(edims, sdims):
shapeY[n] = V[n].shape[1] if transp else V[n].shape[0]
# Allocate Y (final result) and v (vectors for elementwise computations)
Y = zeros(shapeY)
shapeY = array(shapeY)
v = [None for _ in range(len(edims))]
for i in range(np.prod(shapeY[edims])):
rsubs = unravel_index(shapeY[edims], i) | python | def _ttm_me_compute(self, V, edims, sdims, transp):
"""
Assume Y = T x_i V_i for i = 1...n can fit into memory
"""
shapeY = np.copy(self.shape)
# Determine size of Y
for n in np.union1d(edims, sdims):
shapeY[n] = V[n].shape[1] if transp else V[n].shape[0]
# Allocate Y (final result) and v (vectors for elementwise computations)
Y = zeros(shapeY)
shapeY = array(shapeY)
v = [None for _ in range(len(edims))]
for i in range(np.prod(shapeY[edims])):
rsubs = unravel_index(shapeY[edims], i) | [
"def",
"_ttm_me_compute",
"(",
"self",
",",
"V",
",",
"edims",
",",
"sdims",
",",
"transp",
")",
":",
"shapeY",
"=",
"np",
".",
"copy",
"(",
"self",
".",
"shape",
")",
"# Determine size of Y",
"for",
"n",
"in",
"np",
".",
"union1d",
"(",
"edims",
",",
"sdims",
")",
":",
"shapeY",
"[",
"n",
"]",
"=",
"V",
"[",
"n",
"]",
".",
"shape",
"[",
"1",
"]",
"if",
"transp",
"else",
"V",
"[",
"n",
"]",
".",
"shape",
"[",
"0",
"]",
"# Allocate Y (final result) and v (vectors for elementwise computations)",
"Y",
"=",
"zeros",
"(",
"shapeY",
")",
"shapeY",
"=",
"array",
"(",
"shapeY",
")",
"v",
"=",
"[",
"None",
"for",
"_",
"in",
"range",
"(",
"len",
"(",
"edims",
")",
")",
"]",
"for",
"i",
"in",
"range",
"(",
"np",
".",
"prod",
"(",
"shapeY",
"[",
"edims",
"]",
")",
")",
":",
"rsubs",
"=",
"unravel_index",
"(",
"shapeY",
"[",
"edims",
"]",
",",
"i",
")"
] | Assume Y = T x_i V_i for i = 1...n can fit into memory | [
"Assume",
"Y",
"=",
"T",
"x_i",
"V_i",
"for",
"i",
"=",
"1",
"...",
"n",
"can",
"fit",
"into",
"memory"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/sptensor.py#L179-L195 | train |
mnick/scikit-tensor | sktensor/sptensor.py | sptensor.transpose | def transpose(self, axes=None):
"""
Compute transpose of sparse tensors.
Parameters
----------
axes : array_like of ints, optional
Permute the axes according to the values given.
Returns
-------
d : dtensor
dtensor with axes permuted.
"""
if axes is None:
raise NotImplementedError(
'Sparse tensor transposition without axes argument is not supported'
)
nsubs = tuple([self.subs[idx] for idx in axes])
nshape = [self.shape[idx] for idx in axes]
return sptensor(nsubs, self.vals, nshape) | python | def transpose(self, axes=None):
"""
Compute transpose of sparse tensors.
Parameters
----------
axes : array_like of ints, optional
Permute the axes according to the values given.
Returns
-------
d : dtensor
dtensor with axes permuted.
"""
if axes is None:
raise NotImplementedError(
'Sparse tensor transposition without axes argument is not supported'
)
nsubs = tuple([self.subs[idx] for idx in axes])
nshape = [self.shape[idx] for idx in axes]
return sptensor(nsubs, self.vals, nshape) | [
"def",
"transpose",
"(",
"self",
",",
"axes",
"=",
"None",
")",
":",
"if",
"axes",
"is",
"None",
":",
"raise",
"NotImplementedError",
"(",
"'Sparse tensor transposition without axes argument is not supported'",
")",
"nsubs",
"=",
"tuple",
"(",
"[",
"self",
".",
"subs",
"[",
"idx",
"]",
"for",
"idx",
"in",
"axes",
"]",
")",
"nshape",
"=",
"[",
"self",
".",
"shape",
"[",
"idx",
"]",
"for",
"idx",
"in",
"axes",
"]",
"return",
"sptensor",
"(",
"nsubs",
",",
"self",
".",
"vals",
",",
"nshape",
")"
] | Compute transpose of sparse tensors.
Parameters
----------
axes : array_like of ints, optional
Permute the axes according to the values given.
Returns
-------
d : dtensor
dtensor with axes permuted. | [
"Compute",
"transpose",
"of",
"sparse",
"tensors",
"."
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/sptensor.py#L232-L252 | train |
mnick/scikit-tensor | sktensor/sptensor.py | sptensor.concatenate | def concatenate(self, tpl, axis=None):
"""
Concatenates sparse tensors.
Parameters
----------
tpl : tuple of sparse tensors
Tensors to be concatenated.
axis : int, optional
Axis along which concatenation should take place
"""
if axis is None:
raise NotImplementedError(
'Sparse tensor concatenation without axis argument is not supported'
)
T = self
for i in range(1, len(tpl)):
T = _single_concatenate(T, tpl[i], axis=axis)
return T | python | def concatenate(self, tpl, axis=None):
"""
Concatenates sparse tensors.
Parameters
----------
tpl : tuple of sparse tensors
Tensors to be concatenated.
axis : int, optional
Axis along which concatenation should take place
"""
if axis is None:
raise NotImplementedError(
'Sparse tensor concatenation without axis argument is not supported'
)
T = self
for i in range(1, len(tpl)):
T = _single_concatenate(T, tpl[i], axis=axis)
return T | [
"def",
"concatenate",
"(",
"self",
",",
"tpl",
",",
"axis",
"=",
"None",
")",
":",
"if",
"axis",
"is",
"None",
":",
"raise",
"NotImplementedError",
"(",
"'Sparse tensor concatenation without axis argument is not supported'",
")",
"T",
"=",
"self",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"tpl",
")",
")",
":",
"T",
"=",
"_single_concatenate",
"(",
"T",
",",
"tpl",
"[",
"i",
"]",
",",
"axis",
"=",
"axis",
")",
"return",
"T"
] | Concatenates sparse tensors.
Parameters
----------
tpl : tuple of sparse tensors
Tensors to be concatenated.
axis : int, optional
Axis along which concatenation should take place | [
"Concatenates",
"sparse",
"tensors",
"."
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/sptensor.py#L254-L272 | train |
mnick/scikit-tensor | sktensor/sptensor.py | unfolded_sptensor.fold | def fold(self):
"""
Recreate original tensor by folding unfolded_sptensor according toc
``ten_shape``.
Returns
-------
T : sptensor
Sparse tensor that is created by refolding according to ``ten_shape``.
"""
nsubs = zeros((len(self.data), len(self.ten_shape)), dtype=np.int)
if len(self.rdims) > 0:
nidx = unravel_index(self.row, self.ten_shape[self.rdims])
for i in range(len(self.rdims)):
nsubs[:, self.rdims[i]] = nidx[i]
if len(self.cdims) > 0:
nidx = unravel_index(self.col, self.ten_shape[self.cdims])
for i in range(len(self.cdims)):
nsubs[:, self.cdims[i]] = nidx[i]
nsubs = [z.flatten() for z in hsplit(nsubs, len(self.ten_shape))]
return sptensor(tuple(nsubs), self.data, self.ten_shape) | python | def fold(self):
"""
Recreate original tensor by folding unfolded_sptensor according toc
``ten_shape``.
Returns
-------
T : sptensor
Sparse tensor that is created by refolding according to ``ten_shape``.
"""
nsubs = zeros((len(self.data), len(self.ten_shape)), dtype=np.int)
if len(self.rdims) > 0:
nidx = unravel_index(self.row, self.ten_shape[self.rdims])
for i in range(len(self.rdims)):
nsubs[:, self.rdims[i]] = nidx[i]
if len(self.cdims) > 0:
nidx = unravel_index(self.col, self.ten_shape[self.cdims])
for i in range(len(self.cdims)):
nsubs[:, self.cdims[i]] = nidx[i]
nsubs = [z.flatten() for z in hsplit(nsubs, len(self.ten_shape))]
return sptensor(tuple(nsubs), self.data, self.ten_shape) | [
"def",
"fold",
"(",
"self",
")",
":",
"nsubs",
"=",
"zeros",
"(",
"(",
"len",
"(",
"self",
".",
"data",
")",
",",
"len",
"(",
"self",
".",
"ten_shape",
")",
")",
",",
"dtype",
"=",
"np",
".",
"int",
")",
"if",
"len",
"(",
"self",
".",
"rdims",
")",
">",
"0",
":",
"nidx",
"=",
"unravel_index",
"(",
"self",
".",
"row",
",",
"self",
".",
"ten_shape",
"[",
"self",
".",
"rdims",
"]",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"rdims",
")",
")",
":",
"nsubs",
"[",
":",
",",
"self",
".",
"rdims",
"[",
"i",
"]",
"]",
"=",
"nidx",
"[",
"i",
"]",
"if",
"len",
"(",
"self",
".",
"cdims",
")",
">",
"0",
":",
"nidx",
"=",
"unravel_index",
"(",
"self",
".",
"col",
",",
"self",
".",
"ten_shape",
"[",
"self",
".",
"cdims",
"]",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"cdims",
")",
")",
":",
"nsubs",
"[",
":",
",",
"self",
".",
"cdims",
"[",
"i",
"]",
"]",
"=",
"nidx",
"[",
"i",
"]",
"nsubs",
"=",
"[",
"z",
".",
"flatten",
"(",
")",
"for",
"z",
"in",
"hsplit",
"(",
"nsubs",
",",
"len",
"(",
"self",
".",
"ten_shape",
")",
")",
"]",
"return",
"sptensor",
"(",
"tuple",
"(",
"nsubs",
")",
",",
"self",
".",
"data",
",",
"self",
".",
"ten_shape",
")"
] | Recreate original tensor by folding unfolded_sptensor according toc
``ten_shape``.
Returns
-------
T : sptensor
Sparse tensor that is created by refolding according to ``ten_shape``. | [
"Recreate",
"original",
"tensor",
"by",
"folding",
"unfolded_sptensor",
"according",
"toc",
"ten_shape",
"."
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/sptensor.py#L339-L359 | train |
mnick/scikit-tensor | sktensor/rescal.py | _updateA | def _updateA(X, A, R, P, Z, lmbdaA, orthogonalize):
"""Update step for A"""
n, rank = A.shape
F = zeros((n, rank), dtype=A.dtype)
E = zeros((rank, rank), dtype=A.dtype)
AtA = dot(A.T, A)
for i in range(len(X)):
F += X[i].dot(dot(A, R[i].T)) + X[i].T.dot(dot(A, R[i]))
E += dot(R[i], dot(AtA, R[i].T)) + dot(R[i].T, dot(AtA, R[i]))
# regularization
I = lmbdaA * eye(rank, dtype=A.dtype)
# attributes
for i in range(len(Z)):
F += P[i].dot(Z[i].T)
E += dot(Z[i], Z[i].T)
# finally compute update for A
A = solve(I + E.T, F.T).T
return orth(A) if orthogonalize else A | python | def _updateA(X, A, R, P, Z, lmbdaA, orthogonalize):
"""Update step for A"""
n, rank = A.shape
F = zeros((n, rank), dtype=A.dtype)
E = zeros((rank, rank), dtype=A.dtype)
AtA = dot(A.T, A)
for i in range(len(X)):
F += X[i].dot(dot(A, R[i].T)) + X[i].T.dot(dot(A, R[i]))
E += dot(R[i], dot(AtA, R[i].T)) + dot(R[i].T, dot(AtA, R[i]))
# regularization
I = lmbdaA * eye(rank, dtype=A.dtype)
# attributes
for i in range(len(Z)):
F += P[i].dot(Z[i].T)
E += dot(Z[i], Z[i].T)
# finally compute update for A
A = solve(I + E.T, F.T).T
return orth(A) if orthogonalize else A | [
"def",
"_updateA",
"(",
"X",
",",
"A",
",",
"R",
",",
"P",
",",
"Z",
",",
"lmbdaA",
",",
"orthogonalize",
")",
":",
"n",
",",
"rank",
"=",
"A",
".",
"shape",
"F",
"=",
"zeros",
"(",
"(",
"n",
",",
"rank",
")",
",",
"dtype",
"=",
"A",
".",
"dtype",
")",
"E",
"=",
"zeros",
"(",
"(",
"rank",
",",
"rank",
")",
",",
"dtype",
"=",
"A",
".",
"dtype",
")",
"AtA",
"=",
"dot",
"(",
"A",
".",
"T",
",",
"A",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"X",
")",
")",
":",
"F",
"+=",
"X",
"[",
"i",
"]",
".",
"dot",
"(",
"dot",
"(",
"A",
",",
"R",
"[",
"i",
"]",
".",
"T",
")",
")",
"+",
"X",
"[",
"i",
"]",
".",
"T",
".",
"dot",
"(",
"dot",
"(",
"A",
",",
"R",
"[",
"i",
"]",
")",
")",
"E",
"+=",
"dot",
"(",
"R",
"[",
"i",
"]",
",",
"dot",
"(",
"AtA",
",",
"R",
"[",
"i",
"]",
".",
"T",
")",
")",
"+",
"dot",
"(",
"R",
"[",
"i",
"]",
".",
"T",
",",
"dot",
"(",
"AtA",
",",
"R",
"[",
"i",
"]",
")",
")",
"# regularization",
"I",
"=",
"lmbdaA",
"*",
"eye",
"(",
"rank",
",",
"dtype",
"=",
"A",
".",
"dtype",
")",
"# attributes",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"Z",
")",
")",
":",
"F",
"+=",
"P",
"[",
"i",
"]",
".",
"dot",
"(",
"Z",
"[",
"i",
"]",
".",
"T",
")",
"E",
"+=",
"dot",
"(",
"Z",
"[",
"i",
"]",
",",
"Z",
"[",
"i",
"]",
".",
"T",
")",
"# finally compute update for A",
"A",
"=",
"solve",
"(",
"I",
"+",
"E",
".",
"T",
",",
"F",
".",
"T",
")",
".",
"T",
"return",
"orth",
"(",
"A",
")",
"if",
"orthogonalize",
"else",
"A"
] | Update step for A | [
"Update",
"step",
"for",
"A"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/rescal.py#L212-L234 | train |
mnick/scikit-tensor | sktensor/rescal.py | _compute_fval | def _compute_fval(X, A, R, P, Z, lmbdaA, lmbdaR, lmbdaZ, normX):
"""Compute fit for full slices"""
f = lmbdaA * norm(A) ** 2
for i in range(len(X)):
ARAt = dot(A, dot(R[i], A.T))
f += (norm(X[i] - ARAt) ** 2) / normX[i] + lmbdaR * norm(R[i]) ** 2
return f | python | def _compute_fval(X, A, R, P, Z, lmbdaA, lmbdaR, lmbdaZ, normX):
"""Compute fit for full slices"""
f = lmbdaA * norm(A) ** 2
for i in range(len(X)):
ARAt = dot(A, dot(R[i], A.T))
f += (norm(X[i] - ARAt) ** 2) / normX[i] + lmbdaR * norm(R[i]) ** 2
return f | [
"def",
"_compute_fval",
"(",
"X",
",",
"A",
",",
"R",
",",
"P",
",",
"Z",
",",
"lmbdaA",
",",
"lmbdaR",
",",
"lmbdaZ",
",",
"normX",
")",
":",
"f",
"=",
"lmbdaA",
"*",
"norm",
"(",
"A",
")",
"**",
"2",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"X",
")",
")",
":",
"ARAt",
"=",
"dot",
"(",
"A",
",",
"dot",
"(",
"R",
"[",
"i",
"]",
",",
"A",
".",
"T",
")",
")",
"f",
"+=",
"(",
"norm",
"(",
"X",
"[",
"i",
"]",
"-",
"ARAt",
")",
"**",
"2",
")",
"/",
"normX",
"[",
"i",
"]",
"+",
"lmbdaR",
"*",
"norm",
"(",
"R",
"[",
"i",
"]",
")",
"**",
"2",
"return",
"f"
] | Compute fit for full slices | [
"Compute",
"fit",
"for",
"full",
"slices"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/rescal.py#L268-L274 | train |
mnick/scikit-tensor | sktensor/cp.py | als | def als(X, rank, **kwargs):
"""
Alternating least-sqaures algorithm to compute the CP decomposition.
Parameters
----------
X : tensor_mixin
The tensor to be decomposed.
rank : int
Tensor rank of the decomposition.
init : {'random', 'nvecs'}, optional
The initialization method to use.
- random : Factor matrices are initialized randomly.
- nvecs : Factor matrices are initialzed via HOSVD.
(default 'nvecs')
max_iter : int, optional
Maximium number of iterations of the ALS algorithm.
(default 500)
fit_method : {'full', None}
The method to compute the fit of the factorization
- 'full' : Compute least-squares fit of the dense approximation of.
X and X.
- None : Do not compute the fit of the factorization, but iterate
until ``max_iter`` (Useful for large-scale tensors).
(default 'full')
conv : float
Convergence tolerance on difference of fit between iterations
(default 1e-5)
Returns
-------
P : ktensor
Rank ``rank`` factorization of X. ``P.U[i]`` corresponds to the factor
matrix for the i-th mode. ``P.lambda[i]`` corresponds to the weight
of the i-th mode.
fit : float
Fit of the factorization compared to ``X``
itr : int
Number of iterations that were needed until convergence
exectimes : ndarray of floats
Time needed for each single iteration
Examples
--------
Create random dense tensor
>>> from sktensor import dtensor, ktensor
>>> U = [np.random.rand(i,3) for i in (20, 10, 14)]
>>> T = dtensor(ktensor(U).toarray())
Compute rank-3 CP decomposition of ``T`` with ALS
>>> P, fit, itr, _ = als(T, 3)
Result is a decomposed tensor stored as a Kruskal operator
>>> type(P)
<class 'sktensor.ktensor.ktensor'>
Factorization should be close to original data
>>> np.allclose(T, P.totensor())
True
References
----------
.. [1] Kolda, T. G. & Bader, B. W.
Tensor Decompositions and Applications.
SIAM Rev. 51, 455–500 (2009).
.. [2] Harshman, R. A.
Foundations of the PARAFAC procedure: models and conditions for an 'explanatory' multimodal factor analysis.
UCLA Working Papers in Phonetics 16, (1970).
.. [3] Carroll, J. D., Chang, J. J.
Analysis of individual differences in multidimensional scaling via an N-way generalization of 'Eckart-Young' decomposition.
Psychometrika 35, 283–319 (1970).
"""
# init options
ainit = kwargs.pop('init', _DEF_INIT)
maxiter = kwargs.pop('max_iter', _DEF_MAXITER)
fit_method = kwargs.pop('fit_method', _DEF_FIT_METHOD)
conv = kwargs.pop('conv', _DEF_CONV)
dtype = kwargs.pop('dtype', _DEF_TYPE)
if not len(kwargs) == 0:
raise ValueError('Unknown keywords (%s)' % (kwargs.keys()))
N = X.ndim
normX = norm(X)
U = _init(ainit, X, N, rank, dtype)
fit = 0
exectimes = []
for itr in range(maxiter):
tic = time.clock()
fitold = fit
for n in range(N):
Unew = X.uttkrp(U, n)
Y = ones((rank, rank), dtype=dtype)
for i in (list(range(n)) + list(range(n + 1, N))):
Y = Y * dot(U[i].T, U[i])
Unew = Unew.dot(pinv(Y))
# Normalize
if itr == 0:
lmbda = sqrt((Unew ** 2).sum(axis=0))
else:
lmbda = Unew.max(axis=0)
lmbda[lmbda < 1] = 1
U[n] = Unew / lmbda
P = ktensor(U, lmbda)
if fit_method == 'full':
normresidual = normX ** 2 + P.norm() ** 2 - 2 * P.innerprod(X)
fit = 1 - (normresidual / normX ** 2)
else:
fit = itr
fitchange = abs(fitold - fit)
exectimes.append(time.clock() - tic)
_log.debug(
'[%3d] fit: %.5f | delta: %7.1e | secs: %.5f' %
(itr, fit, fitchange, exectimes[-1])
)
if itr > 0 and fitchange < conv:
break
return P, fit, itr, array(exectimes) | python | def als(X, rank, **kwargs):
"""
Alternating least-sqaures algorithm to compute the CP decomposition.
Parameters
----------
X : tensor_mixin
The tensor to be decomposed.
rank : int
Tensor rank of the decomposition.
init : {'random', 'nvecs'}, optional
The initialization method to use.
- random : Factor matrices are initialized randomly.
- nvecs : Factor matrices are initialzed via HOSVD.
(default 'nvecs')
max_iter : int, optional
Maximium number of iterations of the ALS algorithm.
(default 500)
fit_method : {'full', None}
The method to compute the fit of the factorization
- 'full' : Compute least-squares fit of the dense approximation of.
X and X.
- None : Do not compute the fit of the factorization, but iterate
until ``max_iter`` (Useful for large-scale tensors).
(default 'full')
conv : float
Convergence tolerance on difference of fit between iterations
(default 1e-5)
Returns
-------
P : ktensor
Rank ``rank`` factorization of X. ``P.U[i]`` corresponds to the factor
matrix for the i-th mode. ``P.lambda[i]`` corresponds to the weight
of the i-th mode.
fit : float
Fit of the factorization compared to ``X``
itr : int
Number of iterations that were needed until convergence
exectimes : ndarray of floats
Time needed for each single iteration
Examples
--------
Create random dense tensor
>>> from sktensor import dtensor, ktensor
>>> U = [np.random.rand(i,3) for i in (20, 10, 14)]
>>> T = dtensor(ktensor(U).toarray())
Compute rank-3 CP decomposition of ``T`` with ALS
>>> P, fit, itr, _ = als(T, 3)
Result is a decomposed tensor stored as a Kruskal operator
>>> type(P)
<class 'sktensor.ktensor.ktensor'>
Factorization should be close to original data
>>> np.allclose(T, P.totensor())
True
References
----------
.. [1] Kolda, T. G. & Bader, B. W.
Tensor Decompositions and Applications.
SIAM Rev. 51, 455–500 (2009).
.. [2] Harshman, R. A.
Foundations of the PARAFAC procedure: models and conditions for an 'explanatory' multimodal factor analysis.
UCLA Working Papers in Phonetics 16, (1970).
.. [3] Carroll, J. D., Chang, J. J.
Analysis of individual differences in multidimensional scaling via an N-way generalization of 'Eckart-Young' decomposition.
Psychometrika 35, 283–319 (1970).
"""
# init options
ainit = kwargs.pop('init', _DEF_INIT)
maxiter = kwargs.pop('max_iter', _DEF_MAXITER)
fit_method = kwargs.pop('fit_method', _DEF_FIT_METHOD)
conv = kwargs.pop('conv', _DEF_CONV)
dtype = kwargs.pop('dtype', _DEF_TYPE)
if not len(kwargs) == 0:
raise ValueError('Unknown keywords (%s)' % (kwargs.keys()))
N = X.ndim
normX = norm(X)
U = _init(ainit, X, N, rank, dtype)
fit = 0
exectimes = []
for itr in range(maxiter):
tic = time.clock()
fitold = fit
for n in range(N):
Unew = X.uttkrp(U, n)
Y = ones((rank, rank), dtype=dtype)
for i in (list(range(n)) + list(range(n + 1, N))):
Y = Y * dot(U[i].T, U[i])
Unew = Unew.dot(pinv(Y))
# Normalize
if itr == 0:
lmbda = sqrt((Unew ** 2).sum(axis=0))
else:
lmbda = Unew.max(axis=0)
lmbda[lmbda < 1] = 1
U[n] = Unew / lmbda
P = ktensor(U, lmbda)
if fit_method == 'full':
normresidual = normX ** 2 + P.norm() ** 2 - 2 * P.innerprod(X)
fit = 1 - (normresidual / normX ** 2)
else:
fit = itr
fitchange = abs(fitold - fit)
exectimes.append(time.clock() - tic)
_log.debug(
'[%3d] fit: %.5f | delta: %7.1e | secs: %.5f' %
(itr, fit, fitchange, exectimes[-1])
)
if itr > 0 and fitchange < conv:
break
return P, fit, itr, array(exectimes) | [
"def",
"als",
"(",
"X",
",",
"rank",
",",
"*",
"*",
"kwargs",
")",
":",
"# init options",
"ainit",
"=",
"kwargs",
".",
"pop",
"(",
"'init'",
",",
"_DEF_INIT",
")",
"maxiter",
"=",
"kwargs",
".",
"pop",
"(",
"'max_iter'",
",",
"_DEF_MAXITER",
")",
"fit_method",
"=",
"kwargs",
".",
"pop",
"(",
"'fit_method'",
",",
"_DEF_FIT_METHOD",
")",
"conv",
"=",
"kwargs",
".",
"pop",
"(",
"'conv'",
",",
"_DEF_CONV",
")",
"dtype",
"=",
"kwargs",
".",
"pop",
"(",
"'dtype'",
",",
"_DEF_TYPE",
")",
"if",
"not",
"len",
"(",
"kwargs",
")",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"'Unknown keywords (%s)'",
"%",
"(",
"kwargs",
".",
"keys",
"(",
")",
")",
")",
"N",
"=",
"X",
".",
"ndim",
"normX",
"=",
"norm",
"(",
"X",
")",
"U",
"=",
"_init",
"(",
"ainit",
",",
"X",
",",
"N",
",",
"rank",
",",
"dtype",
")",
"fit",
"=",
"0",
"exectimes",
"=",
"[",
"]",
"for",
"itr",
"in",
"range",
"(",
"maxiter",
")",
":",
"tic",
"=",
"time",
".",
"clock",
"(",
")",
"fitold",
"=",
"fit",
"for",
"n",
"in",
"range",
"(",
"N",
")",
":",
"Unew",
"=",
"X",
".",
"uttkrp",
"(",
"U",
",",
"n",
")",
"Y",
"=",
"ones",
"(",
"(",
"rank",
",",
"rank",
")",
",",
"dtype",
"=",
"dtype",
")",
"for",
"i",
"in",
"(",
"list",
"(",
"range",
"(",
"n",
")",
")",
"+",
"list",
"(",
"range",
"(",
"n",
"+",
"1",
",",
"N",
")",
")",
")",
":",
"Y",
"=",
"Y",
"*",
"dot",
"(",
"U",
"[",
"i",
"]",
".",
"T",
",",
"U",
"[",
"i",
"]",
")",
"Unew",
"=",
"Unew",
".",
"dot",
"(",
"pinv",
"(",
"Y",
")",
")",
"# Normalize",
"if",
"itr",
"==",
"0",
":",
"lmbda",
"=",
"sqrt",
"(",
"(",
"Unew",
"**",
"2",
")",
".",
"sum",
"(",
"axis",
"=",
"0",
")",
")",
"else",
":",
"lmbda",
"=",
"Unew",
".",
"max",
"(",
"axis",
"=",
"0",
")",
"lmbda",
"[",
"lmbda",
"<",
"1",
"]",
"=",
"1",
"U",
"[",
"n",
"]",
"=",
"Unew",
"/",
"lmbda",
"P",
"=",
"ktensor",
"(",
"U",
",",
"lmbda",
")",
"if",
"fit_method",
"==",
"'full'",
":",
"normresidual",
"=",
"normX",
"**",
"2",
"+",
"P",
".",
"norm",
"(",
")",
"**",
"2",
"-",
"2",
"*",
"P",
".",
"innerprod",
"(",
"X",
")",
"fit",
"=",
"1",
"-",
"(",
"normresidual",
"/",
"normX",
"**",
"2",
")",
"else",
":",
"fit",
"=",
"itr",
"fitchange",
"=",
"abs",
"(",
"fitold",
"-",
"fit",
")",
"exectimes",
".",
"append",
"(",
"time",
".",
"clock",
"(",
")",
"-",
"tic",
")",
"_log",
".",
"debug",
"(",
"'[%3d] fit: %.5f | delta: %7.1e | secs: %.5f'",
"%",
"(",
"itr",
",",
"fit",
",",
"fitchange",
",",
"exectimes",
"[",
"-",
"1",
"]",
")",
")",
"if",
"itr",
">",
"0",
"and",
"fitchange",
"<",
"conv",
":",
"break",
"return",
"P",
",",
"fit",
",",
"itr",
",",
"array",
"(",
"exectimes",
")"
] | Alternating least-sqaures algorithm to compute the CP decomposition.
Parameters
----------
X : tensor_mixin
The tensor to be decomposed.
rank : int
Tensor rank of the decomposition.
init : {'random', 'nvecs'}, optional
The initialization method to use.
- random : Factor matrices are initialized randomly.
- nvecs : Factor matrices are initialzed via HOSVD.
(default 'nvecs')
max_iter : int, optional
Maximium number of iterations of the ALS algorithm.
(default 500)
fit_method : {'full', None}
The method to compute the fit of the factorization
- 'full' : Compute least-squares fit of the dense approximation of.
X and X.
- None : Do not compute the fit of the factorization, but iterate
until ``max_iter`` (Useful for large-scale tensors).
(default 'full')
conv : float
Convergence tolerance on difference of fit between iterations
(default 1e-5)
Returns
-------
P : ktensor
Rank ``rank`` factorization of X. ``P.U[i]`` corresponds to the factor
matrix for the i-th mode. ``P.lambda[i]`` corresponds to the weight
of the i-th mode.
fit : float
Fit of the factorization compared to ``X``
itr : int
Number of iterations that were needed until convergence
exectimes : ndarray of floats
Time needed for each single iteration
Examples
--------
Create random dense tensor
>>> from sktensor import dtensor, ktensor
>>> U = [np.random.rand(i,3) for i in (20, 10, 14)]
>>> T = dtensor(ktensor(U).toarray())
Compute rank-3 CP decomposition of ``T`` with ALS
>>> P, fit, itr, _ = als(T, 3)
Result is a decomposed tensor stored as a Kruskal operator
>>> type(P)
<class 'sktensor.ktensor.ktensor'>
Factorization should be close to original data
>>> np.allclose(T, P.totensor())
True
References
----------
.. [1] Kolda, T. G. & Bader, B. W.
Tensor Decompositions and Applications.
SIAM Rev. 51, 455–500 (2009).
.. [2] Harshman, R. A.
Foundations of the PARAFAC procedure: models and conditions for an 'explanatory' multimodal factor analysis.
UCLA Working Papers in Phonetics 16, (1970).
.. [3] Carroll, J. D., Chang, J. J.
Analysis of individual differences in multidimensional scaling via an N-way generalization of 'Eckart-Young' decomposition.
Psychometrika 35, 283–319 (1970). | [
"Alternating",
"least",
"-",
"sqaures",
"algorithm",
"to",
"compute",
"the",
"CP",
"decomposition",
"."
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/cp.py#L46-L171 | train |
mnick/scikit-tensor | sktensor/cp.py | _init | def _init(init, X, N, rank, dtype):
"""
Initialization for CP models
"""
Uinit = [None for _ in range(N)]
if isinstance(init, list):
Uinit = init
elif init == 'random':
for n in range(1, N):
Uinit[n] = array(rand(X.shape[n], rank), dtype=dtype)
elif init == 'nvecs':
for n in range(1, N):
Uinit[n] = array(nvecs(X, n, rank), dtype=dtype)
else:
raise 'Unknown option (init=%s)' % str(init)
return Uinit | python | def _init(init, X, N, rank, dtype):
"""
Initialization for CP models
"""
Uinit = [None for _ in range(N)]
if isinstance(init, list):
Uinit = init
elif init == 'random':
for n in range(1, N):
Uinit[n] = array(rand(X.shape[n], rank), dtype=dtype)
elif init == 'nvecs':
for n in range(1, N):
Uinit[n] = array(nvecs(X, n, rank), dtype=dtype)
else:
raise 'Unknown option (init=%s)' % str(init)
return Uinit | [
"def",
"_init",
"(",
"init",
",",
"X",
",",
"N",
",",
"rank",
",",
"dtype",
")",
":",
"Uinit",
"=",
"[",
"None",
"for",
"_",
"in",
"range",
"(",
"N",
")",
"]",
"if",
"isinstance",
"(",
"init",
",",
"list",
")",
":",
"Uinit",
"=",
"init",
"elif",
"init",
"==",
"'random'",
":",
"for",
"n",
"in",
"range",
"(",
"1",
",",
"N",
")",
":",
"Uinit",
"[",
"n",
"]",
"=",
"array",
"(",
"rand",
"(",
"X",
".",
"shape",
"[",
"n",
"]",
",",
"rank",
")",
",",
"dtype",
"=",
"dtype",
")",
"elif",
"init",
"==",
"'nvecs'",
":",
"for",
"n",
"in",
"range",
"(",
"1",
",",
"N",
")",
":",
"Uinit",
"[",
"n",
"]",
"=",
"array",
"(",
"nvecs",
"(",
"X",
",",
"n",
",",
"rank",
")",
",",
"dtype",
"=",
"dtype",
")",
"else",
":",
"raise",
"'Unknown option (init=%s)'",
"%",
"str",
"(",
"init",
")",
"return",
"Uinit"
] | Initialization for CP models | [
"Initialization",
"for",
"CP",
"models"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/cp.py#L190-L205 | train |
mnick/scikit-tensor | sktensor/core.py | nvecs | def nvecs(X, n, rank, do_flipsign=True, dtype=np.float):
"""
Eigendecomposition of mode-n unfolding of a tensor
"""
Xn = X.unfold(n)
if issparse_mat(Xn):
Xn = csr_matrix(Xn, dtype=dtype)
Y = Xn.dot(Xn.T)
_, U = eigsh(Y, rank, which='LM')
else:
Y = Xn.dot(Xn.T)
N = Y.shape[0]
_, U = eigh(Y, eigvals=(N - rank, N - 1))
#_, U = eigsh(Y, rank, which='LM')
# reverse order of eigenvectors such that eigenvalues are decreasing
U = array(U[:, ::-1])
# flip sign
if do_flipsign:
U = flipsign(U)
return U | python | def nvecs(X, n, rank, do_flipsign=True, dtype=np.float):
"""
Eigendecomposition of mode-n unfolding of a tensor
"""
Xn = X.unfold(n)
if issparse_mat(Xn):
Xn = csr_matrix(Xn, dtype=dtype)
Y = Xn.dot(Xn.T)
_, U = eigsh(Y, rank, which='LM')
else:
Y = Xn.dot(Xn.T)
N = Y.shape[0]
_, U = eigh(Y, eigvals=(N - rank, N - 1))
#_, U = eigsh(Y, rank, which='LM')
# reverse order of eigenvectors such that eigenvalues are decreasing
U = array(U[:, ::-1])
# flip sign
if do_flipsign:
U = flipsign(U)
return U | [
"def",
"nvecs",
"(",
"X",
",",
"n",
",",
"rank",
",",
"do_flipsign",
"=",
"True",
",",
"dtype",
"=",
"np",
".",
"float",
")",
":",
"Xn",
"=",
"X",
".",
"unfold",
"(",
"n",
")",
"if",
"issparse_mat",
"(",
"Xn",
")",
":",
"Xn",
"=",
"csr_matrix",
"(",
"Xn",
",",
"dtype",
"=",
"dtype",
")",
"Y",
"=",
"Xn",
".",
"dot",
"(",
"Xn",
".",
"T",
")",
"_",
",",
"U",
"=",
"eigsh",
"(",
"Y",
",",
"rank",
",",
"which",
"=",
"'LM'",
")",
"else",
":",
"Y",
"=",
"Xn",
".",
"dot",
"(",
"Xn",
".",
"T",
")",
"N",
"=",
"Y",
".",
"shape",
"[",
"0",
"]",
"_",
",",
"U",
"=",
"eigh",
"(",
"Y",
",",
"eigvals",
"=",
"(",
"N",
"-",
"rank",
",",
"N",
"-",
"1",
")",
")",
"#_, U = eigsh(Y, rank, which='LM')",
"# reverse order of eigenvectors such that eigenvalues are decreasing",
"U",
"=",
"array",
"(",
"U",
"[",
":",
",",
":",
":",
"-",
"1",
"]",
")",
"# flip sign",
"if",
"do_flipsign",
":",
"U",
"=",
"flipsign",
"(",
"U",
")",
"return",
"U"
] | Eigendecomposition of mode-n unfolding of a tensor | [
"Eigendecomposition",
"of",
"mode",
"-",
"n",
"unfolding",
"of",
"a",
"tensor"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/core.py#L275-L294 | train |
mnick/scikit-tensor | sktensor/core.py | flipsign | def flipsign(U):
"""
Flip sign of factor matrices such that largest magnitude
element will be positive
"""
midx = abs(U).argmax(axis=0)
for i in range(U.shape[1]):
if U[midx[i], i] < 0:
U[:, i] = -U[:, i]
return U | python | def flipsign(U):
"""
Flip sign of factor matrices such that largest magnitude
element will be positive
"""
midx = abs(U).argmax(axis=0)
for i in range(U.shape[1]):
if U[midx[i], i] < 0:
U[:, i] = -U[:, i]
return U | [
"def",
"flipsign",
"(",
"U",
")",
":",
"midx",
"=",
"abs",
"(",
"U",
")",
".",
"argmax",
"(",
"axis",
"=",
"0",
")",
"for",
"i",
"in",
"range",
"(",
"U",
".",
"shape",
"[",
"1",
"]",
")",
":",
"if",
"U",
"[",
"midx",
"[",
"i",
"]",
",",
"i",
"]",
"<",
"0",
":",
"U",
"[",
":",
",",
"i",
"]",
"=",
"-",
"U",
"[",
":",
",",
"i",
"]",
"return",
"U"
] | Flip sign of factor matrices such that largest magnitude
element will be positive | [
"Flip",
"sign",
"of",
"factor",
"matrices",
"such",
"that",
"largest",
"magnitude",
"element",
"will",
"be",
"positive"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/core.py#L297-L306 | train |
mnick/scikit-tensor | sktensor/core.py | khatrirao | def khatrirao(A, reverse=False):
"""
Compute the columnwise Khatri-Rao product.
Parameters
----------
A : tuple of ndarrays
Matrices for which the columnwise Khatri-Rao product should be computed
reverse : boolean
Compute Khatri-Rao product in reverse order
Examples
--------
>>> A = np.random.randn(5, 2)
>>> B = np.random.randn(4, 2)
>>> C = khatrirao((A, B))
>>> C.shape
(20, 2)
>>> (C[:, 0] == np.kron(A[:, 0], B[:, 0])).all()
true
>>> (C[:, 1] == np.kron(A[:, 1], B[:, 1])).all()
true
"""
if not isinstance(A, tuple):
raise ValueError('A must be a tuple of array likes')
N = A[0].shape[1]
M = 1
for i in range(len(A)):
if A[i].ndim != 2:
raise ValueError('A must be a tuple of matrices (A[%d].ndim = %d)' % (i, A[i].ndim))
elif N != A[i].shape[1]:
raise ValueError('All matrices must have same number of columns')
M *= A[i].shape[0]
matorder = arange(len(A))
if reverse:
matorder = matorder[::-1]
# preallocate
P = np.zeros((M, N), dtype=A[0].dtype)
for n in range(N):
ab = A[matorder[0]][:, n]
for j in range(1, len(matorder)):
ab = np.kron(ab, A[matorder[j]][:, n])
P[:, n] = ab
return P | python | def khatrirao(A, reverse=False):
"""
Compute the columnwise Khatri-Rao product.
Parameters
----------
A : tuple of ndarrays
Matrices for which the columnwise Khatri-Rao product should be computed
reverse : boolean
Compute Khatri-Rao product in reverse order
Examples
--------
>>> A = np.random.randn(5, 2)
>>> B = np.random.randn(4, 2)
>>> C = khatrirao((A, B))
>>> C.shape
(20, 2)
>>> (C[:, 0] == np.kron(A[:, 0], B[:, 0])).all()
true
>>> (C[:, 1] == np.kron(A[:, 1], B[:, 1])).all()
true
"""
if not isinstance(A, tuple):
raise ValueError('A must be a tuple of array likes')
N = A[0].shape[1]
M = 1
for i in range(len(A)):
if A[i].ndim != 2:
raise ValueError('A must be a tuple of matrices (A[%d].ndim = %d)' % (i, A[i].ndim))
elif N != A[i].shape[1]:
raise ValueError('All matrices must have same number of columns')
M *= A[i].shape[0]
matorder = arange(len(A))
if reverse:
matorder = matorder[::-1]
# preallocate
P = np.zeros((M, N), dtype=A[0].dtype)
for n in range(N):
ab = A[matorder[0]][:, n]
for j in range(1, len(matorder)):
ab = np.kron(ab, A[matorder[j]][:, n])
P[:, n] = ab
return P | [
"def",
"khatrirao",
"(",
"A",
",",
"reverse",
"=",
"False",
")",
":",
"if",
"not",
"isinstance",
"(",
"A",
",",
"tuple",
")",
":",
"raise",
"ValueError",
"(",
"'A must be a tuple of array likes'",
")",
"N",
"=",
"A",
"[",
"0",
"]",
".",
"shape",
"[",
"1",
"]",
"M",
"=",
"1",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"A",
")",
")",
":",
"if",
"A",
"[",
"i",
"]",
".",
"ndim",
"!=",
"2",
":",
"raise",
"ValueError",
"(",
"'A must be a tuple of matrices (A[%d].ndim = %d)'",
"%",
"(",
"i",
",",
"A",
"[",
"i",
"]",
".",
"ndim",
")",
")",
"elif",
"N",
"!=",
"A",
"[",
"i",
"]",
".",
"shape",
"[",
"1",
"]",
":",
"raise",
"ValueError",
"(",
"'All matrices must have same number of columns'",
")",
"M",
"*=",
"A",
"[",
"i",
"]",
".",
"shape",
"[",
"0",
"]",
"matorder",
"=",
"arange",
"(",
"len",
"(",
"A",
")",
")",
"if",
"reverse",
":",
"matorder",
"=",
"matorder",
"[",
":",
":",
"-",
"1",
"]",
"# preallocate",
"P",
"=",
"np",
".",
"zeros",
"(",
"(",
"M",
",",
"N",
")",
",",
"dtype",
"=",
"A",
"[",
"0",
"]",
".",
"dtype",
")",
"for",
"n",
"in",
"range",
"(",
"N",
")",
":",
"ab",
"=",
"A",
"[",
"matorder",
"[",
"0",
"]",
"]",
"[",
":",
",",
"n",
"]",
"for",
"j",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"matorder",
")",
")",
":",
"ab",
"=",
"np",
".",
"kron",
"(",
"ab",
",",
"A",
"[",
"matorder",
"[",
"j",
"]",
"]",
"[",
":",
",",
"n",
"]",
")",
"P",
"[",
":",
",",
"n",
"]",
"=",
"ab",
"return",
"P"
] | Compute the columnwise Khatri-Rao product.
Parameters
----------
A : tuple of ndarrays
Matrices for which the columnwise Khatri-Rao product should be computed
reverse : boolean
Compute Khatri-Rao product in reverse order
Examples
--------
>>> A = np.random.randn(5, 2)
>>> B = np.random.randn(4, 2)
>>> C = khatrirao((A, B))
>>> C.shape
(20, 2)
>>> (C[:, 0] == np.kron(A[:, 0], B[:, 0])).all()
true
>>> (C[:, 1] == np.kron(A[:, 1], B[:, 1])).all()
true | [
"Compute",
"the",
"columnwise",
"Khatri",
"-",
"Rao",
"product",
"."
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/core.py#L333-L378 | train |
mnick/scikit-tensor | sktensor/core.py | teneye | def teneye(dim, order):
"""
Create tensor with superdiagonal all one, rest zeros
"""
I = zeros(dim ** order)
for f in range(dim):
idd = f
for i in range(1, order):
idd = idd + dim ** (i - 1) * (f - 1)
I[idd] = 1
return I.reshape(ones(order) * dim) | python | def teneye(dim, order):
"""
Create tensor with superdiagonal all one, rest zeros
"""
I = zeros(dim ** order)
for f in range(dim):
idd = f
for i in range(1, order):
idd = idd + dim ** (i - 1) * (f - 1)
I[idd] = 1
return I.reshape(ones(order) * dim) | [
"def",
"teneye",
"(",
"dim",
",",
"order",
")",
":",
"I",
"=",
"zeros",
"(",
"dim",
"**",
"order",
")",
"for",
"f",
"in",
"range",
"(",
"dim",
")",
":",
"idd",
"=",
"f",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"order",
")",
":",
"idd",
"=",
"idd",
"+",
"dim",
"**",
"(",
"i",
"-",
"1",
")",
"*",
"(",
"f",
"-",
"1",
")",
"I",
"[",
"idd",
"]",
"=",
"1",
"return",
"I",
".",
"reshape",
"(",
"ones",
"(",
"order",
")",
"*",
"dim",
")"
] | Create tensor with superdiagonal all one, rest zeros | [
"Create",
"tensor",
"with",
"superdiagonal",
"all",
"one",
"rest",
"zeros"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/core.py#L381-L391 | train |
mnick/scikit-tensor | sktensor/core.py | tensor_mixin.ttm | def ttm(self, V, mode=None, transp=False, without=False):
"""
Tensor times matrix product
Parameters
----------
V : M x N array_like or list of M_i x N_i array_likes
Matrix or list of matrices for which the tensor times matrix
products should be performed
mode : int or list of int's, optional
Modes along which the tensor times matrix products should be
performed
transp: boolean, optional
If True, tensor times matrix products are computed with
transpositions of matrices
without: boolean, optional
It True, tensor times matrix products are performed along all
modes **except** the modes specified via parameter ``mode``
Examples
--------
Create dense tensor
>>> T = zeros((3, 4, 2))
>>> T[:, :, 0] = [[ 1, 4, 7, 10], [ 2, 5, 8, 11], [3, 6, 9, 12]]
>>> T[:, :, 1] = [[13, 16, 19, 22], [14, 17, 20, 23], [15, 18, 21, 24]]
>>> T = dtensor(T)
Create matrix
>>> V = array([[1, 3, 5], [2, 4, 6]])
Multiply tensor with matrix along mode 0
>>> Y = T.ttm(V, 0)
>>> Y[:, :, 0]
array([[ 22., 49., 76., 103.],
[ 28., 64., 100., 136.]])
>>> Y[:, :, 1]
array([[ 130., 157., 184., 211.],
[ 172., 208., 244., 280.]])
"""
if mode is None:
mode = range(self.ndim)
if isinstance(V, np.ndarray):
Y = self._ttm_compute(V, mode, transp)
elif is_sequence(V):
dims, vidx = check_multiplication_dims(mode, self.ndim, len(V), vidx=True, without=without)
Y = self._ttm_compute(V[vidx[0]], dims[0], transp)
for i in xrange(1, len(dims)):
Y = Y._ttm_compute(V[vidx[i]], dims[i], transp)
return Y | python | def ttm(self, V, mode=None, transp=False, without=False):
"""
Tensor times matrix product
Parameters
----------
V : M x N array_like or list of M_i x N_i array_likes
Matrix or list of matrices for which the tensor times matrix
products should be performed
mode : int or list of int's, optional
Modes along which the tensor times matrix products should be
performed
transp: boolean, optional
If True, tensor times matrix products are computed with
transpositions of matrices
without: boolean, optional
It True, tensor times matrix products are performed along all
modes **except** the modes specified via parameter ``mode``
Examples
--------
Create dense tensor
>>> T = zeros((3, 4, 2))
>>> T[:, :, 0] = [[ 1, 4, 7, 10], [ 2, 5, 8, 11], [3, 6, 9, 12]]
>>> T[:, :, 1] = [[13, 16, 19, 22], [14, 17, 20, 23], [15, 18, 21, 24]]
>>> T = dtensor(T)
Create matrix
>>> V = array([[1, 3, 5], [2, 4, 6]])
Multiply tensor with matrix along mode 0
>>> Y = T.ttm(V, 0)
>>> Y[:, :, 0]
array([[ 22., 49., 76., 103.],
[ 28., 64., 100., 136.]])
>>> Y[:, :, 1]
array([[ 130., 157., 184., 211.],
[ 172., 208., 244., 280.]])
"""
if mode is None:
mode = range(self.ndim)
if isinstance(V, np.ndarray):
Y = self._ttm_compute(V, mode, transp)
elif is_sequence(V):
dims, vidx = check_multiplication_dims(mode, self.ndim, len(V), vidx=True, without=without)
Y = self._ttm_compute(V[vidx[0]], dims[0], transp)
for i in xrange(1, len(dims)):
Y = Y._ttm_compute(V[vidx[i]], dims[i], transp)
return Y | [
"def",
"ttm",
"(",
"self",
",",
"V",
",",
"mode",
"=",
"None",
",",
"transp",
"=",
"False",
",",
"without",
"=",
"False",
")",
":",
"if",
"mode",
"is",
"None",
":",
"mode",
"=",
"range",
"(",
"self",
".",
"ndim",
")",
"if",
"isinstance",
"(",
"V",
",",
"np",
".",
"ndarray",
")",
":",
"Y",
"=",
"self",
".",
"_ttm_compute",
"(",
"V",
",",
"mode",
",",
"transp",
")",
"elif",
"is_sequence",
"(",
"V",
")",
":",
"dims",
",",
"vidx",
"=",
"check_multiplication_dims",
"(",
"mode",
",",
"self",
".",
"ndim",
",",
"len",
"(",
"V",
")",
",",
"vidx",
"=",
"True",
",",
"without",
"=",
"without",
")",
"Y",
"=",
"self",
".",
"_ttm_compute",
"(",
"V",
"[",
"vidx",
"[",
"0",
"]",
"]",
",",
"dims",
"[",
"0",
"]",
",",
"transp",
")",
"for",
"i",
"in",
"xrange",
"(",
"1",
",",
"len",
"(",
"dims",
")",
")",
":",
"Y",
"=",
"Y",
".",
"_ttm_compute",
"(",
"V",
"[",
"vidx",
"[",
"i",
"]",
"]",
",",
"dims",
"[",
"i",
"]",
",",
"transp",
")",
"return",
"Y"
] | Tensor times matrix product
Parameters
----------
V : M x N array_like or list of M_i x N_i array_likes
Matrix or list of matrices for which the tensor times matrix
products should be performed
mode : int or list of int's, optional
Modes along which the tensor times matrix products should be
performed
transp: boolean, optional
If True, tensor times matrix products are computed with
transpositions of matrices
without: boolean, optional
It True, tensor times matrix products are performed along all
modes **except** the modes specified via parameter ``mode``
Examples
--------
Create dense tensor
>>> T = zeros((3, 4, 2))
>>> T[:, :, 0] = [[ 1, 4, 7, 10], [ 2, 5, 8, 11], [3, 6, 9, 12]]
>>> T[:, :, 1] = [[13, 16, 19, 22], [14, 17, 20, 23], [15, 18, 21, 24]]
>>> T = dtensor(T)
Create matrix
>>> V = array([[1, 3, 5], [2, 4, 6]])
Multiply tensor with matrix along mode 0
>>> Y = T.ttm(V, 0)
>>> Y[:, :, 0]
array([[ 22., 49., 76., 103.],
[ 28., 64., 100., 136.]])
>>> Y[:, :, 1]
array([[ 130., 157., 184., 211.],
[ 172., 208., 244., 280.]]) | [
"Tensor",
"times",
"matrix",
"product"
] | fe517e9661a08164b8d30d2dddf7c96aeeabcf36 | https://github.com/mnick/scikit-tensor/blob/fe517e9661a08164b8d30d2dddf7c96aeeabcf36/sktensor/core.py#L50-L103 | train |
callowayproject/django-categories | categories/registration.py | _process_registry | def _process_registry(registry, call_func):
"""
Given a dictionary, and a registration function, process the registry
"""
from django.core.exceptions import ImproperlyConfigured
from django.apps import apps
for key, value in list(registry.items()):
model = apps.get_model(*key.split('.'))
if model is None:
raise ImproperlyConfigured(_('%(key)s is not a model') % {'key': key})
if isinstance(value, (tuple, list)):
for item in value:
if isinstance(item, str):
call_func(model, item)
elif isinstance(item, dict):
field_name = item.pop('name')
call_func(model, field_name, extra_params=item)
else:
raise ImproperlyConfigured(_("%(settings)s doesn't recognize the value of %(key)s") %
{'settings': 'CATEGORY_SETTINGS', 'key': key})
elif isinstance(value, str):
call_func(model, value)
elif isinstance(value, dict):
field_name = value.pop('name')
call_func(model, field_name, extra_params=value)
else:
raise ImproperlyConfigured(_("%(settings)s doesn't recognize the value of %(key)s") %
{'settings': 'CATEGORY_SETTINGS', 'key': key}) | python | def _process_registry(registry, call_func):
"""
Given a dictionary, and a registration function, process the registry
"""
from django.core.exceptions import ImproperlyConfigured
from django.apps import apps
for key, value in list(registry.items()):
model = apps.get_model(*key.split('.'))
if model is None:
raise ImproperlyConfigured(_('%(key)s is not a model') % {'key': key})
if isinstance(value, (tuple, list)):
for item in value:
if isinstance(item, str):
call_func(model, item)
elif isinstance(item, dict):
field_name = item.pop('name')
call_func(model, field_name, extra_params=item)
else:
raise ImproperlyConfigured(_("%(settings)s doesn't recognize the value of %(key)s") %
{'settings': 'CATEGORY_SETTINGS', 'key': key})
elif isinstance(value, str):
call_func(model, value)
elif isinstance(value, dict):
field_name = value.pop('name')
call_func(model, field_name, extra_params=value)
else:
raise ImproperlyConfigured(_("%(settings)s doesn't recognize the value of %(key)s") %
{'settings': 'CATEGORY_SETTINGS', 'key': key}) | [
"def",
"_process_registry",
"(",
"registry",
",",
"call_func",
")",
":",
"from",
"django",
".",
"core",
".",
"exceptions",
"import",
"ImproperlyConfigured",
"from",
"django",
".",
"apps",
"import",
"apps",
"for",
"key",
",",
"value",
"in",
"list",
"(",
"registry",
".",
"items",
"(",
")",
")",
":",
"model",
"=",
"apps",
".",
"get_model",
"(",
"*",
"key",
".",
"split",
"(",
"'.'",
")",
")",
"if",
"model",
"is",
"None",
":",
"raise",
"ImproperlyConfigured",
"(",
"_",
"(",
"'%(key)s is not a model'",
")",
"%",
"{",
"'key'",
":",
"key",
"}",
")",
"if",
"isinstance",
"(",
"value",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"for",
"item",
"in",
"value",
":",
"if",
"isinstance",
"(",
"item",
",",
"str",
")",
":",
"call_func",
"(",
"model",
",",
"item",
")",
"elif",
"isinstance",
"(",
"item",
",",
"dict",
")",
":",
"field_name",
"=",
"item",
".",
"pop",
"(",
"'name'",
")",
"call_func",
"(",
"model",
",",
"field_name",
",",
"extra_params",
"=",
"item",
")",
"else",
":",
"raise",
"ImproperlyConfigured",
"(",
"_",
"(",
"\"%(settings)s doesn't recognize the value of %(key)s\"",
")",
"%",
"{",
"'settings'",
":",
"'CATEGORY_SETTINGS'",
",",
"'key'",
":",
"key",
"}",
")",
"elif",
"isinstance",
"(",
"value",
",",
"str",
")",
":",
"call_func",
"(",
"model",
",",
"value",
")",
"elif",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"field_name",
"=",
"value",
".",
"pop",
"(",
"'name'",
")",
"call_func",
"(",
"model",
",",
"field_name",
",",
"extra_params",
"=",
"value",
")",
"else",
":",
"raise",
"ImproperlyConfigured",
"(",
"_",
"(",
"\"%(settings)s doesn't recognize the value of %(key)s\"",
")",
"%",
"{",
"'settings'",
":",
"'CATEGORY_SETTINGS'",
",",
"'key'",
":",
"key",
"}",
")"
] | Given a dictionary, and a registration function, process the registry | [
"Given",
"a",
"dictionary",
"and",
"a",
"registration",
"function",
"process",
"the",
"registry"
] | 3765851320a79b12c6d3306f3784a2302ea64812 | https://github.com/callowayproject/django-categories/blob/3765851320a79b12c6d3306f3784a2302ea64812/categories/registration.py#L118-L146 | train |
callowayproject/django-categories | categories/migration.py | field_exists | def field_exists(app_name, model_name, field_name):
"""
Does the FK or M2M table exist in the database already?
"""
model = apps.get_model(app_name, model_name)
table_name = model._meta.db_table
cursor = connection.cursor()
field_info = connection.introspection.get_table_description(cursor, table_name)
field_names = [f.name for f in field_info]
return field_name in field_names | python | def field_exists(app_name, model_name, field_name):
"""
Does the FK or M2M table exist in the database already?
"""
model = apps.get_model(app_name, model_name)
table_name = model._meta.db_table
cursor = connection.cursor()
field_info = connection.introspection.get_table_description(cursor, table_name)
field_names = [f.name for f in field_info]
return field_name in field_names | [
"def",
"field_exists",
"(",
"app_name",
",",
"model_name",
",",
"field_name",
")",
":",
"model",
"=",
"apps",
".",
"get_model",
"(",
"app_name",
",",
"model_name",
")",
"table_name",
"=",
"model",
".",
"_meta",
".",
"db_table",
"cursor",
"=",
"connection",
".",
"cursor",
"(",
")",
"field_info",
"=",
"connection",
".",
"introspection",
".",
"get_table_description",
"(",
"cursor",
",",
"table_name",
")",
"field_names",
"=",
"[",
"f",
".",
"name",
"for",
"f",
"in",
"field_info",
"]",
"return",
"field_name",
"in",
"field_names"
] | Does the FK or M2M table exist in the database already? | [
"Does",
"the",
"FK",
"or",
"M2M",
"table",
"exist",
"in",
"the",
"database",
"already?"
] | 3765851320a79b12c6d3306f3784a2302ea64812 | https://github.com/callowayproject/django-categories/blob/3765851320a79b12c6d3306f3784a2302ea64812/categories/migration.py#L16-L25 | train |
callowayproject/django-categories | categories/migration.py | drop_field | def drop_field(app_name, model_name, field_name):
"""
Drop the given field from the app's model
"""
app_config = apps.get_app_config(app_name)
model = app_config.get_model(model_name)
field = model._meta.get_field(field_name)
with connection.schema_editor() as schema_editor:
schema_editor.remove_field(model, field) | python | def drop_field(app_name, model_name, field_name):
"""
Drop the given field from the app's model
"""
app_config = apps.get_app_config(app_name)
model = app_config.get_model(model_name)
field = model._meta.get_field(field_name)
with connection.schema_editor() as schema_editor:
schema_editor.remove_field(model, field) | [
"def",
"drop_field",
"(",
"app_name",
",",
"model_name",
",",
"field_name",
")",
":",
"app_config",
"=",
"apps",
".",
"get_app_config",
"(",
"app_name",
")",
"model",
"=",
"app_config",
".",
"get_model",
"(",
"model_name",
")",
"field",
"=",
"model",
".",
"_meta",
".",
"get_field",
"(",
"field_name",
")",
"with",
"connection",
".",
"schema_editor",
"(",
")",
"as",
"schema_editor",
":",
"schema_editor",
".",
"remove_field",
"(",
"model",
",",
"field",
")"
] | Drop the given field from the app's model | [
"Drop",
"the",
"given",
"field",
"from",
"the",
"app",
"s",
"model"
] | 3765851320a79b12c6d3306f3784a2302ea64812 | https://github.com/callowayproject/django-categories/blob/3765851320a79b12c6d3306f3784a2302ea64812/categories/migration.py#L28-L36 | train |
Subsets and Splits