Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {TranslatableErrorType} from './Cell'
import {defaultParseToDateTime} from './DateTimeDefault'
import {DateTime, instanceOfSimpleDate, SimpleDate, SimpleDateTime, SimpleTime} from './DateTimeHelper'
import {
ConfigValueTooSmallError,
ConfigValueTooBigError,
ExpectedValueOfTypeError,
ExpectedOneOfValuesError
ConfigValueTooSmallError,
ExpectedOneOfValuesError,
ExpectedValueOfTypeError
} from './errors'
import {AlwaysDense, ChooseAddressMapping} from './DependencyGraph/AddressMapping/ChooseAddressMappingPolicy'
import {defaultStringifyDateTime, defaultStringifyDuration} from './format/format'
Expand All @@ -19,11 +19,12 @@ import {TranslationPackage} from './i18n'
import {Maybe} from './Maybe'
import {ParserConfig} from './parser/ParserConfig'
import {checkLicenseKeyValidity, LicenseKeyValidityState} from './helpers/licenseKeyValidator'
import {FunctionPluginDefinition} from './interpreter/plugin/FunctionPlugin'
import {FunctionPluginDefinition} from './interpreter'
import GPU from 'gpu.js'

type GPUMode = 'gpu' | 'cpu' | 'dev'
type GPUMode = 'gpu' | 'cpu' | 'dev' | 'fallback'

const PossibleGPUModeString: GPUMode[] = ['gpu', 'cpu', 'dev']
const PossibleGPUModeString: GPUMode[] = ['gpu', 'cpu', 'dev', 'fallback']

export interface ConfigParams {
/**
Expand Down Expand Up @@ -614,6 +615,11 @@ export class Config implements ConfigParams, ParserConfig {
{value: this.functionArgSeparator, name: 'functionArgSeparator'},
{value: this.thousandSeparator, name: 'thousandSeparator'}
)

if (GPU === undefined) {
this.gpuMode = 'fallback'
console.warn('GPU.js not detected. Matrix functions will use plain CPU implementation.')
Comment thread
voodoo11 marked this conversation as resolved.
Resolved
}
}

public getConfig(): ConfigParams { //TODO: avoid pollution
Expand Down
9 changes: 8 additions & 1 deletion src/interpreter/Interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,17 @@ export class Interpreter {
}

public getGpuInstance(): GPU.GPU {
const mode = this.config.gpuMode

if (mode === 'fallback') {
throw Error('Cannot instantiate GPU.js when fallback mode is active.')
}

if (!this.gpu) {
const GPUConstructor = GPU.GPU || GPU
this.gpu = new GPUConstructor({mode: this.config.gpuMode})
this.gpu = new GPUConstructor({ mode })
}

return this.gpu
}

Expand Down
18 changes: 18 additions & 0 deletions src/interpreter/plugin/FunctionPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ export abstract class FunctionPlugin {
formulaAddress: SimpleCellAddress,
functionDefinition: FunctionArguments,
fn: (...arg: any) => InternalScalarValue
) => {
return this.runFunctionTemplate(args, formulaAddress, functionDefinition, fn)
}

protected runMatrixFunction = (
args: Ast[],
formulaAddress: SimpleCellAddress,
functionDefinition: FunctionArguments,
fn: (...arg: any) => InterpreterValue
) => {
return this.runFunctionTemplate(args, formulaAddress, functionDefinition, fn)
}

private runFunctionTemplate = (
args: Ast[],
formulaAddress: SimpleCellAddress,
functionDefinition: FunctionArguments,
fn: (...arg: any) => any
) => {
const argumentDefinitions: FunctionArgument[] = functionDefinition.parameters!
let scalarValues: [InterpreterValue, boolean][]
Expand Down
Loading