MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / generateSequenceTerms

Function generateSequenceTerms

src/compute-engine/sequence.ts:887–924  ·  view source on GitHub ↗
(
  ce: ComputeEngine,
  name: string,
  start: number,
  end: number,
  step: number = 1
)

Source from the content-addressed store, hash-verified

885 engine: ComputeEngine,
886 numericApproximation: boolean | undefined
887 ): number[] | undefined => {
888 if (isMultiIndex) return undefined;
889 offsets ??= lowerTermOffsets(recurrence!, name, variable);
890 for (const offset of offsets) {
891 const lower = [indices[0] - offset];
892 const key = indexKeyOf(lower);
893 if (read.terms.has(key) || read.pending.has(key)) continue;
894 if (!isValidIndex(lower, engine)) continue;
895 if (base.has(lower[0])) continue;
896 if (memoizedTerm(engine, lower, numericApproximation) !== undefined)
897 continue;
898 return lower;
899 }
900 return undefined;
901 };
902
903 /**
904 * Compute the term at `indices` of a pure sequence with the recurrence.
905 * Return the indices of a term that the recurrence reads and that is
906 * not known yet: the computation is then stopped, and it is done again
907 * later. Otherwise, the term is put in `read.terms`, and in the memos
908 * when the state of the engine did not change during the computation.
909 */
910 const computeOneTerm = (
911 indices: number[],
912 read: SequenceRead,
913 engine: ComputeEngine,
914 numericApproximation: boolean | undefined
915 ): number[] | undefined => {
916 const termStamp = memo !== null ? currentStamp(engine) : undefined;
917 read.missing = undefined;
918 read.attempting = true;
919 read.attemptEpoch = restartEpoch;
920
921 let result: Expression | undefined = undefined;
922 try {
923 result = evaluateRecurrence(indices, engine, numericApproximation);
924 } catch (e) {
925 if (e !== read.signal) throw e;
926 } finally {
927 read.attempting = false;

Callers

nothing calls this directly

Calls 5

isNumberFunction · 0.90
isSequenceFunction · 0.70
parseMethod · 0.65
evaluateMethod · 0.65
isIntegerMethod · 0.45

Tested by

no test coverage detected