blob: c9938dea4bb6f5b6d424aa18857f09bf097d49ee [file] [log] [blame]
#-------------------------------------------------------------
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
#-------------------------------------------------------------
# Import function definition override of built-in sum
source("./src/test/scripts/functions/misc/FunctionsL1.dml") as Functions
# Local function definition override of built-in min returning scalar
min = function(integer x) return (integer y)
{
print("override min")
Z = matrix(x, rows=4, cols=2)
y = x*2
}
# Use local min after definition
result = min(1)
print("min is " + result)
M1 = matrix("1 2 3 4", rows=2, cols=2)
M2 = matrix("5 6 7 8", rows=2, cols=2)
# Built-in min not directly accessible in this script due to local override
#result = min(M1)
# Use imported min
result = Functions::min(M1)
# Use imported function with overrides
[min, max] = Functions::minMax(M2)
# Use imported sum
result = Functions::sum(M1)
# Built-in sum accessible since imported override
result = sum(M2)
print("Built-in sum is " + result)
# Use local override before function definition
Z = rand(2)
print("rand sum is " + sum(Z))
# Local function definition override of built-in rand returning matrix
rand = function(int x) return (matrix[double] Z)
{
print("override rand")
Z = matrix(x, rows=4, cols=2)
y = x*2
}